summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBalbir Singh <balbir@linux.vnet.ibm.com>2008-12-17 14:58:42 +0000
committerBalbir Singh <balbir@linux.vnet.ibm.com>2008-12-17 14:58:42 +0000
commitbad09101b968e56f4b85aa964258b7aef33d72c2 (patch)
tree8dd9777e2666d450d7314b1427acc035e559940d /tests
parent5506f09958450f6d654c30827d8e68140587491a (diff)
downloadlibcg-bad09101b968e56f4b85aa964258b7aef33d72c2.tar.gz
libcg-bad09101b968e56f4b85aa964258b7aef33d72c2.tar.xz
libcg-bad09101b968e56f4b85aa964258b7aef33d72c2.zip
libcgroup Test: libcgrouptest-multimnt02
This patch adds a testcase for libcgroup API cgroup_create_cgroup() testing. The API is called under the multimount condition(FS_MOUNTED=2) and return values are checked. The group is checked if it exists under the root directory of the corresponding controller's mountpoint. Signed-off-by: Sudhir Kumar <skumar@linux.vnet.ibm.com> git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@242 4f4bb910-9a46-0410-90c8-c897d4f1cd53
Diffstat (limited to 'tests')
-rw-r--r--tests/libcgrouptest01.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/tests/libcgrouptest01.c b/tests/libcgrouptest01.c
index 914b366..92fd7b4 100644
--- a/tests/libcgrouptest01.c
+++ b/tests/libcgrouptest01.c
@@ -20,6 +20,9 @@ int main(int argc, char *argv[])
{
int fs_mounted, retval;
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;
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];
@@ -250,6 +253,8 @@ int main(int argc, char *argv[])
if (group_exist(path_group) == 0)
printf("Test[1:%2d]\tPASS: cgroup_create_cgroup() retval=%d\n",
++i, retval);
+ else
+ printf("Test[1:%2d]\tFAIL: group not found in fs\n", ++i);
} else
printf("Test[1:%2d]\tFAIL: cgroup_create_cgroup() retval=%d\n", ++i, retval);
@@ -356,6 +361,8 @@ int main(int argc, char *argv[])
if (group_exist(path_group) == -1)
printf("Test[1:%2d]\tPASS: cgroup_delete_cgroup() retval=%d\n",
++i, retval);
+ else
+ printf("Test[1:%2d]\tFAIL: group still found in fs\n", ++i);
} else
printf("Test[1:%2d]\tFAIL: cgroup_delete_cgroup() retval=%d\n", ++i, retval);
@@ -421,6 +428,82 @@ int main(int argc, char *argv[])
printf("Test[2:%2d]\tFAIL: cgroup_attach_task() ret: %d\n",\
++i, retval);
}
+
+ /*
+ * Test03: Create a valid cgroup structure
+ * Exp outcome: no error. 0 return value
+ */
+ strncpy(group, "cpugroup1", sizeof(group));
+ strncpy(val_string, "4096", sizeof(val_string));
+ retval = set_controller(CPU, controller_name, control_file);
+
+ if (retval)
+ fprintf(stderr, "Setting controller failled\n");
+
+ cpu_cgroup1 = new_cgroup(group, controller_name,
+ control_file, STRING);
+
+ /*
+ * Test04: Then Call cgroup_create_cgroup() with this valid group
+ * Exp outcome: zero return value
+ */
+ retval = cgroup_create_cgroup(cpu_cgroup1, 1);
+ if (!retval) {
+ /* Check if the group exists in the dir tree */
+ strncpy(path_group, mountpoint, sizeof(path_group));
+ strncat(path_group, "/cpugroup1", sizeof(path_group));
+ if (group_exist(path_group) == 0)
+ printf("Test[2:%2d]\tPASS: cgroup_create_cgroup() retval=%d\n",
+ ++i, retval);
+ else
+ printf("Test[2:%2d]\tFAIL: group not found in fs\n", ++i);
+ } else
+ printf("Test[2:%2d]\tFAIL: cgroup_create_cgroup() retval=%d\n", ++i, retval);
+
+ /*
+ * Test03: Create a valid cgroup structure
+ * Exp outcome: no error. 0 return value
+ */
+ strncpy(group, "memgroup1", sizeof(group));
+ retval = set_controller(MEMORY, controller_name, control_file);
+ strncpy(val_string, "52428800", sizeof(val_string));
+
+ if (retval)
+ fprintf(stderr, "Setting controller failled\n");
+
+ mem_cgroup1 = new_cgroup(group, controller_name,
+ control_file, STRING);
+
+ /*
+ * Test04: Then Call cgroup_create_cgroup() with this valid group
+ * Exp outcome: zero return value
+ */
+ retval = cgroup_create_cgroup(mem_cgroup1, 1);
+ if (!retval) {
+ /* Check if the group exists in the dir tree */
+ strncpy(path_group, mountpoint2, sizeof(path_group));
+ strncat(path_group, "/memgroup1", sizeof(path_group));
+ if (group_exist(path_group) == 0)
+ printf("Test[2:%2d]\tPASS: cgroup_create_cgroup() retval=%d\n",
+ ++i, retval);
+ else
+ printf("Test[2:%2d]\tFAIL: cgroup_create_cgroup() group not found in fs\n", ++i);
+ } else
+ printf("Test[2:%2d]\tFAIL: cgroup_create_cgroup() retval=%d\n", ++i, retval);
+
+
+ /*
+ * Test05: Call cgroup_create_cgroup() with the same group
+ * Exp outcome: non zero return value
+ */
+ retval = cgroup_create_cgroup(cpu_cgroup1, 1);
+ /* BUG: The error should be ECGROUPALREADYEXISTS */
+ if (retval == ECGROUPNOTALLOWED)
+ printf("Test[2:%2d]\tPASS: cgroup_create_cgroup().Second Call. retval=%d\n",
+ ++i, retval);
+ else
+ printf("Test[2:%2d]\tFAIL: cgroup_create_cgroup(): Second call. retval=%d\n", ++i, retval);
+
break;
default: