]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
libcgrouptest:attach exclusive pid support in test_cgroup_attach_task() function
authorDhaval Giani <dhaval@linux.vnet.ibm.com>
Fri, 9 Jan 2009 16:26:15 +0000 (16:26 +0000)
committerDhaval Giani <dhaval@linux.vnet.ibm.com>
Fri, 9 Jan 2009 16:26:15 +0000 (16:26 +0000)
From: Sudhir Kumar <skumar@linux.vnet.ibm.com>

The function test_attach_task_pid() was attaching the process calling the
function to a group and did not have support to take any pid for attaching
it to a group. This patch does that.

Signed-off-by: Sudhir Kumar <skumar@linux.vnet.ibm.com>
Acked-by: Dhaval Giani <dhaval@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@310 4f4bb910-9a46-0410-90c8-c897d4f1cd53

tests/libcgrouptest.h
tests/libcgrouptest01.c
tests/test_functions.c

index 62f0c680d8345e69cacd11a9ed2480a07f994f92..36edc2680f90c0e3d81831877df4813459d00756 100644 (file)
@@ -110,8 +110,8 @@ extern char mountpoint[], mountpoint2[];
 /* Functions to test each API */
 void test_cgroup_init(int retcode, int i);
 void test_cgroup_attach_task(int retcode, struct cgroup *cgroup1,
-                               const char *group1, const char *group2,
-                                                               int k, int i);
+               const char *group1, const char *group2, pid_t pid,
+               int k, int i);
 struct cgroup *create_new_cgroup_ds(int ctl, const char *grpname,
         int value_type, struct cntl_val_t cval, struct uid_gid_t ids, int i);
 void test_cgroup_create_cgroup(int retcode, struct cgroup *cgrp,
index 2b1fed32f2bab0556f6d0d47c0c93fa70b284637..a4a492d6ad26d56b2f95df6fcb76363625b81e2d 100644 (file)
@@ -105,7 +105,7 @@ int main(int argc, char *argv[])
                 */
 
                test_cgroup_attach_task(ECGROUPNOTINITIALIZED, nullcgroup,
-                                        NULL, NULL, NULLGRP, 2);
+                                                NULL, NULL, 0, NULLGRP, 2);
 
                /*
                 * Test03: Create a valid cgroup ds and check all return values
@@ -165,7 +165,7 @@ int main(int argc, char *argv[])
                 */
 
                test_cgroup_attach_task(ECGROUPNOTINITIALIZED, nullcgroup,
-                                                NULL, NULL, NULLGRP, 1);
+                                                NULL, NULL, 0, NULLGRP, 1);
 
                /*
                 * Test02: call cgroup_init() and check return values
@@ -182,8 +182,8 @@ int main(int argc, char *argv[])
                 * Exp outcome: current task should be attached to root group
                 */
 
-               test_cgroup_attach_task(0, nullcgroup,
-                                                NULL, NULL, NULLGRP, 3);
+               test_cgroup_attach_task(0, nullcgroup, NULL, NULL, 0,
+                                                        NULLGRP, 3);
                /*
                 * Test04: Call cgroup_attach_task_pid() with null group
                 * and invalid pid
@@ -230,7 +230,7 @@ int main(int argc, char *argv[])
                 */
 
                test_cgroup_attach_task(0, cgroup1, "group1", NULL,
-                                                                NOMESSAGE, 7);
+                                                        0, NOMESSAGE, 7);
 
                /*
                 * Test08: modify cgroup with the same cgroup
@@ -378,7 +378,8 @@ int main(int argc, char *argv[])
                 * Exp outcome: current task should be attached to root groups
                 */
 
-               test_cgroup_attach_task(0, nullcgroup, NULL, NULL, NULLGRP, 2);
+               test_cgroup_attach_task(0, nullcgroup, NULL, NULL,
+                                                        0, NULLGRP, 2);
 
                /*
                 * Test03: Create a valid cgroup structure
@@ -436,7 +437,7 @@ int main(int argc, char *argv[])
                 */
 
                test_cgroup_attach_task(0, ctl1_cgroup1, "ctl1_group1",
-                                                        NULL, NOMESSAGE, 8);
+                                                NULL, 0, NOMESSAGE, 8);
 
                /*
                 * Test07: Call cgroup_attach_task() with a group with ctl2
@@ -446,7 +447,7 @@ int main(int argc, char *argv[])
                 */
 
                test_cgroup_attach_task(0, ctl2_cgroup1, "ctl1_group1",
-                                                "ctl2_group1", NOMESSAGE, 9);
+                                        "ctl2_group1", 0, NOMESSAGE, 9);
 
                /*
                 * Test: Create a valid cgroup structure
@@ -467,7 +468,7 @@ int main(int argc, char *argv[])
                 */
 
                test_cgroup_attach_task(ECGROUPNOTEXIST, ctl2_cgroup2,
-                                                NULL, NULL, NOTCRTDGRP, 11);
+                                        NULL, NULL, 0, NOTCRTDGRP, 11);
 
                /*
                 * Create another valid cgroup structure with same group name
@@ -569,7 +570,7 @@ int main(int argc, char *argv[])
                 */
 
                test_cgroup_attach_task(0, common_cgroup, "commongroup",
-                                                "commongroup", COMMONGRP, 20);
+                                        "commongroup", 0, COMMONGRP, 20);
 
                /*
                 * Test18: Create a valid cgroup structure to modify the
index fc64934aaf3fa5e6dbf2d80226451bee5fcbb706..4b8bcbb0bb14d52ddcbf083fb5f2704dede06521 100644 (file)
@@ -66,13 +66,17 @@ void test_cgroup_init(int retcode, int i)
  * @param k the message enum number to print the useful message
  */
 void test_cgroup_attach_task(int retcode, struct cgroup *cgrp,
-                const char *group1, const char *group2, int k, int i)
+        const char *group1, const char *group2, pid_t pid, int k, int i)
 {
        int retval;
        char tasksfile[FILENAME_MAX], tasksfile2[FILENAME_MAX];
        /* Check, In case some error is expected due to a negative scenario */
        if (retcode) {
-               retval = cgroup_attach_task(cgrp);
+               if (pid)
+                       retval = cgroup_attach_task_pid(cgrp, pid);
+               else
+                       retval = cgroup_attach_task(cgrp);
+
                if (retval == retcode)
                        message(i, PASS, "attach_task()", retval, info[k]);
                else
@@ -82,7 +86,11 @@ void test_cgroup_attach_task(int retcode, struct cgroup *cgrp,
        }
 
        /* Now there is no error and it is a genuine call */
-       retval = cgroup_attach_task(cgrp);
+       if (pid)
+               retval = cgroup_attach_task_pid(cgrp, pid);
+       else
+               retval = cgroup_attach_task(cgrp);
+
        /* API returned success, so perform check */
        if (retval == 0) {
                build_path(tasksfile, mountpoint,