summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBalbir Singh <balbir@linux.vnet.ibm.com>2008-12-17 14:59:35 +0000
committerBalbir Singh <balbir@linux.vnet.ibm.com>2008-12-17 14:59:35 +0000
commitb828e0424b82e1a6c74b2d68aae3d6da73f27809 (patch)
treef2604bb83bcccc67b16d60cdacb51ccb3554d223
parentbad09101b968e56f4b85aa964258b7aef33d72c2 (diff)
downloadlibcg-b828e0424b82e1a6c74b2d68aae3d6da73f27809.tar.gz
libcg-b828e0424b82e1a6c74b2d68aae3d6da73f27809.tar.xz
libcg-b828e0424b82e1a6c74b2d68aae3d6da73f27809.zip
libcgroup Test: libcgrouptest-multimnt03
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 argument of the api is a valid group under one controller's(say cpu) mountpoint. This group exist only under one controller(cpu). So the attached task is checked under this group for this(cpu) controller and under the root group for the other(memory) controller. In the second call the argument is a group under other controller(memory) and hence now task is checked under the two groups of both controllers. In the third calll we give the argument as a non existing group, so the return value should be ECGROUPNOTEXIST. Signed-off-by: Sudhir Kumar <skumar@linux.vnet.ibm.com> git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@243 4f4bb910-9a46-0410-90c8-c897d4f1cd53
-rw-r--r--tests/libcgrouptest01.c74
1 files changed, 73 insertions, 1 deletions
diff --git a/tests/libcgrouptest01.c b/tests/libcgrouptest01.c
index 92fd7b4..71dcec4 100644
--- a/tests/libcgrouptest01.c
+++ b/tests/libcgrouptest01.c
@@ -22,7 +22,7 @@ int main(int argc, char *argv[])
struct cgroup *cgroup1, *cgroup2, *cgroup3, *nullcgroup = NULL;
/* In case of multimount for readability we use the controller name
* before the cgroup structure name */
- struct cgroup *cpu_cgroup1, *mem_cgroup1;
+ struct cgroup *cpu_cgroup1, *mem_cgroup1, *mem_cgroup2;
char controller_name[FILENAME_MAX], control_file[FILENAME_MAX],
path_group[FILENAME_MAX], path_control_file[FILENAME_MAX];
char mountpoint[FILENAME_MAX], tasksfile[FILENAME_MAX], group[FILENAME_MAX];
@@ -504,6 +504,78 @@ int main(int argc, char *argv[])
else
printf("Test[2:%2d]\tFAIL: cgroup_create_cgroup(): Second call. retval=%d\n", ++i, retval);
+
+ /*
+ * Test06: Call cgroup_attach_task() with a group with cpu
+ * controller and check if return values are correct. If yes
+ * check if task exists in that group under only cpu controller
+ * hierarchy and in the root group under other controllers
+ * hierarchy.
+ * TODO: This test needs some modification in script
+ * Shall we hardcode mountpoints for each controller ?
+ */
+ retval = cgroup_attach_task(cpu_cgroup1);
+ if (retval == 0) {
+ strncpy(tasksfile, mountpoint, sizeof(tasksfile));
+ strncat(tasksfile, "/cpugroup1", sizeof(tasksfile));
+ strncat(tasksfile, "/tasks", sizeof(tasksfile));
+
+ strncpy(tasksfile2, mountpoint2, sizeof(tasksfile2));
+ strncat(tasksfile2, "/tasks", sizeof(tasksfile2));
+
+ if (check_task(tasksfile) || i-- && check_task(tasksfile2))
+ return -1;
+ } else {
+ printf("Test[2:%2d]\tFAIL: cgroup_attach_task() ret: %d\n",\
+ ++i, retval);
+ }
+
+ /*
+ * Test07: Call cgroup_attach_task() with a group with memory
+ * controller and check if return values are correct. If yes
+ * check if task exists in the groups under both cpu controller
+ * hierarchy and other controllers hierarchy.
+ * TODO: This test needs some modification in script
+ * Shall we hardcode mountpoints for each controller ?
+ */
+ retval = cgroup_attach_task(mem_cgroup1);
+ if (retval == 0) {
+ strncpy(tasksfile, mountpoint, sizeof(tasksfile));
+ strncat(tasksfile, "/cpugroup1", sizeof(tasksfile));
+ strncat(tasksfile, "/tasks", sizeof(tasksfile));
+
+ strncpy(tasksfile2, mountpoint2, sizeof(tasksfile2));
+ strncat(tasksfile2, "/memgroup1", sizeof(tasksfile2));
+ strncat(tasksfile2, "/tasks", sizeof(tasksfile2));
+
+ if (check_task(tasksfile) || i-- && check_task(tasksfile2))
+ return -1;
+ } else {
+ printf("Test[2:%2d]\tFAIL: cgroup_attach_task() ret: %d\n",\
+ ++i, retval);
+ }
+
+ /*
+ * Test: Create a valid cgroup structure
+ * Exp outcome: no error. 0 return value
+ */
+ strncpy(group, "memgroup2", sizeof(group));
+ mem_cgroup2 = new_cgroup(group, controller_name,
+ control_file, STRING);
+
+ /*
+ * Test08: Try to attach a task to this non existing group.
+ * Group does not exist in fs so should return ECGROUPNOTEXIST
+ */
+ retval = cgroup_attach_task(mem_cgroup2);
+ if (retval == ECGROUPNOTEXIST) {
+ printf("Test[1:%2d]\tPASS: cgroup_attach_task() ret: %d\n",\
+ ++i, retval);
+ } else {
+ printf("Test[2:%2d]\tFAIL: cgroup_attach_task() ret: %d\n",\
+ ++i, retval);
+ }
+
break;
default: