]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
libcgroup Test: libcgrouptest-multimnt01
authorBalbir Singh <balbir@linux.vnet.ibm.com>
Wed, 17 Dec 2008 14:57:54 +0000 (14:57 +0000)
committerBalbir Singh <balbir@linux.vnet.ibm.com>
Wed, 17 Dec 2008 14:57:54 +0000 (14:57 +0000)
This patch adds a testcase for libcgroup API cgroup_attach_task() testing.
The API is called under the multimount condition(FS_MOUNTED=2) and return
values are checked. The task pid is checked if it exists under the root
group's tasks file of both the mountpoints.

The patch also puts the common code in a function.

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

tests/libcgrouptest.h
tests/libcgrouptest01.c

index 73c4a9bca08090167b24175a4ae4e763e3bc546d..63696fc17d4b38d901ad143fae259943367776f2 100644 (file)
@@ -69,6 +69,7 @@ static int group_modified(char *path_control_file, int value_type);
 struct cgroup *new_cgroup(char *group, char *controller_name,
                                 char *control_file, int value_type);
 int check_fsmounted();
+static int check_task(char *tasksfile);
 
 static inline pid_t cgrouptest_gettid()
 {
index 19a237bb2f677da4df5f77f1b1b6ec5874ffdc66..914b36679d645c9f7978a357577853704486134a 100644 (file)
 
 int main(int argc, char *argv[])
 {
-       int fs_mounted, retval, pass = 0;
-       pid_t curr_tid, tid;
+       int fs_mounted, retval;
        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;
        char mountpoint[FILENAME_MAX], tasksfile[FILENAME_MAX], group[FILENAME_MAX];
 
+       /* Hardcode second mountpoint for now. Will update soon */
+       char mountpoint2[FILENAME_MAX] = "/dev/cgroup_controllers-2";
+       char tasksfile2[FILENAME_MAX];
+
        if ((argc < 3) || (atoi(argv[1]) < 0)) {
                printf("ERROR: Wrong no of parameters recieved from script\n");
                printf("Exiting the libcgroup testset\n");
@@ -194,26 +196,8 @@ int main(int argc, char *argv[])
                if (retval == 0) {
                        strncpy(tasksfile, mountpoint, sizeof(mountpoint));
                        strcat(tasksfile, "/tasks");
-                       file = fopen(tasksfile, "r");
-                       if (!file) {
-                               printf("ERROR: in opening %s\n", tasksfile);
+                       if (check_task(tasksfile))
                                return -1;
-                       }
-
-                       curr_tid = cgrouptest_gettid();
-                       while (!feof(file)) {
-                               fscanf(file, "%u", &tid);
-                               if (tid == curr_tid) {
-                                       pass = 1;
-                                       break;
-                               }
-                       }
-                       if (pass)
-                               printf("Test[1:%2d]\tPASS: Task found in %s\n",\
-                                                        ++i, tasksfile);
-                       else
-                               printf("Test[1:%2d]\tFAIL: Task not found in %s\n",\
-                                                                ++i, tasksfile);
                } else {
                        printf("Test[1:%2d]\tFAIL: cgroup_attach_task() ret: %d\n",\
                                                                 ++i, retval);
@@ -404,6 +388,7 @@ int main(int argc, char *argv[])
                 * Test01: call apis and check return values
                 * Exp outcome:
                 */
+
                /*
                 * Scenario 1: cgroup fs is multi mounted
                 * Exp outcome: no error. 0 return value
@@ -418,9 +403,24 @@ int main(int argc, char *argv[])
                                                                 ++i, retval);
 
                /*
-                * Will add further testcases in separate patchset
+                * Test02: Call cgroup_attach_task() with null group and check if
+                * return values are correct. If yes check if task exists in
+                * root group tasks file for each controller
+                * TODO: This test needs some modification in script
+                * Exp outcome: current task should be attached to root groups
                 */
-
+               retval = cgroup_attach_task(nullcgroup);
+               if (retval == 0) {
+                       strncpy(tasksfile, mountpoint, sizeof(mountpoint));
+                       strcat(tasksfile, "/tasks");
+                       strncpy(tasksfile2, mountpoint2, sizeof(mountpoint));
+                       strcat(tasksfile2, "/tasks");
+                       if (check_task(tasksfile) || i-- && check_task(tasksfile2))
+                               return -1;
+               } else {
+                       printf("Test[2:%2d]\tFAIL: cgroup_attach_task() ret: %d\n",\
+                                                ++i, retval);
+               }
                break;
 
        default:
@@ -619,3 +619,31 @@ int check_fsmounted()
        }
        return 1;
 }
+
+static int check_task(char *tasksfile)
+{
+       FILE *file;
+       pid_t curr_tid, tid;
+       int pass = 0;
+
+       file = fopen(tasksfile, "r");
+       if (!file) {
+               printf("ERROR: in opening %s\n", tasksfile);
+               return -1;
+       }
+
+       curr_tid = cgrouptest_gettid();
+       while (!feof(file)) {
+               fscanf(file, "%u", &tid);
+               if (tid == curr_tid) {
+                       pass = 1;
+                       break;
+               }
+       }
+       if (pass)
+               printf("Test[2:%2d]\tPASS: Task found in %s\n", ++i, tasksfile);
+       else
+               printf("Test[2:%2d]\tFAIL: Task not found in %s\n", ++i, tasksfile);
+
+       return 0;
+}