summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIvana Hutarova Varekova <varekova@redhat.com>2010-02-08 13:31:56 +0100
committerBalbir Singh <balbir@linux.vnet.ibm.com>2010-02-10 16:43:36 +0530
commit3b85cd32d20b674325114f045cf972fb07a29079 (patch)
treef9c9f0840e5068c489a6fd1ae25a78849bbc2e62
parent49f97cacb816379f629625cf23beb94729a4bbdb (diff)
downloadlibcg-3b85cd32d20b674325114f045cf972fb07a29079.tar.gz
libcg-3b85cd32d20b674325114f045cf972fb07a29079.tar.xz
libcg-3b85cd32d20b674325114f045cf972fb07a29079.zip
This is the test program for listing controller variables
This is the test program for new internal functions: int cgroup_get_value_name_count(struct cgroup_controller *controller) char *cgroup_get_value_name(struct cgroup_controller *controller, int index) The program display the variables of input controllers. Signed-off-by: Ivana Hutarova Varekova <varekova@redhat.com> Signed-off-by: Balbir Singh <balbir@linux.vnet.ibm.com>
-rw-r--r--tests/Makefile.am5
-rw-r--r--tests/get_variable_names.c59
2 files changed, 62 insertions, 2 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b88688b..b4cb11e 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,8 +1,8 @@
INCLUDES = -I$(top_srcdir)/include
-LDADD = $(top_builddir)/src/.libs/libcgroup.la
+LDADD = $(top_srcdir)/src/.libs/libcgroup.la
# compile the tests, but do not install them
-noinst_PROGRAMS = libcgrouptest01 libcg_ba setuid pathtest walk_test read_stats walk_task get_controller get_mount_point proctest get_all_controller
+noinst_PROGRAMS = libcgrouptest01 libcg_ba setuid pathtest walk_test read_stats walk_task get_controller get_mount_point proctest get_all_controller get_variable_names
libcgrouptest01_SOURCES=libcgrouptest01.c test_functions.c libcgrouptest.h
libcg_ba_SOURCES=libcg_ba.cpp
@@ -15,6 +15,7 @@ get_controller_SOURCES=get_controller.c
get_mount_point_SOURCES=get_mount_point.c
proctest_SOURCES=proctest.c
get_all_controller_SOURCES=get_all_controller.c
+get_variable_names_SOURCES=get_variable_names.c
EXTRA_DIST = pathtest.sh runlibcgrouptest.sh
diff --git a/tests/get_variable_names.c b/tests/get_variable_names.c
new file mode 100644
index 0000000..dc2ef14
--- /dev/null
+++ b/tests/get_variable_names.c
@@ -0,0 +1,59 @@
+#include <libcgroup.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "../src/libcgroup-internal.h"
+
+int main(int argc, char *argv[])
+{
+ int ret;
+ int i, j;
+ int count;
+ char *name;
+ struct cgroup_controller *group_controller = NULL;
+ struct cgroup *group = NULL;
+ char group_name[] = "/";
+
+ if (argc < 2) {
+ printf("no list of groups provided\n");
+ return -1;
+ }
+
+ ret = cgroup_init();
+
+ if (ret) {
+ printf("cgroup_init failed with %s\n", cgroup_strerror(ret));
+ exit(1);
+ }
+
+ group = cgroup_new_cgroup(group_name);
+ if (group == NULL) {
+ printf("cannot create group '%s'\n", group_name);
+ return -1;
+ }
+
+ ret = cgroup_get_cgroup(group);
+ if (ret != 0) {
+ printf("cannot read group '%s': %s\n",
+ group_name, cgroup_strerror(ret));
+ }
+
+ for (i = 1; i < argc; i++) {
+
+ group_controller = cgroup_get_controller(group, argv[i]);
+ if (group_controller == NULL) {
+ printf("cannot find controller "\
+ "'%s' in group '%s'\n", argv[i], group_name);
+ ret = -1;
+ continue;
+ }
+ count = cgroup_get_value_name_count(group_controller);
+ for (j = 0; j < count; j++) {
+ name = cgroup_get_value_name(group_controller, j);
+ if (name != NULL)
+ printf("%s \n", name);
+ }
+ }
+
+ return ret;
+}