mono-test.sh 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. #! /bin/sh -e
  2. test_suite="$1"
  3. test_argument_1="$2"
  4. test_argument_2="$3"
  5. xunit_results_path="$(pwd)/testResults.xml"
  6. cd "$(dirname "$0")" || exit 1
  7. r=$(pwd)
  8. MONO_CFG_DIR="$r/_tmpinst/etc"
  9. PATH="$r/_tmpinst/bin:$PATH"
  10. MONO_EXECUTABLE=${MONO_EXECUTABLE:-"$r/mono-sgen"}
  11. MONO_PATH="$r/net_4_x"
  12. export MONO_CFG_DIR MONO_PATH MONO_EXECUTABLE PATH
  13. sed "s,\$test_root_dir,$r,g" "$r/_tmpinst/etc/mono/config.tmpl" > "$r/_tmpinst/etc/mono/config"
  14. sed "s,\$test_root_dir,$r,g" "$r/tests/runtime/tests-config.tmpl" > "$r/tests/runtime/tests-config"
  15. chmod +x "${MONO_EXECUTABLE}"
  16. echo "---------------------------------------------------------------------------------------"
  17. "${MONO_EXECUTABLE}" --version
  18. echo "---------------------------------------------------------------------------------------"
  19. case "$(uname)" in
  20. "Linux")
  21. mkdir -p ~/.config/.mono/
  22. wget -qO- https://download.mono-project.com/test/new-certs.tgz| tar zx -C ~/.config/.mono/
  23. ;;
  24. esac
  25. if [ "$test_suite" = "--xunit" ]; then
  26. cd net_4_x || exit 1
  27. export MONO_PATH="$r/net_4_x/tests:$MONO_PATH"
  28. export REMOTE_EXECUTOR="$r/net_4_x/tests/RemoteExecutorConsoleApp.exe"
  29. case "$test_argument_1" in
  30. *"Mono.Profiler.Log"*)
  31. # necessary for the runtime to find libmono-profiler-log
  32. export LD_LIBRARY_PATH="$r:$LD_LIBRARY_PATH"
  33. export DYLD_LIBRARY_PATH="$r:$LD_LIBRARY_PATH"
  34. ;;
  35. *"System.Net.Http"*)
  36. export MONO_URI_DOTNETRELATIVEORABSOLUTE=true
  37. ;;
  38. esac
  39. case "$(uname)" in
  40. "Darwin")
  41. ADDITIONAL_TRAITS="-notrait category=nonosxtests"
  42. ;;
  43. "Linux")
  44. ADDITIONAL_TRAITS="-notrait category=nonlinuxtests"
  45. ;;
  46. esac
  47. "${MONO_EXECUTABLE}" --config "$r/_tmpinst/etc/mono/config" --debug "$r/net_4_x/xunit.console.exe" "$r/$test_argument_1" -noappdomain -noshadow -parallel none -xml "${xunit_results_path}" -notrait category=failing -notrait category=nonmonotests -notrait Benchmark=true -notrait category=outerloop $ADDITIONAL_TRAITS
  48. exit $?
  49. fi
  50. if [ "$test_suite" = "--nunit" ]; then
  51. cd net_4_x || exit 1
  52. export MONO_PATH="$r/net_4_x/tests:$MONO_PATH"
  53. export MONO_SYSTEMWEB_CACHEDEPENDENCY_SHARED_FSW=1
  54. case "$test_argument_1" in
  55. *"Microsoft.Build"*)
  56. export TESTING_MONO=a
  57. export MSBuildExtensionsPath="$r/net_4_x/tests/xbuild/extensions"
  58. export XBUILD_FRAMEWORK_FOLDERS_PATH="$r/net_4_x/tests/xbuild/frameworks"
  59. case "$test_argument_1" in
  60. "xbuild_12"*) export MONO_PATH="$r/xbuild_12:$r/xbuild_12/tests:$MONO_PATH" ;;
  61. "xbuild_14"*) export MONO_PATH="$r/xbuild_14:$r/xbuild_14/tests:$MONO_PATH" ;;
  62. esac
  63. ;;
  64. *"Mono.Messaging.RabbitMQ"*)
  65. export MONO_MESSAGING_PROVIDER=Mono.Messaging.RabbitMQ.RabbitMQMessagingProvider,Mono.Messaging.RabbitMQ
  66. ;;
  67. *"System.Windows.Forms"*)
  68. sudo apt install -y xvfb xauth
  69. XVFBRUN="xvfb-run -a --"
  70. ADDITIONAL_TEST_EXCLUDES="NotWithXvfb" # TODO: find out why this works on Jenkins?
  71. ;;
  72. esac
  73. case "$test_argument_2" in
  74. "--flaky-test-retries="*)
  75. export MONO_FLAKY_TEST_RETRIES=$(echo "$test_argument_2" | cut -d "=" -f2)
  76. ;;
  77. esac
  78. cp -f "$r/$test_argument_1.nunitlite.config" "$r/net_4_x/nunit-lite-console.exe.config"
  79. MONO_REGISTRY_PATH="$HOME/.mono/registry" MONO_TESTS_IN_PROGRESS="yes" $XVFBRUN "${MONO_EXECUTABLE}" --config "$r/_tmpinst/etc/mono/config" --debug "$r/net_4_x/nunit-lite-console.exe" "$r/$test_argument_1" -exclude=NotWorking,CAS,$ADDITIONAL_TEST_EXCLUDES -labels -format:xunit -result:"${xunit_results_path}"
  80. exit $?
  81. fi
  82. if [ "$test_suite" = "--verify" ]; then
  83. verifiable_files=$(find net_4_x -maxdepth 1 -name "*.dll" -or -name "*.exe" | grep -v System.Runtime.CompilerServices.Unsafe.dll | grep -v Xunit.NetCore.Extensions.dll)
  84. ok=true
  85. for asm in $verifiable_files; do
  86. echo "$asm"
  87. if [ ! -f "$asm" ]; then continue; fi
  88. if "${MONO_EXECUTABLE}" --config "$r/_tmpinst/etc/mono/config" --compile-all --verify-all --security=verifiable "$asm"; then
  89. echo "$asm verified OK"
  90. else
  91. echo "$asm verification failed"
  92. ok=false
  93. fi
  94. done;
  95. if [ "$ok" = "true" ]; then
  96. echo "<?xml version=\"1.0\" encoding=\"utf-8\"?><assemblies><assembly name=\"verify\" environment=\"Mono\" test-framework=\"custom\" run-date=\"$(date +%F)\" run-time=\"$(date +%T)\" total=\"1\" passed=\"1\" failed=\"0\" skipped=\"0\" errors=\"0\" time=\"0\"><collection total=\"1\" passed=\"1\" failed=\"0\" skipped=\"0\" name=\"Test collection for verify\" time=\"0\"><test name=\"verify.all\" type=\"verify\" method=\"all\" time=\"0\" result=\"Pass\"></test></collection></assembly></assemblies>" > "${xunit_results_path}";
  97. exit 0
  98. else
  99. echo "<?xml version=\"1.0\" encoding=\"utf-8\"?><assemblies><assembly name=\"verify\" environment=\"Mono\" test-framework=\"custom\" run-date=\"$(date +%F)\" run-time=\"$(date +%T)\" total=\"1\" passed=\"0\" failed=\"1\" skipped=\"0\" errors=\"0\" time=\"0\"><collection total=\"1\" passed=\"0\" failed=\"1\" skipped=\"0\" name=\"Test collection for verify\" time=\"0\"><test name=\"verify.all\" type=\"verify\" method=\"all\" time=\"0\" result=\"Fail\"><failure exception-type=\"VerifyException\"><message><![CDATA[Verifying framework assemblies failed. Check the log for more details.]]></message></failure></test></collection></assembly></assemblies>" > "${xunit_results_path}";
  100. exit 1
  101. fi
  102. fi
  103. if [ "$test_suite" = "--mcs" ]; then
  104. cd tests/mcs || exit 1
  105. "${MONO_EXECUTABLE}" --config "$r/_tmpinst/etc/mono/config" --verify-all compiler-tester.exe -mode:pos -files:v4 -compiler:"$r/net_4_x/mcs.exe" -reference-dir:"$r/net_4_x" -issues:known-issues-net_4_x -log:net_4_x.log -il:ver-il-net_4_x.xml -resultXml:"${xunit_results_path}" -compiler-options:"-d:NET_4_0;NET_4_5 -debug"
  106. exit $?
  107. fi
  108. if [ "$test_suite" = "--mcs-errors" ]; then
  109. cd tests/mcs-errors || exit 1
  110. "${MONO_EXECUTABLE}" --config "$r/_tmpinst/etc/mono/config" compiler-tester.exe -mode:neg -files:v4 -compiler:"$r/net_4_x/mcs.exe" -reference-dir:"$r/net_4_x" -issues:known-issues-net_4_x -log:net_4_x.log -resultXml:"${xunit_results_path}" -compiler-options:"-v --break-on-ice -d:NET_4_0;NET_4_5"
  111. exit $?
  112. fi
  113. if [ "$test_suite" = "--aot-test" ]; then
  114. failed=0
  115. passed=0
  116. failed_tests=""
  117. profile="$r/net_4_x"
  118. tmpfile=$(mktemp -t mono_aot_outputXXXXXX) || exit 1
  119. rm -f "test-aot-*.stdout" "test-aot-*.stderr" "${xunit_results_path}.cases.xml"
  120. for assembly in "$profile"/*.dll; do
  121. asm_name=$(basename "$assembly")
  122. echo "... $asm_name"
  123. for conf in "|regular" "--gc=boehm|boehm"; do
  124. name=$(echo $conf | cut -d\| -f 2)
  125. params=$(echo $conf | cut -d\| -f 1)
  126. test_name="${asm_name}|${name}"
  127. echo " $test_name"
  128. if "${MONO_EXECUTABLE}" --config "$r/_tmpinst/etc/mono/config" $params --aot=outfile="$tmpfile" "$assembly" > "test-aot-${name}-${asm_name}.stdout" 2> "test-aot-${name}-${asm_name}.stderr"
  129. then
  130. passed=$((passed + 1))
  131. resultstring="Pass"
  132. else \
  133. failed=$((failed + 1))
  134. failed_tests="${failed_tests} $test_name"
  135. resultstring="Fail"
  136. fi
  137. echo "<test name=\"aot-test.$name.$asm_name\" type=\"aot-test.$name\" method=\"$asm_name\" time=\"0\" result=\"$resultstring\">" >> "${xunit_results_path}.cases.xml"
  138. if [ "$resultstring" = "Fail" ]; then
  139. echo "<failure exception-type=\"AotTestException\"><message><![CDATA[
  140. STDOUT:
  141. $(cat "test-aot-${name}-${asm_name}.stdout")
  142. STDERR:
  143. $(cat "test-aot-${name}-${asm_name}.stderr")]]></message><stack-trace></stack-trace></failure>" >> "${xunit_results_path}.cases.xml"; fi
  144. echo "</test>" >> "${xunit_results_path}.cases.xml"
  145. done
  146. done
  147. echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\
  148. <assemblies>\
  149. <assembly name=\"aot-test\" environment=\"Mono\" test-framework=\"custom\" run-date=\"$(date +%F)\" run-time=\"$(date +%T)\" total=\"$((passed + failed))\" passed=\"$passed\" failed=\"$failed\" skipped=\"0\" errors=\"0\" time=\"0\">\
  150. <collection total=\"$((passed + failed))\" passed=\"$passed\" failed=\"$failed\" skipped=\"0\" name=\"Test collection for aot-test\" time=\"0\">\
  151. $(cat "${xunit_results_path}.cases.xml")
  152. </collection>\
  153. </assembly>\
  154. </assemblies>" > "${xunit_results_path}";
  155. rm "$tmpfile"
  156. echo "${passed} test(s) passed. ${failed} test(s) did not pass."
  157. if [ "${failed}" != 0 ]; then
  158. echo ""
  159. echo "Failed tests:"
  160. echo ""
  161. for i in ${failed_tests}; do
  162. echo "${i}";
  163. done
  164. exit 1
  165. fi
  166. exit 0
  167. fi
  168. if [ "$test_suite" = "--mini" ]; then
  169. cd tests/mini || exit 1
  170. "${MONO_EXECUTABLE}" --config "$r/_tmpinst/etc/mono/config" --regression ./*.exe > regressiontests.out 2>&1
  171. cat regressiontests.out
  172. if grep -q "100% pass" regressiontests.out; then
  173. resultstring="Pass"
  174. failurescount=0
  175. successcount=1
  176. else
  177. resultstring="Fail"
  178. failurescount=1
  179. successcount=0
  180. fi
  181. echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\
  182. <assemblies>\
  183. <assembly name=\"mini.regression-tests\" environment=\"Mono\" test-framework=\"custom\" run-date=\"$(date +%F)\" run-time=\"$(date +%T)\" total=\"1\" passed=\"$successcount\" failed=\"$failurescount\" skipped=\"0\" errors=\"0\" time=\"0\">\
  184. <collection total=\"1\" passed=\"$successcount\" failed=\"$failurescount\" skipped=\"0\" name=\"Test collection for mini.regression-tests\" time=\"0\">\
  185. <test name=\"mini.regression-tests.all\" type=\"mini.regression-tests\" method=\"all\" time=\"0\" result=\"$resultstring\">" > "${xunit_results_path}"
  186. if [ "$resultstring" = "Fail" ]; then echo "<failure exception-type=\"MiniRegressionTestsException\"><message><![CDATA[$(cat regressiontests.out)]]></message><stack-trace></stack-trace></failure>" >> "${xunit_results_path}"; fi
  187. echo "</test>
  188. </collection>\
  189. </assembly>\
  190. </assemblies>" >> "${xunit_results_path}";
  191. exit $failurescount
  192. fi
  193. if [ "$test_suite" = "--symbolicate" ]; then
  194. cd tests/symbolicate || exit 1
  195. "${MONO_EXECUTABLE}" --config "$r/_tmpinst/etc/mono/config" --aot 2>&1 | grep -q "AOT compilation is not supported" && echo "No AOT support, skipping tests." && exit 0
  196. ok=true
  197. for config in without-aot with-aot with-aot-msym; do
  198. OUT_DIR="$config"
  199. MSYM_DIR="$OUT_DIR/msymdir"
  200. STACKTRACE_FILE="$OUT_DIR/stacktrace.out"
  201. SYMBOLICATE_RAW_FILE="$OUT_DIR/symbolicate_raw.out"
  202. SYMBOLICATE_RESULT_FILE="$OUT_DIR/symbolicate.result"
  203. SYMBOLICATE_EXPECTED_FILE=symbolicate.expected
  204. echo "Checking StackTraceDumper.exe in configuration $config..."
  205. rm -rf "$OUT_DIR"
  206. mkdir -p "$OUT_DIR"
  207. mkdir -p "$MSYM_DIR"
  208. cp StackTraceDumper.exe "$OUT_DIR"
  209. cp StackTraceDumper.pdb "$OUT_DIR"
  210. # store symbols
  211. "${MONO_EXECUTABLE}" --config "$r/_tmpinst/etc/mono/config" "$r/net_4_x/mono-symbolicate.exe" store-symbols "$MSYM_DIR" "$OUT_DIR"
  212. "${MONO_EXECUTABLE}" --config "$r/_tmpinst/etc/mono/config" "$r/net_4_x/mono-symbolicate.exe" store-symbols "$MSYM_DIR" "$r/net_4_x"
  213. if [ "$config" = "with-aot" ]; then "${MONO_EXECUTABLE}" --config "$r/_tmpinst/etc/mono/config" -O=-inline --aot "$OUT_DIR/StackTraceDumper.exe"; fi
  214. if [ "$config" = "with-aot-msym" ]; then "${MONO_EXECUTABLE}" --config "$r/_tmpinst/etc/mono/config" -O=-inline --aot=msym-dir="$MSYM_DIR" "$OUT_DIR/StackTraceDumper.exe"; fi
  215. # check diff
  216. "${MONO_EXECUTABLE}" --config "$r/_tmpinst/etc/mono/config" -O=-inline StackTraceDumper.exe > "$STACKTRACE_FILE"
  217. "${MONO_EXECUTABLE}" --config "$r/_tmpinst/etc/mono/config" "$r/net_4_x/mono-symbolicate.exe" "$MSYM_DIR" "$STACKTRACE_FILE" > "$SYMBOLICATE_RAW_FILE"
  218. tr "\\\\" "/" < "$SYMBOLICATE_RAW_FILE" | sed "s,) .* in .*/mcs/,) in mcs/," | sed "s,) .* in .*/external/,) in external/," | sed '/\[MVID\]/d' | sed '/\[AOTID\]/d' > "$SYMBOLICATE_RESULT_FILE"
  219. DIFF=$(diff -up "$SYMBOLICATE_EXPECTED_FILE" "$SYMBOLICATE_RESULT_FILE")
  220. if [ ! -z "$DIFF" ]; then
  221. echo "ERROR: Symbolicate tests failed."
  222. echo "If $SYMBOLICATE_RESULT_FILE is correct copy it to $SYMBOLICATE_EXPECTED_FILE."
  223. echo "Otherwise runtime sequence points need to be fixed."
  224. echo ""
  225. echo "$DIFF"
  226. ok=false
  227. else
  228. echo "Success."
  229. fi
  230. done
  231. if [ "$ok" = "true" ]; then
  232. echo "<?xml version=\"1.0\" encoding=\"utf-8\"?><assemblies><assembly name=\"symbolicate\" environment=\"Mono\" test-framework=\"custom\" run-date=\"$(date +%F)\" run-time=\"$(date +%T)\" total=\"1\" passed=\"1\" failed=\"0\" skipped=\"0\" errors=\"0\" time=\"0\"><collection total=\"1\" passed=\"1\" failed=\"0\" skipped=\"0\" name=\"Test collection for symbolicate\" time=\"0\"><test name=\"symbolicate.all\" type=\"symbolicate\" method=\"all\" time=\"0\" result=\"Pass\"></test></collection></assembly></assemblies>" > "${xunit_results_path}";
  233. exit 0
  234. else
  235. echo "<?xml version=\"1.0\" encoding=\"utf-8\"?><assemblies><assembly name=\"symbolicate\" environment=\"Mono\" test-framework=\"custom\" run-date=\"$(date +%F)\" run-time=\"$(date +%T)\" total=\"1\" passed=\"0\" failed=\"1\" skipped=\"0\" errors=\"0\" time=\"0\"><collection total=\"1\" passed=\"0\" failed=\"1\" skipped=\"0\" name=\"Test collection for symbolicate\" time=\"0\"><test name=\"symbolicate.all\" type=\"symbolicate\" method=\"all\" time=\"0\" result=\"Fail\"><failure exception-type=\"SymbolicateException\"><message><![CDATA[Symbolicate tests failed. Check the log for more details.]]></message></failure></test></collection></assembly></assemblies>" > "${xunit_results_path}";
  236. exit 1
  237. fi
  238. fi
  239. if [ "$test_suite" = "--csi" ]; then
  240. cd tests/csi || error 1
  241. echo "Console.WriteLine (\"hello world: \" + DateTime.Now)" > csi-test.csx
  242. ok=true
  243. "${MONO_EXECUTABLE}" --config "$r/_tmpinst/etc/mono/config" csi.exe csi-test.csx > csi-test-output.txt || ok=false
  244. cat csi-test-output.txt && grep -q "hello world" csi-test-output.txt || ok=false
  245. if [ "$ok" = "true" ]; then
  246. echo "<?xml version=\"1.0\" encoding=\"utf-8\"?><assemblies><assembly name=\"csi\" environment=\"Mono\" test-framework=\"custom\" run-date=\"$(date +%F)\" run-time=\"$(date +%T)\" total=\"1\" passed=\"1\" failed=\"0\" skipped=\"0\" errors=\"0\" time=\"0\"><collection total=\"1\" passed=\"1\" failed=\"0\" skipped=\"0\" name=\"Test collection for csi\" time=\"0\"><test name=\"csi.all\" type=\"csi\" method=\"all\" time=\"0\" result=\"Pass\"></test></collection></assembly></assemblies>" > "${xunit_results_path}";
  247. exit 0
  248. else
  249. echo "<?xml version=\"1.0\" encoding=\"utf-8\"?><assemblies><assembly name=\"csi\" environment=\"Mono\" test-framework=\"custom\" run-date=\"$(date +%F)\" run-time=\"$(date +%T)\" total=\"1\" passed=\"0\" failed=\"1\" skipped=\"0\" errors=\"0\" time=\"0\"><collection total=\"1\" passed=\"0\" failed=\"1\" skipped=\"0\" name=\"Test collection for csi\" time=\"0\"><test name=\"csi.all\" type=\"csi\" method=\"all\" time=\"0\" result=\"Fail\"><failure exception-type=\"CsiException\"><message><![CDATA[csi.exe tests failed. Check the log for more details.]]></message></failure></test></collection></assembly></assemblies>" > "${xunit_results_path}";
  250. exit 1
  251. fi
  252. fi
  253. if [ "$test_suite" = "--profiler" ]; then
  254. cd tests/profiler || exit 1
  255. chmod +x "$r/mprof-report"
  256. perl ptestrunner.pl out-of-tree xunit "${xunit_results_path}"
  257. exit $?
  258. fi
  259. if [ "$test_suite" = "--runtime" ]; then
  260. cd tests/runtime || exit 1
  261. # TODO: only ported runtest-managed for now
  262. "${MONO_EXECUTABLE}" --config "$r/_tmpinst/etc/mono/config" --debug test-runner.exe --verbose --xunit "${xunit_results_path}" --config tests-config --runtime "${MONO_EXECUTABLE}" --mono-path "$r/net_4_x" -j a --testsuite-name "runtime" --timeout 300 --disabled "$DISABLED_TESTS" --input-file runtime-test-list.txt
  263. exit $?
  264. fi