Path: blob/main/contrib/jemalloc/scripts/gen_run_tests.py
39507 views
#!/usr/bin/env python312import sys3from itertools import combinations4from os import uname5from multiprocessing import cpu_count6from subprocess import call78# Later, we want to test extended vaddr support. Apparently, the "real" way of9# checking this is flaky on OS X.10bits_64 = sys.maxsize > 2**321112nparallel = cpu_count() * 21314uname = uname()[0]1516if call("command -v gmake", shell=True) == 0:17make_cmd = 'gmake'18else:19make_cmd = 'make'2021def powerset(items):22result = []23for i in range(len(items) + 1):24result += combinations(items, i)25return result2627possible_compilers = []28for cc, cxx in (['gcc', 'g++'], ['clang', 'clang++']):29try:30cmd_ret = call([cc, "-v"])31if cmd_ret == 0:32possible_compilers.append((cc, cxx))33except:34pass35possible_compiler_opts = [36'-m32',37]38possible_config_opts = [39'--enable-debug',40'--enable-prof',41'--disable-stats',42'--enable-opt-safety-checks',43'--with-lg-page=16',44]45if bits_64:46possible_config_opts.append('--with-lg-vaddr=56')4748possible_malloc_conf_opts = [49'tcache:false',50'dss:primary',51'percpu_arena:percpu',52'background_thread:true',53]5455print('set -e')56print('if [ -f Makefile ] ; then %(make_cmd)s relclean ; fi' % {'make_cmd':57make_cmd})58print('autoconf')59print('rm -rf run_tests.out')60print('mkdir run_tests.out')61print('cd run_tests.out')6263ind = 064for cc, cxx in possible_compilers:65for compiler_opts in powerset(possible_compiler_opts):66for config_opts in powerset(possible_config_opts):67for malloc_conf_opts in powerset(possible_malloc_conf_opts):68if cc == 'clang' \69and '-m32' in possible_compiler_opts \70and '--enable-prof' in config_opts:71continue72config_line = (73'EXTRA_CFLAGS=-Werror EXTRA_CXXFLAGS=-Werror '74+ 'CC="{} {}" '.format(cc, " ".join(compiler_opts))75+ 'CXX="{} {}" '.format(cxx, " ".join(compiler_opts))76+ '../../configure '77+ " ".join(config_opts) + (' --with-malloc-conf=' +78",".join(malloc_conf_opts) if len(malloc_conf_opts) > 079else '')80)8182# We don't want to test large vaddr spaces in 32-bit mode.83if ('-m32' in compiler_opts and '--with-lg-vaddr=56' in84config_opts):85continue8687# Per CPU arenas are only supported on Linux.88linux_supported = ('percpu_arena:percpu' in malloc_conf_opts \89or 'background_thread:true' in malloc_conf_opts)90# Heap profiling and dss are not supported on OS X.91darwin_unsupported = ('--enable-prof' in config_opts or \92'dss:primary' in malloc_conf_opts)93if (uname == 'Linux' and linux_supported) \94or (not linux_supported and (uname != 'Darwin' or \95not darwin_unsupported)):96print("""cat <<EOF > run_test_%(ind)d.sh97#!/bin/sh9899set -e100101abort() {102echo "==> Error" >> run_test.log103echo "Error; see run_tests.out/run_test_%(ind)d.out/run_test.log"104exit 255 # Special exit code tells xargs to terminate.105}106107# Environment variables are not supported.108run_cmd() {109echo "==> \$@" >> run_test.log110\$@ >> run_test.log 2>&1 || abort111}112113echo "=> run_test_%(ind)d: %(config_line)s"114mkdir run_test_%(ind)d.out115cd run_test_%(ind)d.out116117echo "==> %(config_line)s" >> run_test.log118%(config_line)s >> run_test.log 2>&1 || abort119120run_cmd %(make_cmd)s all tests121run_cmd %(make_cmd)s check122run_cmd %(make_cmd)s distclean123EOF124chmod 755 run_test_%(ind)d.sh""" % {'ind': ind, 'config_line': config_line,125'make_cmd': make_cmd})126ind += 1127128print('for i in `seq 0 %(last_ind)d` ; do echo run_test_${i}.sh ; done | xargs'129' -P %(nparallel)d -n 1 sh' % {'last_ind': ind-1, 'nparallel': nparallel})130131132