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