test_wamr.sh 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199
  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|posan)"
  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. # please sync with .github/actions/install-wasi-sdk-wabt/action.yml
  333. case ${PLATFORM} in
  334. cosmopolitan)
  335. ;;
  336. linux)
  337. WABT_URL=https://github.com/WebAssembly/wabt/releases/download/1.0.37/wabt-1.0.37-ubuntu-20.04.tar.gz
  338. WABT_VERSION=1.0.37
  339. ;;
  340. darwin)
  341. WABT_URL=https://github.com/WebAssembly/wabt/releases/download/1.0.36/wabt-1.0.36-macos-12.tar.gz
  342. WABT_VERSION=1.0.36
  343. ;;
  344. windows)
  345. WABT_URL=https://github.com/WebAssembly/wabt/releases/download/1.0.37/wabt-1.0.37-windows.tar.gz
  346. WABT_VERSION=1.0.37
  347. ;;
  348. *)
  349. echo "wabt platform for ${PLATFORM} in unknown"
  350. exit 1
  351. ;;
  352. esac
  353. if [ ${WABT_BINARY_RELEASE} == "YES" ]; then
  354. echo "download a binary release and install"
  355. local WAT2WASM=${WORK_DIR}/wabt/out/gcc/Release/wat2wasm
  356. if [ ! -f ${WAT2WASM} ]; then
  357. pushd /tmp
  358. wget -O wabt-tar.gz --progress=dot:giga ${WABT_URL}
  359. tar xf wabt-tar.gz
  360. popd
  361. mkdir -p ${WORK_DIR}/wabt/out/gcc/Release/
  362. cp /tmp/wabt-${WABT_VERSION}/bin/* ${WORK_DIR}/wabt/out/gcc/Release/
  363. fi
  364. else
  365. echo "download source code and compile and install"
  366. if [ ! -d "wabt" ];then
  367. echo "wabt not exist, clone it from github"
  368. git clone --recursive https://github.com/WebAssembly/wabt
  369. fi
  370. echo "upate wabt"
  371. cd wabt \
  372. && git fetch origin \
  373. && git reset --hard origin/main \
  374. && git checkout tags/${WABT_VERSION} -B ${WABT_VERSION} \
  375. && git submodule update --init \
  376. && cd .. \
  377. && make -C wabt gcc-release -j 4 || exit 1
  378. fi
  379. }
  380. function compile_reference_interpreter()
  381. {
  382. echo "compile the reference interpreter"
  383. pushd interpreter
  384. make
  385. if [ $? -ne 0 ]
  386. then
  387. echo "Failed to compile the reference interpreter"
  388. exit 1
  389. fi
  390. popd
  391. }
  392. # TODO: with iwasm only
  393. function spec_test()
  394. {
  395. local RUNNING_MODE="$1"
  396. echo "Now start spec tests"
  397. touch ${REPORT_DIR}/spec_test_report.txt
  398. cd ${WORK_DIR}
  399. # update basic test cases
  400. echo "downloading spec test cases..."
  401. rm -rf spec
  402. if [ ${ENABLE_MULTI_THREAD} == 1 ]; then
  403. echo "checkout spec from threads proposal"
  404. # check spec test cases for threads
  405. git clone -b main --single-branch https://github.com/WebAssembly/threads.git spec
  406. pushd spec
  407. # May 31, 2012 [interpreter] implement atomic.wait and atomic.notify (#194)
  408. git reset --hard 09f2831349bf409187abb6f7868482a8079f2264
  409. git apply --ignore-whitespace ../../spec-test-script/thread_proposal_ignore_cases.patch || exit 1
  410. git apply --ignore-whitespace ../../spec-test-script/thread_proposal_fix_atomic_case.patch || exit 1
  411. git apply --ignore-whitespace ../../spec-test-script/thread_proposal_remove_memory64_flag_case.patch
  412. elif [ ${ENABLE_EH} == 1 ]; then
  413. echo "checkout exception-handling test cases"
  414. git clone -b main --single-branch https://github.com/WebAssembly/exception-handling spec
  415. pushd spec
  416. # Jun 6, 2023 Merge branch 'upstream' into merge-upstream
  417. git reset --hard 51c721661b671bb7dc4b3a3acb9e079b49778d36
  418. git apply --ignore-whitespace ../../spec-test-script/exception_handling.patch || exit 1
  419. elif [[ ${ENABLE_GC} == 1 ]]; then
  420. echo "checkout spec for GC proposal"
  421. # check spec test cases for GC
  422. git clone -b main --single-branch https://github.com/WebAssembly/gc.git spec
  423. pushd spec
  424. # Dec 9, 2024. Merge branch 'funcref'
  425. git reset --hard 756060f5816c7e2159f4817fbdee76cf52f9c923
  426. git apply --ignore-whitespace ../../spec-test-script/gc_ignore_cases.patch || exit 1
  427. if [[ ${ENABLE_QEMU} == 1 ]]; then
  428. # Decrease the recursive count for tail call cases as nuttx qemu's
  429. # native stack size is much smaller
  430. git apply --ignore-whitespace ../../spec-test-script/gc_nuttx_tail_call.patch || exit 1
  431. fi
  432. # As of version 1.0.36, wabt is still unable to correctly handle the GC proposal.
  433. #
  434. # $ $ /opt/wabt-1.0.36/bin/wast2json --enable-all ../spec/test/core/br_if.wast
  435. #
  436. # ../spec/test/core/br_if.wast:670:26: error: unexpected token "null", expected a numeric index or a name (e.g. 12 or $foo).
  437. # (func $f (param (ref null $t)) (result funcref) (local.get 0))
  438. #
  439. compile_reference_interpreter
  440. elif [[ ${ENABLE_MEMORY64} == 1 ]]; then
  441. echo "checkout spec for memory64 proposal"
  442. # check spec test cases for memory64
  443. git clone -b main --single-branch https://github.com/WebAssembly/memory64.git spec
  444. pushd spec
  445. # Reset to commit: "Merge remote-tracking branch 'upstream/main' into merge2"
  446. git reset --hard 48e69f394869c55b7bbe14ac963c09f4605490b6
  447. git checkout 044d0d2e77bdcbe891f7e0b9dd2ac01d56435f0b -- test/core/elem.wast test/core/data.wast
  448. # Patch table64 extension
  449. 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
  450. git apply --ignore-whitespace ../../spec-test-script/memory64_ignore_cases.patch || exit 1
  451. elif [[ ${ENABLE_MULTI_MEMORY} == 1 ]]; then
  452. echo "checkout spec for multi memory proposal"
  453. # check spec test cases for multi memory
  454. git clone -b main --single-branch https://github.com/WebAssembly/multi-memory.git spec
  455. pushd spec
  456. # Reset to commit: "Merge pull request #48 from backes/specify-memcpy-immediate-order"
  457. git reset --hard fbc99efd7a788db300aec3dd62a14577ec404f1b
  458. git checkout 044d0d2e77bdcbe891f7e0b9dd2ac01d56435f0b -- test/core/elem.wast
  459. git apply --ignore-whitespace ../../spec-test-script/multi_memory_ignore_cases.patch || exit 1
  460. if [[ ${RUNNING_MODE} == "aot" ]]; then
  461. git apply --ignore-whitespace ../../spec-test-script/multi_module_aot_ignore_cases.patch || exit 1
  462. fi
  463. else
  464. echo "checkout spec for default proposal"
  465. git clone -b main --single-branch https://github.com/WebAssembly/spec
  466. pushd spec
  467. # Dec 20, 2024. Use WPT version of test harness for HTML core test conversion (#1859)
  468. git reset --hard f3a0e06235d2d84bb0f3b5014da4370613886965
  469. git apply --ignore-whitespace ../../spec-test-script/ignore_cases.patch || exit 1
  470. if [[ ${ENABLE_SIMD} == 1 ]]; then
  471. git apply --ignore-whitespace ../../spec-test-script/simd_ignore_cases.patch || exit 1
  472. fi
  473. if [[ ${ENABLE_MULTI_MODULE} == 1 ]]; then
  474. git apply --ignore-whitespace ../../spec-test-script/multi_module_ignore_cases.patch || exit 1
  475. if [[ ${RUNNING_MODE} == "aot" ]]; then
  476. git apply --ignore-whitespace ../../spec-test-script/multi_module_aot_ignore_cases.patch || exit 1
  477. fi
  478. fi
  479. fi
  480. popd
  481. echo $(pwd)
  482. #TODO: remove it when we can assume wabt is installed
  483. # especially for CI Or there is installation script in the project
  484. # that we can rely on
  485. setup_wabt
  486. ln -sf ${WORK_DIR}/../spec-test-script/all.py .
  487. ln -sf ${WORK_DIR}/../spec-test-script/runtest.py .
  488. local ARGS_FOR_SPEC_TEST=""
  489. if [[ 1 == ${ENABLE_MULTI_MODULE} ]]; then
  490. ARGS_FOR_SPEC_TEST+="-M "
  491. fi
  492. if [[ 1 == ${ENABLE_EH} ]]; then
  493. ARGS_FOR_SPEC_TEST+="-e "
  494. fi
  495. if [[ ${SGX_OPT} == "--sgx" ]];then
  496. ARGS_FOR_SPEC_TEST+="-x "
  497. fi
  498. if [[ ${ENABLE_SIMD} == 1 ]]; then
  499. ARGS_FOR_SPEC_TEST+="-S "
  500. fi
  501. if [[ ${ENABLE_MULTI_THREAD} == 1 ]]; then
  502. ARGS_FOR_SPEC_TEST+="-p "
  503. fi
  504. if [[ ${ENABLE_XIP} == 1 ]]; then
  505. ARGS_FOR_SPEC_TEST+="-X "
  506. fi
  507. # set the current running target
  508. ARGS_FOR_SPEC_TEST+="-m ${TARGET} "
  509. # require warmc only in aot mode
  510. if [[ $1 == 'aot' ]]; then
  511. ARGS_FOR_SPEC_TEST+="-t "
  512. ARGS_FOR_SPEC_TEST+="--aot-compiler ${WAMRC_CMD} "
  513. fi
  514. if [[ ${PARALLELISM} == 1 ]]; then
  515. ARGS_FOR_SPEC_TEST+="--parl "
  516. fi
  517. if [[ ${ENABLE_GC} == 1 ]]; then
  518. ARGS_FOR_SPEC_TEST+="--gc "
  519. fi
  520. if [[ 1 == ${ENABLE_MEMORY64} ]]; then
  521. ARGS_FOR_SPEC_TEST+="--memory64 "
  522. fi
  523. # multi memory is only enabled in interp and aot mode
  524. if [[ 1 == ${ENABLE_MULTI_MEMORY} ]]; then
  525. if [[ $1 == 'classic-interp' || $1 == 'aot' ]]; then
  526. ARGS_FOR_SPEC_TEST+="--multi-memory "
  527. fi
  528. fi
  529. if [[ ${ENABLE_QEMU} == 1 ]]; then
  530. ARGS_FOR_SPEC_TEST+="--qemu "
  531. ARGS_FOR_SPEC_TEST+="--qemu-firmware ${QEMU_FIRMWARE} "
  532. fi
  533. if [[ ${PLATFORM} == "windows" ]]; then
  534. ARGS_FOR_SPEC_TEST+="--no-pty "
  535. fi
  536. # set log directory
  537. ARGS_FOR_SPEC_TEST+="--log ${REPORT_DIR}"
  538. cd ${WORK_DIR}
  539. echo "${PYTHON_EXE} ./all.py ${ARGS_FOR_SPEC_TEST} | tee -a ${REPORT_DIR}/spec_test_report.txt"
  540. ${PYTHON_EXE} ./all.py ${ARGS_FOR_SPEC_TEST} | tee -a ${REPORT_DIR}/spec_test_report.txt
  541. if [[ ${PIPESTATUS[0]} -ne 0 ]];then
  542. echo -e "\nspec tests FAILED" | tee -a ${REPORT_DIR}/spec_test_report.txt
  543. exit 1
  544. fi
  545. cd -
  546. echo -e "\nFinish spec tests" | tee -a ${REPORT_DIR}/spec_test_report.txt
  547. }
  548. function wamr_compiler_test()
  549. {
  550. if [[ $1 != "aot" ]]; then
  551. echo "WAMR compiler tests only support AOT mode, skip $1"
  552. return 0
  553. fi
  554. echo "Now start WAMR compiler tests"
  555. setup_wabt
  556. cd ${WORK_DIR}/../wamr-compiler-test-script
  557. ./run_wamr_compiler_tests.sh ${WORK_DIR}/wabt/out/gcc/Release/wat2wasm $WAMRC_CMD $IWASM_CMD \
  558. | tee -a ${REPORT_DIR}/wamr_compiler_test_report.txt
  559. ret=${PIPESTATUS[0]}
  560. if [[ ${ret} -ne 0 ]];then
  561. echo -e "\nWAMR compiler tests FAILED" | tee -a ${REPORT_DIR}/wamr_compiler_test_report.txt
  562. exit 1
  563. fi
  564. echo -e "\nFinish WAMR compiler tests" | tee -a ${REPORT_DIR}/wamr_compiler_test_report.txt
  565. }
  566. function wasi_certification_test()
  567. {
  568. echo "Now start wasi certification tests"
  569. cd ${WORK_DIR}
  570. if [ ! -d "wasi-testsuite" ]; then
  571. echo "wasi-testsuite not exist, clone it from github"
  572. git clone -b prod/testsuite-all \
  573. --single-branch https://github.com/WebAssembly/wasi-testsuite.git
  574. fi
  575. cd wasi-testsuite
  576. git reset --hard ${WASI_TESTSUITE_COMMIT}
  577. TSAN_OPTIONS=${TSAN_OPTIONS} bash ../../wasi-test-script/run_wasi_tests.sh $1 $TARGET $WASI_TEST_FILTER \
  578. | tee -a ${REPORT_DIR}/wasi_test_report.txt
  579. ret=${PIPESTATUS[0]}
  580. if [[ ${ret} -ne 0 ]];then
  581. echo -e "\nwasi tests FAILED" | tee -a ${REPORT_DIR}/wasi_test_report.txt
  582. exit 1
  583. fi
  584. echo -e "\nFinish wasi tests" | tee -a ${REPORT_DIR}/wasi_test_report.txt
  585. }
  586. function polybench_test()
  587. {
  588. echo "Now start polybench tests"
  589. cd ${WORK_DIR}/../polybench
  590. if [[ $1 == "aot" || $1 == "jit" ]];then
  591. ./build.sh AOT ${SGX_OPT}
  592. ./test_aot.sh $1 ${SGX_OPT}
  593. else
  594. ./build.sh
  595. ./test_interp.sh ${SGX_OPT}
  596. fi
  597. cp report.txt ${REPORT_DIR}/polybench_$1_test_report.txt
  598. echo "Finish polybench tests"
  599. }
  600. function libsodium_test()
  601. {
  602. echo "Now start libsodium tests"
  603. cd ${WORK_DIR}/../libsodium
  604. if [[ $1 == "aot" || $1 == "jit" ]];then
  605. ./build.sh ${SGX_OPT}
  606. ./test_aot.sh $1 ${SGX_OPT}
  607. else
  608. ./test_interp.sh ${SGX_OPT}
  609. fi
  610. cp report.txt ${REPORT_DIR}/libsodium_$1_test_report.txt
  611. echo "Finish libsodium tests"
  612. }
  613. function malformed_test()
  614. {
  615. # build iwasm firstly
  616. cd ${WORK_DIR}/../../malformed
  617. ./malformed_test.py --run ${IWASM_CMD} | tee ${REPORT_DIR}/malfomed_$1_test_report.txt
  618. }
  619. function collect_standalone()
  620. {
  621. if [[ ${COLLECT_CODE_COVERAGE} == 1 ]]; then
  622. pushd ${WORK_DIR} > /dev/null 2>&1
  623. CODE_COV_FILE=""
  624. if [[ -z "${CODE_COV_FILE}" ]]; then
  625. CODE_COV_FILE="${WORK_DIR}/wamr.lcov"
  626. else
  627. CODE_COV_FILE="${CODE_COV_FILE}"
  628. fi
  629. STANDALONE_DIR=${WORK_DIR}/../../standalone
  630. echo "Collect code coverage of standalone dump-call-stack"
  631. ./collect_coverage.sh "${CODE_COV_FILE}" "${STANDALONE_DIR}/dump-call-stack/build"
  632. echo "Collect code coverage of standalone dump-mem-profiling"
  633. ./collect_coverage.sh "${CODE_COV_FILE}" "${STANDALONE_DIR}/dump-mem-profiling/build"
  634. echo "Collect code coverage of standalone dump-perf-profiling"
  635. ./collect_coverage.sh "${CODE_COV_FILE}" "${STANDALONE_DIR}/dump-perf-profiling/build"
  636. if [[ $1 == "aot" ]]; then
  637. echo "Collect code coverage of standalone pad-test"
  638. ./collect_coverage.sh "${CODE_COV_FILE}" "${STANDALONE_DIR}/pad-test/build"
  639. fi
  640. echo "Collect code coverage of standalone test-invoke-native"
  641. ./collect_coverage.sh "${CODE_COV_FILE}" "${STANDALONE_DIR}/test-invoke-native/build"
  642. echo "Collect code coverage of standalone test-running-modes"
  643. ./collect_coverage.sh "${CODE_COV_FILE}" "${STANDALONE_DIR}/test-running-modes/build"
  644. echo "Collect code coverage of standalone test-running-modes/c-embed"
  645. ./collect_coverage.sh "${CODE_COV_FILE}" "${STANDALONE_DIR}/test-running-modes/c-embed/build"
  646. echo "Collect code coverage of standalone test-ts2"
  647. ./collect_coverage.sh "${CODE_COV_FILE}" "${STANDALONE_DIR}/test-ts2/build"
  648. echo "Collect code coverage of standalone test-module-malloc"
  649. ./collect_coverage.sh "${CODE_COV_FILE}" "${STANDALONE_DIR}/test-module-malloc/build"
  650. popd > /dev/null 2>&1
  651. fi
  652. }
  653. function standalone_test()
  654. {
  655. if [[ ${COLLECT_CODE_COVERAGE} == 1 ]]; then
  656. export COLLECT_CODE_COVERAGE=1
  657. fi
  658. cd ${WORK_DIR}/../../standalone
  659. args="--$1"
  660. [[ ${SGX_OPT} == "--sgx" ]] && args="$args --sgx" || args="$args --no-sgx"
  661. [[ ${ENABLE_MULTI_THREAD} == 1 ]] && args="$args --thread" || args="$args --no-thread"
  662. [[ ${ENABLE_SIMD} == 1 ]] && args="$args --simd" || args="$args --no-simd"
  663. args="$args ${TARGET}"
  664. ./standalone.sh $args | tee ${REPORT_DIR}/standalone_$1_test_report.txt
  665. collect_standalone "$1"
  666. }
  667. function build_iwasm_with_cfg()
  668. {
  669. echo "Build iwasm with compile flags " $* " for spec test" \
  670. | tee -a ${REPORT_DIR}/spec_test_report.txt
  671. if [[ ${SGX_OPT} == "--sgx" ]];then
  672. cd ${WAMR_DIR}/product-mini/platforms/linux-sgx \
  673. && if [ -d build ]; then rm -rf build/*; else mkdir build; fi \
  674. && cd build \
  675. && cmake $* .. \
  676. && make -j 4
  677. cd ${WAMR_DIR}/product-mini/platforms/linux-sgx/enclave-sample \
  678. && make clean \
  679. && make SPEC_TEST=1
  680. else
  681. cd ${WAMR_DIR}/product-mini/platforms/${PLATFORM} \
  682. && if [ -d build ]; then rm -rf build/*; else mkdir build; fi \
  683. && cd build \
  684. && cmake $* .. \
  685. && cmake --build . -j 4 --config RelWithDebInfo --target iwasm
  686. fi
  687. if [ "$?" != 0 ];then
  688. echo -e "build iwasm failed"
  689. exit 1
  690. fi
  691. if [[ ${PLATFORM} == "cosmopolitan" ]]; then
  692. # convert from APE to ELF so it can be ran easier
  693. # HACK: link to linux so tests work when platform is detected by uname
  694. cp iwasm.com iwasm \
  695. && ./iwasm --assimilate \
  696. && rm -rf ../../linux/build \
  697. && mkdir ../../linux/build \
  698. && ln -s ../../cosmopolitan/build/iwasm ../../linux/build/iwasm
  699. if [ "$?" != 0 ];then
  700. echo -e "build iwasm failed (cosmopolitan)"
  701. exit 1
  702. fi
  703. fi
  704. }
  705. function build_wamrc()
  706. {
  707. if [[ "${TARGET_LIST[*]}" =~ "${TARGET}" ]]; then
  708. echo "suppose wamrc is already built"
  709. return
  710. fi
  711. BUILD_LLVM_SH=build_llvm.sh
  712. if [ ${TARGET} = "XTENSA" ]; then
  713. BUILD_LLVM_SH=build_llvm_xtensa.sh
  714. fi
  715. echo "Build wamrc for spec test under aot compile type"
  716. cd ${WAMR_DIR}/wamr-compiler \
  717. && ./${BUILD_LLVM_SH} \
  718. && if [ -d build ]; then rm -r build/*; else mkdir build; fi \
  719. && cd build \
  720. && cmake .. \
  721. -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE} \
  722. -DWAMR_BUILD_SHRUNK_MEMORY=0 \
  723. && make -j 4
  724. }
  725. ### Need to add a test suite?
  726. ### The function name should be ${suite_name}_test
  727. # function xxx_test()
  728. # {
  729. #
  730. # }
  731. function collect_coverage()
  732. {
  733. if [[ ${COLLECT_CODE_COVERAGE} == 1 ]]; then
  734. ln -sf ${WORK_DIR}/../spec-test-script/collect_coverage.sh ${WORK_DIR}
  735. CODE_COV_FILE=""
  736. if [[ -z "${CODE_COV_FILE}" ]]; then
  737. CODE_COV_FILE="${WORK_DIR}/wamr.lcov"
  738. else
  739. CODE_COV_FILE="${CODE_COV_FILE}"
  740. fi
  741. pushd ${WORK_DIR} > /dev/null 2>&1
  742. echo "Collect code coverage of iwasm"
  743. ./collect_coverage.sh ${CODE_COV_FILE} ${IWASM_LINUX_ROOT_DIR}/build
  744. if [[ $1 == "llvm-aot" ]]; then
  745. echo "Collect code coverage of wamrc"
  746. ./collect_coverage.sh ${CODE_COV_FILE} ${WAMR_DIR}/wamr-compiler/build
  747. fi
  748. for suite in "${TEST_CASE_ARR[@]}"; do
  749. if [[ ${suite} = "unit" ]]; then
  750. echo "Collect code coverage of unit test"
  751. ./collect_coverage.sh ${CODE_COV_FILE} ${WORK_DIR}/unittest-build
  752. break
  753. fi
  754. done
  755. popd > /dev/null 2>&1
  756. else
  757. echo "code coverage isn't collected"
  758. fi
  759. }
  760. # decide whether execute test cases in current running mode based on the current configuration or not
  761. # return 1 if the test case should be executed, otherwise return 0
  762. function do_execute_in_running_mode()
  763. {
  764. local RUNNING_MODE="$1"
  765. # filter out uncompatible running mode based on targeting proposal features
  766. # keep alpha order
  767. if [[ ${ENABLE_EH} -eq 1 ]]; then
  768. if [[ "${RUNNING_MODE}" != "classic-interp" ]]; then
  769. echo "support exception handling in classic-interp"
  770. return 0;
  771. fi
  772. fi
  773. if [[ ${ENABLE_GC} -eq 1 ]]; then
  774. if [[ "${RUNNING_MODE}" != "classic-interp" \
  775. && "${RUNNING_MODE}" != "fast-interp" \
  776. && "${RUNNING_MODE}" != "jit" \
  777. && "${RUNNING_MODE}" != "aot" ]]; then
  778. echo "support gc in both interp modes, llvm-jit mode and aot mode"
  779. return 0;
  780. fi
  781. fi
  782. if [[ ${ENABLE_MEMORY64} -eq 1 ]]; then
  783. if [[ "${RUNNING_MODE}" != "classic-interp" \
  784. && "${RUNNING_MODE}" != "aot" ]]; then
  785. echo "support memory64(wasm64) in classic-interp mode and aot mode"
  786. return 0
  787. fi
  788. fi
  789. if [[ ${ENABLE_MULTI_MEMORY} -eq 1 ]]; then
  790. if [[ "${RUNNING_MODE}" != "classic-interp" ]]; then
  791. echo "support multi-memory in classic-interp mode mode"
  792. return 0
  793. fi
  794. fi
  795. if [[ ${ENABLE_MULTI_MODULE} -eq 1 ]]; then
  796. if [[ "${RUNNING_MODE}" != "classic-interp" \
  797. && "${RUNNING_MODE}" != "fast-interp" \
  798. && "${RUNNING_MODE}" != "aot" ]]; then
  799. echo "support multi-module in both interp modes"
  800. return 0
  801. fi
  802. fi
  803. if [[ ${ENABLE_SIMD} -eq 1 ]]; then
  804. if [[ "${RUNNING_MODE}" != "jit" && "${RUNNING_MODE}" != "aot" && "${RUNNING_MODE}" != "fast-interp" ]]; then
  805. echo "support simd in llvm-jit, aot and fast-interp mode"
  806. return 0;
  807. fi
  808. fi
  809. # filter out uncompatible running mode based on SGX support
  810. if [[ ${SGX_OPT} == "--sgx" ]]; then
  811. if [[ "${RUNNING_MODE}" != "classic-interp" \
  812. && "${RUNNING_MODE}" != "fast-interp" \
  813. && "${RUNNING_MODE}" != "aot" \
  814. && "${RUNNING_MODE}" != "fast-jit" ]]; then
  815. echo "support sgx in both interp modes, fast-jit mode and aot mode"
  816. return 0
  817. fi
  818. fi
  819. # filter out uncompatible running mode based on architecture
  820. if [[ ${TARGET} == "X86_32" ]]; then
  821. if [[ "${RUNNING_MODE}" == "jit" || "${RUNNING_MODE}" == "fast-jit" || "${RUNNING_MODE}" == "multi-tier-jit" ]]; then
  822. echo "both llvm-jit, fast-jit and multi-tier-jit mode do not support X86_32 target"
  823. return 0;
  824. fi
  825. if [[ ${ENABLE_MEMORY64} -eq 1 ]]; then
  826. echo "memory64 does not support X86_32 target"
  827. return 0;
  828. fi
  829. if [[ ${ENABLE_MULTI_MEMORY} -eq 1 ]]; then
  830. echo "multi-memory does not support X86_32 target"
  831. return 0;
  832. fi
  833. if [[ ${ENABLE_SIMD} -eq 1 ]]; then
  834. echo "simd does not support X86_32 target"
  835. return 0;
  836. fi
  837. fi
  838. # by default, always execute the test case
  839. return 1
  840. }
  841. function trigger()
  842. {
  843. # Check if REQUIREMENT_NAME is set, if set, only calling requirement test and early return
  844. if [[ -n $REQUIREMENT_NAME ]]; then
  845. python ${REQUIREMENT_SCRIPT_DIR}/run_requirement.py -o ${REPORT_DIR}/ -r "$REQUIREMENT_NAME" "${SUBREQUIREMENT_IDS[@]}"
  846. # early return with the python script exit status
  847. return $?
  848. fi
  849. local EXTRA_COMPILE_FLAGS=""
  850. # for spec test
  851. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_SPEC_TEST=1"
  852. EXTRA_COMPILE_FLAGS+=" -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE}"
  853. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_SHRUNK_MEMORY=0"
  854. # default enabled features
  855. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_BULK_MEMORY=1"
  856. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_REF_TYPES=1"
  857. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_LIBC_WASI=0"
  858. if [[ ${ENABLE_MULTI_MODULE} == 1 ]];then
  859. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_MULTI_MODULE=1"
  860. else
  861. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_MULTI_MODULE=0"
  862. fi
  863. if [[ ${ENABLE_MEMORY64} == 1 ]];then
  864. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_MEMORY64=1"
  865. else
  866. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_MEMORY64=0"
  867. fi
  868. if [[ ${ENABLE_MULTI_MEMORY} == 1 ]];then
  869. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_MULTI_MEMORY=1"
  870. else
  871. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_MULTI_MEMORY=0"
  872. fi
  873. if [[ ${ENABLE_MULTI_THREAD} == 1 ]];then
  874. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_LIB_PTHREAD=1"
  875. fi
  876. if [[ ${ENABLE_SIMD} == 1 ]]; then
  877. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_SIMD=1"
  878. else
  879. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_SIMD=0"
  880. fi
  881. if [[ ${ENABLE_GC} == 1 ]]; then
  882. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_GC=1"
  883. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_BULK_MEMORY=1"
  884. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_TAIL_CALL=1"
  885. fi
  886. if [[ ${ENABLE_DEBUG_VERSION} == 1 ]]; then
  887. EXTRA_COMPILE_FLAGS+=" -DCMAKE_BUILD_TYPE=Debug"
  888. fi
  889. if [[ ${ENABLE_GC_HEAP_VERIFY} == 1 ]]; then
  890. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_GC_HEAP_VERIFY=1"
  891. fi
  892. if [[ ${ENABLE_WASI_THREADS} == 1 ]]; then
  893. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_LIB_WASI_THREADS=1"
  894. fi
  895. if [[ ${ENABLE_EH} == 1 ]]; then
  896. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_EXCE_HANDLING=1"
  897. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_TAIL_CALL=1"
  898. fi
  899. echo "SANITIZER IS" $WAMR_BUILD_SANITIZER
  900. if [[ "$WAMR_BUILD_SANITIZER" == "ubsan" ]]; then
  901. echo "Setting run with ubsan"
  902. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_SANITIZER=ubsan"
  903. fi
  904. if [[ "$WAMR_BUILD_SANITIZER" == "asan" ]]; then
  905. echo "Setting run with asan"
  906. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_SANITIZER=asan"
  907. fi
  908. if [[ "$WAMR_BUILD_SANITIZER" == "tsan" ]]; then
  909. echo "Setting run with tsan"
  910. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_SANITIZER=tsan"
  911. fi
  912. if [[ "$WAMR_BUILD_SANITIZER" == "posan" ]]; then
  913. echo "Setting run with posan"
  914. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_SANITIZER=posan"
  915. fi
  916. # Make sure we're using the builtin WASI libc implementation
  917. # if we're running the wasi certification tests.
  918. if [[ $TEST_CASE_ARR ]]; then
  919. for test in "${TEST_CASE_ARR[@]}"; do
  920. if [[ "$test" == "wasi_certification" ]]; then
  921. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_WASI_TEST=1"
  922. fi
  923. if [[ "$test" == "wasi_certification"
  924. || "$test" == "standalone" ]]; then
  925. EXTRA_COMPILE_FLAGS+=" -DWAMR_BUILD_LIBC_UVWASI=0 -DWAMR_BUILD_LIBC_WASI=1"
  926. break
  927. fi
  928. done
  929. fi
  930. for t in "${TYPE[@]}"; do
  931. do_execute_in_running_mode $t
  932. if [[ $? -eq 1 ]]; then
  933. echo "execute in running mode" $t
  934. else
  935. echo "skip in running mode" $t
  936. continue
  937. fi
  938. case $t in
  939. "classic-interp")
  940. # classic-interp
  941. BUILD_FLAGS="$CLASSIC_INTERP_COMPILE_FLAGS $EXTRA_COMPILE_FLAGS"
  942. if [[ ${ENABLE_QEMU} == 0 ]]; then
  943. build_iwasm_with_cfg $BUILD_FLAGS
  944. fi
  945. for suite in "${TEST_CASE_ARR[@]}"; do
  946. $suite"_test" classic-interp
  947. done
  948. collect_coverage classic-interp
  949. ;;
  950. "fast-interp")
  951. # fast-interp
  952. BUILD_FLAGS="$FAST_INTERP_COMPILE_FLAGS $EXTRA_COMPILE_FLAGS"
  953. if [[ ${ENABLE_QEMU} == 0 ]]; then
  954. build_iwasm_with_cfg $BUILD_FLAGS
  955. fi
  956. for suite in "${TEST_CASE_ARR[@]}"; do
  957. $suite"_test" fast-interp
  958. done
  959. collect_coverage fast-interp
  960. ;;
  961. "jit")
  962. echo "work in orc jit eager compilation mode"
  963. BUILD_FLAGS="$ORC_EAGER_JIT_COMPILE_FLAGS $EXTRA_COMPILE_FLAGS"
  964. build_iwasm_with_cfg $BUILD_FLAGS
  965. for suite in "${TEST_CASE_ARR[@]}"; do
  966. $suite"_test" jit
  967. done
  968. collect_coverage llvm-jit
  969. echo "work in orc jit lazy compilation mode"
  970. BUILD_FLAGS="$ORC_LAZY_JIT_COMPILE_FLAGS $EXTRA_COMPILE_FLAGS"
  971. build_iwasm_with_cfg $BUILD_FLAGS
  972. for suite in "${TEST_CASE_ARR[@]}"; do
  973. $suite"_test" jit
  974. done
  975. collect_coverage llvm-jit
  976. ;;
  977. "aot")
  978. echo "work in aot mode"
  979. # aot
  980. BUILD_FLAGS="$AOT_COMPILE_FLAGS $EXTRA_COMPILE_FLAGS"
  981. if [[ ${ENABLE_QEMU} == 0 ]]; then
  982. build_iwasm_with_cfg $BUILD_FLAGS
  983. fi
  984. if [ -z "${WAMRC_CMD}" ]; then
  985. build_wamrc
  986. WAMRC_CMD=${WAMRC_CMD_DEFAULT}
  987. fi
  988. for suite in "${TEST_CASE_ARR[@]}"; do
  989. $suite"_test" aot
  990. done
  991. collect_coverage llvm-aot
  992. ;;
  993. "fast-jit")
  994. echo "work in fast-jit mode"
  995. # fast-jit
  996. BUILD_FLAGS="$FAST_JIT_COMPILE_FLAGS $EXTRA_COMPILE_FLAGS"
  997. build_iwasm_with_cfg $BUILD_FLAGS
  998. for suite in "${TEST_CASE_ARR[@]}"; do
  999. $suite"_test" fast-jit
  1000. done
  1001. collect_coverage fast-jit
  1002. ;;
  1003. "multi-tier-jit")
  1004. echo "work in multi-tier-jit mode"
  1005. # multi-tier-jit
  1006. BUILD_FLAGS="$MULTI_TIER_JIT_COMPILE_FLAGS $EXTRA_COMPILE_FLAGS"
  1007. build_iwasm_with_cfg $BUILD_FLAGS
  1008. for suite in "${TEST_CASE_ARR[@]}"; do
  1009. $suite"_test" multi-tier-jit
  1010. done
  1011. collect_coverage multi-tier-jit
  1012. ;;
  1013. *)
  1014. echo "unexpected mode, do nothing"
  1015. ;;
  1016. esac
  1017. done
  1018. }
  1019. # if collect code coverage, ignore -s, test all test cases.
  1020. if [[ $TEST_CASE_ARR ]];then
  1021. trigger || (echo "TEST FAILED"; exit 1)
  1022. else
  1023. # test all suite, ignore polybench and libsodium because of long time cost
  1024. TEST_CASE_ARR=("spec" "malformed" "standalone")
  1025. : '
  1026. if [[ $COLLECT_CODE_COVERAGE == 1 ]];then
  1027. # add polybench if collecting code coverage data
  1028. TEST_CASE_ARR+=("polybench")
  1029. # add libsodium if needed, which takes long time to run
  1030. TEST_CASE_ARR+=("libsodium")
  1031. fi
  1032. '
  1033. trigger || (echo "TEST FAILED"; exit 1)
  1034. # Add more suites here
  1035. fi
  1036. echo -e "Test finish. Reports are under ${REPORT_DIR}"
  1037. DEBUG set +exv pipefail
  1038. echo "TEST SUCCESSFUL"
  1039. exit 0