]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
libcgroup Test: cleanup1
authorBalbir Singh <balbir@linux.vnet.ibm.com>
Wed, 17 Dec 2008 15:04:52 +0000 (15:04 +0000)
committerBalbir Singh <balbir@linux.vnet.ibm.com>
Wed, 17 Dec 2008 15:04:52 +0000 (15:04 +0000)
Hi,
This patch does cleanup in first set of testcases.
It defines a new function to print test results.

Signed-off-by: Sudhir Kumar <skumar@linux.vnet.ibm.com>
git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@248 4f4bb910-9a46-0410-90c8-c897d4f1cd53

tests/libcgrouptest.h
tests/libcgrouptest01.c

index 35832891738ebfa8a33d8197a12f4701d1c29cef..8a112418dd077c97c8f26395553c5241385610b3 100644 (file)
 
 #include <libcgroup.h>
 
+#define SIZE 100       /* Max size of a message to be printed */
+#define PASS 1         /* test passed */
+#define FAIL 0         /* test failed */
+
 int cpu = 0, memory = 0;
 
 enum cgroup_mount_t {
@@ -61,6 +65,9 @@ uid_t tasks_uid;
 gid_t tasks_gid;
 static int i;
 
+/* No extra message unless specified */
+char extra[SIZE] = "\n";
+
 void get_controllers(char *name, int *exist);
 static int group_exist(char *path_group);
 static int set_controller(int controller, char *controller_name,
@@ -70,6 +77,8 @@ struct cgroup *new_cgroup(char *group, char *controller_name,
                                 char *control_file, int value_type);
 int check_fsmounted(int multimnt);
 static int check_task(char *tasksfile);
+/* function to print messages in better format */
+static inline void message(int num, int pass, char *api, int ret, char *extra);
 
 static inline pid_t cgrouptest_gettid()
 {
index 7cd70c427fba18424a5efdc444dc95d89adf085f..28afaf1fbbdbaa447f5a66b56e0c2c5f9571c6d5 100644 (file)
@@ -29,7 +29,8 @@ int main(int argc, char *argv[])
 
        /* The path to the common group under different controllers */
        char path1_common_group[FILENAME_MAX], path2_common_group[FILENAME_MAX];
-       char mountpoint[FILENAME_MAX], tasksfile[FILENAME_MAX], group[FILENAME_MAX];
+       char mountpoint[FILENAME_MAX], tasksfile[FILENAME_MAX];
+       char group[FILENAME_MAX];
 
        /* Hardcode second mountpoint for now. Will update soon */
        char mountpoint2[FILENAME_MAX] = "/dev/cgroup_controllers-2";
@@ -79,24 +80,22 @@ int main(int argc, char *argv[])
 
                retval = cgroup_init();
                if (retval == ECGROUPNOTMOUNTED)
-                       printf("Test[0:%2d]\tPASS: cgroup_init() retval= %d:\n",\
-                                                                ++i, retval);
+                       message(++i, PASS, "init()\t", retval, extra);
                else
-                       printf("Test[0:%2d]\tFAIL: cgroup_init() retval= %d:\n",\
-                                                                ++i, retval);
+                       message(++i, FAIL, "init()",  retval, extra);
 
                /*
                 * Test02: call cgroup_attach_task() with null group
                 * Exp outcome: error non zero return value
                 */
+               strncpy(extra, " Called with NULL cgroup argument\n", SIZE);
                retval = cgroup_attach_task(nullcgroup);
                if (retval != 0)
-                       printf("Test[0:%2d]\tPASS: cgroup_attach_task() ret: %d\n",\
-                                                                ++i, retval);
+                       message(++i, PASS, "attach_task()", retval, extra);
                else
-                       printf("Test[0:%2d]\tFAIL: cgroup_attach_task() ret: %d\n",\
-                                                                ++i, retval);
+                       message(++i, FAIL, "attach_task()", retval, extra);
 
+               strncpy(extra, "\n", SIZE);
                /*
                 * Test03: Create a valid cgroup and check all return values
                 * Exp outcome: no error. 0 return value
@@ -113,14 +112,14 @@ int main(int argc, char *argv[])
                                                 control_file, STRING);
 
                /*
-                * Test04: Then Call cgroup_create_cgroup() with this valid group
+                * Test04: Then Call cgroup_create_cgroup() with this valid grp
                 * Exp outcome: non zero return value
                 */
                retval = cgroup_create_cgroup(cgroup1, 1);
                if (retval)
-                       printf("Test[0:%2d]\tPASS: cgroup_create_cgroup() retval=%d\n", ++i, retval);
+                       message(++i, PASS, "create_cgroup()", retval, extra);
                else
-                       printf("Test[0:%2d]\tFAIL: cgroup_create_cgroup() retval=%d\n", ++i, retval);
+                       message(++i, FAIL, "create_cgroup()", retval, extra);
 
                /*
                 * Test05: delete cgroup
@@ -128,28 +127,34 @@ int main(int argc, char *argv[])
                 */
                retval = cgroup_delete_cgroup(cgroup1, 1);
                if (retval)
-                       printf("Test[0:%2d]\tPASS: cgroup_delete_cgroup() retval=%d\n", ++i, retval);
+                       message(++i, PASS, "delete_cgroup()", retval, extra);
                else
-                       printf("Test[0:%2d]\tFAIL: cgroup_delete_cgroup() retval=%d\n", ++i, retval);
+                       message(++i, FAIL, "delete_cgroup()", retval, extra);
 
                /*
                 * Test06: Check if cgroup_create_cgroup() handles a NULL cgroup
                 * Exp outcome: error ECGINVAL
                 */
+               strncpy(extra, " Called with NULL cgroup argument\n", SIZE);
                retval = cgroup_create_cgroup(nullcgroup, 1);
                if (retval)
-                       printf("Test[0:%2d]\tPASS: cgroup_create_cgroup() nullcgroup handled\n", ++i);
+                       message(++i, PASS, "create_cgroup()", retval, extra);
                else
-                       printf("Test[0:%2d]\tFAIL: cgroup_create_cgroup() nullcgroup not handled\n", ++i);
+                       message(++i, FAIL, "create_cgroup()", retval, extra);
+
+               strncpy(extra, "\n", SIZE);
 
                /*
                 * Test07: delete nullcgroup
                 */
+               strncpy(extra, " Called with NULL cgroup argument\n", SIZE);
                retval = cgroup_delete_cgroup(nullcgroup, 1);
                if (retval)
-                       printf("Test[0:%2d]\tPASS: cgroup_delete_cgroup() nullcgroup handled\n", ++i);
+                       message(++i, PASS, "delete_cgroup()", retval, extra);
                else
-                       printf("Test[0:%2d]\tFAIL: cgroup_delete_cgroup() Unable to handle nullcgroup\n", ++i);
+                       message(++i, FAIL, "delete_cgroup()", retval, extra);
+
+               strncpy(extra, "\n", SIZE);
 
                cgroup_free(&nullcgroup);
                cgroup_free(&cgroup1);
@@ -814,6 +819,7 @@ struct cgroup *new_cgroup(char *group, char *controller_name,
                                 char *control_file, int value_type)
 {
        int retval;
+       char wr[SIZE]; /* Na,es of wrapper apis */
        struct cgroup *newcgroup;
        struct cgroup_controller *newcontroller;
        newcgroup = cgroup_new_cgroup(group);
@@ -834,18 +840,22 @@ struct cgroup *new_cgroup(char *group, char *controller_name,
                        case BOOL:
                                retval = cgroup_add_value_bool(newcontroller,
                                                 control_file, val_bool);
+                               snprintf(wr, sizeof(wr), "add_value_bool()");
                                break;
                        case INT64:
                                retval = cgroup_add_value_int64(newcontroller,
                                                 control_file, val_int64);
+                               snprintf(wr, sizeof(wr), "add_value_int64()");
                                break;
                        case UINT64:
                                retval = cgroup_add_value_uint64(newcontroller,
                                                 control_file, val_uint64);
+                               snprintf(wr, sizeof(wr), "add_value_uint64()");
                                break;
                        case STRING:
                                retval = cgroup_add_value_string(newcontroller,
                                                 control_file, val_string);
+                               snprintf(wr, sizeof(wr), "add_value_string()");
                                break;
                        default:
                                printf("ERROR: wrong value in new_cgroup()\n");
@@ -854,17 +864,19 @@ struct cgroup *new_cgroup(char *group, char *controller_name,
                        }
 
                        if (!retval) {
-                               printf("Test[1:%2d]\tPASS: cgroup_new_cgroup() success\n", ++i);
+                               message(++i, PASS, "new_cgroup()",
+                                                                retval, extra);
                        } else {
-                               printf("Test[1:%2d]\tFAIL: cgroup_add_value_string()\n", ++i);
+                               message(++i, FAIL, wr, retval, extra);
                                return NULL;
                        }
                 } else {
-                       printf("Test[1:%2d]\tFAIL: cgroup_add_controller()\n", ++i);
+                       /* Since these wrappers do not return an int so -1 */
+                       message(++i, FAIL, "add_controller", -1, extra);
                        return NULL;
                }
        } else {
-               printf("Test[1:%2d]\tFAIL: cgroup_new_cgroup() fails\n", ++i);
+               message(++i, FAIL, "new_cgroup", -1, extra);
                return NULL;
        }
        return newcgroup;
@@ -933,3 +945,18 @@ static int check_task(char *tasksfile)
 
        return 0;
 }
+
+static inline void message(int num, int pass, char *api,
+                                        int retval, char *extra)
+{
+       char res[10];
+       char buf[2*SIZE];
+       if (pass)
+               strncpy(res, "PASS :", 10);
+       else
+               strncpy(res, "FAIL :", 10);
+
+       /* Populate message buffer for the api */
+       snprintf(buf, sizeof(buf), "cgroup_%s\t\t Ret Value = ", api);
+       fprintf(stdout, "TEST%2d:%s %s%d\t%s", num, res, buf, retval, extra);
+}