Skip to content

Commit ead9247

Browse files
authored
Merge pull request #1 from etiamz/parallelize-optiscope
Parallelize Optiscope testing
2 parents 5e9f791 + ebb6aff commit ead9247

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

optiscope.py

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/env python3
22

33
import subprocess
4+
import multiprocessing
5+
from functools import partial
46

57
# we group tests because otherwise the "translation unit" is too large for clang :-(
68
GROUP = 100
@@ -166,12 +168,10 @@ def genFile(funcs, tests):
166168
"""
167169

168170

169-
passed, timeout, failed = 0, 0, 0
170-
171-
172171
def runRange(start, end):
173-
global passed, timeout, failed
174-
172+
global funcId
173+
funcId = start
174+
175175
funcs = ""
176176
cases = ""
177177
for l in TESTS[start:end]:
@@ -192,21 +192,35 @@ def runRange(start, end):
192192
"cc",
193193
f"optiscopeTests{start}.c",
194194
"optiscope/optiscope.c",
195+
"-o",
196+
f"optiscopeTests{start}.out",
195197
]
196198
)
197-
out = subprocess.check_output("./a.out", stderr=subprocess.STDOUT).decode(
199+
out = subprocess.check_output(f"./optiscopeTests{start}.out", stderr=subprocess.STDOUT).decode(
198200
"utf-8"
199201
)
200202

201-
passed += out.count("Good")
202-
timeout += out.count("Timeout")
203-
failed += out.count("Failed") # TODO: does not count NF mismatches
204-
print(passed, timeout, failed)
205-
206-
207-
for start in range(0, len(TESTS), GROUP):
208-
runRange(start, start + GROUP)
209-
210-
print("passed:", passed)
211-
print("timeout:", timeout)
212-
print("failed:", failed)
203+
passed = out.count("Good")
204+
timeout = out.count("Timeout")
205+
failed = out.count("Failed") # TODO: does not count NF mismatches
206+
207+
print(f"Group {start}-{end}: passed={passed}, timeout={timeout}, failed={failed}", flush=True)
208+
209+
subprocess.run(["rm", f"optiscopeTests{start}.c", f"optiscopeTests{start}.out"], stderr=subprocess.DEVNULL)
210+
211+
return passed, timeout, failed
212+
213+
214+
if __name__ == "__main__":
215+
ranges = [(start, min(start + GROUP, len(TESTS))) for start in range(0, len(TESTS), GROUP)]
216+
217+
with multiprocessing.Pool(processes=4) as pool:
218+
results = pool.starmap(runRange, ranges)
219+
220+
total_passed = sum(r[0] for r in results)
221+
total_timeout = sum(r[1] for r in results)
222+
total_failed = sum(r[2] for r in results)
223+
224+
print("passed:", total_passed)
225+
print("timeout:", total_timeout)
226+
print("failed:", total_failed)

0 commit comments

Comments
 (0)