run.sh 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. #!/bin/bash
  2. set -e -o pipefail
  3. echo "Checking installed Java"
  4. java -version
  5. TESTS_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
  6. export TESTS_DIR="$TESTS_DIR"
  7. export RED='\033[0;31m'
  8. export CYAN='\033[1;36m'
  9. export BLUE='\033[1;34m'
  10. export YELLOW='\033[1;33m'
  11. export GREEN='\033[1;32m'
  12. export NC='\033[0m'
  13. ARGS_CPP=""
  14. ARGS_VALID_CPP_STANDARDS=",11,14,17,20,23,26,"
  15. ARGS_CPP_STANDARDS=","
  16. ARGS_CPP_VERSIONS=","
  17. ARGS_TESTS=","
  18. ARGS_CPP_BITS=""
  19. for arg in "$@"; do
  20. if [[ "$arg" == test-* ]]; then
  21. ARGS_TESTS="${ARGS_TESTS}${arg},"
  22. continue
  23. fi
  24. if [[ "$arg" == "32" || "$arg" == "64" ]]; then
  25. if [[ -n "$ARGS_CPP_BITS" ]]; then
  26. echo Expected at most one bits-argument: 32 or 64
  27. exit 1
  28. fi
  29. ARGS_CPP_BITS="$arg"
  30. continue
  31. fi
  32. if [[ "$ARGS_VALID_CPP_STANDARDS" == *,$arg,* ]]; then
  33. ARGS_CPP_STANDARDS="$ARGS_CPP_STANDARDS$arg,"
  34. else
  35. if [[ "$arg" == v* ]]; then
  36. ARGS_CPP_VERSIONS="$ARGS_CPP_VERSIONS${arg:1},"
  37. else
  38. if [[ -n "$ARGS_CPP" ]]; then
  39. echo Expected just one non-version argument: g++, clang++ or msvc, but found "$ARGS_CPP" and "$arg"
  40. exit 1
  41. fi
  42. if [[ ! "$arg" == "g++" && ! "$arg" == "clang++" && ! "$arg" == "msvc" ]]; then
  43. echo Expected just one non-version argument: g++, clang++ or msvc, but "$arg" found
  44. exit 1
  45. fi
  46. ARGS_CPP="$arg"
  47. fi
  48. fi
  49. done
  50. if [[ ! "$ARGS_TESTS" == "," ]]; then
  51. echo [INFO] Filter tests: ${ARGS_TESTS:1:${#ARGS_TESTS}-2}
  52. fi
  53. if [[ ! "$ARGS_CPP" == "" ]]; then
  54. echo [INFO] Filter CPP: "$ARGS_CPP"
  55. fi
  56. if [[ ! "$ARGS_CPP_STANDARDS" == "," ]]; then
  57. echo [INFO] Filter standards: ${ARGS_CPP_STANDARDS:1:${#ARGS_CPP_STANDARDS}-2}
  58. fi
  59. if [[ ! "$ARGS_CPP_VERSIONS" == "," ]]; then
  60. echo [INFO] Filter versions: ${ARGS_CPP_VERSIONS:1:${#ARGS_CPP_VERSIONS}-2}
  61. fi
  62. if [[ ! "$ARGS_CPP_BITS" == "" ]]; then
  63. echo [INFO] Filter target arch.: "$ARGS_CPP_BITS"
  64. fi
  65. COMPILERS=('clang++' 'g++')
  66. if [[ ! "$ARGS_CPP" == "" ]]; then
  67. if [[ "$ARGS_CPP" == "msvc" ]]; then
  68. COMPILERS=()
  69. else
  70. COMPILERS=("$ARGS_CPP")
  71. fi
  72. fi
  73. echo ""
  74. echo GNU-like compilers:
  75. printf ' %s\n' "${COMPILERS[@]}"
  76. CPP_STANDARDS=()
  77. MSVC_CPP_STANDARDS=()
  78. for v in 11 14 17 20 23 26; do
  79. if [[ "$ARGS_CPP_STANDARDS" == "," || "$ARGS_CPP_STANDARDS" == *,$v,* ]]; then
  80. CPP_STANDARDS+=("--std=c++$v")
  81. MSVC_CPP_STANDARDS+=("-std:c++$v")
  82. fi
  83. done
  84. echo ""
  85. echo Standards:
  86. printf ' %s\n' "${CPP_STANDARDS[@]}"
  87. uname_output="$(uname -s)"
  88. case "${uname_output}" in
  89. Linux*) machine=Linux ;;
  90. Darwin*) machine=Mac ;;
  91. CYGWIN*) machine=Windows ;;
  92. MINGW*) machine=Windows ;;
  93. MSYS*) machine=Windows ;;
  94. *) echo "Unknown system '${uname_output}'" && exit 1 ;;
  95. esac
  96. export MACHINE="$machine"
  97. run_tests() {
  98. export INVOCATION_ID=$RANDOM
  99. export CPP="$1"
  100. export CPP_STANDARD="$2"
  101. echo -e Running tests \("${CYAN}""$CPP"@"$CPP_STANDARD""${NC}"\)
  102. echo ""
  103. for test_dir in "$TESTS_DIR"/*/; do
  104. test=$(basename "$test_dir")
  105. if [[ $test == test-* ]]; then
  106. if [[ "$ARGS_TESTS" == "," || "$ARGS_TESTS" == *,$test,* ]]; then
  107. echo -e Running "${BLUE}${test}${NC}" \("$CPP"@"$CPP_STANDARD"\)
  108. export TEST_DIR="$test_dir"
  109. export CPP_INCLUDE_DIR=${TESTS_DIR}/..
  110. export CPP_OPTS=""
  111. if [[ -n "$ARGS_CPP_BITS" ]]; then
  112. export CPP_OPTS="-m$ARGS_CPP_BITS"
  113. fi
  114. pushd "$test_dir" 1>/dev/null 2>&1
  115. bash "${test_dir}run.sh"
  116. echo -e Done "${BLUE}$test${NC}" \("${CYAN}""$CPP"@"$CPP_STANDARD""${NC}"\)
  117. echo ""
  118. popd 1>&2 1>/dev/null 2>&1
  119. fi
  120. fi
  121. done
  122. rm -rf "$TESTS_DIR"/tester-lcmp
  123. echo -e Done all tests \("${CYAN}""$CPP"@"$CPP_STANDARD""${NC}"\)
  124. echo ""
  125. }
  126. VALGRIND=""
  127. valgrind_output=$(valgrind 2>&1 || true)
  128. if [[ $valgrind_output == *"--help"* ]]; then
  129. VALGRIND="valgrind -q"
  130. echo Valgrind mode is ON
  131. else
  132. echo Valgrind mode is OFF
  133. fi
  134. export VALGRIND="$VALGRIND"
  135. done=""
  136. if [[ "$machine" == "Windows" && ("$ARGS_CPP" == "" || "$ARGS_CPP" == "msvc") ]]; then
  137. VS_RELEASES=("Professional" "Enterprise" "Community")
  138. PROGRAM_FILES=("${PROGRAMFILES}" "${PROGRAMFILES} (x86)")
  139. for vs_release in "${VS_RELEASES[@]}"; do
  140. for program_files in "${PROGRAM_FILES[@]}"; do
  141. for ((version = 2000; version <= 2100; version++)); do
  142. vs_dir="$program_files\\Microsoft Visual Studio\\$version\\$vs_release\\VC\\Auxiliary\\Build"
  143. if [[ -d $vs_dir ]]; then
  144. for bits in 32 64; do
  145. vcvars_bat_file="$vs_dir\\vcvars$bits.bat"
  146. if [[ -f $vcvars_bat_file ]]; then
  147. echo "Compiler Visual Studio $version ($vs_release-$bits) has been found"
  148. echo call \""$vcvars_bat_file"\" >do-vcvars.bat
  149. echo "bash -c export > vcvars.env" >>do-vcvars.bat
  150. python file-runner.py do-vcvars.bat
  151. grep -v -E "(\(.*=)|(\!.*=)|([A-Z]\-[A-Z].*=)" <vcvars.env >vcvars_filtered.env
  152. source vcvars_filtered.env
  153. rm -f do-vcvars.bat vcvars.env vcvars_filtered.env
  154. for cpp_standard in "${MSVC_CPP_STANDARDS[@]}"; do
  155. touch empty_file.cpp
  156. cpp_output=$(cl.exe "$cpp_standard" empty_file.cpp 2>&1 || true)
  157. rm -f empty_file.*
  158. if [[ ! $cpp_output == *"unknown"* ]]; then
  159. echo Testing msvc-"$version"-$bits@"$cpp_standard"
  160. run_tests "cl.exe" "$cpp_standard"
  161. if [[ ! "$done" == "" ]]; then
  162. done="$done, "
  163. fi
  164. done="${done}msvc-$version-$bits@$cpp_standard"
  165. fi
  166. done
  167. fi
  168. done
  169. fi
  170. done
  171. done
  172. done
  173. fi
  174. # Find /c/Programs/*/bin/g++ in case of Windows and no ARGS_CPP
  175. if [[ "$MACHINE" == "Windows" && "$ARGS_CPP" == "" ]]; then
  176. for d in /c/Programs/*/; do
  177. dir="${d}bin"
  178. OLD_PATH="$PATH"
  179. export PATH="$dir":$PATH
  180. gpp="${d}bin/g++.exe"
  181. gpp_output=$($gpp 2>&1 || true)
  182. if [[ $gpp_output == *"no input files"* ]]; then
  183. for gpp_standard in "${CPP_STANDARDS[@]}"; do
  184. touch empty_file.cpp
  185. gpp_output=$($gpp "$gpp_standard" empty_file.cpp 2>&1 || true)
  186. if [[ ! $gpp_output == *"unrecognized"* && ! $gpp_output == *"standard"* ]]; then
  187. run_tests "$gpp" "$gpp_standard"
  188. if [[ ! "$done" == "" ]]; then
  189. done="$done, "
  190. fi
  191. done="$done$gpp@$gpp_standard"
  192. fi
  193. rm -f empty_file.*
  194. done
  195. fi
  196. export PATH="$OLD_PATH"
  197. done
  198. fi
  199. for compiler in "${COMPILERS[@]}"; do
  200. for version in 0 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
  201. if [[ "$ARGS_CPP_VERSIONS" == "," || "$ARGS_CPP_VERSIONS" == *,$version,* ]]; then
  202. cpp="$compiler-$version"
  203. if [[ "$version" == 0 ]]; then
  204. cpp="$compiler"
  205. fi
  206. cpp_output=$($cpp 2>&1 || true)
  207. if [[ $cpp_output == *"no input files"* ]]; then
  208. echo "Compiler '$cpp' has been found"
  209. for cpp_standard in "${CPP_STANDARDS[@]}"; do
  210. touch empty_file.cpp
  211. cpp_output=$($cpp "$cpp_standard" empty_file.cpp 2>&1 || true)
  212. if [[ ! $cpp_output == *"unrecognized"* && ! $cpp_output == *"standard"* ]]; then
  213. if [[ "$machine" == "Windows" && "$cpp" == "clang++" && "$cpp_standard" == "--std=c++11" ]]; then
  214. echo Ignore "$cpp" "$cpp_standard" on $machine
  215. continue
  216. fi
  217. run_tests "$cpp" "$cpp_standard"
  218. if [[ ! "$done" == "" ]]; then
  219. done="$done, "
  220. fi
  221. done="$done$cpp@$cpp_standard"
  222. fi
  223. rm -f empty_file.*
  224. done
  225. fi
  226. fi
  227. done
  228. done
  229. if [[ -z "$done" ]]; then
  230. echo -e "${RED}[ERROR]${NC} No compilers found\n"
  231. exit 1
  232. fi
  233. echo -e "${GREEN}Successfully tested on${NC}: $done\n"