diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile | 6 | ||||
-rw-r--r-- | tests/pathtest.c | 40 | ||||
-rwxr-xr-x | tests/pathtest.sh | 12 |
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 |