diff --git a/test/others/criu-ns/Makefile b/test/others/criu-ns/Makefile new file mode 100644 index 0000000000..d81733ef4d --- /dev/null +++ b/test/others/criu-ns/Makefile @@ -0,0 +1,2 @@ +run: + ../../zdtm_ct run.py diff --git a/test/others/criu-ns/run.py b/test/others/criu-ns/run.py new file mode 100755 index 0000000000..ec0f829b1f --- /dev/null +++ b/test/others/criu-ns/run.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python + +import os +import shutil +import signal +import subprocess +import sys + +CR_NS = "../../.././scripts/criu-ns" + +os.chdir(os.getcwd()) + + +def check_dumpdir(): + if os.access("dumpdir", os.X_OK): + shutil.rmtree("dumpdir") + os.mkdir("dumpdir", 0o755) + + +check_dumpdir() + +# dump with --shell-job +cmd = ["sleep", "inf"] +print("Run: %s" % " ".join(cmd)) +pid = subprocess.Popen(cmd).pid +cmd = [CR_NS, "dump", "-D", "dumpdir", "-v4", "-o", "dump.log", + "--shell-job", "-t", str(pid)] +ret = subprocess.Popen(cmd).wait() +if ret != 0: + os.kill(pid, signal.SIGTERM) + sys.exit(ret) + +# restore with --shell-job +cmd = [CR_NS, "restore", "-D", "dumpdir", "-v4", "-o", "restore.log", + "--shell-job"] +ret = subprocess.Popen(cmd).wait() +if ret != 0: + sys.exit(ret) + +check_dumpdir() + +# dump without --shell-job +cmd = ["setsid", "./test.sh"] +print("Run: %s" % " ".join(cmd)) +pid = subprocess.Popen(cmd, stdin=subprocess.DEVNULL, + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).pid +cmd = [CR_NS, "dump", "-D", "dumpdir", "-v4", "-o", "dump.log", + "-t", str(pid)] +ret = subprocess.Popen(cmd).wait() +if ret != 0: + os.kill(pid, signal.SIGTERM) + sys.exit(ret) + +# restore without --shell-job +cmd = [CR_NS, "restore", "-D", "dumpdir", "-v4", "-o", "restore.log"] +ret = subprocess.Popen(cmd).wait() +if ret != 0: + sys.exit(ret) + +check_dumpdir() + +# dump to test with --restore-detached +cmd = ["setsid", "./test.sh"] +print("Run: %s" % " ".join(cmd)) +pid = subprocess.Popen(cmd, stdin=subprocess.DEVNULL, + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).pid +cmd = [CR_NS, "dump", "-D", "dumpdir", "-v4", "-o", "dump.log", + "-t", str(pid)] +ret = subprocess.Popen(cmd).wait() +if ret != 0: + os.kill(pid, signal.SIGTERM) + sys.exit(ret) + +# restore with --restore-detached +cmd = [CR_NS, "restore", "-D", "dumpdir", "-v4", "-o", "restore.log", + "--restore-detached"] +ret = subprocess.Popen(cmd).wait() +if ret != 0: + sys.exit(ret) + +sys.exit(0) diff --git a/test/others/criu-ns/test.sh b/test/others/criu-ns/test.sh new file mode 100755 index 0000000000..25337d12ee --- /dev/null +++ b/test/others/criu-ns/test.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +while :; do + sleep 1 + date +done +EOF