@@ -46,6 +46,16 @@ def next():
46
46
print("NEXT")
47
47
multitest.flush()
48
48
@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
49
59
def globals(**gs):
50
60
for g in gs:
51
61
print("SET {{}} = {{!r}}".format(g, gs[g]))
@@ -126,22 +136,20 @@ def run_script(self, script):
126
136
127
137
def start_script (self , script ):
128
138
self .popen = subprocess .Popen (
129
- self .argv ,
139
+ self .argv + [ "-c" , script ] ,
130
140
stdin = subprocess .PIPE ,
131
141
stdout = subprocess .PIPE ,
132
142
stderr = subprocess .STDOUT ,
133
143
env = self .env ,
134
144
)
135
- self .popen .stdin .write (script )
136
- self .popen .stdin .close ()
137
145
self .finished = False
138
146
139
147
def stop (self ):
140
148
if self .popen and self .popen .poll () is None :
141
149
self .popen .terminate ()
142
150
143
151
def readline (self ):
144
- sel = select .select ([self .popen .stdout .raw ], [], [], 0.1 )
152
+ sel = select .select ([self .popen .stdout .raw ], [], [], 0.001 )
145
153
if not sel [0 ]:
146
154
self .finished = self .popen .poll () is not None
147
155
return None , None
@@ -152,6 +160,10 @@ def readline(self):
152
160
else :
153
161
return str (out .rstrip (), "ascii" ), None
154
162
163
+ def write (self , data ):
164
+ self .popen .stdin .write (data )
165
+ self .popen .stdin .flush ()
166
+
155
167
def is_finished (self ):
156
168
return self .finished
157
169
@@ -220,6 +232,9 @@ def readline(self):
220
232
err = None
221
233
return str (out .rstrip (), "ascii" ), err
222
234
235
+ def write (self , data ):
236
+ self .pyb .serial .write (data )
237
+
223
238
def is_finished (self ):
224
239
return self .finished
225
240
@@ -318,7 +333,12 @@ def run_test_on_instances(test_file, num_instances, instances):
318
333
last_read_time [idx ] = time .time ()
319
334
if out is not None and not any (m in out for m in IGNORE_OUTPUT_MATCHES ):
320
335
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 )
322
342
if err is not None :
323
343
trace_instance_output (idx , err )
324
344
output [idx ].append (err )
0 commit comments