From d8121b1d5e9f3d241e1ab928501b1d211114379d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5kan=20Th=C3=B6rngren?= Date: Thu, 13 Oct 2016 11:20:32 -0700 Subject: [PATCH] Allow timeout on test cases Certain commands are likely to fail to terminate in case something goes wrong. Having the ability to force such commands to terminate after a certain time is useful. --- python/cmdtest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/cmdtest.py b/python/cmdtest.py index 43b7cbe..391ed7a 100755 --- a/python/cmdtest.py +++ b/python/cmdtest.py @@ -407,7 +407,7 @@ class TestCase: with open(tgt_file, "w", encoding=tgt_encoding) as f: f.write(data) - def cmd(self, cmdline): + def cmd(self, cmdline, timeout=None): tmpdir = self.__tmpdir before = tmpdir.snapshot() stdout_log = tmpdir.stdout_log() @@ -417,7 +417,7 @@ class TestCase: print("### cmdline:", cmdline) with open(stdout_log, "w") as stdout, open(stderr_log, "w") as stderr: if cmdline: - err = subprocess.call(cmdline, stdout=stdout, stderr=stderr, shell=True) + err = subprocess.call(cmdline, stdout=stdout, stderr=stderr, shell=True, timeout=timeout) else: err = 0 after = tmpdir.snapshot()