summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBalbir Singh <balbir@linux.vnet.ibm.com>2008-12-17 14:57:54 +0000
committerBalbir Singh <balbir@linux.vnet.ibm.com>2008-12-17 14:57:54 +0000
commit5506f09958450f6d654c30827d8e68140587491a (patch)
treecf593f10e74e46446649959fe3193e94e0b010a4 /tests
parent39424259a3a058cb5e5368848bf153a5b5e82318 (diff)
downloadlibcg-5506f09958450f6d654c30827d8e68140587491a.tar.gz
libcg-5506f09958450f6d654c30827d8e68140587491a.tar.xz
libcg-5506f09958450f6d654c30827d8e68140587491a.zip
libcgroup Test: libcgrouptest-multimnt01
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 task pid is checked if it exists under the root group's tasks file of both the mountpoints. The patch also puts the common code in a function. Signed-off-by: Sudhir Kumar <skumar@linux.vnet.ibm.com> git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@241 4f4bb910-9a46-0410-90c8-c897d4f1cd53
Diffstat (limited to 'tests')
-rw-r--r--tests/libcgrouptest.h1
-rw-r--r--tests/libcgrouptest01.c76
2 files changed, 53 insertions, 24 deletions
diff --git a/tests/libcgrouptest.h b/tests/libcgrouptest.h
index 73c4a9b..63696fc 100644
--- a/tests/libcgrouptest.h
+++ b/tests/libcgrouptest.h
@@ -69,6 +69,7 @@ static int group_modified(char *path_control_file, int value_type);
struct cgroup *new_cgroup(char *group, char *controller_name,
char *control_file, int value_type);
int check_fsmounted();
+static int check_task(char *tasksfile);
static inline pid_t cgrouptest_gettid()
{
diff --git a/tests/libcgrouptest01.c b/tests/libcgrouptest01.c
index 19a237b..914b366 100644
--- a/tests/libcgrouptest01.c
+++ b/tests/libcgrouptest01.c
@@ -18,14 +18,16 @@
int main(int argc, char *argv[])
{
- int fs_mounted, retval, pass = 0;
- pid_t curr_tid, tid;
+ int fs_mounted, retval;
struct cgroup *cgroup1, *cgroup2, *cgroup3, *nullcgroup = NULL;
char controller_name[FILENAME_MAX], control_file[FILENAME_MAX],
path_group[FILENAME_MAX], path_control_file[FILENAME_MAX];
- FILE *file;
char mountpoint[FILENAME_MAX], tasksfile[FILENAME_MAX], group[FILENAME_MAX];
+ /* Hardcode second mountpoint for now. Will update soon */
+ char mountpoint2[FILENAME_MAX] = "/dev/cgroup_controllers-2";
+ char tasksfile2[FILENAME_MAX];
+
if ((argc < 3) || (atoi(argv[1]) < 0)) {
printf("ERROR: Wrong no of parameters recieved from script\n");
printf("Exiting the libcgroup testset\n");
@@ -194,26 +196,8 @@ int main(int argc, char *argv[])
if (retval == 0) {
strncpy(tasksfile, mountpoint, sizeof(mountpoint));
strcat(tasksfile, "/tasks");
- file = fopen(tasksfile, "r");
- if (!file) {
- printf("ERROR: in opening %s\n", tasksfile);
+ if (check_task(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);
@@ -404,6 +388,7 @@ int main(int argc, char *argv[])
* Test01: call apis and check return values
* Exp outcome:
*/
+
/*
* Scenario 1: cgroup fs is multi mounted
* Exp outcome: no error. 0 return value
@@ -418,9 +403,24 @@ int main(int argc, char *argv[])
++i, retval);
/*
- * Will add further testcases in separate patchset
+ * Test02: 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 for each controller
+ * TODO: This test needs some modification in script
+ * Exp outcome: current task should be attached to root groups
*/
-
+ retval = cgroup_attach_task(nullcgroup);
+ if (retval == 0) {
+ strncpy(tasksfile, mountpoint, sizeof(mountpoint));
+ strcat(tasksfile, "/tasks");
+ strncpy(tasksfile2, mountpoint2, sizeof(mountpoint));
+ strcat(tasksfile2, "/tasks");
+ if (check_task(tasksfile) || i-- && check_task(tasksfile2))
+ return -1;
+ } else {
+ printf("Test[2:%2d]\tFAIL: cgroup_attach_task() ret: %d\n",\
+ ++i, retval);
+ }
break;
default:
@@ -619,3 +619,31 @@ int check_fsmounted()
}
return 1;
}
+
+static int check_task(char *tasksfile)
+{
+ FILE *file;
+ pid_t curr_tid, tid;
+ int pass = 0;
+
+ 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[2:%2d]\tPASS: Task found in %s\n", ++i, tasksfile);
+ else
+ printf("Test[2:%2d]\tFAIL: Task not found in %s\n", ++i, tasksfile);
+
+ return 0;
+}