summaryrefslogtreecommitdiffstats
path: root/tests/libcgrouptest.h
diff options
context:
space:
mode:
authorDhaval Giani <dhaval@linux.vnet.ibm.com>2009-01-09 10:19:02 +0000
committerDhaval Giani <dhaval@linux.vnet.ibm.com>2009-01-09 10:19:02 +0000
commita6fd09eca79d1626bba110fb2dc77c00a8eddf24 (patch)
treec39945327b1569d4723be8688693978023f04867 /tests/libcgrouptest.h
parent16dec13a18c4fae5c7cf6441f75bfa354151f1b4 (diff)
downloadlibcg-a6fd09eca79d1626bba110fb2dc77c00a8eddf24.tar.gz
libcg-a6fd09eca79d1626bba110fb2dc77c00a8eddf24.tar.xz
libcg-a6fd09eca79d1626bba110fb2dc77c00a8eddf24.zip
libcgrouptest: Avoid external variables usage
From: Sudhir Kumar <skumar@linux.vnet.ibm.com> A lack of proper initial thought let me use some variables globaly, which is not a good idea at all. However fixing this issue at this stage is not very good from the point that it changes variables for a lot of functions. But still it has to be done for a better and reusable code. This patch does that while putting related variables in meaningful structs. Thanks to Balbir for a good suggestion. TODO: Fill these data structures from a configuration file after analyzing requirements from different test functions. Signed-off-by: Sudhir Kumar <skumar@linux.vnet.ibm.com> Acked-by: Balbir Singh <balbir@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@307 4f4bb910-9a46-0410-90c8-c897d4f1cd53
Diffstat (limited to 'tests/libcgrouptest.h')
-rw-r--r--tests/libcgrouptest.h54
1 files changed, 32 insertions, 22 deletions
diff --git a/tests/libcgrouptest.h b/tests/libcgrouptest.h
index eee6e62..b436568 100644
--- a/tests/libcgrouptest.h
+++ b/tests/libcgrouptest.h
@@ -34,8 +34,6 @@
#define PASS 1 /* test passed */
#define FAIL 0 /* test failed */
-int cpu = 0, memory = 0;
-
enum cgroup_mount_t {
FS_NOT_MOUNTED,
FS_MOUNTED,
@@ -78,26 +76,36 @@ enum info_message_t {
NOMESSAGE,
};
+/* Keep a single struct of all ids */
+struct uid_gid_t {
+ uid_t control_uid;
+ gid_t control_gid;
+ uid_t tasks_uid;
+ gid_t tasks_gid;
+};
+
+/* Keep a single struct of all control values */
+struct cntl_val_t {
+ int64_t val_int64;
+ u_int64_t val_uint64;
+ bool val_bool;
+ /* size worth of 100 digit num is fair enough */
+ char val_string[100]; /* string value of control parameter */
+};
+
+extern int cpu, memory;
+
/* The set of verbose messages useful to the user */
extern char info[NUM_MSGS][SIZE];
-int64_t val_int64;
-u_int64_t val_uint64;
-bool val_bool;
-/* Doubt: size of following string. is'nt this wrong ?*/
-char val_string[FILENAME_MAX]; /* string value of control parameter */
-uid_t control_uid;
-gid_t control_gid;
-uid_t tasks_uid;
-gid_t tasks_gid;
/* this variable is never modified */
-int fs_mounted;
-
-/* The mountpoints as received from script */
-char mountpoint[FILENAME_MAX], mountpoint2[FILENAME_MAX];
+extern int fs_mounted;
-/* No extra message unless specified */
-char extra[SIZE] = "\n";
+/* The mountpoints as received from script
+ * We use mountpoint for single mount.
+ * For multimount we use mountpoint and mountpoint2.
+ */
+extern char mountpoint[], mountpoint2[];
/* Functions to test each API */
void test_cgroup_init(int retcode, int i);
@@ -105,7 +113,7 @@ void test_cgroup_attach_task(int retcode, struct cgroup *cgroup1,
const char *group1, const char *group2,
int k, int i);
struct cgroup *create_new_cgroup_ds(int ctl, const char *grpname,
- int value_type, int i);
+ int value_type, struct cntl_val_t cval, struct uid_gid_t ids, int i);
void test_cgroup_create_cgroup(int retcode, struct cgroup *cgrp,
const char *name, int common, int mpnt, int ign, int i);
void test_cgroup_delete_cgroup(int retcode, struct cgroup *cgrp,
@@ -113,7 +121,7 @@ void test_cgroup_delete_cgroup(int retcode, struct cgroup *cgrp,
void test_cgroup_modify_cgroup(int retcode, struct cgroup *cgrp,
const char *name, int which_ctl, int ctl1, int ctl2,
int value_type, int i);
-void test_cgroup_get_cgroup(int ctl1, int ctl2, int i);
+void test_cgroup_get_cgroup(int ctl1, int ctl2, struct uid_gid_t ids, int i);
/* API test functions end here */
void test_cgroup_compare_cgroup(int ctl1, int ctl2, int i);
@@ -122,11 +130,13 @@ void get_controllers(const char *name, int *exist);
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 group_modified(char *path_control_file, int value_type,
+ struct cntl_val_t cval);
static int add_control_value(struct cgroup_controller *newcontroller,
- char * control_file, char *wr, int value_type);
+ char *control_file, char *wr, int value_type, struct cntl_val_t cval);
struct cgroup *new_cgroup(char *group, char *controller_name,
- char *control_file, int value_type, int i);
+ char *control_file, int value_type, struct cntl_val_t cval,
+ struct uid_gid_t ids, int i);
int check_fsmounted(int multimnt);
static int check_task(char *tasksfile);
/* function to print messages in better format */