gen_run_tests.py revision 1.1.1.1.14.1 1 #!/usr/bin/env python3
2
3 import sys
4 from itertools import combinations
5 from os import uname
6 from multiprocessing import cpu_count
7 from subprocess import call
8
9 # Later, we want to test extended vaddr support. Apparently, the "real" way of
10 # checking this is flaky on OS X.
11 bits_64 = sys.maxsize > 2**32
12
13 nparallel = cpu_count() * 2
14
15 uname = uname()[0]
16
17 if call("command -v gmake", shell=True) == 0:
18 make_cmd = 'gmake'
19 else:
20 make_cmd = 'make'
21
22 def powerset(items):
23 result = []
24 for i in range(len(items) + 1):
25 result += combinations(items, i)
26 return result
27
28 possible_compilers = []
29 for cc, cxx in (['gcc', 'g++'], ['clang', 'clang++']):
30 try:
31 cmd_ret = call([cc, "-v"])
32 if cmd_ret == 0:
33 possible_compilers.append((cc, cxx))
34 except:
35 pass
36 possible_compiler_opts = [
37 '-m32',
38 ]
39 possible_config_opts = [
40 '--enable-debug',
41 '--enable-prof',
42 '--disable-stats',
43 '--enable-opt-safety-checks',
44 '--with-lg-page=16',
45 ]
46 if bits_64:
47 possible_config_opts.append('--with-lg-vaddr=56')
48
49 possible_malloc_conf_opts = [
50 'tcache:false',
51 'dss:primary',
52 'percpu_arena:percpu',
53 'background_thread:true',
54 ]
55
56 print('set -e')
57 print('if [ -f Makefile ] ; then %(make_cmd)s relclean ; fi' % {'make_cmd':
58 make_cmd})
59 print('autoconf')
60 print('rm -rf run_tests.out')
61 print('mkdir run_tests.out')
62 print('cd run_tests.out')
63
64 ind = 0
65 for cc, cxx in possible_compilers:
66 for compiler_opts in powerset(possible_compiler_opts):
67 for config_opts in powerset(possible_config_opts):
68 for malloc_conf_opts in powerset(possible_malloc_conf_opts):
69 if cc == 'clang' \
70 and '-m32' in possible_compiler_opts \
71 and '--enable-prof' in config_opts:
72 continue
73 config_line = (
74 'EXTRA_CFLAGS=-Werror EXTRA_CXXFLAGS=-Werror '
75 + 'CC="{} {}" '.format(cc, " ".join(compiler_opts))
76 + 'CXX="{} {}" '.format(cxx, " ".join(compiler_opts))
77 + '../../configure '
78 + " ".join(config_opts) + (' --with-malloc-conf=' +
79 ",".join(malloc_conf_opts) if len(malloc_conf_opts) > 0
80 else '')
81 )
82
83 # We don't want to test large vaddr spaces in 32-bit mode.
84 if ('-m32' in compiler_opts and '--with-lg-vaddr=56' in
85 config_opts):
86 continue
87
88 # Per CPU arenas are only supported on Linux.
89 linux_supported = ('percpu_arena:percpu' in malloc_conf_opts \
90 or 'background_thread:true' in malloc_conf_opts)
91 # Heap profiling and dss are not supported on OS X.
92 darwin_unsupported = ('--enable-prof' in config_opts or \
93 'dss:primary' in malloc_conf_opts)
94 if (uname == 'Linux' and linux_supported) \
95 or (not linux_supported and (uname != 'Darwin' or \
96 not darwin_unsupported)):
97 print("""cat <<EOF > run_test_%(ind)d.sh
98 #!/bin/sh
99
100 set -e
101
102 abort() {
103 echo "==> Error" >> run_test.log
104 echo "Error; see run_tests.out/run_test_%(ind)d.out/run_test.log"
105 exit 255 # Special exit code tells xargs to terminate.
106 }
107
108 # Environment variables are not supported.
109 run_cmd() {
110 echo "==> \$@" >> run_test.log
111 \$@ >> run_test.log 2>&1 || abort
112 }
113
114 echo "=> run_test_%(ind)d: %(config_line)s"
115 mkdir run_test_%(ind)d.out
116 cd run_test_%(ind)d.out
117
118 echo "==> %(config_line)s" >> run_test.log
119 %(config_line)s >> run_test.log 2>&1 || abort
120
121 run_cmd %(make_cmd)s all tests
122 run_cmd %(make_cmd)s check
123 run_cmd %(make_cmd)s distclean
124 EOF
125 chmod 755 run_test_%(ind)d.sh""" % {'ind': ind, 'config_line': config_line,
126 'make_cmd': make_cmd})
127 ind += 1
128
129 print('for i in `seq 0 %(last_ind)d` ; do echo run_test_${i}.sh ; done | xargs'
130 ' -P %(nparallel)d -n 1 sh' % {'last_ind': ind-1, 'nparallel': nparallel})
131