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 13, 2023
1 parent e663060 commit a88fa8d
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
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
81 changes: 81 additions & 0 deletions test/others/criu-ns/run.py
Original file line number Diff line number Diff line change
@@ -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)
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 a88fa8d

Please sign in to comment.