Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/checkpoint-restore/criu.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMichał Cłapiński <mclapinski@google.com>2019-08-14 22:13:34 +0300
committerAndrei Vagin <avagin@gmail.com>2020-02-04 23:37:37 +0300
commitcf0080505ac3b3194f664d77edccccfa47bf450a (patch)
tree1122aeb8c8344ee2c238998ce1db1b87f67b32c8 /test
parent2f337652ad5c40f7a420fdd9a7c57767af4ba8a0 (diff)
test: implement test for new --cgroup-yard option
Signed-off-by: Michał Cłapiński <mclapinski@google.com>
Diffstat (limited to 'test')
-rwxr-xr-xtest/zdtm.py4
-rw-r--r--test/zdtm/static/Makefile3
l---------test/zdtm/static/cgroup_yard.c1
-rw-r--r--test/zdtm/static/cgroup_yard.desc7
-rwxr-xr-xtest/zdtm/static/cgroup_yard.hook70
5 files changed, 82 insertions, 3 deletions
diff --git a/test/zdtm.py b/test/zdtm.py
index 0153c6058..f0a102413 100755
--- a/test/zdtm.py
+++ b/test/zdtm.py
@@ -2018,7 +2018,7 @@ def print_sep(title, sep="=", width=80):
def print_error(line):
line = line.rstrip()
- print(line)
+ print(line.encode('utf-8'))
if line.endswith('>'): # combine pie output
return True
return False
@@ -2028,7 +2028,7 @@ def grep_errors(fname):
first = True
print_next = False
before = []
- with open(fname) as fd:
+ with open(fname, errors='replace') as fd:
for l in fd:
before.append(l)
if len(before) > 5:
diff --git a/test/zdtm/static/Makefile b/test/zdtm/static/Makefile
index d8279d6f8..a38482f44 100644
--- a/test/zdtm/static/Makefile
+++ b/test/zdtm/static/Makefile
@@ -319,7 +319,8 @@ TST_DIR = \
cgroup03 \
cgroup04 \
cgroup_ifpriomap \
- cgroup_stray \
+ cgroup_stray \
+ cgroup_yard \
unlink_fstat04 \
unlink_fstat041 \
mntns_remap \
diff --git a/test/zdtm/static/cgroup_yard.c b/test/zdtm/static/cgroup_yard.c
new file mode 120000
index 000000000..f3683c2b4
--- /dev/null
+++ b/test/zdtm/static/cgroup_yard.c
@@ -0,0 +1 @@
+cgroup00.c \ No newline at end of file
diff --git a/test/zdtm/static/cgroup_yard.desc b/test/zdtm/static/cgroup_yard.desc
new file mode 100644
index 000000000..8736d6780
--- /dev/null
+++ b/test/zdtm/static/cgroup_yard.desc
@@ -0,0 +1,7 @@
+{
+'flavor': 'h',
+'flags': 'suid',
+# We create the external cgroup yard in working directory during --pre-dump
+# hook. We have to go up a few directories to find the yard.
+'opts': '--manage-cgroups --cgroup-yard ../../../../../../external_yard'
+}
diff --git a/test/zdtm/static/cgroup_yard.hook b/test/zdtm/static/cgroup_yard.hook
new file mode 100755
index 000000000..7ae53342c
--- /dev/null
+++ b/test/zdtm/static/cgroup_yard.hook
@@ -0,0 +1,70 @@
+#!/usr/bin/env python
+
+import sys
+import os
+import subprocess
+import tempfile
+
+yard = "external_yard"
+
+if sys.argv[1] == "--pre-dump":
+ '''
+ Create external cgroup yard to be passed to CRIU via --cgroup-yard
+ '''
+ os.mkdir(yard)
+ with open("/proc/self/cgroup") as f:
+ for line in f:
+ cgr = line.split(":")[1]
+
+ if cgr == "":
+ continue
+
+ if cgr.startswith("name="):
+ ctrl = cgr[len("name="):]
+ opts = "none," + cgr
+ else:
+ ctrl = cgr
+ opts = cgr
+
+ os.mkdir(yard + "/" + ctrl)
+ subprocess.check_call(["mount", "-t", "cgroup", "none", yard + "/" + ctrl, "-o", opts])
+
+if sys.argv[1] == "--post-restore":
+ '''
+ Clean up the cgroup yard created during `--pre-dump`
+ '''
+ with open("/proc/self/cgroup") as f:
+ for line in f:
+ cgr = line.split(":")[1]
+
+ if cgr == "":
+ continue
+
+ if cgr.startswith("name="):
+ ctrl = cgr[len("name="):]
+ else:
+ ctrl = cgr
+
+ subprocess.check_call(["umount", yard + "/" + ctrl])
+ os.rmdir(yard + "/" + ctrl)
+ os.rmdir(yard)
+
+if sys.argv[1] in ["--pre-restore", "--clean"]:
+ '''
+ Clean up the leftover cgroups created by the test
+ '''
+ tname = tempfile.mkdtemp()
+ subprocess.call(["mount", "-t", "cgroup", "none", tname, "-o", "none,name=zdtmtst"])
+
+ try:
+ os.rmdir(os.path.join(tname, "subcg00", "subsubcg"))
+ except:
+ pass
+
+ try:
+ os.rmdir(os.path.join(tname, "subcg00"))
+ except:
+ pass
+
+ subprocess.call(["umount", tname])
+ os.rmdir(tname)