From: Kamalesh Babulal Date: Tue, 7 Feb 2023 23:23:08 +0000 (-0700) Subject: tests/gunit: Extend the fuzzer to test cgroup_new_cgroup() X-Git-Tag: v3.1.0~220 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=be62c2649a845726ca67faa7707fbeae7eb84c90;p=thirdparty%2Flibcgroup.git 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 --- 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); +}