| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
import os |
| 4 |
import sys |
| 5 |
import subprocess |
| 6 |
import multiprocessing |
| 7 |
|
| 8 |
def thread(task): |
| 9 |
valgrind,o,p,n,offset = task |
| 10 |
|
| 11 |
command = ['PROJECT-test',o,p,'.',str(n),str(offset)] |
| 12 |
if valgrind: |
| 13 |
command = ['env','valgrind_multiplier=1','valgrind','-q','--error-exitcode=99']+command |
| 14 |
|
| 15 |
result = subprocess.run(command,stdout=subprocess.PIPE,stderr=subprocess.PIPE,universal_newlines=True) |
| 16 |
|
| 17 |
if result.returncode: |
| 18 |
return task,(f'nonzero return code {result.returncode}',result.stdout,result.stderr) |
| 19 |
|
| 20 |
if len(result.stderr) > 0: # bug in test program |
| 21 |
return task,(f'nonempty errors',result.stdout,result.stderr) |
| 22 |
|
| 23 |
saidsuccess = False |
| 24 |
saidimplementation = False |
| 25 |
saiddeclassify = False |
| 26 |
for line in result.stdout.splitlines(): |
| 27 |
x = line.split() |
| 28 |
if x == ['all','tests','succeeded']: saidsuccess = True |
| 29 |
if len(x) >= 3 and x[2] == 'implementation': saidimplementation = True |
| 30 |
if x == ['valgrind','1','declassify','1']: saiddeclassify = True |
| 31 |
|
| 32 |
if not saidsuccess: # bug in test program |
| 33 |
return task,(f'did not say all tests succeeded',result.stdout,result.stderr) |
| 34 |
|
| 35 |
if not saidimplementation: |
| 36 |
return task,(f'CPU does not support implementation',result.stdout,result.stderr) |
| 37 |
|
| 38 |
if valgrind and not saiddeclassify: |
| 39 |
return task,(f'test does not support declassify',result.stdout,result.stderr) |
| 40 |
|
| 41 |
return task,(None,result.stdout,result.stderr) |
| 42 |
|
| 43 |
def checkresult(task,result): |
| 44 |
valgrind,o,p,n,offset = task |
| 45 |
failure,out,err = result |
| 46 |
|
| 47 |
printtask = f'{o}/{p} impl {n} offset {offset}' |
| 48 |
printtask += ' dataflow' if valgrind else ' conventional' |
| 49 |
|
| 50 |
for desc,what in ('output',out),('error',err): |
| 51 |
for line in what.splitlines(): |
| 52 |
print(f'{printtask} {desc}: {line}') |
| 53 |
|
| 54 |
if failure is None: |
| 55 |
print(f'{printtask} result: success') |
| 56 |
else: |
| 57 |
print(f'{printtask} result: {failure}') |
| 58 |
|
| 59 |
sys.stdout.flush() |
| 60 |
return failure is None |
| 61 |
|
| 62 |
def doit(todo): |
| 63 |
todo = list(todo) |
| 64 |
print(f'tests to run: {len(todo)}') |
| 65 |
|
| 66 |
try: |
| 67 |
threads = len(os.sched_getaffinity(0)) |
| 68 |
except: |
| 69 |
threads = multiprocessing.cpu_count() |
| 70 |
threads = os.getenv('THREADS',default=threads) |
| 71 |
threads = int(threads) |
| 72 |
threads = max(threads,1) |
| 73 |
threads = min(threads,len(todo)) |
| 74 |
print(f'maximum threads allowed: {threads}') |
| 75 |
|
| 76 |
results = {} |
| 77 |
printpos = 0 |
| 78 |
ok = True |
| 79 |
|
| 80 |
with multiprocessing.Pool(threads) as p: |
| 81 |
for task,result in p.imap_unordered(thread,todo,chunksize=1): |
| 82 |
results[task] = result |
| 83 |
while printpos < len(todo): |
| 84 |
task = todo[printpos] |
| 85 |
if task not in results: break |
| 86 |
if not checkresult(task,results[task]): |
| 87 |
ok = False |
| 88 |
printpos += 1 |
| 89 |
|
| 90 |
assert printpos == len(todo) |
| 91 |
return ok |