-
Notifications
You must be signed in to change notification settings - Fork 4
/
runtests
executable file
·48 lines (35 loc) · 1.21 KB
/
runtests
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/python2
import subprocess
import tempfile
from multiprocessing import Pool
def explode_ref(ref, dest):
"""Write contents from ref to dest dir"""
p1 = subprocess.Popen(['git', 'archive', ref], stdout=subprocess.PIPE)
p2 = subprocess.Popen(['tar', '-x'], cwd=dest, stdin=p1.stdout)
p1.stdout.close()
p2.communicate()
def checkout_run(cmd, ref='HEAD'):
"""Run command in a fresh checkout of ref and return output"""
tempdir = tempfile.mkdtemp(prefix='koji-runtests-')
explode_ref(ref, tempdir)
try:
output = subprocess.check_output(cmd, cwd=tempdir,
stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
print("Command failed with code %s" % e.returncode)
output = e.output
return output
def run_test2():
return checkout_run(['make', 'test2'])
def run_test3():
return checkout_run(['make', 'test3'])
def main():
"""Run our test targets in parallel using fresh checkouts of HEAD"""
print("Running tests...")
p = Pool(2)
results = [p.apply_async(f) for f in [run_test2, run_test3]]
for r in results:
print(r.get().decode('utf-8'))
p.close()
if __name__ == '__main__':
main()