gen_run_tests.py 4.0 KB

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