xref: /netbsd-src/external/bsd/jemalloc.old/dist/scripts/gen_run_tests.py (revision 8e33eff89e26cf71871ead62f0d5063e1313c33a)
1*8e33eff8Schristos#!/usr/bin/env python
2*8e33eff8Schristos
3*8e33eff8Schristosimport sys
4*8e33eff8Schristosfrom itertools import combinations
5*8e33eff8Schristosfrom os import uname
6*8e33eff8Schristosfrom multiprocessing import cpu_count
7*8e33eff8Schristos
8*8e33eff8Schristos# Later, we want to test extended vaddr support.  Apparently, the "real" way of
9*8e33eff8Schristos# checking this is flaky on OS X.
10*8e33eff8Schristosbits_64 = sys.maxsize > 2**32
11*8e33eff8Schristos
12*8e33eff8Schristosnparallel = cpu_count() * 2
13*8e33eff8Schristos
14*8e33eff8Schristosuname = uname()[0]
15*8e33eff8Schristos
16*8e33eff8Schristosdef powerset(items):
17*8e33eff8Schristos    result = []
18*8e33eff8Schristos    for i in xrange(len(items) + 1):
19*8e33eff8Schristos        result += combinations(items, i)
20*8e33eff8Schristos    return result
21*8e33eff8Schristos
22*8e33eff8Schristospossible_compilers = [('gcc', 'g++'), ('clang', 'clang++')]
23*8e33eff8Schristospossible_compiler_opts = [
24*8e33eff8Schristos    '-m32',
25*8e33eff8Schristos]
26*8e33eff8Schristospossible_config_opts = [
27*8e33eff8Schristos    '--enable-debug',
28*8e33eff8Schristos    '--enable-prof',
29*8e33eff8Schristos    '--disable-stats',
30*8e33eff8Schristos]
31*8e33eff8Schristosif bits_64:
32*8e33eff8Schristos    possible_config_opts.append('--with-lg-vaddr=56')
33*8e33eff8Schristos
34*8e33eff8Schristospossible_malloc_conf_opts = [
35*8e33eff8Schristos    'tcache:false',
36*8e33eff8Schristos    'dss:primary',
37*8e33eff8Schristos    'percpu_arena:percpu',
38*8e33eff8Schristos    'background_thread:true',
39*8e33eff8Schristos]
40*8e33eff8Schristos
41*8e33eff8Schristosprint 'set -e'
42*8e33eff8Schristosprint 'if [ -f Makefile ] ; then make relclean ; fi'
43*8e33eff8Schristosprint 'autoconf'
44*8e33eff8Schristosprint 'rm -rf run_tests.out'
45*8e33eff8Schristosprint 'mkdir run_tests.out'
46*8e33eff8Schristosprint 'cd run_tests.out'
47*8e33eff8Schristos
48*8e33eff8Schristosind = 0
49*8e33eff8Schristosfor cc, cxx in possible_compilers:
50*8e33eff8Schristos    for compiler_opts in powerset(possible_compiler_opts):
51*8e33eff8Schristos        for config_opts in powerset(possible_config_opts):
52*8e33eff8Schristos            for malloc_conf_opts in powerset(possible_malloc_conf_opts):
53*8e33eff8Schristos                if cc is 'clang' \
54*8e33eff8Schristos                  and '-m32' in possible_compiler_opts \
55*8e33eff8Schristos                  and '--enable-prof' in config_opts:
56*8e33eff8Schristos                    continue
57*8e33eff8Schristos                config_line = (
58*8e33eff8Schristos                    'EXTRA_CFLAGS=-Werror EXTRA_CXXFLAGS=-Werror '
59*8e33eff8Schristos                    + 'CC="{} {}" '.format(cc, " ".join(compiler_opts))
60*8e33eff8Schristos                    + 'CXX="{} {}" '.format(cxx, " ".join(compiler_opts))
61*8e33eff8Schristos                    + '../../configure '
62*8e33eff8Schristos                    + " ".join(config_opts) + (' --with-malloc-conf=' +
63*8e33eff8Schristos                    ",".join(malloc_conf_opts) if len(malloc_conf_opts) > 0
64*8e33eff8Schristos                    else '')
65*8e33eff8Schristos                )
66*8e33eff8Schristos
67*8e33eff8Schristos                # We don't want to test large vaddr spaces in 32-bit mode.
68*8e33eff8Schristos		if ('-m32' in compiler_opts and '--with-lg-vaddr=56' in
69*8e33eff8Schristos                  config_opts):
70*8e33eff8Schristos		    continue
71*8e33eff8Schristos
72*8e33eff8Schristos                # Per CPU arenas are only supported on Linux.
73*8e33eff8Schristos                linux_supported = ('percpu_arena:percpu' in malloc_conf_opts \
74*8e33eff8Schristos                  or 'background_thread:true' in malloc_conf_opts)
75*8e33eff8Schristos                # Heap profiling and dss are not supported on OS X.
76*8e33eff8Schristos                darwin_unsupported = ('--enable-prof' in config_opts or \
77*8e33eff8Schristos                  'dss:primary' in malloc_conf_opts)
78*8e33eff8Schristos                if (uname == 'Linux' and linux_supported) \
79*8e33eff8Schristos                  or (not linux_supported and (uname != 'Darwin' or \
80*8e33eff8Schristos                  not darwin_unsupported)):
81*8e33eff8Schristos                    print """cat <<EOF > run_test_%(ind)d.sh
82*8e33eff8Schristos#!/bin/sh
83*8e33eff8Schristos
84*8e33eff8Schristosset -e
85*8e33eff8Schristos
86*8e33eff8Schristosabort() {
87*8e33eff8Schristos    echo "==> Error" >> run_test.log
88*8e33eff8Schristos    echo "Error; see run_tests.out/run_test_%(ind)d.out/run_test.log"
89*8e33eff8Schristos    exit 255 # Special exit code tells xargs to terminate.
90*8e33eff8Schristos}
91*8e33eff8Schristos
92*8e33eff8Schristos# Environment variables are not supported.
93*8e33eff8Schristosrun_cmd() {
94*8e33eff8Schristos    echo "==> \$@" >> run_test.log
95*8e33eff8Schristos    \$@ >> run_test.log 2>&1 || abort
96*8e33eff8Schristos}
97*8e33eff8Schristos
98*8e33eff8Schristosecho "=> run_test_%(ind)d: %(config_line)s"
99*8e33eff8Schristosmkdir run_test_%(ind)d.out
100*8e33eff8Schristoscd run_test_%(ind)d.out
101*8e33eff8Schristos
102*8e33eff8Schristosecho "==> %(config_line)s" >> run_test.log
103*8e33eff8Schristos%(config_line)s >> run_test.log 2>&1 || abort
104*8e33eff8Schristos
105*8e33eff8Schristosrun_cmd make all tests
106*8e33eff8Schristosrun_cmd make check
107*8e33eff8Schristosrun_cmd make distclean
108*8e33eff8SchristosEOF
109*8e33eff8Schristoschmod 755 run_test_%(ind)d.sh""" % {'ind': ind, 'config_line': config_line}
110*8e33eff8Schristos                    ind += 1
111*8e33eff8Schristos
112*8e33eff8Schristosprint '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}
113