xref: /freebsd/contrib/jemalloc/scripts/gen_run_tests.py (revision b5daf675efc746611c7cfcd1fa474b8905064c4b)
1<<<<<<< HEAD
2#!/usr/bin/env python3
3
4import sys
5from itertools import combinations
6from os import uname
7from multiprocessing import cpu_count
8from subprocess import call
9
10# Later, we want to test extended vaddr support.  Apparently, the "real" way of
11# checking this is flaky on OS X.
12bits_64 = sys.maxsize > 2**32
13
14nparallel = cpu_count() * 2
15
16uname = uname()[0]
17
18if call("command -v gmake", shell=True) == 0:
19    make_cmd = 'gmake'
20else:
21    make_cmd = 'make'
22
23def powerset(items):
24    result = []
25    for i in range(len(items) + 1):
26        result += combinations(items, i)
27    return result
28
29possible_compilers = []
30for cc, cxx in (['gcc', 'g++'], ['clang', 'clang++']):
31    try:
32        cmd_ret = call([cc, "-v"])
33        if cmd_ret == 0:
34            possible_compilers.append((cc, cxx))
35    except:
36        pass
37possible_compiler_opts = [
38    '-m32',
39]
40possible_config_opts = [
41    '--enable-debug',
42    '--enable-prof',
43    '--disable-stats',
44    '--enable-opt-safety-checks',
45    '--with-lg-page=16',
46]
47if bits_64:
48    possible_config_opts.append('--with-lg-vaddr=56')
49
50possible_malloc_conf_opts = [
51    'tcache:false',
52    'dss:primary',
53    'percpu_arena:percpu',
54    'background_thread:true',
55]
56
57print('set -e')
58print('if [ -f Makefile ] ; then %(make_cmd)s relclean ; fi' % {'make_cmd':
59    make_cmd})
60print('autoconf')
61print('rm -rf run_tests.out')
62print('mkdir run_tests.out')
63print('cd run_tests.out')
64
65ind = 0
66for cc, cxx in possible_compilers:
67    for compiler_opts in powerset(possible_compiler_opts):
68        for config_opts in powerset(possible_config_opts):
69            for malloc_conf_opts in powerset(possible_malloc_conf_opts):
70                if cc == 'clang' \
71                  and '-m32' in possible_compiler_opts \
72                  and '--enable-prof' in config_opts:
73                    continue
74                config_line = (
75                    'EXTRA_CFLAGS=-Werror EXTRA_CXXFLAGS=-Werror '
76                    + 'CC="{} {}" '.format(cc, " ".join(compiler_opts))
77                    + 'CXX="{} {}" '.format(cxx, " ".join(compiler_opts))
78                    + '../../configure '
79                    + " ".join(config_opts) + (' --with-malloc-conf=' +
80                    ",".join(malloc_conf_opts) if len(malloc_conf_opts) > 0
81                    else '')
82                )
83
84                # We don't want to test large vaddr spaces in 32-bit mode.
85                if ('-m32' in compiler_opts and '--with-lg-vaddr=56' in
86                    config_opts):
87                    continue
88
89                # Per CPU arenas are only supported on Linux.
90                linux_supported = ('percpu_arena:percpu' in malloc_conf_opts \
91                  or 'background_thread:true' in malloc_conf_opts)
92                # Heap profiling and dss are not supported on OS X.
93                darwin_unsupported = ('--enable-prof' in config_opts or \
94                  'dss:primary' in malloc_conf_opts)
95                if (uname == 'Linux' and linux_supported) \
96                  or (not linux_supported and (uname != 'Darwin' or \
97                  not darwin_unsupported)):
98                    print("""cat <<EOF > run_test_%(ind)d.sh
99#!/bin/sh
100
101set -e
102
103abort() {
104    echo "==> Error" >> run_test.log
105    echo "Error; see run_tests.out/run_test_%(ind)d.out/run_test.log"
106    exit 255 # Special exit code tells xargs to terminate.
107}
108
109# Environment variables are not supported.
110run_cmd() {
111    echo "==> \$@" >> run_test.log
112    \$@ >> run_test.log 2>&1 || abort
113}
114
115echo "=> run_test_%(ind)d: %(config_line)s"
116mkdir run_test_%(ind)d.out
117cd run_test_%(ind)d.out
118
119echo "==> %(config_line)s" >> run_test.log
120%(config_line)s >> run_test.log 2>&1 || abort
121
122run_cmd %(make_cmd)s all tests
123run_cmd %(make_cmd)s check
124run_cmd %(make_cmd)s distclean
125EOF
126chmod 755 run_test_%(ind)d.sh""" % {'ind': ind, 'config_line': config_line,
127      'make_cmd': make_cmd})
128                    ind += 1
129
130print('for i in `seq 0 %(last_ind)d` ; do echo run_test_${i}.sh ; done | xargs'
131    ' -P %(nparallel)d -n 1 sh' % {'last_ind': ind-1, 'nparallel': nparallel})
132||||||| dec341af7695
133=======
134#!/usr/bin/env python
135
136import sys
137from itertools import combinations
138from os import uname
139from multiprocessing import cpu_count
140from subprocess import call
141
142# Later, we want to test extended vaddr support.  Apparently, the "real" way of
143# checking this is flaky on OS X.
144bits_64 = sys.maxsize > 2**32
145
146nparallel = cpu_count() * 2
147
148uname = uname()[0]
149
150if "BSD" in uname:
151    make_cmd = 'gmake'
152else:
153    make_cmd = 'make'
154
155def powerset(items):
156    result = []
157    for i in xrange(len(items) + 1):
158        result += combinations(items, i)
159    return result
160
161possible_compilers = []
162for cc, cxx in (['gcc', 'g++'], ['clang', 'clang++']):
163    try:
164        cmd_ret = call([cc, "-v"])
165        if cmd_ret == 0:
166            possible_compilers.append((cc, cxx))
167    except:
168        pass
169possible_compiler_opts = [
170    '-m32',
171]
172possible_config_opts = [
173    '--enable-debug',
174    '--enable-prof',
175    '--disable-stats',
176    '--enable-opt-safety-checks',
177]
178if bits_64:
179    possible_config_opts.append('--with-lg-vaddr=56')
180
181possible_malloc_conf_opts = [
182    'tcache:false',
183    'dss:primary',
184    'percpu_arena:percpu',
185    'background_thread:true',
186]
187
188print 'set -e'
189print 'if [ -f Makefile ] ; then %(make_cmd)s relclean ; fi' % {'make_cmd': make_cmd}
190print 'autoconf'
191print 'rm -rf run_tests.out'
192print 'mkdir run_tests.out'
193print 'cd run_tests.out'
194
195ind = 0
196for cc, cxx in possible_compilers:
197    for compiler_opts in powerset(possible_compiler_opts):
198        for config_opts in powerset(possible_config_opts):
199            for malloc_conf_opts in powerset(possible_malloc_conf_opts):
200                if cc is 'clang' \
201                  and '-m32' in possible_compiler_opts \
202                  and '--enable-prof' in config_opts:
203                    continue
204                config_line = (
205                    'EXTRA_CFLAGS=-Werror EXTRA_CXXFLAGS=-Werror '
206                    + 'CC="{} {}" '.format(cc, " ".join(compiler_opts))
207                    + 'CXX="{} {}" '.format(cxx, " ".join(compiler_opts))
208                    + '../../configure '
209                    + " ".join(config_opts) + (' --with-malloc-conf=' +
210                    ",".join(malloc_conf_opts) if len(malloc_conf_opts) > 0
211                    else '')
212                )
213
214                # We don't want to test large vaddr spaces in 32-bit mode.
215		if ('-m32' in compiler_opts and '--with-lg-vaddr=56' in
216                  config_opts):
217		    continue
218
219                # Per CPU arenas are only supported on Linux.
220                linux_supported = ('percpu_arena:percpu' in malloc_conf_opts \
221                  or 'background_thread:true' in malloc_conf_opts)
222                # Heap profiling and dss are not supported on OS X.
223                darwin_unsupported = ('--enable-prof' in config_opts or \
224                  'dss:primary' in malloc_conf_opts)
225                if (uname == 'Linux' and linux_supported) \
226                  or (not linux_supported and (uname != 'Darwin' or \
227                  not darwin_unsupported)):
228                    print """cat <<EOF > run_test_%(ind)d.sh
229#!/bin/sh
230
231set -e
232
233abort() {
234    echo "==> Error" >> run_test.log
235    echo "Error; see run_tests.out/run_test_%(ind)d.out/run_test.log"
236    exit 255 # Special exit code tells xargs to terminate.
237}
238
239# Environment variables are not supported.
240run_cmd() {
241    echo "==> \$@" >> run_test.log
242    \$@ >> run_test.log 2>&1 || abort
243}
244
245echo "=> run_test_%(ind)d: %(config_line)s"
246mkdir run_test_%(ind)d.out
247cd run_test_%(ind)d.out
248
249echo "==> %(config_line)s" >> run_test.log
250%(config_line)s >> run_test.log 2>&1 || abort
251
252run_cmd %(make_cmd)s all tests
253run_cmd %(make_cmd)s check
254run_cmd %(make_cmd)s distclean
255EOF
256chmod 755 run_test_%(ind)d.sh""" % {'ind': ind, 'config_line': config_line, 'make_cmd': make_cmd}
257                    ind += 1
258
259print 'for i in `seq 0 %(last_ind)d` ; do echo run_test_${i}.sh ; done | xargs -P %(nparallel)d -n 1 sh' % {'last_ind': ind-1, 'nparallel': nparallel}
260>>>>>>> main
261