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