Skip to content

Commit

Permalink
criu-ns: Add tests for criu-ns script (WIP)
Browse files Browse the repository at this point in the history
These changes add test implementations for criu-ns script.

Fixes: #1909

Signed-off-by: Dhanuka Warusadura <csx@tuta.io>
  • Loading branch information
warusadura committed Mar 14, 2023
1 parent e663060 commit dad0b7b
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
1 change: 1 addition & 0 deletions scripts/ci/run-ci-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ if [ -n "$TRAVIS" ] || [ -n "$CIRCLECI" ]; then
# GitHub Actions (and Cirrus CI) does not provide a real TTY and CRIU will fail with:
# Error (criu/tty.c:1014): tty: Don't have tty to inherit session from, aborting
make -C test/others/shell-job/ run
make -C test/others/criu-ns/ run
fi
make -C test/others/skip-file-rwx-check/ run
make -C test/others/rpc/ run
Expand Down
2 changes: 2 additions & 0 deletions test/others/criu-ns/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
run:
../../zdtm_ct run.py
113 changes: 113 additions & 0 deletions test/others/criu-ns/run.py
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)
7 changes: 7 additions & 0 deletions test/others/criu-ns/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

while :; do
sleep 1
date
done
EOF

0 comments on commit dad0b7b

Please sign in to comment.