summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2021-08-12 15:49:27 +1000
committerDamien George <damien@micropython.org>2021-08-13 23:26:34 +1000
commit90d47ee34de707c4a138f3bfe2d434b13e1e6db8 (patch)
treee7fe1fc185c9d061096469602308dda1aba29678 /tests
parente49f6091866b260cb8eec7a66bbd5d4d7bc22aa1 (diff)
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 <damien@micropython.org>
Diffstat (limited to 'tests')
-rwxr-xr-xtests/run-multitests.py30
1 files changed, 25 insertions, 5 deletions
diff --git a/tests/run-multitests.py b/tests/run-multitests.py
index b4afc1e52..34389e429 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)