summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDhaval Giani <dhaval@linux.vnet.ibm.com>2008-07-01 13:48:58 +0000
committerDhaval Giani <dhaval@linux.vnet.ibm.com>2008-07-01 13:48:58 +0000
commit2fd38347726e379945d5506136f7e1fe656bcde7 (patch)
treed7284cbdb35c08b25adf50e630e09270ae761822 /tests
parent2c4706487dee1138e7f76d9e188a7c9bbf4475ef (diff)
downloadlibcg-2fd38347726e379945d5506136f7e1fe656bcde7.tar.gz
libcg-2fd38347726e379945d5506136f7e1fe656bcde7.tar.xz
libcg-2fd38347726e379945d5506136f7e1fe656bcde7.zip
From: Sudhir Kumar <skumar@linux.vnet.ibm.com>
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 <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@89 4f4bb910-9a46-0410-90c8-c897d4f1cd53
Diffstat (limited to 'tests')
-rw-r--r--tests/libcgrouptest01.c86
1 files changed, 84 insertions, 2 deletions
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: