]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
libcgroup: Test case for get_procs
authorDhaval Giani <dhaval.giani@gmail.com>
Tue, 27 Jul 2010 11:55:55 +0000 (13:55 +0200)
committerDhaval Giani <dhaval.giani@gmail.com>
Tue, 27 Jul 2010 11:55:55 +0000 (13:55 +0200)
Test for the get_procs API.

Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com>
tests/Makefile.am
tests/get_procs.c [new file with mode: 0644]

index faf19d19d6fe883ceed039aef056717801210944..5d273424bdc64dc4b89e80468610e0736f2bedd7 100644 (file)
@@ -2,7 +2,7 @@ INCLUDES = -I$(top_srcdir)/include
 LDADD = $(top_builddir)/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 get_variable_names test_named_hierarchy
+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 test_named_hierarchy get_procs
 
 libcgrouptest01_SOURCES=libcgrouptest01.c test_functions.c libcgrouptest.h
 libcg_ba_SOURCES=libcg_ba.cpp
@@ -17,6 +17,7 @@ proctest_SOURCES=proctest.c
 get_all_controller_SOURCES=get_all_controller.c
 get_variable_names_SOURCES=get_variable_names.c
 test_named_hierarchy_SOURCES=test_named_hierarchy.c
+get_procs_SOURCES=get_procs.c
 
 EXTRA_DIST = pathtest.sh runlibcgrouptest.sh
 
diff --git a/tests/get_procs.c b/tests/get_procs.c
new file mode 100644 (file)
index 0000000..424feeb
--- /dev/null
@@ -0,0 +1,37 @@
+#include <stdio.h>
+#include <libcgroup.h>
+#include <stdlib.h>
+
+/*
+ * Assumes the cgroup is already mounted at /cgroup/memory/a
+ *
+ * Assumes some processes are already in the cgroup
+ *
+ * Assumes it is the memory controller is mounted in at that
+ * point
+ */
+int main()
+{
+       int test;
+       int size;
+       pid_t *pids;
+       int ret;
+       int i;
+
+       ret = cgroup_init();
+       if (ret) {
+               printf("FAIL: cgroup_init failed with %s\n", cgroup_strerror(ret));
+               exit(3);
+       }
+
+       ret = cgroup_get_procs("a", "memory", &pids, &size);
+       if (ret) {
+               printf("FAIL: cgroup_get_procs failed with %s\n", cgroup_strerror(ret));
+               exit(3);
+       }
+
+       for (i = 0; i < size; i++)
+               printf("%u\n", pids[i]);
+
+       return 0;
+}