]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
This is the test program for listing controller variables
authorIvana Hutarova Varekova <varekova@redhat.com>
Mon, 8 Feb 2010 12:31:56 +0000 (13:31 +0100)
committerBalbir Singh <balbir@linux.vnet.ibm.com>
Wed, 10 Feb 2010 11:13:36 +0000 (16:43 +0530)
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>
tests/Makefile.am
tests/get_variable_names.c [new file with mode: 0644]

index b88688b35f3e13087c78ad9c1f8651291724a40a..b4cb11ed2824e9cd98cc4ee86bdda1af1e5ae3ee 100644 (file)
@@ -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 (file)
index 0000000..dc2ef14
--- /dev/null
@@ -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;
+}