summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBalbir Singh <balbir@linux.vnet.ibm.com>2008-09-29 12:09:04 +0000
committerBalbir Singh <balbir@linux.vnet.ibm.com>2008-09-29 12:09:04 +0000
commit1d00fc725ba26db40b2c792c75888c2ed777730d (patch)
treecb9343430b0647e6c398c8d323661af22dd6f752 /tests
parent35d2e11a0458a79c89816a2f0be6fb957f91873e (diff)
downloadlibcg-1d00fc725ba26db40b2c792c75888c2ed777730d.tar.gz
libcg-1d00fc725ba26db40b2c792c75888c2ed777730d.tar.xz
libcg-1d00fc725ba26db40b2c792c75888c2ed777730d.zip
The automatic classification engine (cgexec, cgclassify, pam_cgroup)
classify tasks. It is useful for an application to know where it has been classified. I propose to add a new API cgroup_get_current_controller_path() that returns the current classification directory for the specified controller. One can easily add on and build new API that will return paths of all mounted controllers, but I want to start with something simple and useful. I've also added a bunch of test cases for the same purpose. Test output # ./pathtest.sh Test FAIL, get path failed for controller cpuset Test PASS, controller cpu path /default Test PASS, controller cpuacct path /default Test PASS, controller memory path /default Test FAIL, get path failed for controller memrlimit I mounted just cpu, cpuacct and memory, thus the path for cpuset and memrlimit could not be found (as expected). Signed-off-by: Balbir Singh <balbir@linux.vnet.ibm.com> Reviewed-by: Dhaval Giani <dhaval@linux.vnet.ibm.com> git-svn-id: https://libcg.svn.sourceforge.net/svnroot/libcg/trunk@200 4f4bb910-9a46-0410-90c8-c897d4f1cd53
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile6
-rw-r--r--tests/pathtest.c40
-rwxr-xr-xtests/pathtest.sh12
3 files changed, 57 insertions, 1 deletions
diff --git a/tests/Makefile b/tests/Makefile
index 7a38b7a..5c602cb 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -6,7 +6,8 @@ CFLAGS = -g -O2 -Wall -DDEBUG
TARGET= libcgrouptest01 \
libcg_ba \
- setuid
+ setuid \
+ pathtest
all: $(TARGET)
@@ -19,5 +20,8 @@ libcg_ba: libcg_ba.cpp
setuid: setuid.c
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) $(LIBS)
+pathtest: pathtest.c
+ $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) $(LIBS)
+
clean:
\rm -f $(TARGET)
diff --git a/tests/pathtest.c b/tests/pathtest.c
new file mode 100644
index 0000000..076c38a
--- /dev/null
+++ b/tests/pathtest.c
@@ -0,0 +1,40 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <string.h>
+#include <libcgroup.h>
+
+int main(int argc, char *argv[])
+{
+ char *path;
+ char *expected_path, *controller;
+ int ret;
+
+ if (argc < 2) {
+ fprintf(stderr, "Usage %s: <controller name> <path>\n",
+ argv[0]);
+ exit(EXIT_FAILURE);
+ }
+
+ controller = argv[1];
+ expected_path = argv[2];
+
+ cgroup_init();
+
+ ret = cgroup_get_current_controller_path(getpid(), controller, &path);
+ if (ret)
+ printf("Test FAIL, get path failed for controller %s\n",
+ controller);
+ else {
+ if (strcmp(path, expected_path))
+ printf("Test FAIL, expected_path %s, got path %s\n",
+ expected_path, path);
+ else
+ printf("Test PASS, controller %s path %s\n",
+ controller, path);
+ free(path);
+ }
+
+ return EXIT_SUCCESS;
+}
diff --git a/tests/pathtest.sh b/tests/pathtest.sh
new file mode 100755
index 0000000..b373389
--- /dev/null
+++ b/tests/pathtest.sh
@@ -0,0 +1,12 @@
+#!/bin/bash
+
+while read name extra
+do
+ echo $name | grep -q '^#'
+ if [ $? -eq 0 ]
+ then
+ continue
+ fi
+ path=`cat /proc/$$/cgroup | cut -d ':' -f 3`
+ ./pathtest $name $path
+done < /proc/cgroups