Skip to content

Commit 90d47ee

Browse files
committed
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 <[email protected]>
1 parent e49f609 commit 90d47ee

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

tests/run-multitests.py

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ def next():
4646
print("NEXT")
4747
multitest.flush()
4848
@staticmethod
49+
def broadcast(msg):
50+
print("BROADCAST", msg)
51+
multitest.flush()
52+
@staticmethod
53+
def wait(msg):
54+
msg = "BROADCAST " + msg
55+
while True:
56+
if sys.stdin.readline().rstrip() == msg:
57+
return
58+
@staticmethod
4959
def globals(**gs):
5060
for g in gs:
5161
print("SET {{}} = {{!r}}".format(g, gs[g]))
@@ -126,22 +136,20 @@ def run_script(self, script):
126136

127137
def start_script(self, script):
128138
self.popen = subprocess.Popen(
129-
self.argv,
139+
self.argv + ["-c", script],
130140
stdin=subprocess.PIPE,
131141
stdout=subprocess.PIPE,
132142
stderr=subprocess.STDOUT,
133143
env=self.env,
134144
)
135-
self.popen.stdin.write(script)
136-
self.popen.stdin.close()
137145
self.finished = False
138146

139147
def stop(self):
140148
if self.popen and self.popen.poll() is None:
141149
self.popen.terminate()
142150

143151
def readline(self):
144-
sel = select.select([self.popen.stdout.raw], [], [], 0.1)
152+
sel = select.select([self.popen.stdout.raw], [], [], 0.001)
145153
if not sel[0]:
146154
self.finished = self.popen.poll() is not None
147155
return None, None
@@ -152,6 +160,10 @@ def readline(self):
152160
else:
153161
return str(out.rstrip(), "ascii"), None
154162

163+
def write(self, data):
164+
self.popen.stdin.write(data)
165+
self.popen.stdin.flush()
166+
155167
def is_finished(self):
156168
return self.finished
157169

@@ -220,6 +232,9 @@ def readline(self):
220232
err = None
221233
return str(out.rstrip(), "ascii"), err
222234

235+
def write(self, data):
236+
self.pyb.serial.write(data)
237+
223238
def is_finished(self):
224239
return self.finished
225240

@@ -318,7 +333,12 @@ def run_test_on_instances(test_file, num_instances, instances):
318333
last_read_time[idx] = time.time()
319334
if out is not None and not any(m in out for m in IGNORE_OUTPUT_MATCHES):
320335
trace_instance_output(idx, out)
321-
output[idx].append(out)
336+
if out.startswith("BROADCAST "):
337+
for instance2 in instances:
338+
if instance2 is not instance:
339+
instance2.write(bytes(out, "ascii") + b"\r\n")
340+
else:
341+
output[idx].append(out)
322342
if err is not None:
323343
trace_instance_output(idx, err)
324344
output[idx].append(err)

0 commit comments

Comments
 (0)