Skip to content
This repository was archived by the owner on Feb 20, 2021. It is now read-only.

Commit fabc548

Browse files
krallinsolarkennedy
authored andcommitted
Exercise pdeathsignal in tests
See: krallin#114 (comment)
1 parent 396464c commit fabc548

3 files changed

Lines changed: 72 additions & 1 deletion

File tree

test/pdeathsignal/stage_1.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python
2+
from __future__ import print_function
3+
4+
import os
5+
import sys
6+
import subprocess
7+
8+
9+
def main():
10+
pid = os.getpid()
11+
12+
tini = sys.argv[1]
13+
ret = sys.argv[2]
14+
stage_2 = os.path.join(os.path.dirname(__file__), "stage_2.py")
15+
16+
cmd = [
17+
tini,
18+
"-vvv",
19+
"-p",
20+
"SIGUSR1",
21+
"--",
22+
stage_2,
23+
str(pid),
24+
ret
25+
]
26+
27+
subprocess.Popen(cmd).wait()
28+
29+
if __name__ == "__main__":
30+
main()

test/pdeathsignal/stage_2.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env python
2+
from __future__ import print_function
3+
4+
import os
5+
import sys
6+
import signal
7+
import time
8+
9+
10+
def main():
11+
ret = sys.argv[2]
12+
13+
def handler(*args):
14+
with open(ret, "w") as f:
15+
f.write("ok")
16+
sys.exit(0)
17+
18+
signal.signal(signal.SIGUSR1, handler)
19+
pid = int(sys.argv[1])
20+
21+
os.kill(pid, signal.SIGKILL)
22+
time.sleep(5)
23+
24+
if __name__ == "__main__":
25+
main()

test/run_inner_tests.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import bitmap
1010
import re
1111
import itertools
12+
import tempfile
1213

1314
DEVNULL = open(os.devnull, 'wb')
1415

@@ -133,7 +134,7 @@ def main():
133134
assert ret == 1, "Reaping test succeeded (it should have failed)!"
134135

135136
# Test that the signals are properly in place here.
136-
print "running signal configuration test"
137+
print "Running signal configuration test"
137138

138139
p = subprocess.Popen([os.path.join(build, "sigconf-test"), tini, "cat", "/proc/self/status"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
139140
out, err = p.communicate()
@@ -156,6 +157,21 @@ def main():
156157
# Use signum - 1 because the bitmap is 0-indexed but represents signals strting at 1
157158
assert (signum - 1) in props[signal_set_name].nonzero(), "{0} ({1}) is missing in {2}!".format(SIGNUM_TO_SIGNAME[signum], signum, signal_set_name)
158159

160+
# Test parent death signal handling.
161+
if not args_disabled:
162+
print "Running parent death signal test"
163+
f = tempfile.NamedTemporaryFile()
164+
try:
165+
p = subprocess.Popen(
166+
[os.path.join(src, "test", "pdeathsignal", "stage_1.py"), tini, f.name],
167+
stdout=DEVNULL, stderr=DEVNULL
168+
)
169+
p.wait()
170+
171+
busy_wait(lambda: open(f.name).read() == "ok", 10)
172+
finally:
173+
f.close()
174+
159175
print "---------------------------"
160176
print "All done, tests as expected"
161177
print "---------------------------"

0 commit comments

Comments
 (0)