run.sh 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. #!/bin/bash
  2. set -e -o 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. MSVC_INCLUDE_YEAR="2022"
  18. WINKIT_INCLUDE_VERSION="10.0.19041.0"
  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; 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. #if [[ "$machine" == "Windows" && ("$ARGS_CPP" == "" || "$ARGS_CPP" == "clang++") ]]; then
  98. # for f in msvc-${MSVC_INCLUDE_YEAR}-include windows-kit-${WINKIT_INCLUDE_VERSION}-include; do
  99. # rm -rf "${TESTS_DIR:?}"/lib/$f && mkdir -p "$TESTS_DIR"/lib/$f
  100. # 7z x -o"${TESTS_DIR:?}"/lib/$f "$TESTS_DIR"/lib/$f.7z
  101. # done
  102. #fi
  103. run_tests() {
  104. export INVOCATION_ID=$RANDOM
  105. export CPP="$1"
  106. export CPP_STANDARD="$2"
  107. echo -e Running tests \("${CYAN}""$CPP"@"$CPP_STANDARD""${NC}"\)
  108. echo ""
  109. for test_dir in "$TESTS_DIR"/*/; do
  110. test=$(basename "$test_dir")
  111. if [[ $test == test-* ]]; then
  112. if [[ "$ARGS_TESTS" == "," || "$ARGS_TESTS" == *,$test,* ]]; then
  113. echo -e Running "${BLUE}${test}${NC}" \("$CPP"@"$CPP_STANDARD"\)
  114. export TEST_DIR="$test_dir"
  115. export CPP_INCLUDE_DIR=${TESTS_DIR}/..
  116. export CPP_OPTS=""
  117. if [[ -n "$ARGS_CPP_BITS" ]]; then
  118. export CPP_OPTS="-m$ARGS_CPP_BITS"
  119. fi
  120. pushd "$test_dir" 1>/dev/null 2>&1
  121. bash "${test_dir}run.sh"
  122. echo -e Done "${BLUE}$test${NC}" \("${CYAN}""$CPP"@"$CPP_STANDARD""${NC}"\)
  123. echo ""
  124. popd 1>&2 1>/dev/null 2>&1
  125. fi
  126. fi
  127. done
  128. rm -rf "$TESTS_DIR"/tester-lcmp
  129. echo -e Done all tests \("${CYAN}""$CPP"@"$CPP_STANDARD""${NC}"\)
  130. echo ""
  131. }
  132. VALGRIND=""
  133. valgrind_output=$(valgrind 2>&1 || true)
  134. if [[ $valgrind_output == *"--help"* ]]; then
  135. VALGRIND="valgrind -q"
  136. echo Valgrind mode is ON
  137. else
  138. echo Valgrind mode is OFF
  139. fi
  140. export VALGRIND="$VALGRIND"
  141. done=""
  142. if [[ "$machine" == "Windows" && ("$ARGS_CPP" == "" || "$ARGS_CPP" == "msvc") ]]; then
  143. VS_RELEASES=("Professional" "Enterprise" "Community")
  144. PROGRAM_FILES=("${PROGRAMFILES}" "${PROGRAMFILES} (x86)")
  145. for vs_release in "${VS_RELEASES[@]}"; do
  146. for program_files in "${PROGRAM_FILES[@]}"; do
  147. for ((version = 2000; version <= 2100; version++)); do
  148. vs_dir="$program_files\\Microsoft Visual Studio\\$version\\$vs_release\\VC\\Auxiliary\\Build"
  149. if [[ -d $vs_dir ]]; then
  150. for bits in 32 64; do
  151. vcvars_bat_file="$vs_dir\\vcvars$bits.bat"
  152. if [[ -f $vcvars_bat_file ]]; then
  153. echo "Compiler Visual Studio $version ($vs_release-$bits) has been found"
  154. echo call \""$vcvars_bat_file"\" >do-vcvars.bat
  155. echo "bash -c export > vcvars.env" >>do-vcvars.bat
  156. python file-runner.py do-vcvars.bat
  157. grep -v -E "(\(.*=)|(\!.*=)|([A-Z]\-[A-Z].*=)" <vcvars.env >vcvars_filtered.env
  158. source vcvars_filtered.env
  159. rm -f do-vcvars.bat vcvars.env vcvars_filtered.env
  160. for cpp_standard in "${MSVC_CPP_STANDARDS[@]}"; do
  161. touch empty_file.cpp
  162. cpp_output=$(cl.exe "$cpp_standard" empty_file.cpp 2>&1 || true)
  163. rm -f empty_file.*
  164. if [[ ! $cpp_output == *"unknown"* ]]; then
  165. echo Testing msvc-"$version"-$bits@"$cpp_standard"
  166. run_tests "cl.exe" "$cpp_standard"
  167. if [[ ! "$done" == "" ]]; then
  168. done="$done, "
  169. fi
  170. done="${done}msvc-$version-$bits@$cpp_standard"
  171. fi
  172. done
  173. fi
  174. done
  175. fi
  176. done
  177. done
  178. done
  179. fi
  180. # Find /c/Programs/*/bin/g++ in case of Windows and no ARGS_CPP
  181. if [[ "$MACHINE" == "Windows" && "$ARGS_CPP" == "" ]]; then
  182. for d in /c/Programs/*/; do
  183. dir="${d}bin"
  184. OLD_PATH="$PATH"
  185. export PATH="$dir":$PATH
  186. gpp="${d}bin/g++.exe"
  187. gpp_output=$($gpp 2>&1 || true)
  188. if [[ $gpp_output == *"no input files"* ]]; then
  189. for gpp_standard in "${CPP_STANDARDS[@]}"; do
  190. touch empty_file.cpp
  191. gpp_output=$($gpp "$gpp_standard" empty_file.cpp 2>&1 || true)
  192. if [[ ! $gpp_output == *"unrecognized"* && ! $gpp_output == *"standard"* ]]; then
  193. run_tests "$gpp" "$gpp_standard"
  194. if [[ ! "$done" == "" ]]; then
  195. done="$done, "
  196. fi
  197. done="$done$gpp@$gpp_standard"
  198. fi
  199. rm -f empty_file.*
  200. done
  201. fi
  202. export PATH="$OLD_PATH"
  203. done
  204. fi
  205. for compiler in "${COMPILERS[@]}"; do
  206. for version in 0 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
  207. if [[ "$ARGS_CPP_VERSIONS" == "," || "$ARGS_CPP_VERSIONS" == *,$version,* ]]; then
  208. cpp="$compiler-$version"
  209. if [[ "$version" == 0 ]]; then
  210. cpp="$compiler"
  211. fi
  212. cpp_output=$($cpp 2>&1 || true)
  213. if [[ $cpp_output == *"no input files"* ]]; then
  214. echo "Compiler '$cpp' has been found"
  215. for cpp_standard in "${CPP_STANDARDS[@]}"; do
  216. touch empty_file.cpp
  217. cpp_output=$($cpp "$cpp_standard" empty_file.cpp 2>&1 || true)
  218. if [[ ! $cpp_output == *"unrecognized"* && ! $cpp_output == *"standard"* ]]; then
  219. if [[ "$machine" == "Windows" && "$cpp" == "clang++" && "$cpp_standard" == "--std=c++11" ]]; then
  220. echo Ignore "$cpp" "$cpp_standard" on $machine
  221. continue
  222. fi
  223. run_tests "$cpp" "$cpp_standard"
  224. if [[ ! "$done" == "" ]]; then
  225. done="$done, "
  226. fi
  227. done="$done$cpp@$cpp_standard"
  228. fi
  229. rm -f empty_file.*
  230. done
  231. fi
  232. fi
  233. done
  234. done
  235. #if [[ "$machine" == "Windows" ]]; then
  236. # for f in msvc-${MSVC_INCLUDE_YEAR}-include windows-kit-${WINKIT_INCLUDE_VERSION}-include; do
  237. # rm -rf "${TESTS_DIR:?}"/lib/$f
  238. # done
  239. #fi
  240. if [[ -z "$done" ]]; then
  241. echo -e "${RED}[ERROR]${NC} No compilers found\n"
  242. exit 1
  243. fi
  244. echo -e "${GREEN}Successfully tested on${NC}: $done\n"