aboutsummaryrefslogtreecommitdiff
path: root/runtest.py
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2015-03-02 17:36:09 -0600
committerJoel Martin <github@martintribe.org>2015-03-02 17:36:09 -0600
commit612bfe4af7dbb1111bdd4746a67670b6cafba090 (patch)
tree72b9a63c3f24d2733d80ed70ca7d17063ac39224 /runtest.py
parent992543a7229e03ea6d60c53dfec07a8c4cc18ee7 (diff)
downloadmal-612bfe4af7dbb1111bdd4746a67670b6cafba090.tar.gz
mal-612bfe4af7dbb1111bdd4746a67670b6cafba090.zip
runtest.py: cleanup all grandchildren too.
Launch Popen with process group and kill that instead. Use atexit to register cleanup function rather than direct calls.
Diffstat (limited to 'runtest.py')
-rwxr-xr-xruntest.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/runtest.py b/runtest.py
index e1db90a..a7f0e44 100755
--- a/runtest.py
+++ b/runtest.py
@@ -3,7 +3,7 @@
import os, sys, re
import argparse, time
-import pty
+import pty, signal, atexit
from subprocess import Popen, STDOUT, PIPE
from select import select
@@ -33,16 +33,24 @@ parser.add_argument('mal_cmd', nargs="*",
class Runner():
def __init__(self, args, mono=False):
+ #print "args: %s" % repr(args)
self.mono = mono
- print "args: %s" % repr(args)
+
+ # Cleanup child process on exit
+ atexit.register(self.cleanup)
+
if mono:
- self.p = Popen(args, bufsize=0, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
+ self.p = Popen(args, bufsize=0,
+ stdin=PIPE, stdout=PIPE, stderr=STDOUT,
+ preexec_fn=os.setsid)
self.stdin = self.p.stdin
self.stdout = self.p.stdout
else:
# provide tty to get 'interactive' readline to work
master, slave = pty.openpty()
- self.p = Popen(args, bufsize=0, stdin=slave, stdout=slave, stderr=STDOUT)
+ self.p = Popen(args, bufsize=0,
+ stdin=slave, stdout=slave, stderr=STDOUT,
+ preexec_fn=os.setsid)
self.stdin = os.fdopen(master, 'r+b', 0)
self.stdout = self.stdin
@@ -79,8 +87,9 @@ class Runner():
self.buf += str + "\r\n"
def cleanup(self):
+ #print "cleaning up"
if self.p:
- self.p.kill()
+ os.killpg(self.p.pid, signal.SIGTERM)
self.p = None
@@ -139,7 +148,6 @@ def assert_prompt(timeout):
else:
print "Did not get 'user> ' or 'mal-user> ' prompt"
print " Got : %s" % repr(r.buf)
- r.cleanup()
sys.exit(1)
@@ -177,9 +185,7 @@ while test_data:
fail_cnt += 1
except:
print "Got Exception"
- r.cleanup()
sys.exit(1)
-r.cleanup()
if fail_cnt > 0:
print "FAILURES: %d" % fail_cnt