From 2fd38347726e379945d5506136f7e1fe656bcde7 Mon Sep 17 00:00:00 2001 From: Dhaval Giani Date: Tue, 1 Jul 2008 13:48:58 +0000 Subject: From: Sudhir Kumar libcgroup: libcgroup testcases for cgroup_attach_task() This patch adds 3 testcases for libcgroup API cgroup_attach_task() testing. The API is called under the same but two conditions(FS_MOUNTED=0/1) and return values are checked. For FS_MOUNTED=1 the API is first called without intializing ie without calling cgroup_init(), and then after cg_init(). Each time the null cgroup is passed. The task is checked if it exists under the root group's tasks file. The 4th testcase calls cgroup_attach_task_pid() with an invalid pid. Testcases for FS_MOUNTED=2 have to be added. Signed-off-by: Sudhir Kumar Signed-off-by: Dhaval Giani git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@89 4f4bb910-9a46-0410-90c8-c897d4f1cd53 --- tests/libcgrouptest01.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 84 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/libcgrouptest01.c b/tests/libcgrouptest01.c index 05bf9d8..394c883 100644 --- a/tests/libcgrouptest01.c +++ b/tests/libcgrouptest01.c @@ -18,7 +18,11 @@ int main(int argc, char *argv[]) { - int fs_mounted, retval, i = 0; + int fs_mounted, retval, i = 0, pass = 0; + pid_t curr_tid, tid; + struct cgroup *nullcgroup = NULL; + FILE *file; + char mountpoint[FILENAME_MAX], tasksfile[FILENAME_MAX]; if ((argc < 3) || (atoi(argv[1]) < 0)) { printf("ERROR: Wrong no of parameters recieved from script\n"); @@ -26,6 +30,9 @@ int main(int argc, char *argv[]) exit(1); } fs_mounted = atoi(argv[1]); + strcpy(mountpoint, argv[2]); + dbg("C:DBG: fs_mounted as recieved from script=%d\n", fs_mounted); + dbg("C:DBG: mountpoint as recieved from script=%s\n", mountpoint); /* * Testsets: Testcases are broadly devided into 3 categories based on @@ -50,12 +57,38 @@ int main(int argc, char *argv[]) printf("Test[0:%2d]\tFAIL: cgroup_init() retval= %d:\n",\ ++i, retval); + /* + * Test02: call cgroup_attach_task() with null group + * Exp outcome: error non zero return value + */ + retval = cgroup_attach_task(nullcgroup); + if (retval != 0) + printf("Test[0:%2d]\tPASS: cgroup_attach_task() ret: %d\n",\ + ++i, retval); + else + printf("Test[0:%2d]\tFAIL: cgroup_attach_task() ret: %d\n",\ + ++i, retval); + break; case FS_MOUNTED: /* - * Test01: call cgroup_init() and check return values + * Test01: call cgroup_attach_task() with null group + * without calling cgroup_inti(). We can check other apis too. + * Exp outcome: error ECGROUPNOTINITIALIZED + */ + retval = cgroup_attach_task(nullcgroup); + if (retval == ECGROUPNOTINITIALIZED) + printf("Test[1:%2d]\tPASS: cgroup_attach_task() ret: %d\n",\ + ++i, retval); + else + printf("Test[1:%2d]\tFAIL: cgroup_attach_task() ret: %d\n",\ + ++i, retval); + + + /* + * Test02: call cgroup_init() and check return values * Exp outcome: no error. return value 0 */ @@ -67,6 +100,55 @@ int main(int argc, char *argv[]) printf("Test[1:%2d]\tFAIL: cgroup_init() retval= %d:\n",\ ++i, retval); + /* + * Test03: 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 + * TODO: This test needs some modification in script + * Exp outcome: current task should be attached to root group + */ + retval = cgroup_attach_task(nullcgroup); + if (retval == 0) { + strncpy(tasksfile, mountpoint, sizeof(mountpoint)); + strcat(tasksfile, "/tasks"); + 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[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); + } + + /* + * Test04: Call cgroup_attach_task_pid() with null group + * and invalid pid + * Exp outcome: error + */ + retval = cgroup_attach_task_pid(nullcgroup, 0); + if (retval != 0) + printf("Test[1:%2d]\tPASS: cgroup_attach_task_pid() ret: %d\n",\ + ++i, retval); + else + printf("Test[1:%2d]\tFAIL: cgroup_attach_task_pid() ret: %d\n",\ + ++i, retval); + break; case FS_MULTI_MOUNTED: -- cgit