-
Notifications
You must be signed in to change notification settings - Fork 614
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
criu-ns: Add tests for criu-ns script (WIP)
These changes add test implementations for criu-ns script. Fixes: #1909 Signed-off-by: Dhanuka Warusadura <csx@tuta.io>
- Loading branch information
1 parent
e663060
commit dad0b7b
Showing
4 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
run: | ||
../../zdtm_ct run.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#!/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.path.isdir("dumpdir"): | ||
shutil.rmtree("dumpdir") | ||
os.mkdir("dumpdir", 0o755) | ||
|
||
|
||
def test_dump_and_restore_with_shell_job(): | ||
check_dumpdir() | ||
|
||
pid = os.fork() | ||
if pid == 0: | ||
# no need to setsid() since we'are passing --shell-job | ||
cmd = ["sleep", "inf"] | ||
print("Run: %s" % " ".join(cmd)) | ||
ret = subprocess.Popen(cmd).wait() | ||
|
||
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) | ||
|
||
pid = os.fork() | ||
if pid == 0: | ||
cmd = [CR_NS, "restore", "-D", "dumpdir", "-v4", "-o", "restore.log", | ||
"--shell-job"] | ||
ret = subprocess.Popen(cmd).wait() | ||
if ret != 0: | ||
os._exit(1) | ||
|
||
os.waitpid(pid, 0) | ||
|
||
|
||
def test_dump_and_restore_without_shell_job(): | ||
check_dumpdir() | ||
|
||
pid = os.fork() | ||
if pid == 0: | ||
os.setsid() | ||
cmd = ["./test.sh"] | ||
print("Run: %s" % " ".join(cmd)) | ||
ret = subprocess.Popen(cmd, stdin=subprocess.DEVNULL, | ||
stdout=subprocess.DEVNULL, | ||
stderr=subprocess.DEVNULL).wait() | ||
|
||
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) | ||
|
||
pid = os.fork() | ||
if pid == 0: | ||
os.setsid() | ||
cmd = [CR_NS, "restore", "-D", "dumpdir", "-v4", "-o", "restore.log"] | ||
ret = subprocess.Popen(cmd).wait() | ||
if ret != 0: | ||
os._exit(ret) | ||
|
||
os.waitpid(pid, 0) | ||
|
||
|
||
def test_dump_and_restore_with_restore_detached(): | ||
check_dumpdir() | ||
|
||
pid = os.fork() | ||
if pid == 0: | ||
os.setsid() | ||
cmd = ["./test.sh"] | ||
print("Run: %s" % " ".join(cmd)) | ||
ret = subprocess.Popen(cmd, stdin=subprocess.DEVNULL, | ||
stdout=subprocess.DEVNULL, | ||
stderr=subprocess.DEVNULL).wait() | ||
|
||
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) | ||
|
||
pid = os.fork() | ||
if pid == 0: | ||
os.setsid() | ||
cmd = [CR_NS, "restore", "-D", "dumpdir", "-v4", "-o", "restore.log", | ||
"--restore-detached"] | ||
ret = subprocess.Popen(cmd).wait() | ||
if ret != 0: | ||
os._exit(ret) | ||
|
||
os.waitpid(pid, 0) | ||
|
||
|
||
if __name__ == "__main__": | ||
test_dump_and_restore_with_shell_job() | ||
test_dump_and_restore_without_shell_job() | ||
test_dump_and_restore_with_restore_detached() | ||
sys.exit(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/bin/sh | ||
|
||
while :; do | ||
sleep 1 | ||
date | ||
done | ||
EOF |