[CRIU] [PATCH 2/2] tests: add a test for memory/devices "specialness"

Tycho Andersen tycho.andersen at canonical.com
Mon Sep 12 08:47:09 PDT 2016


v2: add cgroup04.hook which removes the cgroups in between, so things are
    actually restored :)

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
CC: Cyrill Gorcunov <gorcunov at openvz.org>
---
 test/zdtm/static/cgroup04.c    | 18 ++++++++++++++++++
 test/zdtm/static/cgroup04.hook | 15 +++++++++++++++
 2 files changed, 33 insertions(+)
 create mode 100755 test/zdtm/static/cgroup04.hook

diff --git a/test/zdtm/static/cgroup04.c b/test/zdtm/static/cgroup04.c
index 7fe601b..57dbb20 100644
--- a/test/zdtm/static/cgroup04.c
+++ b/test/zdtm/static/cgroup04.c
@@ -71,6 +71,9 @@ int mount_and_add(const char *controller, const char *path, const char *prop, co
 	if (write_value(paux, aux) < 0)
 		goto err_rs;
 
+	sprintf(paux, "%s/%s/special_prop_check", subdir, path);
+	mkdir(paux, 0600);
+
 	return 0;
 err_rs:
 	umount(dirname);
@@ -110,6 +113,7 @@ int main(int argc, char **argv)
 {
 	int ret = -1, i;
 	char buf[1024], path[PATH_MAX];
+	struct stat sb;
 
 	char *deny[] = {
 		"c *:* m",
@@ -161,9 +165,23 @@ int main(int argc, char **argv)
 		goto out;
 	}
 
+	sprintf(path, "%s/devices/%s/special_prop_check", dirname, cgname);
+	if (stat(path, &sb) < 0) {
+		fail("special_prop_check doesn't exist?");
+		goto out;
+	}
+
+	if (!S_ISDIR(sb.st_mode)) {
+		fail("special_prop_check not a directory?");
+		goto out;
+	}
+
 	pass();
 	ret = 0;
 out:
+	sprintf(path, "%s/devices/%s/special_prop_check", dirname, cgname);
+	rmdir(path);
+
 	sprintf(path, "%s/devices/%s", dirname, cgname);
 	rmdir(path);
 	sprintf(path, "%s/devices", dirname);
diff --git a/test/zdtm/static/cgroup04.hook b/test/zdtm/static/cgroup04.hook
new file mode 100755
index 0000000..f3eb616
--- /dev/null
+++ b/test/zdtm/static/cgroup04.hook
@@ -0,0 +1,15 @@
+#!/bin/bash
+
+[ "$1" == "--clean" -o "$1" == "--pre-restore" ] || exit 0
+
+tname=$(mktemp -d cgclean.XXXXXX)
+mount -t cgroup none $tname -o "devices"
+
+echo "Cleaning $tname"
+set +e
+rmdir "$tname/zdtmtst/special_prop_check"
+rmdir "$tname/zdtmtst"
+set -e
+
+umount "$tname"
+rmdir "$tname"
-- 
2.7.4



More information about the CRIU mailing list