These test the introduced memory layer 2 APIs.

Signed-off-by: Dhaval Giani <[email protected]>

---
 tests/Makefile.am |    3 -
 tests/memory.c    |  120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 122 insertions(+), 1 deletion(-)

Index: libcg/tests/memory.c
===================================================================
--- /dev/null
+++ libcg/tests/memory.c
@@ -0,0 +1,120 @@
+/*
+ * Copyright IBM Corporation. 2010
+ *
+ * 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 MEMORY_LIMIT_A 102400  /* 100 MB */
+#define MEMORY_LIMIT_B 204800  /* 200 MB */
+
+#include <libcgroup.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+       struct cgroup *cgroup;
+       struct cgroup_controller *cgc;
+       int ret;
+       u_int64_t limit;
+
+       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, "memory");
+       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);
+       }
+
+       cgroup_free(&cgroup);
+
+       ret = cgroup_memory_set_limit("test", MEMORY_LIMIT_A);
+       if (ret) {
+               printf("FAIL: cgroup_memory_set_limit 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);
+       }
+
+       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, "memory");
+       if (!cgc) {
+               printf("FAIL: cgroup_get_controller failed\n");
+               exit(3);
+       }
+
+       ret = cgroup_get_value_uint64(cgc, "memory.limit_in_bytes", &limit);
+       if (ret) {
+               printf("FAIL: cgroup_get_value failed with %s\n",
+                                                       cgroup_strerror(ret));
+               exit(3);
+       }
+
+       if (limit == MEMORY_LIMIT_A) {
+               printf("PASS: cgroup_memory_set_limit\n");
+       } else {
+               printf("FAIL: cgroup_memory_set_limit\n");
+               exit(3);
+       }
+
+       cgroup_free(&cgroup);
+
+       limit = 0;
+
+       ret = cgroup_memory_get_limit("test", &limit);
+       if (ret) {
+               printf("FAIL: cgroup_memory_get_limit failed with %s\n",
+                                                       cgroup_strerror(ret));
+               exit(3);
+       }
+
+       if (limit != MEMORY_LIMIT_A) {
+               printf("FAIL: cgroup_memory_get_limit\n");
+               exit(3);
+       }
+
+       printf("PASS: cgroup_memory_get_limit\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 
cpu
+noinst_PROGRAMS = libcgrouptest01 libcg_ba setuid pathtest walk_test 
read_stats walk_task get_controller get_mount_point proctest get_all_controller 
cpu memory
 
 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.
 proctest_SOURCES=proctest.c
 get_all_controller_SOURCES=get_all_controller.c
 cpu_SOURCES=cpu.c
+memory_SOURCES=memory.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

Reply via email to