From bf1c1a60f29dc2435bc0029c8f07a88559bfc8fb Mon Sep 17 00:00:00 2001 From: Balbir Singh Date: Wed, 17 Dec 2008 15:18:23 +0000 Subject: libcgroup Test: libcgroup-create-function-for-init-api This patch creates a function test_cgroup_init() to test the libcgroup api cgroup_init() under different scenario. In the earlier approach we were not usong functions and were testing the api sequentialy under different conditions. The new approach has a single function for 1 api which can handle the testing under all conditions. The advantage is that the code repetition has reduced now. Signed-off-by: Sudhir Kumar git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@267 4f4bb910-9a46-0410-90c8-c897d4f1cd53 --- tests/libcgrouptest01.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'tests/libcgrouptest01.c') diff --git a/tests/libcgrouptest01.c b/tests/libcgrouptest01.c index efe423a..f69d022 100644 --- a/tests/libcgrouptest01.c +++ b/tests/libcgrouptest01.c @@ -95,11 +95,7 @@ int main(int argc, char *argv[]) * Exp outcome: error ECGROUPNOTMOUNTED */ - retval = cgroup_init(); - if (retval == ECGROUPNOTMOUNTED) - message(++i, PASS, "init()\t", retval, extra); - else - message(++i, FAIL, "init()", retval, extra); + test_cgroup_init(ECGROUPNOTMOUNTED, 1); /* * Test02: call cgroup_attach_task() with null group @@ -209,11 +205,7 @@ int main(int argc, char *argv[]) * Exp outcome: no error. return value 0 */ - retval = cgroup_init(); - if (retval == 0) - message(++i, PASS, "init()\t", retval, extra); - else - message(++i, FAIL, "init()\t", retval, extra); + test_cgroup_init(0, 2); /* * Test03: Call cgroup_attach_task() with null group and check @@ -512,11 +504,7 @@ int main(int argc, char *argv[]) * Exp outcome: no error. 0 return value */ - retval = cgroup_init(); - if (retval == 0) - message(++i, PASS, "init()\t", retval, extra); - else - message(++i, FAIL, "init()\t", retval, extra); + test_cgroup_init(0, 1); /* * Test02: Call cgroup_attach_task() with null group and check @@ -1063,6 +1051,19 @@ int main(int argc, char *argv[]) return 0; } + +void test_cgroup_init(int retcode, int i) +{ + int retval; + char extra[SIZE] = "\n"; + + retval = cgroup_init(); + if (retval == retcode) + message(i, PASS, "init()\t", retval, extra); + else + message(i, FAIL, "init()", retval, extra); +} + void get_controllers(char *name, int *exist) { int hierarchy, num_cgroups, enabled; -- cgit