]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
libcgroup: Test the modified cgroup_init
authorDhaval Giani <dhaval.giani@gmail.com>
Mon, 17 May 2010 16:54:49 +0000 (18:54 +0200)
committerDhaval Giani <dhaval.giani@gmail.com>
Mon, 17 May 2010 21:50:15 +0000 (23:50 +0200)
Signed-off-by: Dhaval Giani <dhaval.giani@gmail.com>
tests/Makefile.am
tests/test_named_hierarchy.c [new file with mode: 0644]

index b4cb11ed2824e9cd98cc4ee86bdda1af1e5ae3ee..70a187ebded7029206a09d1441ff5cd3d2cde645 100644 (file)
@@ -2,7 +2,7 @@ INCLUDES = -I$(top_srcdir)/include
 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 get_variable_names
+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
 
 libcgrouptest01_SOURCES=libcgrouptest01.c test_functions.c libcgrouptest.h
 libcg_ba_SOURCES=libcg_ba.cpp
@@ -16,6 +16,7 @@ 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
+test_named_hierarchy_SOURCES=test_named_hierarchy.c
 
 EXTRA_DIST = pathtest.sh runlibcgrouptest.sh
 
diff --git a/tests/test_named_hierarchy.c b/tests/test_named_hierarchy.c
new file mode 100644 (file)
index 0000000..c9375ed
--- /dev/null
@@ -0,0 +1,45 @@
+#include <stdio.h>
+#include <libcgroup.h>
+
+/*
+ * Assumes cgroup is mounted at /cgroup using
+ *
+ * mount -t cgroup -o none,name=test none /cgroup
+ */
+int main()
+{
+       int ret;
+       struct cgroup *cgroup;
+       struct cgroup_controller *cgc;
+
+       ret = cgroup_init();
+       if (ret) {
+               printf("FAIL: cgroup_init failed with %s\n", cgroup_strerror(ret));
+               exit(3);
+       }
+
+       cgroup = cgroup_new_cgroup("test");
+       if (!cgroup) {
+               printf("FAIL: cgroup_new_cgroup failed\n");
+               exit(3);
+       }
+
+       cgc = cgroup_add_controller(cgroup, "name=test");
+       if (!cgc) {
+               printf("FAIL: cgroup_add_controller failed\n");
+               exit(3);
+       }
+
+       ret = cgroup_create_cgroup(cgroup, 1);
+       if (ret) {
+               printf("FAIL: cgroup_create_cgroup failed with %s\n", cgroup_strerror(ret));
+               exit(3);
+       }
+
+       if (access("/cgroup/test", F_OK))
+               printf("PASS\n");
+       else
+               printf("Failed to create cgroup\n");
+
+       return 0;
+}