-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtest.py
executable file
·89 lines (73 loc) · 2.71 KB
/
test.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/python
'''stuff we test:
* "hello" should work with all enabled schedulers and link against all single-scheduler libraries.
* "sleep" should sleep "quickly" with all enabled schedulers (partitioning test)
* random checker should find bugs.
* valgrind checker should find bugs.
* various stuff - like find, sort and accumulate.
'''
import os
import sys
import build
import commands
tests = 'bug.cpp sleep.cpp nested.cpp grain.cpp acc.cpp cancel.cpp sort.cpp'.split()
with_cpp = 'C++11' in build.enabled
with_pthreads = 'pthreads' in build.enabled
with_openmp = 'OpenMP' in build.enabled
with_tbb = 'TBB' in build.enabled
print '\nbuilding tests'
verbose = build.verbose
built = []
def buildtest(*args):
built.append(build.buildtest(*args))
buildtest('hello_ct.c')
if with_pthreads: buildtest('hello_ct.c','_pthreads')
if with_openmp: buildtest('hello_ct.c','_openmp')
if with_cpp:
buildtest('hello_ctx.cpp')
if with_pthreads: buildtest('hello_ctx.cpp','_pthreads')
if with_openmp: buildtest('hello_ctx.cpp','_openmp')
if with_tbb: buildtest('hello_ctx.cpp','_tbb')
for test in tests:
if test.endswith('.cpp') and not with_cpp:
continue
buildtest(test)
scheds = 'serial shuffle valgrind openmp tbb pthreads'.split()
# remove schedulers which we aren't configured to support
def lower(ls): return [s.lower() for s in ls]
scheds = [sched for sched in scheds if not (sched in lower(build.features) \
and sched not in lower(build.enabled))]
failed = []
def fail(command):
print ' ',command,'FAILED'
failed.append(command)
def runtest(name,args='',expected_status=0,expected_output=None,**env):
envstr=' '.join(['%s=%s'%(n,v) for n,v in env.items()])
command = 'env %s ./bin/%s %s'%(envstr,name,args)
return runcommand(command,expected_status,expected_output)
def runcommand(command,expected_status=0,expected_output=None):
if verbose:
print ' ','running',command
status,output = commands.getstatusoutput(command)
if verbose>1:
print ' ','\n '.join(output.split('\n'))
bad_status = status != expected_status and expected_status != None
bad_output = output != expected_output and expected_output != None
if bad_status or bad_output:
fail(command)
return status, output, command
print '\nrunning tests'
testscripts = 'hello.py bug.py nested.py sleep.py'.split()
for testscript in testscripts:
execfile('test/'+testscript)
for test in built:
if test in 'bug nested sleep'.split() or test.startswith('hello'):
continue
if test == 'sort':
runtest(test,args=str(1024*1024))
else:
runtest(test)
if failed:
print 'FAILED:'
print '\n'.join(failed)
sys.exit(1)