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