]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
From: Sudhir Kumar <skumar@linux.vnet.ibm.com>
authorDhaval Giani <dhaval@linux.vnet.ibm.com>
Tue, 1 Jul 2008 14:07:07 +0000 (14:07 +0000)
committerDhaval Giani <dhaval@linux.vnet.ibm.com>
Tue, 1 Jul 2008 14:07:07 +0000 (14:07 +0000)
libcgroup: testcases for cgroup_modify_cgroup()

This patch adds testcases for libcgroup API cgroup_modify_cgroup() testing. The API
is called with filesystem mounted (FS_MOUNTED=1) and return values are checked.
The API is first called with the same cgroup(the one which is existing in the
file system, and with all the same parameters). The second time it is called
with a null cgroup. Third time it is called with a new cgroup having different
controller.
The filesystem is checked if the values have been modified.

Signed-off-by: Sudhir Kumar <skumar@linux.vnet.ibm.com>
Signed-off-by: Dhaval Giani <dhaval@linux.vnet.ibm.com>
git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@94 4f4bb910-9a46-0410-90c8-c897d4f1cd53

tests/libcgrouptest01.c

index 03cb51c735d265d23952e9362671c016ff632ee5..a57c3ab13f2817f02642a951386b704437eaa1c9 100644 (file)
@@ -20,7 +20,7 @@ int main(int argc, char *argv[])
 {
        int fs_mounted, retval, pass = 0;
        pid_t curr_tid, tid;
-       struct cgroup *cgroup1, *cgroup2, *nullcgroup = NULL;
+       struct cgroup *cgroup1, *cgroup2, *cgroup3, *nullcgroup = NULL;
        char controller_name[FILENAME_MAX], control_file[FILENAME_MAX],
                path_group[FILENAME_MAX], path_control_file[FILENAME_MAX];
        FILE *file;
@@ -285,7 +285,68 @@ int main(int argc, char *argv[])
                        printf("Test[1:%2d]\tFAIL: cgroup_modify_cgroup() retval=%d\n", ++i, retval);
 
                /*
-                * Test08: delete cgroup
+                * Test08: modify cgroup with the same cgroup
+                * Exp outcome: zero return value
+                */
+
+               retval = cgroup_modify_cgroup(cgroup1);
+               /* Check if the values are changed */
+               if (!retval && !group_modified(path_control_file, STRING))
+                       printf("Test[1:%2d]\tPASS: cgroup_modify_cgroup() retval=%d\n", ++i, retval);
+               else
+                       printf("Test[1:%2d]\tFAIL: cgroup_modify_cgroup() retval=%d\n", ++i, retval);
+
+               /*
+                * Test09: modify cgroup with the null cgroup
+                * Exp outcome: zero return value. root group unchanged.
+                */
+
+               strncpy(path_control_file, mountpoint, sizeof(mountpoint));
+               strncat(path_control_file, "/", sizeof("/"));
+               strncat(path_control_file, control_file, sizeof(control_file));
+
+               retval = cgroup_modify_cgroup(nullcgroup);
+               /* Check if the values are changed */
+               if (!retval && !group_modified(path_control_file, STRING))
+                       printf("Test[1:%2d]\tPASS: cgroup_modify_cgroup() retval=%d\n", ++i, retval);
+               else
+                       printf("Test[1:%2d]\tFAIL: cgroup_modify_cgroup() retval=%d\n", ++i, retval);
+
+               /*
+                * Create another valid cgroup structure with diff controller
+                * to modify the existing group
+                * Exp outcome: no error. 0 return value
+                */
+               val_int64 = 2048;
+               strncpy(group, "group1", sizeof(group));
+               retval = set_controller(CPU, controller_name, control_file);
+               if (retval)
+                       fprintf(stderr, "Setting controller failled\n");
+
+               cgroup3 = new_cgroup(group, controller_name,
+                                                control_file, INT64);
+
+               /*
+                * Test10: modify existing group with this cgroup
+                * Exp outcome: zero return value
+                */
+               strncpy(path_control_file, mountpoint, sizeof(mountpoint));
+               strncat(path_control_file, "/group1", sizeof("group2"));
+               strncat(path_control_file, "/", sizeof("/"));
+               strncat(path_control_file, control_file, sizeof(control_file));
+
+               strncpy(val_string, "2048", sizeof(val_string));
+
+               retval = cgroup_modify_cgroup(cgroup3);
+               /* Check if the values are changed */
+               if (!retval && !group_modified(path_control_file, STRING))
+                       printf("Test[1:%2d]\tPASS: cgroup_modify_cgroup() retval=%d\n", ++i, retval);
+               else
+                       printf("Test[1:%2d]\tFAIL: cgroup_modify_cgroup() retval=%d\n", ++i, retval);
+
+
+               /*
+                * Test11: delete cgroup
                 * Exp outcome: zero return value
                 */
                retval = cgroup_delete_cgroup(cgroup1, 1);
@@ -300,7 +361,7 @@ int main(int argc, char *argv[])
                        printf("Test[1:%2d]\tFAIL: cgroup_delete_cgroup() retval=%d\n", ++i, retval);
 
                /*
-                * Test09: Check if cgroup_create_cgroup() handles a NULL cgroup
+                * Test12: Check if cgroup_create_cgroup() handles a NULL cgroup
                 * Exp outcome: error ECGINVAL
                 */
                retval = cgroup_create_cgroup(nullcgroup, 1);
@@ -310,7 +371,7 @@ int main(int argc, char *argv[])
                        printf("Test[1:%2d]\tFAIL: cgroup_create_cgroup() nullcgroup not handled\n", ++i);
 
                /*
-                * Test10: delete nullcgroup
+                * Test13: delete nullcgroup
                 */
                retval = cgroup_delete_cgroup(nullcgroup, 1);
                if (retval)