test_wamr.sh 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172
  1. #!/usr/bin/env bash
  2. #
  3. # Copyright (C) 2019 Intel Corporation. All rights reserved.
  4. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  5. #
  6. function DEBUG() {
  7. [[ -n $(env | grep "\<DEBUG\>") ]] && $@
  8. }
  9. DEBUG set -exv pipefail
  10. function help()
  11. {
  12. echo "test_wamr.sh [options]"
  13. echo "-c clean previous test results, not start test"
  14. echo "-s {suite_name} test only one suite (spec|standalone|malformed|wasi_certification|"
  15. echo " unit|wamr_compiler)"
  16. echo "-m set compile target of iwasm(x86_64|x86_32|armv7|armv7_vfp|thumbv7|thumbv7_vfp|"
  17. echo " riscv32|riscv32_ilp32f|riscv32_ilp32d|riscv64|"
  18. echo " riscv64_lp64f|riscv64_lp64d|aarch64|aarch64_vfp)"
  19. echo "-t set compile type of iwasm(classic-interp|fast-interp|jit|aot|fast-jit|multi-tier-jit)"
  20. echo "-M enable multi module feature"
  21. echo "-p enable multi thread feature"
  22. echo "-S enable SIMD feature"
  23. echo "-G enable GC feature"
  24. echo "-W enable memory64 feature"
  25. echo "-E enable multi memory feature"
  26. echo "-X enable XIP feature"
  27. echo "-e enable exception handling"
  28. echo "-x test SGX"
  29. echo "-w enable WASI threads"
  30. echo "-a test all runtimes in sightglass suite"
  31. echo "-b use the wabt binary release package instead of compiling from the source code"
  32. echo "-g build iwasm with debug version"
  33. echo "-v enable GC heap verification"
  34. echo "-P run the spec test parallelly"
  35. echo "-Q enable qemu"
  36. echo "-F set the firmware path used by qemu"
  37. echo "-C enable code coverage collect"
  38. echo "-j set the platform to test"
  39. echo "-T set sanitizer to use in tests(ubsan|tsan|asan)"
  40. echo "-A use the specified wamrc command instead of building it"
  41. echo "-r [requirement name] [N [N ...]] specify a requirement name followed by one or more"
  42. echo " subrequirement IDs, if no subrequirement is specificed,"
  43. echo " it will run all subrequirements. When this optin is used,"
  44. echo " only run requirement tests"
  45. }
  46. OPT_PARSED=""
  47. WABT_BINARY_RELEASE="NO"
  48. #default type
  49. TYPE=("classic-interp" "fast-interp" "jit" "aot" "fast-jit" "multi-tier-jit")
  50. #default target
  51. TARGET="X86_64"
  52. ENABLE_WASI_THREADS=0
  53. ENABLE_MULTI_MODULE=0
  54. ENABLE_MULTI_THREAD=0
  55. COLLECT_CODE_COVERAGE=0
  56. ENABLE_SIMD=0
  57. ENABLE_GC=0
  58. ENABLE_MEMORY64=0
  59. ENABLE_MULTI_MEMORY=0
  60. ENABLE_XIP=0
  61. ENABLE_EH=0
  62. ENABLE_DEBUG_VERSION=0
  63. ENABLE_GC_HEAP_VERIFY=0
  64. #unit test case arrary
  65. TEST_CASE_ARR=()
  66. SGX_OPT=""
  67. if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then
  68. PLATFORM=windows
  69. PYTHON_EXE=python
  70. else
  71. PLATFORM=$(uname -s | tr A-Z a-z)
  72. PYTHON_EXE=python3
  73. fi
  74. PARALLELISM=0
  75. ENABLE_QEMU=0
  76. QEMU_FIRMWARE=""
  77. WAMRC_CMD=""
  78. # prod/testsuite-all branch
  79. WASI_TESTSUITE_COMMIT="ee807fc551978490bf1c277059aabfa1e589a6c2"
  80. TARGET_LIST=("AARCH64" "AARCH64_VFP" "ARMV7" "ARMV7_VFP" "THUMBV7" "THUMBV7_VFP" \
  81. "RISCV32" "RISCV32_ILP32F" "RISCV32_ILP32D" "RISCV64" "RISCV64_LP64F" "RISCV64_LP64D" "XTENSA")
  82. REQUIREMENT_NAME=""
  83. # Initialize an empty array for subrequirement IDs
  84. SUBREQUIREMENT_IDS=()
  85. while getopts ":s:cabgvt:m:MCpSXexwWEPGQF:j:T:r:A:" opt
  86. do
  87. OPT_PARSED="TRUE"
  88. case $opt in
  89. s)
  90. TEST_CASE_ARR+=($OPTARG)
  91. # get next suite if there are multiple vaule in -s
  92. eval "nxarg=\${$((OPTIND))}"
  93. # just get test cases, loop until the next symbol '-'
  94. # IN ====> -s spec unit -t fast-classic
  95. # GET ====> spec unit
  96. while [[ "${nxarg}" != -* && ${nxarg} ]];
  97. do
  98. TEST_CASE_ARR+=(${nxarg})
  99. OPTIND=$((OPTIND+1))
  100. eval "nxarg=\${$((OPTIND))}"
  101. done
  102. echo "test following cases: ${TEST_CASE_ARR[@]}"
  103. ;;
  104. c)
  105. read -t 5 -p "Are you sure to delete all reports. y/n " cmd
  106. if [[ $cmd == "y" && $(ls -A workspace/report) ]];then
  107. rm -fr workspace/report/*
  108. rm -fr /tmp/*.wasm /tmp/*.wast /tmp/*.aot
  109. echo "cleaned all reports and temp files"
  110. fi
  111. exit 0;;
  112. a)
  113. TEST_ALL_AOT_RUNTIME="all"
  114. echo "test all runtimes in sightglass_aot"
  115. ;;
  116. b)
  117. WABT_BINARY_RELEASE="YES"
  118. echo "use a WABT binary release instead of compiling from source code"
  119. ;;
  120. t)
  121. echo "set compile type of wamr " ${OPTARG}
  122. if [[ ${OPTARG} != "classic-interp" && ${OPTARG} != "fast-interp" \
  123. && ${OPTARG} != "jit" && ${OPTARG} != "aot"
  124. && ${OPTARG} != "fast-jit" && ${OPTARG} != "multi-tier-jit" ]]; then
  125. echo "*----- please varify a type of compile when using -t! -----*"
  126. help
  127. exit 1
  128. fi
  129. TYPE=(${OPTARG})
  130. ;;
  131. m)
  132. echo "set compile target of wamr" ${OPTARG}
  133. TARGET=$(echo "$OPTARG" | tr '[a-z]' '[A-Z]') # set target to uppercase if input x86_32 or x86_64 --> X86_32 and X86_64
  134. ;;
  135. w)
  136. echo "enable WASI threads"
  137. ENABLE_WASI_THREADS=1
  138. ;;
  139. M)
  140. echo "enable multi module feature"
  141. ENABLE_MULTI_MODULE=1
  142. ;;
  143. W)
  144. echo "enable wasm64(memory64) feature"
  145. ENABLE_MEMORY64=1
  146. ;;
  147. E)
  148. echo "enable multi memory feature(auto enable multi module)"
  149. ENABLE_MULTI_MEMORY=1
  150. ENABLE_MULTI_MODULE=1
  151. ;;
  152. C)
  153. echo "enable code coverage"
  154. COLLECT_CODE_COVERAGE=1
  155. ;;
  156. p)
  157. echo "enable multi thread feature"
  158. ENABLE_MULTI_THREAD=1
  159. ;;
  160. S)
  161. echo "enable SIMD feature"
  162. ENABLE_SIMD=1
  163. ;;
  164. X)
  165. echo "enable XIP feature"
  166. ENABLE_XIP=1
  167. ;;
  168. e)
  169. echo "enable exception handling feature"
  170. ENABLE_EH=1
  171. ;;
  172. x)
  173. echo "test SGX"
  174. SGX_OPT="--sgx"
  175. ;;
  176. g)
  177. echo "enable build iwasm with debug version"
  178. ENABLE_DEBUG_VERSION=1
  179. ;;
  180. v)
  181. echo "enable GC heap verification"
  182. ENABLE_GC_HEAP_VERIFY=1
  183. ;;
  184. G)
  185. echo "enable GC feature"
  186. ENABLE_GC=1
  187. ;;
  188. P)
  189. PARALLELISM=1
  190. ;;
  191. Q)
  192. echo "enable QEMU"
  193. ENABLE_QEMU=1
  194. ;;
  195. F)
  196. echo "QEMU firmware" ${OPTARG}
  197. QEMU_FIRMWARE=${OPTARG}
  198. ;;
  199. j)
  200. echo "test platform " ${OPTARG}
  201. PLATFORM=${OPTARG}
  202. ;;
  203. T)
  204. echo "sanitizer is " ${OPTARG}
  205. WAMR_BUILD_SANITIZER=${OPTARG}
  206. ;;
  207. r)
  208. REQUIREMENT_NAME=$OPTARG
  209. # get next arg if there are multiple values after -r
  210. eval "nxarg=\${$((OPTIND))}"
  211. # loop until the next symbol '-' or the end of arguments
  212. while [[ "${nxarg}" =~ ^[0-9]+$ ]]; do
  213. SUBREQUIREMENT_IDS+=("$nxarg")
  214. OPTIND=$((OPTIND+1))
  215. eval "nxarg=\${$((OPTIND))}"
  216. done
  217. echo "Only Test requirement name: ${REQUIREMENT_NAME}"
  218. [[ ${#SUBREQUIREMENT_IDS[@]} -ne 0 ]] && echo "Choose subrequirement IDs: ${SUBREQUIREMENT_IDS[@]}"
  219. ;;
  220. A)
  221. echo "Using wamrc ${OPTARG}"
  222. WAMRC_CMD=${OPTARG}
  223. ;;
  224. ?)
  225. help
  226. exit 1
  227. ;;
  228. esac
  229. done
  230. # Parameters are not allowed, use options instead
  231. if [ -z "$OPT_PARSED" ];
  232. then
  233. if [ ! -z "$1" ];
  234. then
  235. help
  236. exit 1
  237. fi
  238. fi
  239. mkdir -p workspace
  240. cd workspace
  241. readonly WORK_DIR=$PWD
  242. readonly DATE=$(date +%Y-%m-%d_%H:%M:%S)
  243. readonly REPORT_DIR=${WORK_DIR}/report/${DATE}
  244. mkdir -p ${REPORT_DIR}
  245. readonly WAMR_DIR=${WORK_DIR}/../../..
  246. readonly REQUIREMENT_SCRIPT_DIR=${WORK_DIR}/../requirement-engineering-test-script
  247. if [[ ${SGX_OPT} == "--sgx" ]];then
  248. readonly IWASM_LINUX_ROOT_DIR="${WAMR_DIR}/product-mini/platforms/linux-sgx"
  249. readonly IWASM_CMD="${WAMR_DIR}/product-mini/platforms/linux-sgx/enclave-sample/iwasm"
  250. else
  251. readonly IWASM_LINUX_ROOT_DIR="${WAMR_DIR}/product-mini/platforms/${PLATFORM}"
  252. readonly IWASM_CMD="${WAMR_DIR}/product-mini/platforms/${PLATFORM}/build/iwasm"
  253. fi
  254. readonly WAMRC_CMD_DEFAULT="${WAMR_DIR}/wamr-compiler/build/wamrc"
  255. readonly CLASSIC_INTERP_COMPILE_FLAGS="\
  256. -DWAMR_BUILD_TARGET=${TARGET} \
  257. -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_INTERP=0 \
  258. -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_AOT=0"
  259. readonly FAST_INTERP_COMPILE_FLAGS="\
  260. -DWAMR_BUILD_TARGET=${TARGET} \
  261. -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_INTERP=1 \
  262. -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_AOT=0"
  263. # jit: report linking error if set COLLECT_CODE_COVERAGE,
  264. # now we don't collect code coverage of jit type
  265. readonly ORC_EAGER_JIT_COMPILE_FLAGS="\
  266. -DWAMR_BUILD_TARGET=${TARGET} \
  267. -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_FAST_INTERP=0 \
  268. -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_AOT=1 \
  269. -DWAMR_BUILD_LAZY_JIT=0"
  270. readonly ORC_LAZY_JIT_COMPILE_FLAGS="\
  271. -DWAMR_BUILD_TARGET=${TARGET} \
  272. -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_FAST_INTERP=0 \
  273. -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_AOT=1 \
  274. -DWAMR_BUILD_LAZY_JIT=1"
  275. readonly AOT_COMPILE_FLAGS="\
  276. -DWAMR_BUILD_TARGET=${TARGET} \
  277. -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_FAST_INTERP=0 \
  278. -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_AOT=1"
  279. readonly FAST_JIT_COMPILE_FLAGS="\
  280. -DWAMR_BUILD_TARGET=${TARGET} \
  281. -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_INTERP=0 \
  282. -DWAMR_BUILD_JIT=0 -DWAMR_BUILD_AOT=0 \
  283. -DWAMR_BUILD_FAST_JIT=1"
  284. readonly MULTI_TIER_JIT_COMPILE_FLAGS="\
  285. -DWAMR_BUILD_TARGET=${TARGET} \
  286. -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_INTERP=0 \
  287. -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=1"
  288. readonly COMPILE_FLAGS=(
  289. "${CLASSIC_INTERP_COMPILE_FLAGS}"
  290. "${FAST_INTERP_COMPILE_FLAGS}"
  291. "${ORC_EAGER_JIT_COMPILE_FLAGS}"
  292. "${ORC_LAZY_JIT_COMPILE_FLAGS}"
  293. "${AOT_COMPILE_FLAGS}"
  294. "${FAST_JIT_COMPILE_FLAGS}"
  295. "${MULTI_TIER_JIT_COMPILE_FLAGS}"
  296. )
  297. function unit_test()
  298. {
  299. echo "Now start unit tests"
  300. cd ${WORK_DIR}
  301. rm -fr unittest-build && mkdir unittest-build
  302. cd unittest-build
  303. echo "Build unit test"
  304. touch ${REPORT_DIR}/unit_test_report.txt
  305. cmake ${WORK_DIR}/../../unit -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE}
  306. make -j
  307. make test | tee -a ${REPORT_DIR}/unit_test_report.txt
  308. echo "Finish unit tests"
  309. }
  310. function sightglass_test()
  311. {
  312. echo "Now start sightglass benchmark tests"
  313. cd ${WORK_DIR}/../sightglass/benchmarks
  314. # build iwasm first
  315. if [[ $1 == "classic-interp" || $1 == "fast-interp" ]];then
  316. ./test_interp.sh ${SGX_OPT}
  317. cp report.txt ${REPORT_DIR}/sightglass_$1_test_report.txt
  318. fi
  319. if [[ $1 == "aot" ]];then
  320. ./test_aot.sh ${SGX_OPT}
  321. cp report.txt ${REPORT_DIR}/sightglass_aot_test_report.txt
  322. fi
  323. if [[ $1 == "jit" ]];then
  324. [[ $TEST_ALL_AOT_RUNTIME ]] && ./test_aot.sh ${TEST_ALL_AOT_RUNTIME} ${SGX_OPT} \
  325. || ./test_aot.sh jit ${SGX_OPT}
  326. cp report.txt ${REPORT_DIR}/sightglass_jit_test_report.txt
  327. fi
  328. echo "Finish sightglass benchmark tests"
  329. }
  330. function setup_wabt()
  331. {
  332. WABT_VERSION=1.0.36
  333. if [ ${WABT_BINARY_RELEASE} == "YES" ]; then
  334. echo "download a binary release and install"
  335. local WAT2WASM=${WORK_DIR}/wabt/out/gcc/Release/wat2wasm
  336. if [ ! -f ${WAT2WASM} ]; then
  337. case ${PLATFORM} in
  338. cosmopolitan)
  339. ;;
  340. linux)
  341. WABT_PLATFORM=ubuntu-20.04
  342. ;;
  343. darwin)
  344. WABT_PLATFORM=macos-12
  345. ;;
  346. windows)
  347. WABT_PLATFORM=windows
  348. ;;
  349. *)
  350. echo "wabt platform for ${PLATFORM} in unknown"
  351. exit 1
  352. ;;
  353. esac
  354. if [ ! -f /tmp/wabt-${WABT_VERSION}-${WABT_PLATFORM}.tar.gz ]; then
  355. curl -L \
  356. https://github.com/WebAssembly/wabt/releases/download/${WABT_VERSION}/wabt-${WABT_VERSION}-${WABT_PLATFORM}.tar.gz \
  357. -o /tmp/wabt-${WABT_VERSION}-${WABT_PLATFORM}.tar.gz
  358. fi
  359. cd /tmp \
  360. && tar zxf wabt-${WABT_VERSION}-${WABT_PLATFORM}.tar.gz \
  361. && mkdir -p ${WORK_DIR}/wabt/out/gcc/Release/ \
  362. && install wabt-${WABT_VERSION}/bin/* ${WORK_DIR}/wabt/out/gcc/Release/ \
  363. && cd -
  364. fi
  365. else
  366. echo "download source code and compile and install"
  367. if [ ! -d "wabt" ];then
  368. echo "wabt not exist, clone it from github"
  369. git clone --recursive https://github.com/WebAssembly/wabt
  370. fi
  371. echo "upate wabt"
  372. cd wabt \
  373. && git fetch origin \
  374. && git reset --hard origin/main \
  375. && git checkout tags/${WABT_VERSION} -B ${WABT_VERSION} \
  376. && git submodule update --init \
  377. && cd .. \
  378. && make -C wabt gcc-release -j 4 || exit 1
  379. fi
  380. }
  381. function compile_reference_interpreter()
  382. {
  383. echo "compile the reference intepreter"
  384. pushd interpreter
  385. make
  386. if [ $? -ne 0 ]
  387. then
  388. echo "Failed to compile the reference interpreter"
  389. exit 1
  390. fi
  391. popd
  392. }
  393. # TODO: with iwasm only
  394. function spec_test()
  395. {
  396. local RUNNING_MODE="$1"
  397. echo "Now start spec tests"
  398. touch ${REPORT_DIR}/spec_test_report.txt
  399. cd ${WORK_DIR}
  400. # update basic test cases
  401. echo "downloading spec test cases..."
  402. rm -rf spec
  403. if [ ${ENABLE_MULTI_THREAD} == 1 ]; then
  404. echo "checkout spec from threads proposal"
  405. # check spec test cases for threads
  406. git clone -b main --single-branch https://github.com/WebAssembly/threads.git spec
  407. pushd spec
  408. # May 31, 2012 [interpreter] implement atomic.wait and atomic.notify (#194)
  409. git reset --hard 09f2831349bf409187abb6f7868482a8079f2264
  410. git apply ../../spec-test-script/thread_proposal_ignore_cases.patch || exit 1
  411. git apply ../../spec-test-script/thread_proposal_fix_atomic_case.patch || exit 1
  412. git apply ../../spec-test-script/thread_proposal_remove_memory64_flag_case.patch
  413. elif [ ${ENABLE_EH} == 1 ]; then
  414. echo "checkout exception-handling test cases"
  415. git clone -b main --single-branch https://github.com/WebAssembly/exception-handling spec
  416. pushd spec
  417. # Jun 6, 2023 Merge branch 'upstream' into merge-upstream
  418. git reset --hard 51c721661b671bb7dc4b3a3acb9e079b49778d36
  419. git apply ../../spec-test-script/exception_handling.patch || exit 1
  420. elif [[ ${ENABLE_GC} == 1 ]]; then
  421. echo "checkout spec for GC proposal"
  422. # check spec test cases for GC
  423. git clone -b main --single-branch https://github.com/WebAssembly/gc.git spec
  424. pushd spec
  425. # Dec 9, 2024. Merge branch 'funcref'
  426. git reset --hard 756060f5816c7e2159f4817fbdee76cf52f9c923
  427. git apply ../../spec-test-script/gc_ignore_cases.patch || exit 1
  428. if [[ ${ENABLE_QEMU} == 1 ]]; then
  429. # Decrease the recursive count for tail call cases as nuttx qemu's
  430. # native stack size is much smaller
  431. git apply ../../spec-test-script/gc_nuttx_tail_call.patch || exit 1
  432. fi
  433. # As of version 1.0.36, wabt is still unable to correctly handle the GC proposal.
  434. #
  435. # $ $ /opt/wabt-1.0.36/bin/wast2json --enable-all ../spec/test/core/br_if.wast
  436. #
  437. # ../spec/test/core/br_if.wast:670:26: error: unexpected token "null", expected a numeric index or a name (e.g. 12 or $foo).
  438. # (func $f (param (ref null $t)) (result funcref) (local.get 0))
  439. #
  440. compile_reference_interpreter
  441. elif [[ ${ENABLE_MEMORY64} == 1 ]]; then
  442. echo "checkout spec for memory64 proposal"
  443. # check spec test cases for memory64
  444. git clone -b main --single-branch https://github.com/WebAssembly/memory64.git spec
  445. pushd spec
  446. # Reset to commit: "Merge remote-tracking branch 'upstream/main' into merge2"
  447. git reset --hard 48e69f394869c55b7bbe14ac963c09f4605490b6
  448. git checkout 044d0d2e77bdcbe891f7e0b9dd2ac01d56435f0b -- test/core/elem.wast test/core/data.wast
  449. # Patch table64 extension
  450. git checkout 940398cd4823522a9b36bec4984be4b153dedb81 -- test/core/call_indirect.wast test/core/table.wast test/core/table_copy.wast test/core/table_copy_mixed.wast test/core/table_fill.wast test/core/table_get.wast test/core/table_grow.wast test/core/table_init.wast test/core/table_set.wast test/core/table_size.wast
  451. git apply ../../spec-test-script/memory64_ignore_cases.patch || exit 1
  452. elif [[ ${ENABLE_MULTI_MEMORY} == 1 ]]; then
  453. echo "checkout spec for multi memory proposal"
  454. # check spec test cases for multi memory
  455. git clone -b main --single-branch https://github.com/WebAssembly/multi-memory.git spec
  456. pushd spec
  457. # Reset to commit: "Merge pull request #48 from backes/specify-memcpy-immediate-order"
  458. git reset --hard fbc99efd7a788db300aec3dd62a14577ec404f1b
  459. git checkout 044d0d2e77bdcbe891f7e0b9dd2ac01d56435f0b -- test/core/elem.wast
  460. git apply ../../spec-test-script/multi_memory_ignore_cases.patch || exit 1
  461. if [[ ${RUNNING_MODE} == "aot" ]]; then
  462. git apply ../../spec-test-script/multi_module_aot_ignore_cases.patch || exit 1
  463. fi
  464. else
  465. echo "checkout spec for default proposal"
  466. git clone -b main --single-branch https://github.com/WebAssembly/spec
  467. pushd spec
  468. # Dec 20, 2024. Use WPT version of test harness for HTML core test conversion (#1859)
  469. git reset --hard f3a0e06235d2d84bb0f3b5014da4370613886965
  470. git apply ../../spec-test-script/ignore_cases.patch || exit 1
  471. if [[ ${ENABLE_SIMD} == 1 ]]; then
  472. git apply ../../spec-test-script/simd_ignore_cases.patch || exit 1
  473. fi
  474. if [[ ${ENABLE_MULTI_MODULE} == 1 ]]; then
  475. git apply ../../spec-test-script/multi_module_ignore_cases.patch || exit 1
  476. if [[ ${RUNNING_MODE} == "aot" ]]; then
  477. git apply ../../spec-test-script/multi_module_aot_ignore_cases.patch || exit 1
  478. fi
  479. fi
  480. fi
  481. popd
  482. echo $(pwd)
  483. setup_wabt
  484. ln -sf ${WORK_DIR}/../spec-test-script/all.py .
  485. ln -sf ${WORK_DIR}/../spec-test-script/runtest.py .
  486. local ARGS_FOR_SPEC_TEST=""
  487. if [[ 1 == ${ENABLE_MULTI_MODULE} ]]; then
  488. ARGS_FOR_SPEC_TEST+="-M "
  489. fi
  490. if [[ 1 == ${ENABLE_EH} ]]; then
  491. ARGS_FOR_SPEC_TEST+="-e "
  492. fi
  493. if [[ ${SGX_OPT} == "--sgx" ]];then
  494. ARGS_FOR_SPEC_TEST+="-x "
  495. fi
  496. if [[ ${ENABLE_SIMD} == 1 ]]; then
  497. ARGS_FOR_SPEC_TEST+="-S "
  498. fi
  499. if [[ ${ENABLE_MULTI_THREAD} == 1 ]]; then
  500. ARGS_FOR_SPEC_TEST+="-p "
  501. fi
  502. if [[ ${ENABLE_XIP} == 1 ]]; then
  503. ARGS_FOR_SPEC_TEST+="-X "
  504. fi
  505. # set the current running target
  506. ARGS_FOR_SPEC_TEST+="-m ${TARGET} "
  507. # require warmc only in aot mode
  508. if [[ $1 == 'aot' ]]; then
  509. ARGS_FOR_SPEC_TEST+="-t "
  510. ARGS_FOR_SPEC_TEST+="--aot-compiler ${WAMRC_CMD} "
  511. fi
  512. if [[ ${PARALLELISM} == 1 ]]; then
  513. ARGS_FOR_SPEC_TEST+="--parl "
  514. fi
  515. if [[ ${ENABLE_GC} == 1 ]]; then
  516. ARGS_FOR_SPEC_TEST+="--gc "
  517. fi
  518. if [[ 1 == ${ENABLE_MEMORY64} ]]; then
  519. ARGS_FOR_SPEC_TEST+="--memory64 "
  520. fi
  521. # multi memory is only enabled in interp and aot mode
  522. if [[ 1 == ${ENABLE_MULTI_MEMORY} ]]; then
  523. if [[ $1 == 'classic-interp' || $1 == 'aot' ]]; then
  524. ARGS_FOR_SPEC_TEST+="--multi-memory "
  525. fi
  526. fi
  527. if [[ ${ENABLE_QEMU} == 1 ]]; then
  528. ARGS_FOR_SPEC_TEST+="--qemu "
  529. ARGS_FOR_SPEC_TEST+="--qemu-firmware ${QEMU_FIRMWARE} "
  530. fi
  531. if [[ ${PLATFORM} == "windows" ]]; then
  532. ARGS_FOR_SPEC_TEST+="--no-pty "
  533. fi
  534. # set log directory
  535. ARGS_FOR_SPEC_TEST+="--log ${REPORT_DIR}"
  536. cd ${WORK_DIR}
  537. echo "${PYTHON_EXE} ./all.py ${ARGS_FOR_SPEC_TEST} | tee -a ${REPORT_DIR}/spec_test_report.txt"
  538. ${PYTHON_EXE} ./all.py ${ARGS_FOR_SPEC_TEST} | tee -a ${REPORT_DIR}/spec_test_report.txt
  539. if [[ ${PIPESTATUS[0]} -ne 0 ]];then
  540. echo -e "\nspec tests FAILED" | tee -a ${REPORT_DIR}/spec_test_report.txt
  541. exit 1
  542. fi
  543. cd -
  544. echo -e "\nFinish spec tests" | tee -a ${REPORT_DIR}/spec_test_report.txt
  545. }
  546. function wamr_compiler_test()
  547. {
  548. if [[ $1 != "aot" ]]; then
  549. echo "WAMR compiler tests only support AOT mode"
  550. exit 1
  551. fi
  552. echo "Now start WAMR compiler tests"
  553. setup_wabt
  554. cd ${WORK_DIR}/../wamr-compiler-test-script
  555. ./run_wamr_compiler_tests.sh ${WORK_DIR}/wabt/out/gcc/Release/wat2wasm $WAMRC_CMD $IWASM_CMD \
  556. | tee -a ${REPORT_DIR}/wamr_compiler_test_report.txt
  557. ret=${PIPESTATUS[0]}
  558. if [[ ${ret} -ne 0 ]];then
  559. echo -e "\nWAMR compiler tests FAILED" | tee -a ${REPORT_DIR}/wamr_compiler_test_report.txt
  560. exit 1
  561. fi
  562. echo -e "\nFinish WAMR compiler tests" | tee -a ${REPORT_DIR}/wamr_compiler_test_report.txt
  563. }
  564. function wasi_certification_test()
  565. {
  566. echo "Now start wasi certification tests"
  567. cd ${WORK_DIR}
  568. if [ ! -d "wasi-testsuite" ]; then
  569. echo "wasi-testsuite not exist, clone it from github"
  570. git clone -b prod/testsuite-all \
  571. --single-branch https://github.com/WebAssembly/wasi-testsuite.git
  572. fi
  573. cd wasi-testsuite
  574. git reset --hard ${WASI_TESTSUITE_COMMIT}
  575. TSAN_OPTIONS=${TSAN_OPTIONS} bash ../../wasi-test-script/run_wasi_tests.sh $1 $TARGET $WASI_TEST_FILTER \
  576. | tee -a ${REPORT_DIR}/wasi_test_report.txt
  577. ret=${PIPESTATUS[0]}
  578. if [[ ${ret} -ne 0 ]];then
  579. echo -e "\nwasi tests FAILED" | tee -a ${REPORT_DIR}/wasi_test_report.txt
  580. exit 1
  581. fi
  582. echo -e "\nFinish wasi tests" | tee -a ${REPORT_DIR}/wasi_test_report.txt
  583. }
  584. function polybench_test()
  585. {
  586. echo "Now start polybench tests"
  587. cd ${WORK_DIR}/../polybench
  588. if [[ $1 == "aot" || $1 == "jit" ]];then
  589. ./build.sh AOT ${SGX_OPT}
  590. ./test_aot.sh $1 ${SGX_OPT}
  591. else
  592. ./build.sh
  593. ./test_interp.sh ${SGX_OPT}
  594. fi
  595. cp report.txt ${REPORT_DIR}/polybench_$1_test_report.txt
  596. echo "Finish polybench tests"
  597. }
  598. function libsodium_test()
  599. {
  600. echo "Now start libsodium tests"
  601. cd ${WORK_DIR}/../libsodium
  602. if [[ $1 == "aot" || $1 == "jit" ]];then
  603. ./build.sh ${SGX_OPT}
  604. ./test_aot.sh $1 ${SGX_OPT}
  605. else
  606. ./test_interp.sh ${SGX_OPT}
  607. fi
  608. cp report.txt ${REPORT_DIR}/libsodium_$1_test_report.txt
  609. echo "Finish libsodium tests"
  610. }
  611. function malformed_test()
  612. {
  613. # build iwasm firstly
  614. cd ${WORK_DIR}/../../malformed
  615. ./malformed_test.py --run ${IWASM_CMD} | tee ${REPORT_DIR}/malfomed_$1_test_report.txt
  616. }
  617. function collect_standalone()
  618. {
  619. if [[ ${COLLECT_CODE_COVERAGE} == 1 ]]; then
  620. pushd ${WORK_DIR} > /dev/null 2>&1
  621. CODE_COV_FILE=""
  622. if [[ -z "${CODE_COV_FILE}" ]]; then
  623. CODE_COV_FILE="${WORK_DIR}/wamr.lcov"
  624. else
  625. CODE_COV_FILE="${CODE_COV_FILE}"
  626. fi
  627. STANDALONE_DIR=${WORK_DIR}/../../standalone
  628. echo "Collect code coverage of standalone dump-call-stack"
  629. ./collect_coverage.sh "${CODE_COV_FILE}" "${STANDALONE_DIR}/dump-call-stack/build"
  630. echo "Collect code coverage of standalone dump-mem-profiling"
  631. ./collect_coverage.sh "${CODE_COV_FILE}" "${STANDALONE_DIR}/dump-mem-profiling/build"
  632. echo "Collect code coverage of standalone dump-perf-profiling"
  633. ./collect_coverage.sh "${CODE_COV_FILE}" "${STANDALONE_DIR}/dump-perf-profiling/build"
  634. if [[ $1 == "aot" ]]; then
  635. echo "Collect code coverage of standalone pad-test"
  636. ./collect_coverage.sh "${CODE_COV_FILE}" "${STANDALONE_DIR}/pad-test/build"
  637. fi
  638. echo "Collect code coverage of standalone test-invoke-native"
  639. ./collect_coverage.sh "${CODE_COV_FILE}" "${STANDALONE_DIR}/test-invoke-native/build"
  640. echo "Collect code coverage of standalone test-running-modes"
  641. ./collect_coverage.sh "${CODE_COV_FILE}" "${STANDALONE_DIR}/test-running-modes/build"
  642. echo "Collect code coverage of standalone test-running-modes/c-embed"
  643. ./collect_coverage.sh "${CODE_COV_FILE}" "${STANDALONE_DIR}/test-running-modes/c-embed/build"
  644. echo "Collect code coverage of standalone test-ts2"
  645. ./collect_coverage.sh "${CODE_COV_FILE}" "${STANDALONE_DIR}/test-ts2/build"
  646. echo "Collect code coverage of standalone test-module-malloc"
  647. ./collect_coverage.sh "${CODE_COV_FILE}" "${STANDALONE_DIR}/test-module-malloc/build"
  648. popd > /dev/null 2>&1
  649. fi
  650. }
  651. function standalone_test()
  652. {
  653. if [[ ${COLLECT_CODE_COVERAGE} == 1 ]]; then
  654. export COLLECT_CODE_COVERAGE=1
  655. fi
  656. cd ${WORK_DIR}/../../standalone
  657. args="--$1"
  658. [[ ${SGX_OPT} == "--sgx" ]] && args="$args --sgx" || args="$args --no-sgx"
  659. [[ ${ENABLE_MULTI_THREAD} == 1 ]] && args="$args --thread" || args="$args --no-thread"
  660. [[ ${ENABLE_SIMD} == 1 ]] && args="$args --simd" || args="$args --no-simd"
  661. args="$args ${TARGET}"
  662. ./standalone.sh $args | tee ${REPORT_DIR}/standalone_$1_test_report.txt
  663. collect_standalone "$1"
  664. }
  665. function build_iwasm_with_cfg()
  666. {
  667. echo "Build iwasm with compile flags " $* " for spec test" \
  668. | tee -a ${REPORT_DIR}/spec_test_report.txt
  669. if [[ ${SGX_OPT} == "--sgx" ]];then
  670. cd ${WAMR_DIR}/product-mini/platforms/linux-sgx \
  671. && if [ -d build ]; then rm -rf build/*; else mkdir build; fi \
  672. && cd build \
  673. && cmake $* .. \
  674. && make -j 4
  675. cd ${WAMR_DIR}/product-mini/platforms/linux-sgx/enclave-sample \
  676. && make clean \
  677. && make SPEC_TEST=1
  678. else
  679. cd ${WAMR_DIR}/product-mini/platforms/${PLATFORM} \
  680. && if [ -d build ]; then rm -rf build/*; else mkdir build; fi \
  681. && cd build \
  682. && cmake $* .. \
  683. && cmake --build . -j 4 --config RelWithDebInfo --target iwasm
  684. fi
  685. if [ "$?" != 0 ];then
  686. echo -e "build iwasm failed"
  687. exit 1
  688. fi
  689. if [[ ${PLATFORM} == "cosmopolitan" ]]; then
  690. # convert from APE to ELF so it can be ran easier
  691. # HACK: link to linux so tests work when platform is detected by uname
  692. cp iwasm.com iwasm \
  693. && ./iwasm --assimilate \
  694. && rm -rf ../../linux/build \
  695. && mkdir ../../linux/build \
  696. && ln -s ../../cosmopolitan/build/iwasm ../../linux/build/iwasm
  697. if [ "$?" != 0 ];then
  698. echo -e "build iwasm failed (cosmopolitan)"
  699. exit 1
  700. fi
  701. fi
  702. }
  703. function build_wamrc()
  704. {
  705. if [[ "${TARGET_LIST[*]}" =~ "${TARGET}" ]]; then
  706. echo "suppose wamrc is already built"
  707. return
  708. fi
  709. BUILD_LLVM_SH=build_llvm.sh
  710. if [ ${TARGET} = "XTENSA" ]; then
  711. BUILD_LLVM_SH=build_llvm_xtensa.sh
  712. fi
  713. echo "Build wamrc for spec test under aot compile type"
  714. cd ${WAMR_DIR}/wamr-compiler \
  715. && ./${BUILD_LLVM_SH} \
  716. && if [ -d build ]; then rm -r build/*; else mkdir build; fi \
  717. && cd build \
  718. && cmake .. \
  719. -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE} \
  720. -DWAMR_BUILD_SHRUNK_MEMORY=0 \
  721. && make -j 4
  722. }
  723. ### Need to add a test suite?
  724. ### The function name should be ${suite_name}_test
  725. # function xxx_test()
  726. # {
  727. #
  728. # }
  729. function collect_coverage()
  730. {
  731. if [[ ${COLLECT_CODE_COVERAGE} == 1 ]]; then
  732. ln -sf ${WORK_DIR}/../spec-test-script/collect_coverage.sh ${WORK_DIR}
  733. CODE_COV_FILE=""
  734. if [[ -z "${CODE_COV_FILE}" ]]; then
  735. CODE_COV_FILE="${WORK_DIR}/wamr.lcov"
  736. else
  737. CODE_COV_FILE="${CODE_COV_FILE}"
  738. fi
  739. pushd ${WORK_DIR} > /dev/null 2>&1
  740. echo "Collect code coverage of iwasm"
  741. ./collect_coverage.sh ${CODE_COV_FILE} ${IWASM_LINUX_ROOT_DIR}/build
  742. if [[ $1 == "llvm-aot" ]]; then
  743. echo "Collect code coverage of wamrc"
  744. ./collect_coverage.sh ${CODE_COV_FILE} ${WAMR_DIR}/wamr-compiler/build
  745. fi
  746. for suite in "${TEST_CASE_ARR[@]}"; do
  747. if [[ ${suite} = "unit" ]]; then
  748. echo "Collect code coverage of unit test"
  749. ./collect_coverage.sh ${CODE_COV_FILE} ${WORK_DIR}/unittest-build
  750. break
  751. fi
  752. done
  753. popd > /dev/null 2>&1
  754. else
  755. echo "code coverage isn't collected"
  756. fi
  757. }
  758. # decide whether execute test cases in current running mode based on the current configuration or not
  759. # return 1 if the test case should be executed, otherwise return 0
  760. function do_execute_in_running_mode()
  761. {
  762. local RUNNING_MODE="$1"
  763. if [[ ${ENABLE_MULTI_MEMORY} -eq 1 ]]; then
  764. if [[ "${RUNNING_MODE}" != "classic-interp" \
  765. && "${RUNNING_MODE}" != "aot" ]]; then
  766. echo "support multi-memory in classic-interp mode and aot mode"
  767. return 0
  768. fi
  769. fi
  770. if [[ ${ENABLE_MEMORY64} -eq 1 ]]; then
  771. if [[ "${RUNNING_MODE}" != "classic-interp" \
  772. && "${RUNNING_MODE}" != "aot" ]]; then
  773. echo "support memory64(wasm64) in classic-interp mode and aot mode"
  774. return 0
  775. fi
  776. fi
  777. if [[ ${ENABLE_MULTI_MODULE} -eq 1 ]]; then
  778. if [[ "${RUNNING_MODE}" != "classic-interp" \
  779. && "${RUNNING_MODE}" != "fast-interp" \
  780. && "${RUNNING_MODE}" != "aot" ]]; then
  781. echo "support multi-module in both interp modes"
  782. return 0
  783. fi
  784. fi
  785. if [[ ${SGX_OPT} == "--sgx" ]]; then
  786. if [[ "${RUNNING_MODE}" != "classic-interp" \
  787. && "${RUNNING_MODE}" != "fast-interp" \
  788. && "${RUNNING_MODE}" != "aot" \
  789. && "${RUNNING_MODE}" != "fast-jit" ]]; then
  790. echo "support sgx in both interp modes, fast-jit mode and aot mode"
  791. return 0
  792. fi
  793. fi
  794. if [[ ${ENABLE_SIMD} -eq 1 ]]; then
  795. if [[ "${RUNNING_MODE}" != "jit" && "${RUNNING_MODE}" != "aot" && "${RUNNING_MODE}" != "fast-interp" ]]; then
  796. echo "support simd in llvm-jit, aot and fast-interp mode"
  797. return 0;
  798. fi
  799. fi
  800. if [[ ${TARGET} == "X86_32" ]]; then
  801. if [[ "${RUNNING_MODE}" == "jit" || "${RUNNING_MODE}" == "fast-jit" ]]; then
  802. echo "both llvm-jit mode and fast-jit mode do not support X86_32 target"
  803. return 0;
  804. fi
  805. fi
  806. if [[ ${ENABLE_GC} -eq 1 ]]; then
  807. if [[ "${RUNNING_MODE}" != "classic-interp" \
  808. && "${RUNNING_MODE}" != "fast-interp" \
  809. && "${RUNNING_MODE}" != "jit" \
  810. && "${RUNNING_MODE}" != "aot" ]]; then
  811. echo "support gc in both interp modes, llvm-jit mode and aot mode"
  812. return 0;
  813. fi
  814. fi
  815. if [[ ${ENABLE_EH} -eq 1 ]]; then
  816. if [[ "${RUNNING_MODE}" != "classic-interp" ]]; then
  817. echo "support exception handling in classic-interp"
  818. return 0;
  819. fi
  820. fi
  821. # by default, always execute the test case
  822. return 1
  823. }
  824. function trigger()
  825. {
  826. # Check if REQUIREMENT_NAME is set, if set, only calling requirement test and early return
  827. if [[ -n $REQUIREMENT_NAME ]]; then
  828. python ${REQUIREMENT_SCRIPT_DIR}/run_requirement.py -o ${REPORT_DIR}/ -r "$REQUIREMENT_NAME" "${SUBREQUIREMENT_IDS[@]}"
  829. # early return with the python script exit status
  830. return $?
  831. fi
  832. local EXTRA_COMPILE_FLAGS=""
  833. # for spec test
  834. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_SPEC_TEST=1"
  835. EXTRA_COMPILE_FLAGS+=" -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE}"
  836. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_SHRUNK_MEMORY=0"
  837. # default enabled features
  838. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_BULK_MEMORY=1"
  839. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_REF_TYPES=1"
  840. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_LIBC_WASI=0"
  841. if [[ ${ENABLE_MULTI_MODULE} == 1 ]];then
  842. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_MULTI_MODULE=1"
  843. else
  844. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_MULTI_MODULE=0"
  845. fi
  846. if [[ ${ENABLE_MEMORY64} == 1 ]];then
  847. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_MEMORY64=1"
  848. else
  849. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_MEMORY64=0"
  850. fi
  851. if [[ ${ENABLE_MULTI_MEMORY} == 1 ]];then
  852. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_MULTI_MEMORY=1"
  853. else
  854. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_MULTI_MEMORY=0"
  855. fi
  856. if [[ ${ENABLE_MULTI_THREAD} == 1 ]];then
  857. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_LIB_PTHREAD=1"
  858. fi
  859. if [[ ${ENABLE_SIMD} == 1 ]]; then
  860. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_SIMD=1"
  861. else
  862. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_SIMD=0"
  863. fi
  864. if [[ ${ENABLE_GC} == 1 ]]; then
  865. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_GC=1"
  866. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_BULK_MEMORY=1"
  867. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_TAIL_CALL=1"
  868. fi
  869. if [[ ${ENABLE_DEBUG_VERSION} == 1 ]]; then
  870. EXTRA_COMPILE_FLAGS+=" -DCMAKE_BUILD_TYPE=Debug"
  871. fi
  872. if [[ ${ENABLE_GC_HEAP_VERIFY} == 1 ]]; then
  873. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_GC_HEAP_VERIFY=1"
  874. fi
  875. if [[ ${ENABLE_WASI_THREADS} == 1 ]]; then
  876. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_LIB_WASI_THREADS=1"
  877. fi
  878. if [[ ${ENABLE_EH} == 1 ]]; then
  879. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_EXCE_HANDLING=1"
  880. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_TAIL_CALL=1"
  881. fi
  882. echo "SANITIZER IS" $WAMR_BUILD_SANITIZER
  883. if [[ "$WAMR_BUILD_SANITIZER" == "ubsan" ]]; then
  884. echo "Setting run with ubsan"
  885. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_SANITIZER=ubsan"
  886. fi
  887. if [[ "$WAMR_BUILD_SANITIZER" == "asan" ]]; then
  888. echo "Setting run with asan"
  889. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_SANITIZER=asan"
  890. fi
  891. if [[ "$WAMR_BUILD_SANITIZER" == "tsan" ]]; then
  892. echo "Setting run with tsan"
  893. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_SANITIZER=tsan"
  894. fi
  895. # Make sure we're using the builtin WASI libc implementation
  896. # if we're running the wasi certification tests.
  897. if [[ $TEST_CASE_ARR ]]; then
  898. for test in "${TEST_CASE_ARR[@]}"; do
  899. if [[ "$test" == "wasi_certification" ]]; then
  900. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_WASI_TEST=1"
  901. fi
  902. if [[ "$test" == "wasi_certification"
  903. || "$test" == "standalone" ]]; then
  904. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_LIBC_UVWASI=0 -DWAMR_BUILD_LIBC_WASI=1"
  905. break
  906. fi
  907. done
  908. fi
  909. for t in "${TYPE[@]}"; do
  910. do_execute_in_running_mode $t
  911. if [[ $? -eq 1 ]]; then
  912. echo "execute in running mode" $t
  913. else
  914. echo "skip in running mode" $t
  915. continue
  916. fi
  917. case $t in
  918. "classic-interp")
  919. # classic-interp
  920. BUILD_FLAGS="$CLASSIC_INTERP_COMPILE_FLAGS $EXTRA_COMPILE_FLAGS"
  921. if [[ ${ENABLE_QEMU} == 0 ]]; then
  922. build_iwasm_with_cfg $BUILD_FLAGS
  923. fi
  924. for suite in "${TEST_CASE_ARR[@]}"; do
  925. $suite"_test" classic-interp
  926. done
  927. collect_coverage classic-interp
  928. ;;
  929. "fast-interp")
  930. # fast-interp
  931. BUILD_FLAGS="$FAST_INTERP_COMPILE_FLAGS $EXTRA_COMPILE_FLAGS"
  932. if [[ ${ENABLE_QEMU} == 0 ]]; then
  933. build_iwasm_with_cfg $BUILD_FLAGS
  934. fi
  935. for suite in "${TEST_CASE_ARR[@]}"; do
  936. $suite"_test" fast-interp
  937. done
  938. collect_coverage fast-interp
  939. ;;
  940. "jit")
  941. echo "work in orc jit eager compilation mode"
  942. BUILD_FLAGS="$ORC_EAGER_JIT_COMPILE_FLAGS $EXTRA_COMPILE_FLAGS"
  943. build_iwasm_with_cfg $BUILD_FLAGS
  944. for suite in "${TEST_CASE_ARR[@]}"; do
  945. $suite"_test" jit
  946. done
  947. collect_coverage llvm-jit
  948. echo "work in orc jit lazy compilation mode"
  949. BUILD_FLAGS="$ORC_LAZY_JIT_COMPILE_FLAGS $EXTRA_COMPILE_FLAGS"
  950. build_iwasm_with_cfg $BUILD_FLAGS
  951. for suite in "${TEST_CASE_ARR[@]}"; do
  952. $suite"_test" jit
  953. done
  954. collect_coverage llvm-jit
  955. ;;
  956. "aot")
  957. echo "work in aot mode"
  958. # aot
  959. BUILD_FLAGS="$AOT_COMPILE_FLAGS $EXTRA_COMPILE_FLAGS"
  960. if [[ ${ENABLE_QEMU} == 0 ]]; then
  961. build_iwasm_with_cfg $BUILD_FLAGS
  962. fi
  963. if [ -z "${WAMRC_CMD}" ]; then
  964. build_wamrc
  965. WAMRC_CMD=${WAMRC_CMD_DEFAULT}
  966. fi
  967. for suite in "${TEST_CASE_ARR[@]}"; do
  968. $suite"_test" aot
  969. done
  970. collect_coverage llvm-aot
  971. ;;
  972. "fast-jit")
  973. echo "work in fast-jit mode"
  974. # fast-jit
  975. BUILD_FLAGS="$FAST_JIT_COMPILE_FLAGS $EXTRA_COMPILE_FLAGS"
  976. build_iwasm_with_cfg $BUILD_FLAGS
  977. for suite in "${TEST_CASE_ARR[@]}"; do
  978. $suite"_test" fast-jit
  979. done
  980. collect_coverage fast-jit
  981. ;;
  982. "multi-tier-jit")
  983. echo "work in multi-tier-jit mode"
  984. # multi-tier-jit
  985. BUILD_FLAGS="$MULTI_TIER_JIT_COMPILE_FLAGS $EXTRA_COMPILE_FLAGS"
  986. build_iwasm_with_cfg $BUILD_FLAGS
  987. for suite in "${TEST_CASE_ARR[@]}"; do
  988. $suite"_test" multi-tier-jit
  989. done
  990. collect_coverage multi-tier-jit
  991. ;;
  992. *)
  993. echo "unexpected mode, do nothing"
  994. ;;
  995. esac
  996. done
  997. }
  998. # if collect code coverage, ignore -s, test all test cases.
  999. if [[ $TEST_CASE_ARR ]];then
  1000. trigger || (echo "TEST FAILED"; exit 1)
  1001. else
  1002. # test all suite, ignore polybench and libsodium because of long time cost
  1003. TEST_CASE_ARR=("spec" "malformed" "standalone")
  1004. : '
  1005. if [[ $COLLECT_CODE_COVERAGE == 1 ]];then
  1006. # add polybench if collecting code coverage data
  1007. TEST_CASE_ARR+=("polybench")
  1008. # add libsodium if needed, which takes long time to run
  1009. TEST_CASE_ARR+=("libsodium")
  1010. fi
  1011. '
  1012. trigger || (echo "TEST FAILED"; exit 1)
  1013. # Add more suites here
  1014. fi
  1015. echo -e "Test finish. Reports are under ${REPORT_DIR}"
  1016. DEBUG set +exv pipefail
  1017. echo "TEST SUCCESSFUL"
  1018. exit 0