This is a test case to test the newly introduced CPU controller layer 2 APIs.
Signed-off-by: Dhaval Giani <[email protected]> Cc: Linus Walleij <[email protected]> --- tests/Makefile.am | 3 - tests/cpu.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 1 deletion(-) Index: libcg/tests/cpu.c =================================================================== --- /dev/null +++ libcg/tests/cpu.c @@ -0,0 +1,121 @@ +/* + * Copyright IBM Corporation. 2009 + * + * Author: Dhaval Giani <[email protected]> + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of version 2.1 of the GNU Lesser General Public License + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it would be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * + * Code initiated and designed by Dhaval Giani. All faults are most likely + * his mistake. + * + */ + +#define TEST_SHARES 4096 + +#include <libcgroup.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +int main() +{ + struct cgroup *cgroup; + struct cgroup_controller *cgc; + int ret; + u_int64_t shares; + + 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: unable to make a new structure\n"); + exit(3); + } + + cgc = cgroup_add_controller(cgroup, "cpu"); + if (!cgc) { + printf("FAIL: unable to creat controller data structure\n"); + exit(3); + } + + ret = cgroup_create_cgroup(cgroup, 1); + if (ret) { + printf("FAIL: unable to create cgroup with %s\n", + cgroup_strerror(ret)); + exit(3); + } + + cgroup_free(&cgroup); + + ret = cgroup_cpu_set_shares("test", TEST_SHARES); + if (ret) { + printf("FAIL: unable to set shares with %s\n", + cgroup_strerror(ret)); + exit(3); + } + + cgroup = cgroup_new_cgroup("test"); + if (!cgroup) { + printf("FAIL: unable to make a new structure\n"); + exit(3); + } + + ret = cgroup_get_cgroup(cgroup); + if (ret) { + printf("FAIL: cgroup_get_cgroup() failed with %s\n", + cgroup_strerror(ret)); + exit(3); + } + + cgc = cgroup_get_controller(cgroup, "cpu"); + if (!cgc) { + printf("FAIL: cgroup_get_controller failed\n"); + exit(3); + } + + ret = cgroup_get_value_uint64(cgc, "cpu.shares", &shares); + if (ret) { + printf("FAIL: cgroup_get_value failed with %s\n", + cgroup_strerror(ret)); + exit(3); + } + + if (shares == TEST_SHARES) { + printf("PASS: cgroup_cpu_set_shares\n"); + } else { + printf("FAIL: cgroup_cpu_set_shares\n"); + exit(3); + } + + cgroup_free(&cgroup); + + shares = 0; + + ret = cgroup_cpu_get_shares("test", &shares); + if (ret) { + printf("FAIL: unable to get shares with %s\n", + cgroup_strerror(ret)); + exit(3); + } + + if (shares != TEST_SHARES) { + printf("FAIL: cgroup_cpu_get_shares failed\n"); + exit(3); + } + + printf("PASS: cgroup_cpu_get_shares\n"); + + return 0; +} Index: libcg/tests/Makefile.am =================================================================== --- libcg.orig/tests/Makefile.am +++ libcg/tests/Makefile.am @@ -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 +noinst_PROGRAMS = libcgrouptest01 libcg_ba setuid pathtest walk_test read_stats walk_task get_controller get_mount_point proctest get_all_controller cpu 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 +cpu_SOURCES=cpu.c EXTRA_DIST = pathtest.sh runlibcgrouptest.sh ------------------------------------------------------------------------------ This SF.Net email is sponsored by the Verizon Developer Community Take advantage of Verizon's best-in-class app development support A streamlined, 14 day to market process makes app distribution fast and easy Join now and get one step closer to millions of Verizon customers http://p.sf.net/sfu/verizon-dev2dev _______________________________________________ Libcg-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/libcg-devel
