From: Dhaval Giani Date: Mon, 17 May 2010 16:54:49 +0000 (+0200) Subject: libcgroup: Test the modified cgroup_init X-Git-Tag: v0.36~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3b9a5dc51702b918a46766cf81bba0052be07054;p=thirdparty%2Flibcgroup.git libcgroup: Test the modified cgroup_init Signed-off-by: Dhaval Giani --- diff --git a/tests/Makefile.am b/tests/Makefile.am index b4cb11ed..70a187eb 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 00000000..c9375ed4 --- /dev/null +++ b/tests/test_named_hierarchy.c @@ -0,0 +1,45 @@ +#include +#include + +/* + * 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; +}