From 2b1b8bedf09ef044725673e273e184994f38da0d Mon Sep 17 00:00:00 2001 From: baldurk Date: Mon, 18 May 2020 16:58:23 +0100 Subject: [PATCH] Print test runner output when running out-of-process --- util/test/rdtest/runner.py | 39 ++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/util/test/rdtest/runner.py b/util/test/rdtest/runner.py index b9f398e3b..d3d9d86c1 100644 --- a/util/test/rdtest/runner.py +++ b/util/test/rdtest/runner.py @@ -77,6 +77,9 @@ def _run_test(testclass, failedcases: list): if RUNNER_DEBUG: print("Waiting for test runner to complete...") + out_pending = "" + err_pending = "" + while test_run.poll() is None: out = err = "" @@ -102,11 +105,39 @@ def _run_test(testclass, failedcases: list): except queue.Empty: err = None # No output - if RUNNER_DEBUG and out is not None: - print("Test stdout: {}".format(out)) + if RUNNER_DEBUG: + if out is not None: + print("Test stdout: {}".format(out)) - if RUNNER_DEBUG and err is not None: - print("Test stderr: {}".format(err)) + if err is not None: + print("Test stderr: {}".format(err)) + else: + if out is not None: + out_pending += out + if err is not None: + err_pending += err + + while True: + try: + nl = out_pending.index('\n') + line = out_pending[0:nl] + out_pending = out_pending[nl+1:] + line = line.replace('\r', '') + sys.stdout.write(line + '\n') + sys.stdout.flush() + except: + break + + while True: + try: + nl = err_pending.index('\n') + line = err_pending[0:nl] + err_pending = err_pending[nl+1:] + line = line.replace('\r', '') + sys.stderr.write(line + '\n') + sys.stderr.flush() + except: + break if out is None and err is None and test_run.poll() is None: log.error('Timed out, no output within {}s elapsed'.format(RUNNER_TIMEOUT))