From 5d16282a5f418bb7030ba33363bf570bec056a0b Mon Sep 17 00:00:00 2001 From: Balbir Singh Date: Wed, 17 Dec 2008 15:21:32 +0000 Subject: libcgroup Test: libcgroup-split-new-cgroup-function This patch splits the earlier created function new_cgroup() into two to make it more useful for other testcases. Signed-off-by: Sudhir Kumar git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@274 4f4bb910-9a46-0410-90c8-c897d4f1cd53 --- tests/libcgrouptest.h | 2 ++ tests/libcgrouptest01.c | 65 ++++++++++++++++++++++++++++--------------------- 2 files changed, 39 insertions(+), 28 deletions(-) (limited to 'tests') diff --git a/tests/libcgrouptest.h b/tests/libcgrouptest.h index c04eaa6..983d9be 100644 --- a/tests/libcgrouptest.h +++ b/tests/libcgrouptest.h @@ -87,6 +87,8 @@ static int group_exist(char *path_group); static int set_controller(int controller, char *controller_name, char *control_file); static int group_modified(char *path_control_file, int value_type); +static int add_control_value(struct cgroup_controller *newcontroller, + char * control_file, char *wr, int value_type); struct cgroup *new_cgroup(char *group, char *controller_name, char *control_file, int value_type); int check_fsmounted(int multimnt); diff --git a/tests/libcgrouptest01.c b/tests/libcgrouptest01.c index 333957b..5bd9dd5 100644 --- a/tests/libcgrouptest01.c +++ b/tests/libcgrouptest01.c @@ -1109,12 +1109,46 @@ static int group_modified(char *path_control_file, int value_type) } return 1; } +static int add_control_value(struct cgroup_controller *newcontroller, + char * control_file, char *wr, int value_type) +{ + int retval; + + switch (value_type) { + + case BOOL: + retval = cgroup_add_value_bool(newcontroller, + control_file, val_bool); + snprintf(wr, SIZE, "add_value_bool()"); + break; + case INT64: + retval = cgroup_add_value_int64(newcontroller, + control_file, val_int64); + snprintf(wr, SIZE, "add_value_int64()"); + break; + case UINT64: + retval = cgroup_add_value_uint64(newcontroller, + control_file, val_uint64); + snprintf(wr, SIZE, "add_value_uint64()"); + break; + case STRING: + retval = cgroup_add_value_string(newcontroller, + control_file, val_string); + snprintf(wr, SIZE, "add_value_string()"); + break; + default: + printf("ERROR: wrong value in add_control_value()\n"); + return 1; + break; + } + return retval; +} 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 */ + char wr[SIZE]; /* Names of wrapper apis */ struct cgroup *newcgroup; struct cgroup_controller *newcontroller; newcgroup = cgroup_new_cgroup(group); @@ -1130,33 +1164,8 @@ struct cgroup *new_cgroup(char *group, char *controller_name, newcontroller = cgroup_add_controller(newcgroup, controller_name); if (newcontroller) { - switch (value_type) { - - 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"); - return NULL; - break; - } + retval = add_control_value(newcontroller, + control_file, wr, value_type); if (!retval) { message(++i, PASS, "new_cgroup()", -- cgit