summaryrefslogtreecommitdiffstats
path: root/tests/libcgrouptest01.c
diff options
context:
space:
mode:
authorDhaval Giani <dhaval@linux.vnet.ibm.com>2008-12-22 19:04:55 +0000
committerDhaval Giani <dhaval@linux.vnet.ibm.com>2008-12-22 19:04:55 +0000
commit298234f29860180126ea8be222519714b5a25dcb (patch)
tree3301f2fd490d73fecc8ec90fe4ece4d743c67e00 /tests/libcgrouptest01.c
parentd025dcbb4ea5b08cf5db8dcb77a1170e0dba89b9 (diff)
downloadlibcg-298234f29860180126ea8be222519714b5a25dcb.tar.gz
libcg-298234f29860180126ea8be222519714b5a25dcb.tar.xz
libcg-298234f29860180126ea8be222519714b5a25dcb.zip
libcgroup: test for cgroup_get_cgroup
From: Sudhir Kumar <skumar@linux.vnet.ibm.com> This patch adds one testcase for cgroup_get_cgroup() api. The test creates a group in filesystem, reads it in another cgroup and compares the two and throws the results. Also bounds the execution of certain basic testcases for the same api under single mount only, as not required under multimnt. 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@291 4f4bb910-9a46-0410-90c8-c897d4f1cd53
Diffstat (limited to 'tests/libcgrouptest01.c')
-rw-r--r--tests/libcgrouptest01.c102
1 files changed, 75 insertions, 27 deletions
diff --git a/tests/libcgrouptest01.c b/tests/libcgrouptest01.c
index 454c466..ece14bf 100644
--- a/tests/libcgrouptest01.c
+++ b/tests/libcgrouptest01.c
@@ -297,9 +297,11 @@ int main(int argc, char *argv[])
* filesystem. Read it using the api and check if the values
* are correct as we know all the control values now.
* WARN: If any of the previous api fails and control reaches
- * here, this api also will fail
+ * here, this api also will fail. Also the test function assumes
+ * that "group1" exists in fs. So call cgroup_create_cgroup()
+ * with "group1" named group before calling this test function.
*/
- test_cgroup_get_cgroup(14);
+ test_cgroup_get_cgroup(ctl1, ctl2, 14);
/*
* Test16: delete cgroup
@@ -607,6 +609,7 @@ int main(int argc, char *argv[])
*/
test_cgroup_delete_cgroup(0, common_cgroup,
"commongroup", 1, 2, 1, 23);
+ test_cgroup_get_cgroup(ctl1, ctl2, 24);
/* Free the cgroup structures */
cgroup_free(&nullcgroup);
@@ -1407,39 +1410,84 @@ void test_cgroup_compare_cgroup(int ctl1, int ctl2, int i)
cgroup_free(&cgroup2);
}
-void test_cgroup_get_cgroup(int i)
+void test_cgroup_get_cgroup(int ctl1, int ctl2, int i)
{
- struct cgroup *cgroup_filled;
+ struct cgroup *cgroup_filled, *cgroup_a, *cgroup_b;
+ struct cgroup_controller *controller;
+ char controller_name[FILENAME_MAX], control_file[FILENAME_MAX];
int ret;
- /* Test with nullcgroup first */
- ret = cgroup_get_cgroup(NULL);
- if (ret == ECGROUPNOTALLOWED)
- message(i++, PASS, "get_cgroup()", ret, info[NULLGRP]);
- else
- message(i++, FAIL, "get_cgroup()", ret, info[NULLGRP]);
+ /*
+ * No need to test the next 3 scenarios again for Multimnt
+ * so testing them only under single mount
+ */
+ if (fs_mounted == FS_MOUNTED) {
+ /* 1. Test with nullcgroup first */
+ ret = cgroup_get_cgroup(NULL);
+ if (ret == ECGROUPNOTALLOWED)
+ message(i++, PASS, "get_cgroup()", ret, info[NULLGRP]);
+ else
+ message(i++, FAIL, "get_cgroup()", ret, info[NULLGRP]);
- /* Test with invalid name filled cgroup(non existing) */
- cgroup_filled = cgroup_new_cgroup("nogroup");
- if (!cgroup_filled)
- message(i++, FAIL, "new_cgroup()", 0, info[NOMESSAGE]);
+ /* 2. Test with invalid name filled cgroup(non existing) */
+ cgroup_filled = cgroup_new_cgroup("nogroup");
+ if (!cgroup_filled)
+ message(i++, FAIL, "new_cgroup()", 0, info[NOMESSAGE]);
- ret = cgroup_get_cgroup(cgroup_filled);
- if (ret)
- message(i++, PASS, "get_cgroup()", ret, info[NOTCRTDGRP]);
- else
- message(i++, FAIL, "get_cgroup()", ret, info[NOTCRTDGRP]);
+ ret = cgroup_get_cgroup(cgroup_filled);
+ if (ret)
+ message(i++, PASS, "get_cgroup()", ret,
+ info[NOTCRTDGRP]);
+ else
+ message(i++, FAIL, "get_cgroup()", ret,
+ info[NOTCRTDGRP]);
- /* Test with name filled cgroup */
- cgroup_filled = cgroup_new_cgroup("group1");
- if (!cgroup_filled)
- message(i++, FAIL, "new_cgroup()", 0, info[NOMESSAGE]);
+ /* 3.
+ * Test with name filled cgroup. Ensure the group group1 exists
+ * in the filesystem before calling this test function
+ */
+ cgroup_filled = cgroup_new_cgroup("group1");
+ if (!cgroup_filled)
+ message(i++, FAIL, "new_cgroup()", 0, info[NOMESSAGE]);
- ret = cgroup_get_cgroup(cgroup_filled);
- if (!ret)
- message(i++, PASS, "get_cgroup()", ret, info[NOMESSAGE]);
- else
+ ret = cgroup_get_cgroup(cgroup_filled);
+ if (!ret)
+ message(i++, PASS, "get_cgroup()", ret,
+ info[NOMESSAGE]);
+ else
+ message(i++, FAIL, "get_cgroup()", ret,
+ info[NOMESSAGE]);
+ }
+
+ /* MULTIMOUNT: Create, get and compare a cgroup under both mounts */
+
+ /* get cgroup_a ds and create group_a in filesystem */
+ cgroup_a = create_new_cgroup_ds(ctl1, "group_a", STRING, 00);
+ if (fs_mounted == FS_MULTI_MOUNTED) {
+ /* Create under another controller also */
+ ret = set_controller(ctl2, controller_name, control_file);
+ controller = cgroup_add_controller(cgroup_a, controller_name);
+ }
+ test_cgroup_create_cgroup(0, cgroup_a, "group_a", 0, 1, 1, 00);
+
+ /* create group_b ds to be filled by cgroup_get_cgroup */
+ cgroup_b = cgroup_new_cgroup("group_a");
+ if (!cgroup_b)
+ message(i++, FAIL, "new_cgroup()", 0, info[NOMESSAGE]);
+ /* Fill the ds and compare the two */
+ ret = cgroup_get_cgroup(cgroup_b);
+ if (!ret) {
+ ret = cgroup_compare_cgroup(cgroup_a, cgroup_b);
+ if (ret == 0)
+ message(i++, PASS, "get_cgroup()", ret, info[SAMEGRP]);
+ else
+ message(i++, FAIL, "get_cgroup()", ret,
+ info[NOMESSAGE]);
+ } else {
message(i++, FAIL, "get_cgroup()", ret, info[NOMESSAGE]);
+ }
+ cgroup_free(&cgroup_a);
+ cgroup_free(&cgroup_b);
cgroup_free(&cgroup_filled);
}