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