From 90d47ee34de707c4a138f3bfe2d434b13e1e6db8 Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 12 Aug 2021 15:49:27 +1000 Subject: [PATCH] tests/run-multitests.py: Add broadcast and wait facility. Test instances can now use the following methods to synchronise their execution: multitest.broadcast("sync message") multitest.wait("sync message") Signed-off-by: Damien George --- tests/run-multitests.py | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/tests/run-multitests.py b/tests/run-multitests.py index b4afc1e526..34389e4292 100755 --- a/tests/run-multitests.py +++ b/tests/run-multitests.py @@ -46,6 +46,16 @@ class multitest: print("NEXT") multitest.flush() @staticmethod + def broadcast(msg): + print("BROADCAST", msg) + multitest.flush() + @staticmethod + def wait(msg): + msg = "BROADCAST " + msg + while True: + if sys.stdin.readline().rstrip() == msg: + return + @staticmethod def globals(**gs): for g in gs: print("SET {{}} = {{!r}}".format(g, gs[g])) @@ -126,14 +136,12 @@ class PyInstanceSubProcess(PyInstance): def start_script(self, script): self.popen = subprocess.Popen( - self.argv, + self.argv + ["-c", script], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=self.env, ) - self.popen.stdin.write(script) - self.popen.stdin.close() self.finished = False def stop(self): @@ -141,7 +149,7 @@ class PyInstanceSubProcess(PyInstance): self.popen.terminate() def readline(self): - sel = select.select([self.popen.stdout.raw], [], [], 0.1) + sel = select.select([self.popen.stdout.raw], [], [], 0.001) if not sel[0]: self.finished = self.popen.poll() is not None return None, None @@ -152,6 +160,10 @@ class PyInstanceSubProcess(PyInstance): else: return str(out.rstrip(), "ascii"), None + def write(self, data): + self.popen.stdin.write(data) + self.popen.stdin.flush() + def is_finished(self): return self.finished @@ -220,6 +232,9 @@ class PyInstancePyboard(PyInstance): err = None return str(out.rstrip(), "ascii"), err + def write(self, data): + self.pyb.serial.write(data) + def is_finished(self): return self.finished @@ -318,7 +333,12 @@ def run_test_on_instances(test_file, num_instances, instances): last_read_time[idx] = time.time() if out is not None and not any(m in out for m in IGNORE_OUTPUT_MATCHES): trace_instance_output(idx, out) - output[idx].append(out) + if out.startswith("BROADCAST "): + for instance2 in instances: + if instance2 is not instance: + instance2.write(bytes(out, "ascii") + b"\r\n") + else: + output[idx].append(out) if err is not None: trace_instance_output(idx, err) output[idx].append(err)