run.sh 8.2 KB

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