From 1487373aa2e870950b1a9f4c1ce748d91e1547a5 Mon Sep 17 00:00:00 2001 From: Thomas Orozco Date: Thu, 19 Apr 2018 16:58:00 +0200 Subject: [PATCH] Exercise pdeathsignal in tests See: https://github.com/krallin/tini/pull/114#issuecomment-382756277 --- test/pdeathsignal/stage_1.py | 30 ++++++++++++++++++++++++++++++ test/pdeathsignal/stage_2.py | 25 +++++++++++++++++++++++++ test/run_inner_tests.py | 18 +++++++++++++++++- 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100755 test/pdeathsignal/stage_1.py create mode 100755 test/pdeathsignal/stage_2.py diff --git a/test/pdeathsignal/stage_1.py b/test/pdeathsignal/stage_1.py new file mode 100755 index 0000000..60dd463 --- /dev/null +++ b/test/pdeathsignal/stage_1.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +from __future__ import print_function + +import os +import sys +import subprocess + + +def main(): + pid = os.getpid() + + tini = sys.argv[1] + ret = sys.argv[2] + stage_2 = os.path.join(os.path.dirname(__file__), "stage_2.py") + + cmd = [ + tini, + "-vvv", + "-p", + "SIGUSR1", + "--", + stage_2, + str(pid), + ret + ] + + subprocess.Popen(cmd).wait() + +if __name__ == "__main__": + main() diff --git a/test/pdeathsignal/stage_2.py b/test/pdeathsignal/stage_2.py new file mode 100755 index 0000000..43eb537 --- /dev/null +++ b/test/pdeathsignal/stage_2.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +from __future__ import print_function + +import os +import sys +import signal +import time + + +def main(): + ret = sys.argv[2] + + def handler(*args): + with open(ret, "w") as f: + f.write("ok") + sys.exit(0) + + signal.signal(signal.SIGUSR1, handler) + pid = int(sys.argv[1]) + + os.kill(pid, signal.SIGKILL) + time.sleep(5) + +if __name__ == "__main__": + main() diff --git a/test/run_inner_tests.py b/test/run_inner_tests.py index 47e1a10..4468797 100755 --- a/test/run_inner_tests.py +++ b/test/run_inner_tests.py @@ -9,6 +9,7 @@ import psutil import bitmap import re import itertools +import tempfile DEVNULL = open(os.devnull, 'wb') @@ -133,7 +134,7 @@ def main(): assert ret == 1, "Reaping test succeeded (it should have failed)!" # Test that the signals are properly in place here. - print "running signal configuration test" + print "Running signal configuration test" p = subprocess.Popen([os.path.join(build, "sigconf-test"), tini, "cat", "/proc/self/status"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() @@ -156,6 +157,21 @@ def main(): # Use signum - 1 because the bitmap is 0-indexed but represents signals strting at 1 assert (signum - 1) in props[signal_set_name].nonzero(), "{0} ({1}) is missing in {2}!".format(SIGNUM_TO_SIGNAME[signum], signum, signal_set_name) + # Test parent death signal handling. + if not args_disabled: + print "Running parent death signal test" + f = tempfile.NamedTemporaryFile() + try: + p = subprocess.Popen( + [os.path.join(src, "test", "pdeathsignal", "stage_1.py"), tini, f.name], + stdout=DEVNULL, stderr=DEVNULL + ) + p.wait() + + busy_wait(lambda: open(f.name).read() == "ok", 10) + finally: + f.close() + print "---------------------------" print "All done, tests as expected" print "---------------------------"