aboutsummaryrefslogtreecommitdiff
path: root/tests/image-fuzzer/runner.py
diff options
context:
space:
mode:
authorMaria Kustova <maxa@catit.be>2014-08-19 00:02:35 +0400
committerKevin Wolf <kwolf@redhat.com>2014-08-20 11:51:28 +0200
commit18a7d0c56e1377f3d5fa1dc4d78a15dbab01cd83 (patch)
treeb92b58b7d327d14e7294470e19a0df0c9fdc067d /tests/image-fuzzer/runner.py
parent9d256ca616a298495e46c64da249b1620540930a (diff)
runner: Kill a program under test by time-out
If a program under test get frozen, the test should finish and report about its failure. In such cases the runner waits for 10 minutes until the program ends its execution. After this time-out the program will be terminated and the test will be marked as failed. For current limitation of test image size to 10 MB as a maximum an execution of each command takes about several seconds in general, so 10 minutes is enough to discriminate freeze, but not drastically increase an overall test duration. Signed-off-by: Maria Kustova <maria.k@catit.be> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'tests/image-fuzzer/runner.py')
-rwxr-xr-xtests/image-fuzzer/runner.py29
1 files changed, 25 insertions, 4 deletions
diff --git a/tests/image-fuzzer/runner.py b/tests/image-fuzzer/runner.py
index 1e38b95fd7..c903c8a342 100755
--- a/tests/image-fuzzer/runner.py
+++ b/tests/image-fuzzer/runner.py
@@ -65,14 +65,35 @@ def run_app(fd, q_args):
"""Start an application with specified arguments and return its exit code
or kill signal depending on the result of execution.
"""
+
+ class Alarm(Exception):
+ """Exception for signal.alarm events."""
+ pass
+
+ def handler(*arg):
+ """Notify that an alarm event occurred."""
+ raise Alarm
+
+ signal.signal(signal.SIGALRM, handler)
+ signal.alarm(600)
+ term_signal = signal.SIGKILL
devnull = open('/dev/null', 'r+')
process = subprocess.Popen(q_args, stdin=devnull,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
- out, err = process.communicate()
- fd.write(out)
- fd.write(err)
- return process.returncode
+ try:
+ out, err = process.communicate()
+ signal.alarm(0)
+ fd.write(out)
+ fd.write(err)
+ fd.flush()
+ return process.returncode
+
+ except Alarm:
+ os.kill(process.pid, term_signal)
+ fd.write('The command was terminated by timeout.\n')
+ fd.flush()
+ return -term_signal
class TestException(Exception):