1
0

run.sh 7.1 KB

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