[CRIU] [PATCH 7/7] zdtm: Stupid test for task-in-cgroup
Pavel Emelyanov
xemul at parallels.com
Thu May 8 06:09:13 PDT 2014
Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
test/zdtm.sh | 2 +
test/zdtm/live/static/Makefile | 1 +
test/zdtm/live/static/cgroup00.c | 94 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 97 insertions(+)
create mode 100644 test/zdtm/live/static/cgroup00.c
diff --git a/test/zdtm.sh b/test/zdtm.sh
index 4de131d..472c51d 100755
--- a/test/zdtm.sh
+++ b/test/zdtm.sh
@@ -105,6 +105,7 @@ static/chroot
static/chroot-file
static/rtc
transition/maps007
+static/cgroup00
"
# Duplicate list with ns/ prefix
TEST_LIST=$TEST_LIST$(echo $TEST_LIST | tr ' ' '\n' | sed 's#^#ns/#')
@@ -164,6 +165,7 @@ tempfs
bind-mount
mountpoints
inotify_irmap
+cgroup00
"
source $(readlink -f `dirname $0`/env.sh) || exit 1
diff --git a/test/zdtm/live/static/Makefile b/test/zdtm/live/static/Makefile
index b0f7807..8745dff 100644
--- a/test/zdtm/live/static/Makefile
+++ b/test/zdtm/live/static/Makefile
@@ -151,6 +151,7 @@ TST_DIR = \
overmount_sock \
tempfs \
bind-mount \
+ cgroup00 \
TST_DIR_FILE = \
chroot \
diff --git a/test/zdtm/live/static/cgroup00.c b/test/zdtm/live/static/cgroup00.c
new file mode 100644
index 0000000..e9669af
--- /dev/null
+++ b/test/zdtm/live/static/cgroup00.c
@@ -0,0 +1,94 @@
+#include <unistd.h>
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/mount.h>
+#include "zdtmtst.h"
+
+const char *test_doc = "Check that cgroups layout is preserved";
+const char *test_author = "Pavel Emelianov <xemul at parallels.com>";
+
+char *dirname;
+TEST_OPTION(dirname, string, "cgroup directory name", 1);
+static const char *cgname = "zdtmtst";
+static const char *subname = "subcg";
+
+int main(int argc, char **argv)
+{
+ int cgfd, l, ret = 1;
+ char aux[32], paux[1024];
+ FILE *cgf;
+
+ test_init(argc, argv);
+
+ if (mkdir(dirname, 0700) < 0) {
+ err("Can't make dir");
+ goto out;
+ }
+
+ sprintf(aux, "none,name=%s", cgname);
+ if (mount("none", dirname, "cgroup", 0, aux)) {
+ err("Can't mount cgroups");
+ goto out_rd;
+ }
+
+ sprintf(paux, "%s/%s", dirname, subname);
+ mkdir(paux, 0600);
+
+ l = sprintf(aux, "%d", getpid());
+ sprintf(paux, "%s/%s/tasks", dirname, subname);
+
+ cgfd = open(paux, O_WRONLY);
+ if (cgfd < 0) {
+ err("Can't open tasks");
+ goto out_rs;
+ }
+
+ l = write(cgfd, aux, l);
+ close(cgfd);
+
+ if (l < 0) {
+ err("Can't move self to subcg");
+ goto out_rs;
+ }
+
+ close(cgfd);
+
+ test_daemon();
+ test_waitsig();
+
+ cgf = fopen("/proc/self/cgroup", "r");
+ if (cgf == NULL) {
+ fail("No cgroups file");
+ goto out_rs;
+ }
+
+ sprintf(aux, "name=%s:/%s\n", cgname, subname);
+ while (fgets(paux, sizeof(paux), cgf)) {
+ char *s;
+
+ s = strchr(paux, ':') + 1;
+ test_msg("CMP [%s] vs [%s]\n", s, aux);
+ if (!strcmp(s, aux)) {
+ ret = 0;
+ break;
+ }
+ }
+
+ fclose(cgf);
+
+ if (!ret)
+ pass();
+ else
+ fail("Task is not in subgroups");
+
+out_rs:
+ sprintf(paux, "%s/%s", dirname, subname);
+ rmdir(paux);
+ umount(dirname);
+out_rd:
+ rmdir(dirname);
+out:
+ return ret;
+}
--
1.8.4.2
More information about the CRIU
mailing list