From be62c2649a845726ca67faa7707fbeae7eb84c90 Mon Sep 17 00:00:00 2001 From: Kamalesh Babulal Date: Tue, 7 Feb 2023 16:23:08 -0700 Subject: [PATCH] tests/gunit: Extend the fuzzer to test cgroup_new_cgroup() Add fuzzing to the cgroup_new_cgroup() API, by passing NULL as cgroup name. [----------] 2 tests from APIArgsTest [ RUN ] APIArgsTest.API_cgroup_set_permissions [ OK ] APIArgsTest.API_cgroup_set_permissions (0 ms) [ RUN ] APIArgsTest.API_cgroup_new_cgroup Signed-off-by: Kamalesh Babulal Signed-off-by: Tom Hromatka --- tests/gunit/017-API_fuzz_test.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/gunit/017-API_fuzz_test.cpp b/tests/gunit/017-API_fuzz_test.cpp index 2cdd72bd..27afcb84 100644 --- a/tests/gunit/017-API_fuzz_test.cpp +++ b/tests/gunit/017-API_fuzz_test.cpp @@ -44,3 +44,20 @@ TEST_F(APIArgsTest, API_cgroup_set_permissions) std::string result = testing::internal::GetCapturedStdout(); ASSERT_EQ(result, "Error: Cgroup, operation not allowed\n"); } + +/** + * Pass NULL cgroup name for creating a cgroup + * @param APIArgsTest googletest test case name + * @param API_cgroup_new_cgroup test name + * + * This test will pass NULL cgroup name to the cgroup_new_cgroup() + * and check it handles it gracefully. + */ +TEST_F(APIArgsTest, API_cgroup_new_cgroup) +{ + struct cgroup *cgroup = NULL; + char *name = NULL; + + cgroup = cgroup_new_cgroup(name); + ASSERT_EQ(cgroup, nullptr); +} -- 2.47.2