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

Submitted by Tycho Andersen on Sept. 13, 2016, 12:52 a.m.

Details

Message ID 1473727961-14464-2-git-send-email-tycho.andersen@canonical.com
State Rejected
Series "Series without cover letter"
Headers show

Commit Message

Tycho Andersen Sept. 13, 2016, 12:52 a.m.
v2: add cgroup04.hook which removes the cgroups in between, so things are
    actually restored :)

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
CC: Cyrill Gorcunov <gorcunov@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

Patch hide | download patch | download mbox

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"

Comments

Cyrill Gorcunov Sept. 13, 2016, 2:11 p.m.
On Mon, Sep 12, 2016 at 06:52:41PM -0600, Tycho Andersen wrote:
> v2: add cgroup04.hook which removes the cgroups in between, so things are
>     actually restored :)
> 
> Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
> CC: Cyrill Gorcunov <gorcunov@openvz.org>
Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>