]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
tests/gunit: Extend the fuzzer to test cgroup_new_cgroup()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Tue, 7 Feb 2023 23:25:03 +0000 (16:25 -0700)
committerTom Hromatka <tom.hromatka@oracle.com>
Tue, 7 Feb 2023 23:25:05 +0000 (16:25 -0700)
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 <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
(cherry picked from commit be62c2649a845726ca67faa7707fbeae7eb84c90)

tests/gunit/017-API_fuzz_test.cpp

index 2cdd72bda0b8f7d6c19fdce964feeffd383cfac0..27afcb8449304032161e4bc0c78cf616882bf807 100644 (file)
@@ -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);
+}