Skip to content

Commit

Permalink
tests/run-tests.py: Add timeout for running PC-based MicroPython test.
Browse files Browse the repository at this point in the history
So the test suite runs to completion, even if the interpreter locks up.

Signed-off-by: Damien George <damien@micropython.org>
  • Loading branch information
dpgeorge committed Apr 21, 2022
1 parent 81c9219 commit 8631753
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tests/run-tests.py
Expand Up @@ -13,6 +13,9 @@
import threading
import tempfile

# Maximum time to run a PC-based test, in seconds.
TEST_TIMEOUT = 30

# See stackoverflow.com/questions/2632199: __file__ nor sys.argv[0]
# are guaranteed to always work, this one should though.
BASEPATH = os.path.dirname(os.path.abspath(inspect.getsourcefile(lambda: None)))
Expand Down Expand Up @@ -178,10 +181,15 @@ def send_get(what):

# run the actual test
try:
output_mupy = subprocess.check_output(cmdlist, stderr=subprocess.STDOUT)
output_mupy = subprocess.check_output(
cmdlist, stderr=subprocess.STDOUT, timeout=TEST_TIMEOUT
)
except subprocess.CalledProcessError as er:
had_crash = True
output_mupy = er.output + b"CRASH"
except subprocess.TimeoutExpired as er:
had_crash = True
output_mupy = (er.output or b"") + b"TIMEOUT"

# clean up if we had an intermediate .mpy file
if args.via_mpy:
Expand Down

0 comments on commit 8631753

Please sign in to comment.