summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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: