diff options
Diffstat (limited to 'fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script')
11 files changed, 3970 insertions, 0 deletions
diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/CHANGES b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/CHANGES new file mode 100644 index 00000000..0b0cc9a6 --- /dev/null +++ b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/CHANGES @@ -0,0 +1,5 @@ +#################### +2021-9-8 + +Modify runtest.py from https://github.com/kanaka/wac/blob/master/runtest.py +to enable testing spec cases with more checks and support more runtime modes. diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/all.py b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/all.py new file mode 100644 index 00000000..8b26d689 --- /dev/null +++ b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/all.py @@ -0,0 +1,525 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# + +import argparse +import multiprocessing as mp +import os +import pathlib +import subprocess +import sys +import time + +""" +The script itself has to be put under the same directory with the "spec". +To run a single non-GC case with interpreter mode: + cd workspace + python3 runtest.py --wast2wasm wabt/bin/wat2wasm --interpreter iwasm \ + spec/test/core/xxx.wast +To run a single non-GC case with aot mode: + cd workspace + python3 runtest.py --aot --wast2wasm wabt/bin/wat2wasm --interpreter iwasm \ + --aot-compiler wamrc spec/test/core/xxx.wast +To run a single GC case: + cd workspace + python3 runtest.py --wast2wasm spec/interpreter/wasm --interpreter iwasm \ + --aot-compiler wamrc --gc spec/test/core/xxx.wast +""" + +PLATFORM_NAME = os.uname().sysname.lower() +IWASM_CMD = "../../../product-mini/platforms/" + PLATFORM_NAME + "/build/iwasm" +IWASM_SGX_CMD = "../../../product-mini/platforms/linux-sgx/enclave-sample/iwasm" +IWASM_QEMU_CMD = "iwasm" +SPEC_TEST_DIR = "spec/test/core" +WAST2WASM_CMD = "./wabt/out/gcc/Release/wat2wasm" +SPEC_INTERPRETER_CMD = "spec/interpreter/wasm" +WAMRC_CMD = "../../../wamr-compiler/build/wamrc" + +class TargetAction(argparse.Action): + TARGET_MAP = { + "ARMV7_VFP": "armv7", + "RISCV32": "riscv32_ilp32", + "RISCV32_ILP32": "riscv32_ilp32", + "RISCV32_ILP32D": "riscv32_ilp32d", + "RISCV64": "riscv64_lp64", + "RISCV64_LP64": "riscv64_lp64", + "RISCV64_LP64D": "riscv64_lp64", + "THUMBV7_VFP": "thumbv7", + "X86_32": "i386", + "X86_64": "x86_64", + } + + def __call__(self, parser, namespace, values, option_string=None): + setattr(namespace, self.dest, self.TARGET_MAP.get(values, "x86_64")) + + +def ignore_the_case( + case_name, + target, + aot_flag=False, + sgx_flag=False, + multi_module_flag=False, + multi_thread_flag=False, + simd_flag=False, + gc_flag=False, + xip_flag=False, + qemu_flag=False +): + if case_name in ["comments", "inline-module", "names"]: + return True + + if not multi_module_flag and case_name in ["imports", "linking"]: + return True + + if "i386" == target and case_name in ["float_exprs"]: + return True + + if gc_flag: + if case_name in ["type-canon", "type-equivalence", "type-rec"]: + return True; + + if sgx_flag: + if case_name in ["conversions", "f32_bitwise", "f64_bitwise"]: + return True + + if aot_flag and case_name in [ + "call_indirect", + "call", + "fac", + "skip-stack-guard-page", + ]: + return True + + if qemu_flag: + if case_name in ["f32_bitwise", "f64_bitwise", "loop", "f64", "f64_cmp", + "conversions", "f32", "f32_cmp", "float_exprs", + "float_misc", "select", "memory_grow"]: + return True + + return False + + +def preflight_check(aot_flag): + if not pathlib.Path(SPEC_TEST_DIR).resolve().exists(): + print(f"Can not find {SPEC_TEST_DIR}") + return False + + if not pathlib.Path(WAST2WASM_CMD).resolve().exists(): + print(f"Can not find {WAST2WASM_CMD}") + return False + + if aot_flag and not pathlib.Path(WAMRC_CMD).resolve().exists(): + print(f"Can not find {WAMRC_CMD}") + return False + + return True + + +def test_case( + case_path, + target, + aot_flag=False, + sgx_flag=False, + multi_module_flag=False, + multi_thread_flag=False, + simd_flag=False, + xip_flag=False, + clean_up_flag=True, + verbose_flag=True, + gc_flag=False, + qemu_flag=False, + qemu_firmware='', + log='', +): + case_path = pathlib.Path(case_path).resolve() + case_name = case_path.stem + + if ignore_the_case( + case_name, + target, + aot_flag, + sgx_flag, + multi_module_flag, + multi_thread_flag, + simd_flag, + gc_flag, + xip_flag, + qemu_flag + ): + return True + + CMD = ["python3", "runtest.py"] + CMD.append("--wast2wasm") + CMD.append(WAST2WASM_CMD if not gc_flag else SPEC_INTERPRETER_CMD) + CMD.append("--interpreter") + if sgx_flag: + CMD.append(IWASM_SGX_CMD) + elif qemu_flag: + CMD.append(IWASM_QEMU_CMD) + else: + CMD.append(IWASM_CMD) + CMD.append("--aot-compiler") + CMD.append(WAMRC_CMD) + + if aot_flag: + CMD.append("--aot") + + CMD.append("--target") + CMD.append(target) + + if multi_module_flag: + CMD.append("--multi-module") + + if multi_thread_flag: + CMD.append("--multi-thread") + + if sgx_flag: + CMD.append("--sgx") + + if simd_flag: + CMD.append("--simd") + + if xip_flag: + CMD.append("--xip") + + if qemu_flag: + CMD.append("--qemu") + CMD.append("--qemu-firmware") + CMD.append(qemu_firmware) + + if not clean_up_flag: + CMD.append("--no_cleanup") + + if gc_flag: + CMD.append("--gc") + + if log != '': + CMD.append("--log-dir") + CMD.append(log) + + CMD.append(case_path) + print(f"============> run {case_name} ", end="") + with subprocess.Popen( + CMD, + bufsize=1, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True, + ) as p: + try: + case_last_words = [] + while not p.poll(): + output = p.stdout.readline() + + if not output: + break + + if verbose_flag: + print(output, end="") + else: + if len(case_last_words) == 16: + case_last_words.pop(0) + case_last_words.append(output) + + p.wait(60) + + if p.returncode: + print(f"failed with a non-zero return code {p.returncode}") + if not verbose_flag: + print( + f"\n==================== LAST LOG of {case_name} ====================\n" + ) + print("".join(case_last_words)) + print("\n==================== LAST LOG END ====================\n") + raise Exception(case_name) + else: + print("successful") + return True + except subprocess.CalledProcessError: + print("failed with CalledProcessError") + raise Exception(case_name) + except subprocess.TimeoutExpired: + print("failed with TimeoutExpired") + raise Exception(case_name) + + +def test_suite( + target, + aot_flag=False, + sgx_flag=False, + multi_module_flag=False, + multi_thread_flag=False, + simd_flag=False, + xip_flag=False, + clean_up_flag=True, + verbose_flag=True, + gc_flag=False, + parl_flag=False, + qemu_flag=False, + qemu_firmware='', + log='', +): + suite_path = pathlib.Path(SPEC_TEST_DIR).resolve() + if not suite_path.exists(): + print(f"can not find spec test cases at {suite_path}") + return False + + case_list = sorted(suite_path.glob("*.wast")) + if simd_flag: + simd_case_list = sorted(suite_path.glob("simd/*.wast")) + case_list.extend(simd_case_list) + + if gc_flag: + gc_case_list = sorted(suite_path.glob("gc/*.wast")) + case_list.extend(gc_case_list) + + case_count = len(case_list) + failed_case = 0 + successful_case = 0 + + if parl_flag: + print(f"----- Run the whole spec test suite on {mp.cpu_count()} cores -----") + with mp.Pool() as pool: + results = {} + for case_path in case_list: + results[case_path.stem] = pool.apply_async( + test_case, + [ + str(case_path), + target, + aot_flag, + sgx_flag, + multi_module_flag, + multi_thread_flag, + simd_flag, + xip_flag, + clean_up_flag, + verbose_flag, + gc_flag, + qemu_flag, + qemu_firmware, + log, + ], + ) + + for case_name, result in results.items(): + try: + if qemu_flag: + # 60 min / case, testing on QEMU may be very slow + result.wait(7200) + else: + # 5 min / case + result.wait(300) + if not result.successful(): + failed_case += 1 + else: + successful_case += 1 + except mp.TimeoutError: + print(f"{case_name} meets TimeoutError") + failed_case += 1 + else: + print(f"----- Run the whole spec test suite -----") + for case_path in case_list: + try: + test_case( + str(case_path), + target, + aot_flag, + sgx_flag, + multi_module_flag, + multi_thread_flag, + simd_flag, + xip_flag, + clean_up_flag, + verbose_flag, + gc_flag, + qemu_flag, + qemu_firmware, + log, + ) + successful_case += 1 + except Exception as e: + failed_case += 1 + raise e + + print( + f"IN ALL {case_count} cases: {successful_case} PASS, {failed_case} FAIL, {case_count - successful_case - failed_case} SKIP" + ) + + return 0 == failed_case + + +def main(): + parser = argparse.ArgumentParser(description="run the whole spec test suite") + + parser.add_argument( + "-M", + action="store_true", + default=False, + dest="multi_module_flag", + help="Running with the Multi-Module feature", + ) + parser.add_argument( + "-m", + action=TargetAction, + choices=list(TargetAction.TARGET_MAP.keys()), + type=str, + dest="target", + default="X86_64", + help="Specify Target ", + ) + parser.add_argument( + "-p", + action="store_true", + default=False, + dest="multi_thread_flag", + help="Running with the Multi-Thread feature", + ) + parser.add_argument( + "-S", + action="store_true", + default=False, + dest="simd_flag", + help="Running with the SIMD feature", + ) + parser.add_argument( + "-X", + action="store_true", + default=False, + dest="xip_flag", + help="Running with the XIP feature", + ) + parser.add_argument( + "-t", + action="store_true", + default=False, + dest="aot_flag", + help="Running with AOT mode", + ) + parser.add_argument( + "-x", + action="store_true", + default=False, + dest="sgx_flag", + help="Running with SGX environment", + ) + parser.add_argument( + "--no_clean_up", + action="store_false", + default=True, + dest="clean_up_flag", + help="Does not remove tmpfiles. But it will be enabled while running parallelly", + ) + parser.add_argument( + "--parl", + action="store_true", + default=False, + dest="parl_flag", + help="To run whole test suite parallelly", + ) + parser.add_argument( + "--qemu", + action="store_true", + default=False, + dest="qemu_flag", + help="To run whole test suite in qemu", + ) + parser.add_argument( + "--qemu-firmware", + default="", + dest="qemu_firmware", + help="Firmware required by qemu", + ) + parser.add_argument( + "--log", + default='', + dest="log", + help="Log directory", + ) + parser.add_argument( + "--quiet", + action="store_false", + default=True, + dest="verbose_flag", + help="Close real time output while running cases, only show last words of failed ones", + ) + parser.add_argument( + "--gc", + action="store_true", + default=False, + dest="gc_flag", + help="Running with GC feature", + ) + parser.add_argument( + "cases", + metavar="path_to__case", + type=str, + nargs="*", + help=f"Specify all wanted cases. If not the script will go through all cases under {SPEC_TEST_DIR}", + ) + + options = parser.parse_args() + print(options) + + if not preflight_check(options.aot_flag): + return False + + if not options.cases: + if options.parl_flag: + # several cases might share the same workspace/tempfile at the same time + # so, disable it while running parallelly + options.clean_up_flag = False + options.verbose_flag = False + + start = time.time_ns() + ret = test_suite( + options.target, + options.aot_flag, + options.sgx_flag, + options.multi_module_flag, + options.multi_thread_flag, + options.simd_flag, + options.xip_flag, + options.clean_up_flag, + options.verbose_flag, + options.gc_flag, + options.parl_flag, + options.qemu_flag, + options.qemu_firmware, + options.log, + ) + end = time.time_ns() + print( + f"It takes {((end - start) / 1000000):,} ms to run test_suite {'parallelly' if options.parl_flag else ''}" + ) + else: + try: + for case in options.cases: + test_case( + case, + options.target, + options.aot_flag, + options.sgx_flag, + options.multi_module_flag, + options.multi_thread_flag, + options.simd_flag, + options.xip_flag, + options.clean_up_flag, + options.verbose_flag, + options.gc_flag, + options.qemu_flag, + options.qemu_firmware, + options.log + ) + else: + ret = True + except Exception: + ret = False + + return ret + + +if __name__ == "__main__": + sys.exit(0 if main() else 1) diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/all.sh b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/all.sh new file mode 100755 index 00000000..09d86815 --- /dev/null +++ b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/all.sh @@ -0,0 +1,162 @@ +#!/bin/bash + +# +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# + +# exit if meet an exception +function DEBUG() { + [[ -n $(env | grep "\<DEBUG\>") ]] && $@ +} +DEBUG set -xevu + +# Run the following command to test a single wast file: +# ./spec-test-script/runtest.py --wast2wasm ./workspace/wabt/out/gcc/Release/wat2wasm \ +# --interpreter iwasm <wast file> + +readonly SPEC_TEST_DIR="spec/test/core" +readonly WAST2WASM_CMD="./wabt/out/gcc/Release/wat2wasm" +readonly WAMRC_CMD="../../../wamr-compiler/build/wamrc" +PLATFORM=$(uname -s | tr A-Z a-z) +IWASM_CMD="../../../product-mini/platforms/${PLATFORM}/build/iwasm" + +# "imports" and "linking" are only avilable when enabling multi modules +# "comments" is for runtest.py + +IGNORE_LIST=( + "comments" "inline-module" "imports" "linking" "names" +) + +readonly -a MULTI_MODULE_LIST=( + "imports" "linking" +) + +SGX_IGNORE_LIST=("conversions" "f32_bitwise" "f64_bitwise") + +# these cases run failed due to native stack overflow check failed +SGX_AOT_IGNORE_LIST=("call_indirect" "call" "fac" "skip-stack-guard-page") + +function usage() { + echo "Usage: all.sh [-t] [-m <x86_64|x86_32|ARMV7_VFP|THUMBV7_VFP>] [-M] [-x] [-S] [-r]" + exit 1 +} + +function run_case_w_aot() { + local test_case=$1 + echo "============> run ${test_case} with AOT" + python2.7 runtest.py \ + --wast2wasm ${WAST2WASM_CMD} \ + --interpreter ${IWASM_CMD} \ + ${SPEC_TEST_DIR}/${test_case} \ + --aot-compiler ${WAMRC_CMD} \ + --aot --aot-target ${TARGET} \ + ${SGX_OPT} \ + ${SIMD_OPT} \ + ${REF_TYPES_OPT} + #--no_cleanup + if [[ $? != 0 ]]; then + echo "============> run ${test_case} failed" + exit 1 + fi +} + +function run_case_wo_aot() { + local test_case=$1 + echo "============> run ${test_case}" + python2.7 runtest.py \ + --wast2wasm ${WAST2WASM_CMD} \ + --interpreter ${IWASM_CMD} \ + ${SPEC_TEST_DIR}/${test_case} \ + --aot-compiler ${WAMRC_CMD} \ + ${SGX_OPT} \ + ${SIMD_OPT} \ + ${REF_TYPES_OPT} + #--no_cleanup + if [[ $? != 0 ]]; then + echo "============> run ${test_case} failed" + exit 1 + fi +} + +ENABLE_MULTI_MODULE=0 +TARGET="X86_64" +SGX_OPT="" +AOT=false +SIMD_OPT="" +REF_TYPES_OPT="" +while getopts ":Mm:txSr" opt; do + case $opt in + t) AOT=true ;; + m) + TARGET=$OPTARG + if [[ ${TARGET} == 'X86_32' ]]; then + TARGET='i386' + elif [[ ${TARGET} == 'X86_64' ]]; then + TARGET='x86_64' + elif [[ ${TARGET} == 'ARMV7_VFP' ]]; then + TARGET='armv7' + elif [[ ${TARGET} == 'THUMBV7_VFP' ]]; then + TARGET='thumbv7' + elif [[ ${TARGET} == 'RISCV64' || ${TARGET} == 'RISCV64_LP64D' ]]; then + TARGET='riscv64_lp64d' + elif [[ ${TARGET} == 'RISCV64_LP64' ]]; then + TARGET='riscv64_lp64' + else + usage + fi ;; + M) ENABLE_MULTI_MODULE=1 ;; + x) SGX_OPT="--sgx" ;; + S) SIMD_OPT="--simd" ;; + r) REF_TYPES_OPT="--ref_types" ;; + *) usage ;; + esac +done + +function contain() { + # [$1, $-1) + local list=${@:0:${#}} + # [$-1] + local item=${@:${#}} + [[ ${list} =~ (^| )${item}($| ) ]] && return 0 || return 1 +} + +if [[ ${SGX_OPT} ]]; then + IWASM_CMD="../../../product-mini/platforms/linux-sgx/enclave-sample/iwasm" + IGNORE_LIST+=("${SGX_IGNORE_LIST[@]}") + if [[ "true" == ${AOT} ]]; then + IGNORE_LIST+=("${SGX_AOT_IGNORE_LIST[@]}") + fi +fi + +if [[ ${TARGET} == "i386" ]]; then + IGNORE_LIST+=("float_exprs") +fi + +declare -i COUNTER=0 +for wast in $(find ${SPEC_TEST_DIR} -name "*.wast" -type f | sort -n); do + # remove a prefix spec/test/core/ + wast=${wast#${SPEC_TEST_DIR}/} + # ${wast%.wast} will remove a surfix .wast + if contain "${IGNORE_LIST[@]}" ${wast%.wast}; then + echo "============> ignore ${wast}" + continue + else + [[ "true" == ${AOT} ]] && run_case_w_aot ${wast} || + run_case_wo_aot ${wast} + ((COUNTER += 1)) + fi +done + +# for now, Multi_Module is always disabled while AOT is true +if [[ "false" == ${AOT} && 1 == ${ENABLE_MULTI_MODULE} ]]; then + echo "============> run cases about multi module" + for wast in ${MULTI_MODULE_LIST[@]}; do + run_case_wo_aot ${wast}.wast + ((COUNTER += 1)) + done +fi + +echo "PASS ALL ${COUNTER} SPEC CASES" +DEBUG set -xevu +exit 0 diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/collect_coverage.sh b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/collect_coverage.sh new file mode 100755 index 00000000..09b1f465 --- /dev/null +++ b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/collect_coverage.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env bash + +# +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# + +readonly WORK_DIR=$PWD +readonly WAMR_DIR=${WORK_DIR}/../../.. +readonly DST_COV_FILE=$1 +readonly SRC_COV_DIR=$2 +readonly SRC_TEMP_COV_FILE=wamr_temp.lcov +readonly SRC_COV_FILE=wamr.lcov + +# get dest folder +dir=$(dirname ${DST_COV_FILE}) +pushd ${dir} > /dev/null 2>&1 +readonly DST_COV_DIR=${PWD} +popd > /dev/null 2>&1 + +if [[ ! -d ${SRC_COV_DIR} ]]; then + echo "${SRC_COV_DIR} doesn't exist, ignore code coverage collection" + exit +fi + +echo "Start to collect code coverage of ${SRC_COV_DIR} .." + +pushd ${SRC_COV_DIR} > /dev/null 2>&1 + +# collect all code coverage data +lcov -q -o ${SRC_TEMP_COV_FILE} -c -d . --rc lcov_branch_coverage=1 +# extract code coverage data of WAMR source files +lcov -q -r ${SRC_TEMP_COV_FILE} -o ${SRC_TEMP_COV_FILE} \ + -rc lcov_branch_coverage=1 \ + "*/usr/*" "*/_deps/*" "*/deps/*" "*/tests/unit/*" \ + "*/llvm/include/*" "*/include/llvm/*" "*/samples/*" \ + "*/app-framework/*" "*/app-mgr/*" "*/test-tools/*" \ + "*/tests/standalone/*" "*/tests/*" + +if [[ -s ${SRC_TEMP_COV_FILE} ]]; then + if [[ -s ${DST_COV_FILE} ]]; then + # merge code coverage data + lcov --rc lcov_branch_coverage=1 \ + --add-tracefile ${SRC_TEMP_COV_FILE} \ + -a ${DST_COV_FILE} -o ${SRC_COV_FILE} + # backup the original lcov file + cp -a ${DST_COV_FILE} "${DST_COV_FILE}.orig" + # replace the lcov file + cp -a ${SRC_COV_FILE} ${DST_COV_FILE} + echo "Code coverage file ${DST_COV_FILE} was appended" + else + cp -a ${SRC_TEMP_COV_FILE} ${SRC_COV_FILE} + cp -a ${SRC_COV_FILE} ${DST_COV_FILE} + echo "Code coverage file ${DST_COV_FILE} was generated" + fi + + # get ignored prefix path + dir=$(dirname ${WAMR_DIR}/../..) + pushd ${dir} > /dev/null 2>&1 + prefix_full_path=${PWD} + popd > /dev/null 2>&1 + + # generate html output for merged code coverage data + rm -fr ${DST_COV_DIR}/wamr-lcov + genhtml -q -t "WAMR Code Coverage" \ + --rc lcov_branch_coverage=1 --prefix=${prefix_full_path} \ + -o ${DST_COV_DIR}/wamr-lcov \ + ${DST_COV_FILE} + + cd ${DST_COV_DIR} + rm -f wamr-lcov.zip + zip -r -q -o wamr-lcov.zip wamr-lcov + rm -fr wamr-lcov + + echo "Code coverage html ${DST_COV_DIR}/wamr-lcov.zip was generated" +else + echo "generate code coverage html failed" +fi + +echo "" + +popd > /dev/null 2>&1 diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/ignore_cases.patch b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/ignore_cases.patch new file mode 100644 index 00000000..1d94d91a --- /dev/null +++ b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/ignore_cases.patch @@ -0,0 +1,805 @@ +diff --git a/test/core/binary.wast b/test/core/binary.wast +index 891aad3..07356a3 100644 +--- a/test/core/binary.wast ++++ b/test/core/binary.wast +@@ -206,7 +206,7 @@ + ) + + ;; Type section with signed LEB128 encoded type +-(assert_malformed ++(;assert_malformed + (module binary + "\00asm" "\01\00\00\00" + "\01" ;; Type section id +@@ -216,7 +216,7 @@ + "\00\00" + ) + "integer representation too long" +-) ++;) + + ;; Unsigned LEB128 must not be overlong + (assert_malformed +@@ -1683,7 +1683,7 @@ + ) + + ;; 2 elem segment declared, 1 given +-(assert_malformed ++(;assert_malformed + (module binary + "\00asm" "\01\00\00\00" + "\01\04\01" ;; type section +@@ -1696,7 +1696,7 @@ + ;; "\00\41\00\0b\01\00" ;; elem 1 (missed) + ) + "unexpected end" +-) ++;) + + ;; 2 elem segment declared, 1.5 given + (assert_malformed +@@ -1813,7 +1813,7 @@ + ) + + ;; 1 br_table target declared, 2 given +-(assert_malformed ++(;assert_malformed + (module binary + "\00asm" "\01\00\00\00" + "\01\04\01" ;; type section +@@ -1832,7 +1832,7 @@ + "\0b\0b\0b" ;; end + ) + "unexpected end" +-) ++;) + + ;; Start section + (module binary +diff --git a/test/core/data.wast b/test/core/data.wast +index 4f339be..0b5b3e6 100644 +--- a/test/core/data.wast ++++ b/test/core/data.wast +@@ -306,9 +306,10 @@ + "\02\01\41\00\0b" ;; active data segment 0 for memory 1 + "\00" ;; empty vec(byte) + ) +- "unknown memory 1" ++ "unknown memory" + ) + ++(; not supported by wat2wasm + ;; Data segment with memory index 0 (no memory section) + (assert_invalid + (module binary +@@ -317,7 +318,7 @@ + "\00\41\00\0b" ;; active data segment 0 for memory 0 + "\00" ;; empty vec(byte) + ) +- "unknown memory 0" ++ "unknown memory" + ) + + ;; Data segment with memory index 1 (no memory section) +@@ -328,7 +329,7 @@ + "\02\01\41\00\0b" ;; active data segment 0 for memory 1 + "\00" ;; empty vec(byte) + ) +- "unknown memory 1" ++ "unknown memory" + ) + + ;; Data segment with memory index 1 and vec(byte) as above, +@@ -348,7 +349,7 @@ + "\20\21\22\23\24\25\26\27\28\29\2a\2b\2c\2d\2e\2f" + "\30\31\32\33\34\35\36\37\38\39\3a\3b\3c\3d" + ) +- "unknown memory 1" ++ "unknown memory" + ) + + ;; Data segment with memory index 1 and specially crafted vec(byte) after. +@@ -368,8 +369,9 @@ + "\20\21\22\23\24\25\26\27\28\29\2a\2b\2c\2d\2e\2f" + "\30\31\32\33\34\35\36\37\38\39\3a\3b\3c\3d" + ) +- "unknown memory 1" ++ "unknown memory" + ) ++;) + + + ;; Invalid offsets +diff --git a/test/core/elem.wast b/test/core/elem.wast +index 575ecef..6eecab9 100644 +--- a/test/core/elem.wast ++++ b/test/core/elem.wast +@@ -571,9 +571,11 @@ + (func $const-i32-d (type $out-i32) (i32.const 68)) + ) + ++(; + (assert_return (invoke $module1 "call-7") (i32.const 67)) + (assert_return (invoke $module1 "call-8") (i32.const 68)) + (assert_return (invoke $module1 "call-9") (i32.const 66)) ++;) + + (module $module3 + (type $out-i32 (func (result i32))) +@@ -584,6 +586,8 @@ + (func $const-i32-f (type $out-i32) (i32.const 70)) + ) + ++(; + (assert_return (invoke $module1 "call-7") (i32.const 67)) + (assert_return (invoke $module1 "call-8") (i32.const 69)) + (assert_return (invoke $module1 "call-9") (i32.const 70)) ++;) +diff --git a/test/core/global.wast b/test/core/global.wast +index 9fa5e22..8c4b949 100644 +--- a/test/core/global.wast ++++ b/test/core/global.wast +@@ -328,10 +328,12 @@ + "type mismatch" + ) + ++(; + (assert_invalid + (module (global (import "" "") externref) (global funcref (global.get 0))) + "type mismatch" + ) ++;) + + (assert_invalid + (module (global (import "test" "global-i32") i32) (global i32 (global.get 0) (global.get 0))) +diff --git a/test/core/imports.wast b/test/core/imports.wast +index 35e8c91..a7a459d 100644 +--- a/test/core/imports.wast ++++ b/test/core/imports.wast +@@ -577,6 +577,7 @@ + (assert_return (invoke "grow" (i32.const 1)) (i32.const -1)) + (assert_return (invoke "grow" (i32.const 0)) (i32.const 2)) + ++(; unsupported by multi-module currently + (module $Mgm + (memory (export "memory") 1) ;; initial size is 1 + (func (export "grow") (result i32) (memory.grow (i32.const 1))) +@@ -596,6 +597,7 @@ + (func (export "size") (result i32) (memory.size)) + ) + (assert_return (invoke $Mgim2 "size") (i32.const 3)) ++;) + + + ;; Syntax errors +diff --git a/test/core/linking.wast b/test/core/linking.wast +index 994e0f4..d0bfb5f 100644 +--- a/test/core/linking.wast ++++ b/test/core/linking.wast +@@ -64,6 +64,7 @@ + (export "Mg.set_mut" (func $set_mut)) + ) + ++(; + (assert_return (get $Mg "glob") (i32.const 42)) + (assert_return (get $Ng "Mg.glob") (i32.const 42)) + (assert_return (get $Ng "glob") (i32.const 43)) +@@ -81,6 +82,7 @@ + (assert_return (get $Ng "Mg.mut_glob") (i32.const 241)) + (assert_return (invoke $Mg "get_mut") (i32.const 241)) + (assert_return (invoke $Ng "Mg.get_mut") (i32.const 241)) ++;) + + + (assert_unlinkable +@@ -165,6 +167,7 @@ + ) + ) + ++(; + (assert_return (invoke $Mt "call" (i32.const 2)) (i32.const 4)) + (assert_return (invoke $Nt "Mt.call" (i32.const 2)) (i32.const 4)) + (assert_return (invoke $Nt "call" (i32.const 2)) (i32.const 5)) +@@ -187,6 +190,7 @@ + + (assert_return (invoke $Nt "call" (i32.const 3)) (i32.const -4)) + (assert_trap (invoke $Nt "call" (i32.const 4)) "indirect call type mismatch") ++;) + + (module $Ot + (type (func (result i32))) +@@ -201,6 +205,7 @@ + ) + ) + ++(; + (assert_return (invoke $Mt "call" (i32.const 3)) (i32.const 4)) + (assert_return (invoke $Nt "Mt.call" (i32.const 3)) (i32.const 4)) + (assert_return (invoke $Nt "call Mt.call" (i32.const 3)) (i32.const 4)) +@@ -225,6 +230,7 @@ + (assert_trap (invoke $Ot "call" (i32.const 0)) "uninitialized element") + + (assert_trap (invoke $Ot "call" (i32.const 20)) "undefined element") ++;) + + (module + (table (import "Mt" "tab") 0 funcref) +@@ -263,6 +269,7 @@ + + ;; Unlike in the v1 spec, active element segments stored before an + ;; out-of-bounds access persist after the instantiation failure. ++(; + (assert_trap + (module + (table (import "Mt" "tab") 10 funcref) +@@ -274,7 +281,9 @@ + ) + (assert_return (invoke $Mt "call" (i32.const 7)) (i32.const 0)) + (assert_trap (invoke $Mt "call" (i32.const 8)) "uninitialized element") ++;) + ++(; + (assert_trap + (module + (table (import "Mt" "tab") 10 funcref) +@@ -286,6 +295,7 @@ + "out of bounds memory access" + ) + (assert_return (invoke $Mt "call" (i32.const 7)) (i32.const 0)) ++;) + + + (module $Mtable_ex +@@ -299,6 +309,7 @@ + (table (import "Mtable_ex" "t-extern") 1 externref) + ) + ++(; + (assert_unlinkable + (module (table (import "Mtable_ex" "t-func") 1 externref)) + "incompatible import type" +@@ -307,6 +318,7 @@ + (module (table (import "Mtable_ex" "t-extern") 1 funcref)) + "incompatible import type" + ) ++;) + + + ;; Memories +@@ -346,10 +358,12 @@ + ) + ) + ++(; + (assert_return (invoke $Mm "load" (i32.const 12)) (i32.const 0xa7)) + (assert_return (invoke $Nm "Mm.load" (i32.const 12)) (i32.const 0xa7)) + (assert_return (invoke $Nm "load" (i32.const 12)) (i32.const 0xf2)) + (assert_return (invoke $Om "load" (i32.const 12)) (i32.const 0xa7)) ++;) + + (module + (memory (import "Mm" "mem") 0) +@@ -372,6 +386,7 @@ + ) + ) + ++(; + (assert_return (invoke $Pm "grow" (i32.const 0)) (i32.const 1)) + (assert_return (invoke $Pm "grow" (i32.const 2)) (i32.const 1)) + (assert_return (invoke $Pm "grow" (i32.const 0)) (i32.const 3)) +@@ -380,6 +395,7 @@ + (assert_return (invoke $Pm "grow" (i32.const 0)) (i32.const 5)) + (assert_return (invoke $Pm "grow" (i32.const 1)) (i32.const -1)) + (assert_return (invoke $Pm "grow" (i32.const 0)) (i32.const 5)) ++;) + + (assert_unlinkable + (module +@@ -403,8 +419,10 @@ + ) + "out of bounds memory access" + ) ++(; + (assert_return (invoke $Mm "load" (i32.const 0)) (i32.const 97)) + (assert_return (invoke $Mm "load" (i32.const 327670)) (i32.const 0)) ++;) + + (assert_trap + (module +@@ -416,7 +434,9 @@ + ) + "out of bounds table access" + ) ++(; + (assert_return (invoke $Mm "load" (i32.const 0)) (i32.const 97)) ++;) + + ;; Store is modified if the start function traps. + (module $Ms +@@ -432,6 +452,7 @@ + ) + (register "Ms" $Ms) + ++(; + (assert_trap + (module + (import "Ms" "memory" (memory 1)) +@@ -451,3 +472,4 @@ + + (assert_return (invoke $Ms "get memory[0]") (i32.const 104)) ;; 'h' + (assert_return (invoke $Ms "get table[0]") (i32.const 0xdead)) ++;) +diff --git a/test/core/ref_func.wast b/test/core/ref_func.wast +index adb5cb7..590f626 100644 +--- a/test/core/ref_func.wast ++++ b/test/core/ref_func.wast +@@ -4,7 +4,8 @@ + (register "M") + + (module +- (func $f (import "M" "f") (param i32) (result i32)) ++ (; aot mode does not support module linking ;) ++ (func $f (param $x i32) (result i32) (local.get $x)) + (func $g (param $x i32) (result i32) + (i32.add (local.get $x) (i32.const 1)) + ) +diff --git a/test/core/select.wast b/test/core/select.wast +index 046e6fe..b677023 100644 +--- a/test/core/select.wast ++++ b/test/core/select.wast +@@ -324,6 +324,7 @@ + (module (func $arity-0 (select (result) (nop) (nop) (i32.const 1)))) + "invalid result arity" + ) ++(; + (assert_invalid + (module (func $arity-2 (result i32 i32) + (select (result i32 i32) +@@ -334,6 +335,7 @@ + )) + "invalid result arity" + ) ++;) + + + (assert_invalid +diff --git a/test/core/table_copy.wast b/test/core/table_copy.wast +index 380e84e..f37e745 100644 +--- a/test/core/table_copy.wast ++++ b/test/core/table_copy.wast +@@ -14,11 +14,12 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ ;; aot mode does not support module linking ++ (func (result i32) (i32.const 0)) ;; index 0 ++ (func (result i32) (i32.const 1)) ++ (func (result i32) (i32.const 2)) ++ (func (result i32) (i32.const 3)) ++ (func (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (elem (table $t0) (i32.const 2) func 3 1 4 1) +@@ -106,11 +107,11 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ (func (export "ef0") (result i32) (i32.const 0)) ;; index 0 ++ (func (export "ef1") (result i32) (i32.const 1)) ++ (func (export "ef2") (result i32) (i32.const 2)) ++ (func (export "ef3") (result i32) (i32.const 3)) ++ (func (export "ef4") (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (elem (table $t0) (i32.const 2) func 3 1 4 1) +@@ -198,11 +199,11 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ (func (result i32) (i32.const 0)) ;; index 0 ++ (func (result i32) (i32.const 1)) ++ (func (result i32) (i32.const 2)) ++ (func (result i32) (i32.const 3)) ++ (func (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (elem (table $t0) (i32.const 2) func 3 1 4 1) +@@ -290,11 +291,11 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ (func (result i32) (i32.const 0)) ;; index 0 ++ (func (result i32) (i32.const 1)) ++ (func (result i32) (i32.const 2)) ++ (func (result i32) (i32.const 3)) ++ (func (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (elem (table $t0) (i32.const 2) func 3 1 4 1) +@@ -382,11 +383,11 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ (func (result i32) (i32.const 0)) ;; index 0 ++ (func (result i32) (i32.const 1)) ++ (func (result i32) (i32.const 2)) ++ (func (result i32) (i32.const 3)) ++ (func (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (elem (table $t0) (i32.const 2) func 3 1 4 1) +@@ -474,11 +475,11 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ (func (result i32) (i32.const 0)) ;; index 0 ++ (func (result i32) (i32.const 1)) ++ (func (result i32) (i32.const 2)) ++ (func (result i32) (i32.const 3)) ++ (func (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (elem (table $t0) (i32.const 2) func 3 1 4 1) +@@ -566,11 +567,11 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ (func (result i32) (i32.const 0)) ;; index 0 ++ (func (result i32) (i32.const 1)) ++ (func (result i32) (i32.const 2)) ++ (func (result i32) (i32.const 3)) ++ (func (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (elem (table $t0) (i32.const 2) func 3 1 4 1) +@@ -658,11 +659,11 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ (func (result i32) (i32.const 0)) ;; index 0 ++ (func (result i32) (i32.const 1)) ++ (func (result i32) (i32.const 2)) ++ (func (result i32) (i32.const 3)) ++ (func (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (elem (table $t0) (i32.const 2) func 3 1 4 1) +@@ -750,11 +751,11 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ (func (result i32) (i32.const 0)) ;; index 0 ++ (func (result i32) (i32.const 1)) ++ (func (result i32) (i32.const 2)) ++ (func (result i32) (i32.const 3)) ++ (func (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (elem (table $t0) (i32.const 2) func 3 1 4 1) +@@ -842,11 +843,11 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ (func (result i32) (i32.const 0)) ;; index 0 ++ (func (result i32) (i32.const 1)) ++ (func (result i32) (i32.const 2)) ++ (func (result i32) (i32.const 3)) ++ (func (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (elem (table $t1) (i32.const 2) func 3 1 4 1) +@@ -934,11 +935,11 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ (func (result i32) (i32.const 0)) ;; index 0 ++ (func (result i32) (i32.const 1)) ++ (func (result i32) (i32.const 2)) ++ (func (result i32) (i32.const 3)) ++ (func (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (elem (table $t1) (i32.const 2) func 3 1 4 1) +@@ -1026,11 +1027,11 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ (func (result i32) (i32.const 0)) ;; index 0 ++ (func (result i32) (i32.const 1)) ++ (func (result i32) (i32.const 2)) ++ (func (result i32) (i32.const 3)) ++ (func (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (elem (table $t1) (i32.const 2) func 3 1 4 1) +@@ -1118,11 +1119,11 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ (func (result i32) (i32.const 0)) ;; index 0 ++ (func (result i32) (i32.const 1)) ++ (func (result i32) (i32.const 2)) ++ (func (result i32) (i32.const 3)) ++ (func (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (elem (table $t1) (i32.const 2) func 3 1 4 1) +@@ -1210,11 +1211,11 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ (func (result i32) (i32.const 0)) ;; index 0 ++ (func (result i32) (i32.const 1)) ++ (func (result i32) (i32.const 2)) ++ (func (result i32) (i32.const 3)) ++ (func (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (elem (table $t1) (i32.const 2) func 3 1 4 1) +@@ -1302,11 +1303,11 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ (func (result i32) (i32.const 0)) ;; index 0 ++ (func (result i32) (i32.const 1)) ++ (func (result i32) (i32.const 2)) ++ (func (result i32) (i32.const 3)) ++ (func (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (elem (table $t1) (i32.const 2) func 3 1 4 1) +@@ -1394,11 +1395,11 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ (func (result i32) (i32.const 0)) ;; index 0 ++ (func (result i32) (i32.const 1)) ++ (func (result i32) (i32.const 2)) ++ (func (result i32) (i32.const 3)) ++ (func (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (elem (table $t1) (i32.const 2) func 3 1 4 1) +@@ -1486,11 +1487,11 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ (func (result i32) (i32.const 0)) ;; index 0 ++ (func (result i32) (i32.const 1)) ++ (func (result i32) (i32.const 2)) ++ (func (result i32) (i32.const 3)) ++ (func (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (elem (table $t1) (i32.const 2) func 3 1 4 1) +@@ -1578,11 +1579,11 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ (func (result i32) (i32.const 0)) ;; index 0 ++ (func (result i32) (i32.const 1)) ++ (func (result i32) (i32.const 2)) ++ (func (result i32) (i32.const 3)) ++ (func (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (elem (table $t1) (i32.const 2) func 3 1 4 1) +diff --git a/test/core/table_init.wast b/test/core/table_init.wast +index 0b2d26f..bdab6a0 100644 +--- a/test/core/table_init.wast ++++ b/test/core/table_init.wast +@@ -14,11 +14,12 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ ;; aot mode does not support module linking ++ (func (result i32) (i32.const 0)) ;; index 0 ++ (func (result i32) (i32.const 1)) ++ (func (result i32) (i32.const 2)) ++ (func (result i32) (i32.const 3)) ++ (func (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (elem (table $t0) (i32.const 2) func 3 1 4 1) +@@ -72,11 +73,12 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ ;; aot mode does not support module linking ++ (func (result i32) (i32.const 0)) ;; index 0 ++ (func (result i32) (i32.const 1)) ++ (func (result i32) (i32.const 2)) ++ (func (result i32) (i32.const 3)) ++ (func (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (elem (table $t0) (i32.const 2) func 3 1 4 1) +@@ -130,11 +132,12 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ ;; aot mode does not support module linking ++ (func (result i32) (i32.const 0)) ;; index 0 ++ (func (result i32) (i32.const 1)) ++ (func (result i32) (i32.const 2)) ++ (func (result i32) (i32.const 3)) ++ (func (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (elem (table $t0) (i32.const 2) func 3 1 4 1) +@@ -196,11 +199,12 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ ;; aot mode does not support module linking ++ (func (result i32) (i32.const 0)) ;; index 0 ++ (func (result i32) (i32.const 1)) ++ (func (result i32) (i32.const 2)) ++ (func (result i32) (i32.const 3)) ++ (func (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (elem (table $t1) (i32.const 2) func 3 1 4 1) +@@ -254,11 +258,12 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ ;; aot mode does not support module linking ++ (func (result i32) (i32.const 0)) ;; index 0 ++ (func (result i32) (i32.const 1)) ++ (func (result i32) (i32.const 2)) ++ (func (result i32) (i32.const 3)) ++ (func (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (elem (table $t1) (i32.const 2) func 3 1 4 1) +@@ -312,11 +317,12 @@ + + (module + (type (func (result i32))) ;; type #0 +- (import "a" "ef0" (func (result i32))) ;; index 0 +- (import "a" "ef1" (func (result i32))) +- (import "a" "ef2" (func (result i32))) +- (import "a" "ef3" (func (result i32))) +- (import "a" "ef4" (func (result i32))) ;; index 4 ++ ;; aot mode does not support module linking ++ (func (result i32) (i32.const 0)) ;; index 0 ++ (func (result i32) (i32.const 1)) ++ (func (result i32) (i32.const 2)) ++ (func (result i32) (i32.const 3)) ++ (func (result i32) (i32.const 4)) ;; index 4 + (table $t0 30 30 funcref) + (table $t1 30 30 funcref) + (elem (table $t1) (i32.const 2) func 3 1 4 1) +diff --git a/test/core/unreached-valid.wast b/test/core/unreached-valid.wast +index b7ebabf..4f2abfb 100644 +--- a/test/core/unreached-valid.wast ++++ b/test/core/unreached-valid.wast +@@ -46,6 +46,7 @@ + + ;; Validation after unreachable + ++(; + (module + (func (export "meet-bottom") + (block (result f64) +@@ -61,3 +62,4 @@ + ) + + (assert_trap (invoke "meet-bottom") "unreachable") ++;) diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/runtest.py b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/runtest.py new file mode 100755 index 00000000..a1e505bd --- /dev/null +++ b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/runtest.py @@ -0,0 +1,1343 @@ +#!/usr/bin/env python + +from __future__ import print_function + +import argparse +import array +import atexit +import fcntl +import math +import os +# Pseudo-TTY and terminal manipulation +import pty +import re +import shutil +import struct +import subprocess +import sys +import tempfile +import termios +import time +import traceback +from select import select +from subprocess import PIPE, STDOUT, Popen + +if sys.version_info[0] == 2: + IS_PY_3 = False +else: + IS_PY_3 = True + +test_aot = False +# "x86_64", "i386", "aarch64", "armv7", "thumbv7", "riscv32_ilp32", "riscv32_ilp32d", "riscv32_lp64", "riscv64_lp64d" +test_target = "x86_64" + +debug_file = None +log_file = None + +# to save the register module with self-define name +temp_file_repo = [] + +# to save the mapping of module files in /tmp by name +temp_module_table = {} + +def debug(data): + if debug_file: + debug_file.write(data) + debug_file.flush() + +def log(data, end='\n'): + if log_file: + log_file.write(data + end) + log_file.flush() + print(data, end=end) + sys.stdout.flush() + +# TODO: do we need to support '\n' too +import platform + +if platform.system().find("CYGWIN_NT") >= 0: + # TODO: this is weird, is this really right on Cygwin? + sep = "\n\r\n" +else: + sep = "\r\n" +rundir = None + +class Runner(): + def __init__(self, args, no_pty=False): + self.no_pty = no_pty + + # Cleanup child process on exit + atexit.register(self.cleanup) + + self.process = None + env = os.environ + env['TERM'] = 'dumb' + env['INPUTRC'] = '/dev/null' + env['PERL_RL'] = 'false' + if no_pty: + self.process = Popen(args, bufsize=0, + stdin=PIPE, stdout=PIPE, stderr=STDOUT, + preexec_fn=os.setsid, + env=env) + self.stdin = self.process.stdin + self.stdout = self.process.stdout + else: + # Use tty to setup an interactive environment + master, slave = pty.openpty() + + # Set terminal size large so that readline will not send + # ANSI/VT escape codes when the lines are long. + buf = array.array('h', [100, 200, 0, 0]) + fcntl.ioctl(master, termios.TIOCSWINSZ, buf, True) + + self.process = Popen(args, bufsize=0, + stdin=slave, stdout=slave, stderr=STDOUT, + preexec_fn=os.setsid, + env=env) + # Now close slave so that we will get an exception from + # read when the child exits early + # http://stackoverflow.com/questions/11165521 + os.close(slave) + self.stdin = os.fdopen(master, 'r+b', 0) + self.stdout = self.stdin + + self.buf = "" + + def read_to_prompt(self, prompts, timeout): + wait_until = time.time() + timeout + while time.time() < wait_until: + [outs,_,_] = select([self.stdout], [], [], 1) + if self.stdout in outs: + read_byte = self.stdout.read(1) + if not read_byte: + # EOF on macOS ends up here. + break + read_byte = read_byte.decode('utf-8') if IS_PY_3 else read_byte + + debug(read_byte) + if self.no_pty: + self.buf += read_byte.replace('\n', '\r\n') + else: + self.buf += read_byte + self.buf = self.buf.replace('\r\r', '\r') + + # filter the prompts + for prompt in prompts: + pattern = re.compile(prompt) + match = pattern.search(self.buf) + if match: + end = match.end() + buf = self.buf[0:end-len(prompt)] + self.buf = self.buf[end:] + return buf + return None + + def writeline(self, str): + str_to_write = str + '\n' + str_to_write = bytes( + str_to_write, 'utf-8') if IS_PY_3 else str_to_write + + self.stdin.write(str_to_write) + + def cleanup(self): + if self.process: + try: + self.writeline("__exit__") + time.sleep(.020) + self.process.kill() + except OSError: + pass + except IOError: + pass + self.process = None + self.stdin.close() + if self.stdin != self.stdout: + self.stdout.close() + self.stdin = None + self.stdout = None + if not IS_PY_3: + sys.exc_clear() + +def assert_prompt(runner, prompts, timeout, is_need_execute_result): + # Wait for the initial prompt + header = runner.read_to_prompt(prompts, timeout=timeout) + if not header and is_need_execute_result: + log(" ---------- will terminate cause the case needs result while there is none inside of buf. ----------") + sys.exit(1) + if not header == None: + if header: + log("Started with:\n%s" % header) + else: + log("Did not one of following prompt(s): %s" % repr(prompts)) + log(" Got : %s" % repr(r.buf)) + sys.exit(1) + + +### WebAssembly specific + +parser = argparse.ArgumentParser( + description="Run a test file against a WebAssembly interpreter") +parser.add_argument('--wast2wasm', type=str, + default=os.environ.get("WAST2WASM", "wast2wasm"), + help="Path to wast2wasm program") +parser.add_argument('--interpreter', type=str, + default=os.environ.get("IWASM_CMD", "iwasm"), + help="Path to WebAssembly interpreter") +parser.add_argument('--aot-compiler', type=str, + default=os.environ.get("WAMRC_CMD", "wamrc"), + help="Path to WebAssembly AoT compiler") + +parser.add_argument('--no_cleanup', action='store_true', + help="Keep temporary *.wasm files") + +parser.add_argument('--rundir', + help="change to the directory before running tests") +parser.add_argument('--start-timeout', default=30, type=int, + help="default timeout for initial prompt") +parser.add_argument('--test-timeout', default=20, type=int, + help="default timeout for each individual test action") +parser.add_argument('--no-pty', action='store_true', + help="Use direct pipes instead of pseudo-tty") +parser.add_argument('--log-file', type=str, + help="Write messages to the named file in addition the screen") +parser.add_argument('--log-dir', type=str, + help="The log directory to save the case file if test failed") +parser.add_argument('--debug-file', type=str, + help="Write all test interaction the named file") + +parser.add_argument('test_file', type=argparse.FileType('r'), + help="a WebAssembly *.wast test file") + +parser.add_argument('--aot', action='store_true', + help="Test with AOT") + +parser.add_argument('--target', type=str, + default="x86_64", + help="Set running target") + +parser.add_argument('--sgx', action='store_true', + help="Test SGX") + +parser.add_argument('--simd', default=False, action='store_true', + help="Enable SIMD") + +parser.add_argument('--xip', default=False, action='store_true', + help="Enable XIP") + +parser.add_argument('--multi-module', default=False, action='store_true', + help="Enable Multi-thread") + +parser.add_argument('--multi-thread', default=False, action='store_true', + help="Enable Multi-thread") + +parser.add_argument('--gc', default=False, action='store_true', + help='Test with GC') + +parser.add_argument('--qemu', default=False, action='store_true', + help="Enable QEMU") + +parser.add_argument('--qemu-firmware', default='', help="Firmware required by qemu") + +parser.add_argument('--verbose', default=False, action='store_true', + help='show more logs') + +# regex patterns of tests to skip +C_SKIP_TESTS = () +PY_SKIP_TESTS = ( + # names.wast + 'invoke \"~!', + # conversions.wast + '18446742974197923840.0', + '18446744073709549568.0', + '9223372036854775808', + 'reinterpret_f.*nan', + # endianness + '.const 0x1.fff' ) + +def read_forms(string): + forms = [] + form = "" + depth = 0 + line = 0 + pos = 0 + while pos < len(string): + # Keep track of line number + if string[pos] == '\n': line += 1 + + # Handle top-level elements + if depth == 0: + # Add top-level comments + if string[pos:pos+2] == ";;": + end = string.find("\n", pos) + if end == -1: end == len(string) + forms.append(string[pos:end]) + pos = end + continue + + # TODO: handle nested multi-line comments + if string[pos:pos+2] == "(;": + # Skip multi-line comment + end = string.find(";)", pos) + if end == -1: + raise Exception("mismatch multiline comment on line %d: '%s'" % ( + line, string[pos:pos+80])) + pos = end+2 + continue + + # Ignore whitespace between top-level forms + if string[pos] in (' ', '\n', '\t'): + pos += 1 + continue + + # Read a top-level form + if string[pos] == '(': depth += 1 + if string[pos] == ')': depth -= 1 + if depth == 0 and not form: + raise Exception("garbage on line %d: '%s'" % ( + line, string[pos:pos+80])) + form += string[pos] + if depth == 0 and form: + forms.append(form) + form = "" + pos += 1 + return forms + +def get_module_exp_from_assert(string): + depth = 0 + pos = 0 + module = "" + exception = "" + start_record = False + result = [] + while pos < len(string): + # record from the " (module " + if string[pos:pos+7] == "(module": + start_record = True + if start_record: + if string[pos] == '(' : depth += 1 + if string[pos] == ')' : depth -= 1 + module += string[pos] + # if we get all (module ) . + if depth == 0 and module: + result.append(module) + start_record = False + # get expected exception + if string[pos] == '"': + end = string.find("\"", pos+1) + if end != -1: + end_rel = string.find("\"",end+1) + if end_rel == -1: + result.append(string[pos+1:end]) + pos += 1 + return result + +def string_to_unsigned(number_in_string, lane_type): + if not lane_type in ['i8x16', 'i16x8', 'i32x4', 'i64x2']: + raise Exception("invalid value {} and type {} and lane_type {}".format(number_in_string, type, lane_type)) + + number = int(number_in_string, 16) if '0x' in number_in_string else int(number_in_string) + + if "i8x16" == lane_type: + if number < 0: + packed = struct.pack('b', number) + number = struct.unpack('B', packed)[0] + elif "i16x8" == lane_type: + if number < 0: + packed = struct.pack('h', number) + number = struct.unpack('H', packed)[0] + elif "i32x4" == lane_type: + if number < 0: + packed = struct.pack('i', number) + number = struct.unpack('I', packed)[0] + else: # "i64x2" == lane_type: + if number < 0: + packed = struct.pack('q', number) + number = struct.unpack('Q', packed)[0] + + return number + +def cast_v128_to_i64x2(numbers, type, lane_type): + numbers = [n.replace("_", "") for n in numbers] + + if "i8x16" == lane_type: + assert(16 == len(numbers)), "{} should like {}".format(numbers, lane_type) + # str -> int + numbers = [string_to_unsigned(n, lane_type) for n in numbers] + # i8 -> i64 + packed = struct.pack(16 * "B", *numbers) + elif "i16x8" == lane_type: + assert(8 == len(numbers)), "{} should like {}".format(numbers, lane_type) + # str -> int + numbers = [string_to_unsigned(n, lane_type) for n in numbers] + # i16 -> i64 + packed = struct.pack(8 * "H", *numbers) + elif "i32x4" == lane_type: + assert(4 == len(numbers)), "{} should like {}".format(numbers, lane_type) + # str -> int + numbers = [string_to_unsigned(n, lane_type) for n in numbers] + # i32 -> i64 + packed = struct.pack(4 * "I", *numbers) + elif "i64x2" == lane_type: + assert(2 == len(numbers)), "{} should like {}".format(numbers, lane_type) + # str -> int + numbers = [string_to_unsigned(n, lane_type) for n in numbers] + # i64 -> i64 + packed = struct.pack(2 * "Q", *numbers) + elif "f32x4" == lane_type: + assert(4 == len(numbers)), "{} should like {}".format(numbers, lane_type) + # str -> int + numbers = [parse_simple_const_w_type(n, "f32")[0] for n in numbers] + # f32 -> i64 + packed = struct.pack(4 * "f", *numbers) + elif "f64x2" == lane_type: + assert(2 == len(numbers)), "{} should like {}".format(numbers, lane_type) + # str -> int + numbers = [parse_simple_const_w_type(n, "f64")[0] for n in numbers] + # f64 -> i64 + packed = struct.pack(2 * "d", *numbers) + else: + raise Exception("invalid value {} and type {} and lane_type {}".format(numbers, type, lane_type)) + + assert(packed) + unpacked = struct.unpack("Q Q", packed) + return unpacked, "[{} {}]:{}:v128".format(unpacked[0], unpacked[1], lane_type) + + +def parse_simple_const_w_type(number, type): + number = number.replace('_', '') + if type in ["i32", "i64"]: + number = int(number, 16) if '0x' in number else int(number) + return number, "0x{:x}:{}".format(number, type) \ + if number >= 0 \ + else "-0x{:x}:{}".format(0 - number, type) + elif type in ["f32", "f64"]: + if "nan:" in number: + # TODO: how to handle this correctly + if "nan:canonical" in number: + return float.fromhex("0x200000"), "nan:{}".format(type) + elif "nan:arithmetic" in number: + return float.fromhex("-0x200000"), "nan:{}".format(type) + else: + return float('nan'), "nan:{}".format(type) + else: + number = float.fromhex(number) if '0x' in number else float(number) + return number, "{:.7g}:{}".format(number, type) + elif type == "ref.null": + if number == "func": + return "func", "func:ref.null" + elif number == "extern": + return "extern", "extern:ref.null" + elif number == "any": + return "any", "any:ref.null" + else: + raise Exception("invalid value {} and type {}".format(number, type)) + elif type == "ref.extern": + number = int(number, 16) if '0x' in number else int(number) + return number, "0x{:x}:ref.extern".format(number) + elif type == "ref.host": + number = int(number, 16) if '0x' in number else int(number) + return number, "0x{:x}:ref.host".format(number) + else: + raise Exception("invalid value {} and type {}".format(number, type)) + +def parse_assertion_value(val): + """ + Parse something like: + "ref.null extern" in (assert_return (invoke "get-externref" (i32.const 0)) (ref.null extern)) + "ref.extern 1" in (assert_return (invoke "get-externref" (i32.const 1)) (ref.extern 1)) + "i32.const 0" in (assert_return (invoke "is_null-funcref" (i32.const 1)) (i32.const 0)) + + in summary: + type.const (sub-type) (val1 val2 val3 val4) ... + type.const val + ref.extern val + ref.null ref_type + ref.array + ref.struct + ref.func + ref.i31 + """ + if not val: + return None, "" + + splitted = re.split('\s+', val) + splitted = [s for s in splitted if s] + type = splitted[0].split(".")[0] + lane_type = splitted[1] if len(splitted) > 2 else "" + numbers = splitted[2:] if len(splitted) > 2 else splitted[1:] + + if type in ["i32", "i64", "f32", "f64"]: + return parse_simple_const_w_type(numbers[0], type) + elif type == "ref": + if splitted[0] in ["ref.array", "ref.struct", "ref.func", "ref.i31"]: + return splitted[0] + # need to distinguish between "ref.null" and "ref.extern" + return parse_simple_const_w_type(numbers[0], splitted[0]) + else: + return cast_v128_to_i64x2(numbers, type, lane_type) + +def int2uint32(i): + return i & 0xffffffff + +def int2int32(i): + val = i & 0xffffffff + if val & 0x80000000: + return val - 0x100000000 + else: + return val + +def int2uint64(i): + return i & 0xffffffffffffffff + +def int2int64(i): + val = i & 0xffffffffffffffff + if val & 0x8000000000000000: + return val - 0x10000000000000000 + else: + return val + + +def num_repr(i): + if isinstance(i, int) or isinstance(i, long): + return re.sub("L$", "", hex(i)) + else: + return "%.16g" % i + +def hexpad16(i): + return "0x%04x" % i + +def hexpad24(i): + return "0x%06x" % i + +def hexpad32(i): + return "0x%08x" % i + +def hexpad64(i): + return "0x%016x" % i + +def invoke(r, args, cmd): + r.writeline(cmd) + + return r.read_to_prompt(['\r\nwebassembly> ', '\nwebassembly> '], + timeout=args.test_timeout) + +def vector_value_comparison(out, expected): + """ + out likes "<number number>:v128" + expected likes "[number number]:v128" + """ + # print("vector value comparision {} vs {}".format(out, expected)) + + out_val, out_type = out.split(':') + # <number nubmer> => number number + out_val = out_val[1:-1] + + expected_val, lane_type, expected_type = expected.split(':') + # [number nubmer] => number number + expected_val = expected_val[1:-1] + + assert("v128" == out_type), "out_type should be v128" + assert("v128" == expected_type), "expected_type should be v128" + + if out_type != expected_type: + return False + + if out_val == expected_val: + return True + + out_val = out_val.split(" ") + expected_val = expected_val.split(" ") + + # since i64x2 + out_packed = struct.pack("QQ", int(out_val[0], 16), int(out_val[1], 16)) + expected_packed = struct.pack("QQ", + int(expected_val[0]) if not "0x" in expected_val[0] else int(expected_val[0], 16), + int(expected_val[1]) if not "0x" in expected_val[1] else int(expected_val[1], 16)) + + if lane_type in ["i8x16", "i16x8", "i32x4", "i64x2"]: + return out_packed == expected_packed; + else: + assert(lane_type in ["f32x4", "f64x2"]), "unexpected lane_type" + + if "f32x4" == lane_type: + out_unpacked = struct.unpack("ffff", out_packed) + expected_unpacked = struct.unpack("ffff", expected_packed) + else: + out_unpacked = struct.unpack("dd", out_packed) + expected_unpacked = struct.unpack("dd", expected_packed) + + out_is_nan = [math.isnan(o) for o in out_unpacked] + expected_is_nan = [math.isnan(e) for e in expected_unpacked] + if out_is_nan and expected_is_nan: + return True; + + # print("compare {} and {}".format(out_unpacked, expected_unpacked)) + result = [o == e for o, e in zip(out_unpacked, expected_unpacked)] + + if not all(result): + result = [ + "{:.7g}".format(o) == "{:.7g}".format(e) + for o, e in zip(out_unpacked, expected_packed) + ] + + return all(result) + + +def simple_value_comparison(out, expected): + """ + compare out of simple types which may like val:i32, val:f64 and so on + """ + if expected == "2.360523e+13:f32" and out == "2.360522e+13:f32": + # one case in float_literals.wast, due to float precision of python + return True + + if expected == "1.797693e+308:f64" and out == "inf:f64": + # one case in float_misc.wast: + # (assert_return (invoke "f64.add" (f64.const 0x1.fffffffffffffp+1023) + # (f64.const 0x1.fffffffffffffp+969)) + # (f64.const 0x1.fffffffffffffp+1023)) + # the add result in x86_32 is inf + return True + + out_val, out_type = out.split(':') + expected_val, expected_type = expected.split(':') + + if not out_type == expected_type: + return False + + out_val, _ = parse_simple_const_w_type(out_val, out_type) + expected_val, _ = parse_simple_const_w_type(expected_val, expected_type) + + if out_val == expected_val \ + or (math.isnan(out_val) and math.isnan(expected_val)): + return True + + if "i32" == expected_type: + out_val_binary = struct.pack('I', out_val) if out_val > 0 \ + else struct.pack('i', out_val) + expected_val_binary = struct.pack('I', expected_val) \ + if expected_val > 0 \ + else struct.pack('i', expected_val) + elif "i64" == expected_type: + out_val_binary = struct.pack('Q', out_val) if out_val > 0 \ + else struct.pack('q', out_val) + expected_val_binary = struct.pack('Q', expected_val) \ + if expected_val > 0 \ + else struct.pack('q', expected_val) + elif "f32" == expected_type: + out_val_binary = struct.pack('f', out_val) + expected_val_binary = struct.pack('f', expected_val) + elif "f64" == expected_type: + out_val_binary = struct.pack('d', out_val) + expected_val_binary = struct.pack('d', expected_val) + elif "ref.extern" == expected_type: + out_val_binary = out_val + expected_val_binary = expected_val + elif "ref.host" == expected_type: + out_val_binary = out_val + expected_val_binary = expected_val + else: + assert(0), "unknown 'expected_type' {}".format(expected_type) + + if out_val_binary == expected_val_binary: + return True + + if expected_type in ["f32", "f64"]: + # compare with a lower precision + out_str = "{:.7g}".format(out_val) + expected_str = "{:.7g}".format(expected_val) + if out_str == expected_str: + return True + + return False + +def value_comparison(out, expected): + if out == expected: + return True + + if not expected: + return False + + if not out in ["ref.array", "ref.struct", "ref.func", "ref.any", "ref.i31"]: + assert(':' in out), "out should be in a form likes numbers:type, but {}".format(out) + if not expected in ["ref.array", "ref.struct", "ref.func", "ref.any", "ref.i31"]: + assert(':' in expected), "expected should be in a form likes numbers:type, but {}".format(expected) + + if 'v128' in out: + return vector_value_comparison(out, expected) + else: + return simple_value_comparison(out, expected) + +def is_result_match_expected(out, expected): + # compare value instead of comparing strings of values + return value_comparison(out, expected) + +def test_assert(r, opts, mode, cmd, expected): + log("Testing(%s) %s = %s" % (mode, cmd, expected)) + out = invoke(r, opts, cmd) + if '\n' in out or ' ' in out: + outs = [''] + out.split('\n')[1:] + out = outs[-1] + + if mode=='trap': + o = re.sub('^Exception: ', '', out) + e = re.sub('^Exception: ', '', expected) + if o.find(e) >= 0 or e.find(o) >= 0: + return True + + if mode=='exhaustion': + o = re.sub('^Exception: ', '', out) + expected = 'Exception: stack overflow' + e = re.sub('^Exception: ', '', expected) + if o.find(e) >= 0 or e.find(o) >= 0: + return True + + ## 0x9:i32,-0x1:i32 -> ['0x9:i32', '-0x1:i32'] + expected_list = re.split(',', expected) + out_list = re.split(',', out) + if len(expected_list) != len(out_list): + raise Exception("Failed:\n Results count incorrect:\n expected: '%s'\n got: '%s'" % (expected, out)) + for i in range(len(expected_list)): + if not is_result_match_expected(out_list[i], expected_list[i]): + raise Exception("Failed:\n Result %d incorrect:\n expected: '%s'\n got: '%s'" % (i, expected_list[i], out_list[i])) + + return True + +def test_assert_return(r, opts, form): + """ + m. to search a pattern like (assert_return (invoke function_name ... ) ...) + n. to search a pattern like (assert_return (invoke $module_name function_name ... ) ...) + """ + # params, return + m = re.search('^\(assert_return\s+\(invoke\s+"((?:[^"]|\\\")*)"\s+(\(.*\))\s*\)\s*(\(.*\))\s*\)\s*$', form, re.S) + # judge if assert_return cmd includes the module name + n = re.search('^\(assert_return\s+\(invoke\s+\$((?:[^\s])*)\s+"((?:[^"]|\\\")*)"\s+(\(.*\))\s*\)\s*(\(.*\))\s*\)\s*$', form, re.S) + + # print("assert_return with {}".format(form)) + + if not m: + # no params, return + m = re.search('^\(assert_return\s+\(invoke\s+"((?:[^"]|\\\")*)"\s*\)\s+()(\(.*\))\s*\)\s*$', form, re.S) + if not m: + # params, no return + m = re.search('^\(assert_return\s+\(invoke\s+"([^"]*)"\s+(\(.*\))()\s*\)\s*\)\s*$', form, re.S) + if not m: + # no params, no return + m = re.search('^\(assert_return\s+\(invoke\s+"([^"]*)"\s*()()\)\s*\)\s*$', form, re.S) + if not m: + # params, return + if not n: + # no params, return + n = re.search('^\(assert_return\s+\(invoke\s+\$((?:[^\s])*)\s+"((?:[^"]|\\\")*)"\s*\)\s+()(\(.*\))\s*\)\s*$', form, re.S) + if not n: + # params, no return + n = re.search('^\(assert_return\s+\(invoke\s+\$((?:[^\s])*)\s+"([^"]*)"\s+(\(.*\))()\s*\)\s*\)\s*$', form, re.S) + if not n: + # no params, no return + n = re.search('^\(assert_return\s+\(invoke\s+\$((?:[^\s])*)\s+"([^"]*)"*()()\)\s*\)\s*$', form, re.S) + if not m and not n: + if re.search('^\(assert_return\s+\(get.*\).*\)$', form, re.S): + log("ignoring assert_return get"); + return + else: + raise Exception("unparsed assert_return: '%s'" % form) + if m and not n: + func = m.group(1) + if ' ' in func: + func = func.replace(' ', '\\') + + if m.group(2) == '': + args = [] + else: + #args = [re.split(' +', v)[1].replace('_', "") for v in re.split("\)\s*\(", m.group(2)[1:-1])] + # split arguments with ')spaces(', remove leading and tailing ) and ( + args_type_and_value = re.split(r'\)\s+\(', m.group(2)[1:-1]) + args_type_and_value = [s.replace('_', '') for s in args_type_and_value] + # args are in two forms: + # f32.const -0x1.000001fffffffffffp-50 + # v128.const i32x4 0 0 0 0 + args = [] + for arg in args_type_and_value: + # remove leading and tailing spaces, it might confuse following assertions + arg = arg.strip() + splitted = re.split('\s+', arg) + splitted = [s for s in splitted if s] + + if splitted[0] in ["i32.const", "i64.const"]: + assert(2 == len(splitted)), "{} should have two parts".format(splitted) + # in wast 01234 means 1234 + # in c 0123 means 83 in oct + number, _ = parse_simple_const_w_type(splitted[1], splitted[0][:3]) + args.append(str(number)) + elif splitted[0] in ["f32.const", "f64.const"]: + # let strtof or strtod handle original arguments + assert(2 == len(splitted)), "{} should have two parts".format(splitted) + args.append(splitted[1]) + elif "v128.const" == splitted[0]: + assert(len(splitted) > 2), "{} should have more than two parts".format(splitted) + numbers, _ = cast_v128_to_i64x2(splitted[2:], 'v128', splitted[1]) + + assert(len(numbers) == 2), "has to reform arguments into i64x2" + args.append("{}\{}".format(numbers[0], numbers[1])) + elif "ref.null" == splitted[0]: + args.append("null") + elif "ref.extern" == splitted[0]: + number, _ = parse_simple_const_w_type(splitted[1], splitted[0]) + args.append(str(number)) + elif "ref.host" == splitted[0]: + number, _ = parse_simple_const_w_type(splitted[1], splitted[0]) + args.append(str(number)) + else: + assert(0), "an unkonwn parameter type" + + if m.group(3) == '': + returns= [] + else: + returns = re.split("\)\s*\(", m.group(3)[1:-1]) + # processed numbers in strings + if len(returns) == 1 and returns[0] in ["ref.array", "ref.struct", "ref.i31", + "ref.eq", "ref.any", "ref.extern", + "ref.func", "ref.null"]: + expected = [returns[0]] + elif len(returns) == 1 and returns[0] in ["func:ref.null", "any:ref.null", + "extern:ref.null"]: + expected = [returns[0]] + else: + expected = [parse_assertion_value(v)[1] for v in returns] + expected = ",".join(expected) + + test_assert(r, opts, "return", "%s %s" % (func, " ".join(args)), expected) + elif not m and n: + module = temp_module_table[n.group(1)].split(".wasm")[0] + # assume the cmd is (assert_return(invoke $ABC "func")). + # run the ABC.wasm firstly + if test_aot: + r = compile_wasm_to_aot(module+".wasm", module+".aot", True, opts, r) + try: + assert_prompt(r, ['Compile success'], opts.start_timeout, False) + except: + _, exc, _ = sys.exc_info() + log("Run wamrc failed:\n got: '%s'" % r.buf) + sys.exit(1) + r = run_wasm_with_repl(module+".wasm", module+".aot" if test_aot else module, opts, r) + # Wait for the initial prompt + try: + assert_prompt(r, ['webassembly> '], opts.start_timeout, False) + except: + _, exc, _ = sys.exc_info() + raise Exception("Failed:\n expected: '%s'\n got: '%s'" % \ + (repr(exc), r.buf)) + func = n.group(2) + if ' ' in func: + func = func.replace(' ', '\\') + + if n.group(3) == '': + args=[] + else: + # convert (ref.null extern/func) into (ref.null null) + n1 = n.group(3).replace("(ref.null extern)", "(ref.null null)") + n1 = n1.replace("ref.null func)", "(ref.null null)") + args = [re.split(' +', v)[1] for v in re.split("\)\s*\(", n1[1:-1])] + + _, expected = parse_assertion_value(n.group(4)[1:-1]) + test_assert(r, opts, "return", "%s %s" % (func, " ".join(args)), expected) + +def test_assert_trap(r, opts, form): + # params + m = re.search('^\(assert_trap\s+\(invoke\s+"([^"]*)"\s+(\(.*\))\s*\)\s*"([^"]+)"\s*\)\s*$', form) + # judge if assert_return cmd includes the module name + n = re.search('^\(assert_trap\s+\(invoke\s+\$((?:[^\s])*)\s+"([^"]*)"\s+(\(.*\))\s*\)\s*"([^"]+)"\s*\)\s*$', form, re.S) + if not m: + # no params + m = re.search('^\(assert_trap\s+\(invoke\s+"([^"]*)"\s*()\)\s*"([^"]+)"\s*\)\s*$', form) + if not m: + if not n: + # no params + n = re.search('^\(assert_trap\s+\(invoke\s+\$((?:[^\s])*)\s+"([^"]*)"\s*()\)\s*"([^"]+)"\s*\)\s*$', form, re.S) + if not m and not n: + raise Exception("unparsed assert_trap: '%s'" % form) + + if m and not n: + func = m.group(1) + if m.group(2) == '': + args = [] + else: + # convert (ref.null extern/func) into (ref.null null) + m1 = m.group(2).replace("(ref.null extern)", "(ref.null null)") + m1 = m1.replace("ref.null func)", "(ref.null null)") + args = [re.split(' +', v)[1] for v in re.split("\)\s*\(", m1[1:-1])] + + expected = "Exception: %s" % m.group(3) + test_assert(r, opts, "trap", "%s %s" % (func, " ".join(args)), expected) + + elif not m and n: + module = n.group(1) + module = tempfile.gettempdir() + "/" + module + + # will trigger the module named in assert_return(invoke $ABC). + # run the ABC.wasm firstly + if test_aot: + r = compile_wasm_to_aot(module+".wasm", module+".aot", True, opts, r) + try: + assert_prompt(r, ['Compile success'], opts.start_timeout, False) + except: + _, exc, _ = sys.exc_info() + log("Run wamrc failed:\n got: '%s'" % r.buf) + sys.exit(1) + r = run_wasm_with_repl(module+".wasm", module+".aot" if test_aot else module, opts, r) + # Wait for the initial prompt + try: + assert_prompt(r, ['webassembly> '], opts.start_timeout, False) + except: + _, exc, _ = sys.exc_info() + raise Exception("Failed:\n expected: '%s'\n got: '%s'" % \ + (repr(exc), r.buf)) + + func = n.group(2) + if n.group(3) == '': + args = [] + else: + args = [re.split(' +', v)[1] for v in re.split("\)\s*\(", n.group(3)[1:-1])] + expected = "Exception: %s" % n.group(4) + test_assert(r, opts, "trap", "%s %s" % (func, " ".join(args)), expected) + +def test_assert_exhaustion(r,opts,form): + # params + m = re.search('^\(assert_exhaustion\s+\(invoke\s+"([^"]*)"\s+(\(.*\))\s*\)\s*"([^"]+)"\s*\)\s*$', form) + if not m: + # no params + m = re.search('^\(assert_exhaustion\s+\(invoke\s+"([^"]*)"\s*()\)\s*"([^"]+)"\s*\)\s*$', form) + if not m: + raise Exception("unparsed assert_exhaustion: '%s'" % form) + func = m.group(1) + if m.group(2) == '': + args = [] + else: + args = [re.split(' +', v)[1] for v in re.split("\)\s*\(", m.group(2)[1:-1])] + expected = "Exception: %s\n" % m.group(3) + test_assert(r, opts, "exhaustion", "%s %s" % (func, " ".join(args)), expected) + +def do_invoke(r, opts, form): + # params + m = re.search('^\(invoke\s+"([^"]+)"\s+(\(.*\))\s*\)\s*$', form) + if not m: + # no params + m = re.search('^\(invoke\s+"([^"]+)"\s*()\)\s*$', form) + if not m: + raise Exception("unparsed invoke: '%s'" % form) + func = m.group(1) + + if ' ' in func: + func = func.replace(' ', '\\') + + if m.group(2) == '': + args = [] + else: + args = [re.split(' +', v)[1] for v in re.split("\)\s*\(", m.group(2)[1:-1])] + + log("Invoking %s(%s)" % ( + func, ", ".join([str(a) for a in args]))) + + invoke(r, opts, "%s %s" % (func, " ".join(args))) + +def skip_test(form, skip_list): + for s in skip_list: + if re.search(s, form): + return True + return False + +def compile_wast_to_wasm(form, wast_tempfile, wasm_tempfile, opts): + log("Writing WAST module to '%s'" % wast_tempfile) + open(wast_tempfile, 'w').write(form) + log("Compiling WASM to '%s'" % wasm_tempfile) + + # default arguments + if opts.gc: + cmd = [opts.wast2wasm, "-u", "-d", wast_tempfile, "-o", wasm_tempfile] + else: + cmd = [opts.wast2wasm, "--enable-thread", "--no-check", + wast_tempfile, "-o", wasm_tempfile ] + + # remove reference-type and bulk-memory enabling options since a WABT + # commit 30c1e983d30b33a8004b39fd60cbd64477a7956c + # Enable reference types by default (#1729) + + log("Running: %s" % " ".join(cmd)) + try: + subprocess.check_call(cmd) + except subprocess.CalledProcessError as e: + print(str(e)) + return False + + return True + +def compile_wasm_to_aot(wasm_tempfile, aot_tempfile, runner, opts, r, output = 'default'): + log("Compiling AOT to '%s'" % aot_tempfile) + cmd = [opts.aot_compiler] + + if test_target == "x86_64": + cmd.append("--target=x86_64") + cmd.append("--cpu=skylake") + elif test_target == "i386": + cmd.append("--target=i386") + elif test_target == "aarch64": + cmd += ["--target=aarch64", "--cpu=cortex-a57"] + elif test_target == "armv7": + cmd += ["--target=armv7", "--target-abi=gnueabihf"] + elif test_target == "thumbv7": + cmd += ["--target=thumbv7", "--target-abi=gnueabihf", "--cpu=cortex-a9", "--cpu-features=-neon"] + elif test_target == "riscv32_ilp32": + cmd += ["--target=riscv32", "--target-abi=ilp32", "--cpu=generic-rv32", "--cpu-features=+m,+a,+c"] + elif test_target == "riscv32_ilp32d": + cmd += ["--target=riscv32", "--target-abi=ilp32d", "--cpu=generic-rv32", "--cpu-features=+m,+a,+c"] + elif test_target == "riscv64_lp64": + cmd += ["--target=riscv64", "--target-abi=lp64", "--cpu=generic-rv64", "--cpu-features=+m,+a,+c"] + elif test_target == "riscv64_lp64d": + cmd += ["--target=riscv64", "--target-abi=lp64d", "--cpu=generic-rv32", "--cpu-features=+m,+a,+c"] + else: + pass + + if opts.sgx: + cmd.append("-sgx") + + if not opts.simd: + cmd.append("--disable-simd") + + if opts.xip: + cmd.append("--enable-indirect-mode") + cmd.append("--disable-llvm-intrinsics") + + if opts.multi_thread: + cmd.append("--enable-multi-thread") + + if output == 'object': + cmd.append("--format=object") + elif output == 'ir': + cmd.append("--format=llvmir-opt") + + # disable llvm link time optimization as it might convert + # code of tail call into code of dead loop, and stack overflow + # exception isn't thrown in several cases + cmd.append("--disable-llvm-lto") + + cmd += ["-o", aot_tempfile, wasm_tempfile] + + log("Running: %s" % " ".join(cmd)) + if not runner: + subprocess.check_call(cmd) + else: + if (r != None): + r.cleanup() + r = Runner(cmd, no_pty=opts.no_pty) + return r + +def run_wasm_with_repl(wasm_tempfile, aot_tempfile, opts, r): + tmpfile = aot_tempfile if test_aot else wasm_tempfile + log("Starting interpreter for module '%s'" % tmpfile) + + cmd_iwasm = [opts.interpreter, "--heap-size=0", "-v=5" if opts.verbose else "-v=0", "--repl", tmpfile] + + if opts.multi_module: + cmd_iwasm.insert(1, "--module-path=" + (tempfile.gettempdir() if not opts.qemu else "/tmp" )) + + if opts.qemu: + if opts.qemu_firmware == '': + raise Exception("QEMU firmware missing") + + if opts.target == "thumbv7": + cmd = ["qemu-system-arm", "-semihosting", "-M", "sabrelite", "-m", "1024", "-smp", "4", "-nographic", "-kernel", opts.qemu_firmware] + elif opts.target == "riscv32_ilp32": + cmd = ["qemu-system-riscv32", "-semihosting", "-M", "virt,aclint=on", "-cpu", "rv32", "-smp", "8", "-nographic", "-bios", "none", "-kernel", opts.qemu_firmware] + elif opts.target == "riscv64_lp64": + cmd = ["qemu-system-riscv64", "-semihosting", "-M", "virt,aclint=on", "-cpu", "rv64", "-smp", "8", "-nographic", "-bios", "none", "-kernel", opts.qemu_firmware] + + else: + cmd = cmd_iwasm + + log("Running: %s" % " ".join(cmd)) + if (r != None): + r.cleanup() + r = Runner(cmd, no_pty=opts.no_pty) + + if opts.qemu: + r.read_to_prompt(['nsh> '], 10) + r.writeline("mount -t hostfs -o fs={} /tmp".format(tempfile.gettempdir())) + r.read_to_prompt(['nsh> '], 10) + r.writeline(" ".join(cmd_iwasm)) + + return r + +def create_tmpfiles(wast_name): + tempfiles = [] + + (t1fd, wast_tempfile) = tempfile.mkstemp(suffix=".wast") + (t2fd, wasm_tempfile) = tempfile.mkstemp(suffix=".wasm") + tempfiles.append(wast_tempfile) + tempfiles.append(wasm_tempfile) + if test_aot: + (t3fd, aot_tempfile) = tempfile.mkstemp(suffix=".aot") + tempfiles.append(aot_tempfile) + + # add these temp file to temporal repo, will be deleted when finishing the test + temp_file_repo.extend(tempfiles) + return tempfiles + +def test_assert_with_exception(form, wast_tempfile, wasm_tempfile, aot_tempfile, opts, r, loadable = True): + details_inside_ast = get_module_exp_from_assert(form) + log("module is ....'%s'"%details_inside_ast[0]) + log("exception is ....'%s'"%details_inside_ast[1]) + # parse the module + module = details_inside_ast[0] + expected = details_inside_ast[1] + + if not compile_wast_to_wasm(module, wast_tempfile, wasm_tempfile, opts): + raise Exception("compile wast to wasm failed") + + if test_aot: + r = compile_wasm_to_aot(wasm_tempfile, aot_tempfile, True, opts, r) + try: + assert_prompt(r, ['Compile success'], opts.start_timeout, True) + except: + _, exc, _ = sys.exc_info() + if (r.buf.find(expected) >= 0): + log("Out exception includes expected one, pass:") + log(" Expected: %s" % expected) + log(" Got: %s" % r.buf) + return + else: + log("Run wamrc failed:\n expected: '%s'\n got: '%s'" % \ + (expected, r.buf)) + sys.exit(1) + + r = run_wasm_with_repl(wasm_tempfile, aot_tempfile if test_aot else None, opts, r) + + # Some module couldn't load so will raise an error directly, so shell prompt won't show here + + if loadable: + # Wait for the initial prompt + try: + assert_prompt(r, ['webassembly> '], opts.start_timeout, True) + except: + _, exc, _ = sys.exc_info() + if (r.buf.find(expected) >= 0): + log("Out exception includes expected one, pass:") + log(" Expected: %s" %expected) + log(" Got: %s" % r.buf) + else: + raise Exception("Failed:\n expected: '%s'\n got: '%s'" % \ + (expected, r.buf)) + +if __name__ == "__main__": + opts = parser.parse_args(sys.argv[1:]) + print('Input param :',opts) + + if opts.aot: test_aot = True + # default x86_64 + test_target = opts.target + + if opts.rundir: os.chdir(opts.rundir) + + if opts.log_file: log_file = open(opts.log_file, "a") + if opts.debug_file: debug_file = open(opts.debug_file, "a") + + if opts.interpreter.endswith(".py"): + SKIP_TESTS = PY_SKIP_TESTS + else: + SKIP_TESTS = C_SKIP_TESTS + + (t1fd, wast_tempfile) = tempfile.mkstemp(suffix=".wast") + (t2fd, wasm_tempfile) = tempfile.mkstemp(suffix=".wasm") + if test_aot: + (t3fd, aot_tempfile) = tempfile.mkstemp(suffix=".aot") + + ret_code = 0 + try: + log("################################################") + log("### Testing %s" % opts.test_file.name) + log("################################################") + forms = read_forms(opts.test_file.read()) + r = None + + for form in forms: + # log("\n### Current Case is " + form + "\n") + if ";;" == form[0:2]: + log(form) + elif skip_test(form, SKIP_TESTS): + log("Skipping test: %s" % form[0:60]) + elif re.match("^\(assert_trap\s+\(module", form): + test_assert_with_exception(form, wast_tempfile, wasm_tempfile, aot_tempfile if test_aot else None, opts, r) + elif re.match("^\(assert_exhaustion\\b.*", form): + test_assert_exhaustion(r, opts, form) + elif re.match("^\(assert_unlinkable\\b.*", form): + test_assert_with_exception(form, wast_tempfile, wasm_tempfile, aot_tempfile if test_aot else None, opts, r, False) + elif re.match("^\(assert_malformed\\b.*", form): + # remove comments in wast + form,n = re.subn(";;.*\n", "", form) + m = re.match("^\(assert_malformed\s*\(module binary\s*(\".*\").*\)\s*\"(.*)\"\s*\)$", form, re.DOTALL) + + if m: + # workaround: spec test changes error message to "malformed" while iwasm still use "invalid" + error_msg = m.group(2).replace("malformed", "invalid") + log("Testing(malformed)") + f = open(wasm_tempfile, 'wb') + s = m.group(1) + while s: + res = re.match("[^\"]*\"([^\"]*)\"(.*)", s, re.DOTALL) + if IS_PY_3: + context = res.group(1).replace("\\", "\\x").encode("latin1").decode("unicode-escape").encode("latin1") + f.write(context) + else: + f.write(res.group(1).replace("\\", "\\x").decode("string-escape")) + s = res.group(2) + f.close() + + # compile wasm to aot + if test_aot: + r = compile_wasm_to_aot(wasm_tempfile, aot_tempfile, True, opts, r) + try: + assert_prompt(r, ['Compile success'], opts.start_timeout, True) + except: + _, exc, _ = sys.exc_info() + if (r.buf.find(error_msg) >= 0): + log("Out exception includes expected one, pass:") + log(" Expected: %s" % error_msg) + log(" Got: %s" % r.buf) + else: + log("Run wamrc failed:\n expected: '%s'\n got: '%s'" % \ + (error_msg, r.buf)) + continue + + r = run_wasm_with_repl(wasm_tempfile, aot_tempfile if test_aot else None, opts, r) + + if (error_msg == "unexpected end of section or function"): + # one case in binary.wast + assert_prompt(r, ["unexpected end", error_msg], opts.start_timeout, True) + elif (error_msg == "invalid value type"): + # one case in binary.wast + assert_prompt(r, ["unexpected end", error_msg], opts.start_timeout, True) + elif (error_msg == "length out of bounds"): + # one case in custom.wast + assert_prompt(r, ["unexpected end", error_msg], opts.start_timeout, True) + elif (error_msg == "integer representation too long"): + # several cases in binary-leb128.wast + assert_prompt(r, ["invalid section id", error_msg], opts.start_timeout, True) + + elif re.match("^\(assert_malformed\s*\(module quote", form): + log("ignoring assert_malformed module quote") + else: + log("unrecognized assert_malformed") + elif re.match("^\(assert_return[_a-z]*_nan\\b.*", form): + log("ignoring assert_return_.*_nan") + pass + elif re.match(".*\(invoke\s+\$\\b.*", form): + # invoke a particular named module's function + if form.startswith("(assert_return"): + test_assert_return(r,opts,form) + elif form.startswith("(assert_trap"): + test_assert_trap(r,opts,form) + elif re.match("^\(module\\b.*", form): + # if the module includes the particular name startswith $ + m = re.search("^\(module\s+\$.\S+", form) + if m: + # get module name + module_name = re.split('\$', m.group(0).strip())[1] + if module_name: + # create temporal files + temp_files = create_tmpfiles(module_name) + if not compile_wast_to_wasm(form, temp_files[0], temp_files[1], opts): + raise Exception("compile wast to wasm failed") + + if test_aot: + r = compile_wasm_to_aot(temp_files[1], temp_files[2], True, opts, r) + try: + assert_prompt(r, ['Compile success'], opts.start_timeout, False) + except: + _, exc, _ = sys.exc_info() + log("Run wamrc failed:\n got: '%s'" % r.buf) + sys.exit(1) + temp_module_table[module_name] = temp_files[1] + r = run_wasm_with_repl(temp_files[1], temp_files[2] if test_aot else None, opts, r) + else: + if not compile_wast_to_wasm(form, wast_tempfile, wasm_tempfile, opts): + raise Exception("compile wast to wasm failed") + + if test_aot: + r = compile_wasm_to_aot(wasm_tempfile, aot_tempfile, True, opts, r) + try: + assert_prompt(r, ['Compile success'], opts.start_timeout, False) + except: + _, exc, _ = sys.exc_info() + log("Run wamrc failed:\n got: '%s'" % r.buf) + sys.exit(1) + + r = run_wasm_with_repl(wasm_tempfile, aot_tempfile if test_aot else None, opts, r) + + # Wait for the initial prompt + try: + assert_prompt(r, ['webassembly> '], opts.start_timeout, False) + except: + _, exc, _ = sys.exc_info() + raise Exception("Failed:\n expected: '%s'\n got: '%s'" % \ + (repr(exc), r.buf)) + + elif re.match("^\(assert_return\\b.*", form): + assert(r), "iwasm repl runtime should be not null" + test_assert_return(r, opts, form) + elif re.match("^\(assert_trap\\b.*", form): + test_assert_trap(r, opts, form) + elif re.match("^\(invoke\\b.*", form): + assert(r), "iwasm repl runtime should be not null" + do_invoke(r, opts, form) + elif re.match("^\(assert_invalid\\b.*", form): + test_assert_with_exception(form, wast_tempfile, wasm_tempfile, aot_tempfile if test_aot else None, opts, r) + elif re.match("^\(register\\b.*", form): + # get module's new name from the register cmd + name_new =re.split('\"',re.search('\".*\"',form).group(0))[1] + if name_new: + new_module = os.path.join(tempfile.gettempdir(), name_new + ".wasm") + shutil.copyfile(temp_module_table.get(name_new, wasm_tempfile), new_module) + + # add new_module copied from the old into temp_file_repo[] + temp_file_repo.append(new_module) + else: + # there is no name defined in register cmd + raise Exception("can not find module name from the register") + else: + raise Exception("unrecognized form '%s...'" % form[0:40]) + except Exception as e: + traceback.print_exc() + print("THE FINAL EXCEPTION IS {}".format(e)) + ret_code = 101 + + shutil.copyfile(wasm_tempfile, os.path.join(opts.log_dir, os.path.basename(wasm_tempfile))) + + if opts.aot or opts.xip: + shutil.copyfile(aot_tempfile, os.path.join(opts.log_dir,os.path.basename(aot_tempfile))) + if "indirect-mode" in str(e): + compile_wasm_to_aot(wasm_tempfile, aot_tempfile, None, opts, None, "object") + shutil.copyfile(aot_tempfile, os.path.join(opts.log_dir,os.path.basename(aot_tempfile)+'.o')) + subprocess.check_call(["llvm-objdump", "-r", aot_tempfile]) + compile_wasm_to_aot(wasm_tempfile, aot_tempfile, None, opts, None, "ir") + shutil.copyfile(aot_tempfile, os.path.join(opts.log_dir,os.path.basename(aot_tempfile)+".ir")) + + else: + ret_code = 0 + finally: + if not opts.no_cleanup: + log("Removing tempfiles") + os.remove(wast_tempfile) + os.remove(wasm_tempfile) + if test_aot: + os.remove(aot_tempfile) + + # remove the files under /tempfiles/ and copy of .wasm files + if temp_file_repo: + for t in temp_file_repo: + if(len(str(t))!=0 and os.path.exists(t)): + os.remove(t) + + log("### End testing %s" % opts.test_file.name) + else: + log("Leaving tempfiles: %s" % ([wast_tempfile, wasm_tempfile])) + + sys.exit(ret_code) diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/simd_ignore_cases.patch b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/simd_ignore_cases.patch new file mode 100644 index 00000000..87d3871e --- /dev/null +++ b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/simd_ignore_cases.patch @@ -0,0 +1,73 @@ +diff --git a/test/core/simd/simd_lane.wast b/test/core/simd/simd_lane.wast +index 9d4b5fd7..4656dd2b 100644 +--- a/test/core/simd/simd_lane.wast ++++ b/test/core/simd/simd_lane.wast +@@ -602,23 +602,23 @@ + "(v128.const i8x16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0) " + "(v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)))") "invalid lane length") + (assert_malformed (module quote "(func (result v128) " +- "(i8x16.shuffle 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15.0) " ++ "(i8x16.shuffle 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15.0 " + "(v128.const i8x16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0) " + "(v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)))") "malformed lane index") + (assert_malformed (module quote "(func (result v128) " +- "(i8x16.shuffle 0.5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) " ++ "(i8x16.shuffle 0.5 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 " + "(v128.const i8x16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0) " + "(v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)))") "malformed lane index") + (assert_malformed (module quote "(func (result v128) " +- "(i8x16.shuffle -inf 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) " ++ "(i8x16.shuffle -inf 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 " + "(v128.const i8x16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0) " + "(v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)))") "malformed lane index") + (assert_malformed (module quote "(func (result v128) " +- "(i8x16.shuffle 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 inf) " ++ "(i8x16.shuffle 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 inf " + "(v128.const i8x16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0) " + "(v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)))") "malformed lane index") + (assert_malformed (module quote "(func (result v128) " +- "(i8x16.shuffle nan 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) " ++ "(i8x16.shuffle nan 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 " + "(v128.const i8x16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0) " + "(v128.const i8x16 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)))") "malformed lane index") + +@@ -858,7 +858,7 @@ + (assert_return (invoke "as-if-condition-value" (v128.const i8x16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)) (i32.const 0)) + (assert_return (invoke "as-return-value-1" (v128.const i16x8 0 0 0 0 0 0 0 0) (i32.const 1)) (v128.const i16x8 1 0 0 0 0 0 0 0)) + (assert_return (invoke "as-local_set-value" (v128.const i32x4 -1 -1 -1 -1)) (i32.const -1)) +-(assert_return (invoke "as-global_set-value-1" (v128.const f32x4 0 0 0 0)(f32.const 3.14)) (v128.const f32x4 3.14 0 0 0)) ++(assert_return (invoke "as-global_set-value-1" (v128.const f32x4 0 0 0 0) (f32.const 3.14)) (v128.const f32x4 3.14 0 0 0)) + + (assert_return (invoke "as-return-value-2" + (v128.const i8x16 -16 -15 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1) +@@ -870,7 +870,7 @@ + (v128.const i8x16 -16 -15 -14 -13 -12 -11 -10 -9 8 7 6 5 4 3 2 1)) + + (assert_return (invoke "as-local_set-value-1" (v128.const i64x2 -1 -1)) (i64.const -1)) +-(assert_return (invoke "as-global_set-value-3" (v128.const f64x2 0 0)(f64.const 3.14)) (v128.const f64x2 3.14 0)) ++(assert_return (invoke "as-global_set-value-3" (v128.const f64x2 0 0) (f64.const 3.14)) (v128.const f64x2 3.14 0)) + + ;; Non-nat lane index + +diff --git a/test/core/simd/simd_load.wast b/test/core/simd/simd_load.wast +index 4b2edc16..c7639218 100644 +--- a/test/core/simd/simd_load.wast ++++ b/test/core/simd/simd_load.wast +@@ -124,7 +124,7 @@ + (i8x16.swizzle (v128.load (i32.const 0)) (v128.load offset=15 (i32.const 1))) + ) + ) +-(assert_return(invoke "as-i8x16.swizzle-operand") (v128.const i8x16 115 114 113 112 111 110 109 108 107 106 105 104 103 102 101 100)) ++(assert_return (invoke "as-i8x16.swizzle-operand") (v128.const i8x16 115 114 113 112 111 110 109 108 107 106 105 104 103 102 101 100)) + + (module (memory 1) + (data (i32.const 0) "\00\01\02\03\04\05\06\07\08\09\0a\0b\0c\0d\0e\0f\00\01\02\03") +@@ -180,7 +180,7 @@ + + (assert_invalid + (module (memory 1) (func (drop (v128.load (local.get 2))))) +- "unknown local 2" ++ "unknown local" + ) + (assert_invalid + (module (memory 1) (func (drop (v128.load)))) diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/tail-call/return_call.wast b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/tail-call/return_call.wast new file mode 100644 index 00000000..df75df40 --- /dev/null +++ b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/tail-call/return_call.wast @@ -0,0 +1,202 @@ +;; Test `return_call` operator + +(module + ;; Auxiliary definitions + (func $const-i32 (result i32) (i32.const 0x132)) + (func $const-i64 (result i64) (i64.const 0x164)) + (func $const-f32 (result f32) (f32.const 0xf32)) + (func $const-f64 (result f64) (f64.const 0xf64)) + + (func $id-i32 (param i32) (result i32) (get_local 0)) + (func $id-i64 (param i64) (result i64) (get_local 0)) + (func $id-f32 (param f32) (result f32) (get_local 0)) + (func $id-f64 (param f64) (result f64) (get_local 0)) + + (func $f32-i32 (param f32 i32) (result i32) (get_local 1)) + (func $i32-i64 (param i32 i64) (result i64) (get_local 1)) + (func $f64-f32 (param f64 f32) (result f32) (get_local 1)) + (func $i64-f64 (param i64 f64) (result f64) (get_local 1)) + + ;; Typing + + (func (export "type-i32") (result i32) (return_call $const-i32)) + (func (export "type-i64") (result i64) (return_call $const-i64)) + (func (export "type-f32") (result f32) (return_call $const-f32)) + (func (export "type-f64") (result f64) (return_call $const-f64)) + + (func (export "type-first-i32") (result i32) (return_call $id-i32 (i32.const 32))) + (func (export "type-first-i64") (result i64) (return_call $id-i64 (i64.const 64))) + (func (export "type-first-f32") (result f32) (return_call $id-f32 (f32.const 1.32))) + (func (export "type-first-f64") (result f64) (return_call $id-f64 (f64.const 1.64))) + + (func (export "type-second-i32") (result i32) + (return_call $f32-i32 (f32.const 32.1) (i32.const 32)) + ) + (func (export "type-second-i64") (result i64) + (return_call $i32-i64 (i32.const 32) (i64.const 64)) + ) + (func (export "type-second-f32") (result f32) + (return_call $f64-f32 (f64.const 64) (f32.const 32)) + ) + (func (export "type-second-f64") (result f64) + (return_call $i64-f64 (i64.const 64) (f64.const 64.1)) + ) + + ;; Recursion + + (func $fac-acc (export "fac-acc") (param i64 i64) (result i64) + (if (result i64) (i64.eqz (get_local 0)) + (then (get_local 1)) + (else + (return_call $fac-acc + (i64.sub (get_local 0) (i64.const 1)) + (i64.mul (get_local 0) (get_local 1)) + ) + ) + ) + ) + + (func $count (export "count") (param i64) (result i64) + (if (result i64) (i64.eqz (get_local 0)) + (then (get_local 0)) + (else (return_call $count (i64.sub (get_local 0) (i64.const 1)))) + ) + ) + + (func $even (export "even") (param i64) (result i32) + (if (result i32) (i64.eqz (get_local 0)) + (then (i32.const 44)) + (else (return_call $odd (i64.sub (get_local 0) (i64.const 1)))) + ) + ) + (func $odd (export "odd") (param i64) (result i32) + (if (result i32) (i64.eqz (get_local 0)) + (then (i32.const 99)) + (else (return_call $even (i64.sub (get_local 0) (i64.const 1)))) + ) + ) +) + +(assert_return (invoke "type-i32") (i32.const 0x132)) +(assert_return (invoke "type-i64") (i64.const 0x164)) +(assert_return (invoke "type-f32") (f32.const 0xf32)) +(assert_return (invoke "type-f64") (f64.const 0xf64)) + +(assert_return (invoke "type-first-i32") (i32.const 32)) +(assert_return (invoke "type-first-i64") (i64.const 64)) +(assert_return (invoke "type-first-f32") (f32.const 1.32)) +(assert_return (invoke "type-first-f64") (f64.const 1.64)) + +(assert_return (invoke "type-second-i32") (i32.const 32)) +(assert_return (invoke "type-second-i64") (i64.const 64)) +(assert_return (invoke "type-second-f32") (f32.const 32)) +(assert_return (invoke "type-second-f64") (f64.const 64.1)) + +(assert_return (invoke "fac-acc" (i64.const 0) (i64.const 1)) (i64.const 1)) +(assert_return (invoke "fac-acc" (i64.const 1) (i64.const 1)) (i64.const 1)) +(assert_return (invoke "fac-acc" (i64.const 5) (i64.const 1)) (i64.const 120)) +(assert_return + (invoke "fac-acc" (i64.const 25) (i64.const 1)) + (i64.const 7034535277573963776) +) + +(assert_return (invoke "count" (i64.const 0)) (i64.const 0)) +(assert_return (invoke "count" (i64.const 1000)) (i64.const 0)) +(assert_return (invoke "count" (i64.const 1_000_000)) (i64.const 0)) + +(assert_return (invoke "even" (i64.const 0)) (i32.const 44)) +(assert_return (invoke "even" (i64.const 1)) (i32.const 99)) +(assert_return (invoke "even" (i64.const 100)) (i32.const 44)) +(assert_return (invoke "even" (i64.const 77)) (i32.const 99)) +(assert_return (invoke "even" (i64.const 1_000_000)) (i32.const 44)) +(assert_return (invoke "even" (i64.const 1_000_001)) (i32.const 99)) +(assert_return (invoke "odd" (i64.const 0)) (i32.const 99)) +(assert_return (invoke "odd" (i64.const 1)) (i32.const 44)) +(assert_return (invoke "odd" (i64.const 200)) (i32.const 99)) +(assert_return (invoke "odd" (i64.const 77)) (i32.const 44)) +(assert_return (invoke "odd" (i64.const 1_000_000)) (i32.const 99)) +(assert_return (invoke "odd" (i64.const 999_999)) (i32.const 44)) + + +;; Invalid typing + +(assert_invalid + (module + (func $type-void-vs-num (result i32) (return_call 1) (i32.const 0)) + (func) + ) + "type mismatch" +) +(assert_invalid + (module + (func $type-num-vs-num (result i32) (return_call 1) (i32.const 0)) + (func (result i64) (i64.const 1)) + ) + "type mismatch" +) + +(assert_invalid + (module + (func $arity-0-vs-1 (return_call 1)) + (func (param i32)) + ) + "type mismatch" +) +(assert_invalid + (module + (func $arity-0-vs-2 (return_call 1)) + (func (param f64 i32)) + ) + "type mismatch" +) + +(module + (func $arity-1-vs-0 (i32.const 1) (return_call 1)) + (func) +) + +(module + (func $arity-2-vs-0 (f64.const 2) (i32.const 1) (return_call 1)) + (func) +) + +(assert_invalid + (module + (func $type-first-void-vs-num (return_call 1 (nop) (i32.const 1))) + (func (param i32 i32)) + ) + "type mismatch" +) +(assert_invalid + (module + (func $type-second-void-vs-num (return_call 1 (i32.const 1) (nop))) + (func (param i32 i32)) + ) + "type mismatch" +) +(assert_invalid + (module + (func $type-first-num-vs-num (return_call 1 (f64.const 1) (i32.const 1))) + (func (param i32 f64)) + ) + "type mismatch" +) +(assert_invalid + (module + (func $type-second-num-vs-num (return_call 1 (i32.const 1) (f64.const 1))) + (func (param f64 i32)) + ) + "type mismatch" +) + + +;; Unbound function + +(assert_invalid + (module (func $unbound-func (return_call 1))) + "unknown function" +) +(assert_invalid + (module (func $large-func (return_call 1012321300))) + "unknown function" +) diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/tail-call/return_call_indirect.wast b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/tail-call/return_call_indirect.wast new file mode 100644 index 00000000..515f15d5 --- /dev/null +++ b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/tail-call/return_call_indirect.wast @@ -0,0 +1,511 @@ +;; Test `return_call_indirect` operator + +(module + ;; Auxiliary definitions + (type $proc (func)) + (type $out-i32 (func (result i32))) + (type $out-i64 (func (result i64))) + (type $out-f32 (func (result f32))) + (type $out-f64 (func (result f64))) + (type $over-i32 (func (param i32) (result i32))) + (type $over-i64 (func (param i64) (result i64))) + (type $over-f32 (func (param f32) (result f32))) + (type $over-f64 (func (param f64) (result f64))) + (type $f32-i32 (func (param f32 i32) (result i32))) + (type $i32-i64 (func (param i32 i64) (result i64))) + (type $f64-f32 (func (param f64 f32) (result f32))) + (type $i64-f64 (func (param i64 f64) (result f64))) + (type $over-i32-duplicate (func (param i32) (result i32))) + (type $over-i64-duplicate (func (param i64) (result i64))) + (type $over-f32-duplicate (func (param f32) (result f32))) + (type $over-f64-duplicate (func (param f64) (result f64))) + + (func $const-i32 (type $out-i32) (i32.const 0x132)) + (func $const-i64 (type $out-i64) (i64.const 0x164)) + (func $const-f32 (type $out-f32) (f32.const 0xf32)) + (func $const-f64 (type $out-f64) (f64.const 0xf64)) + + (func $id-i32 (type $over-i32) (get_local 0)) + (func $id-i64 (type $over-i64) (get_local 0)) + (func $id-f32 (type $over-f32) (get_local 0)) + (func $id-f64 (type $over-f64) (get_local 0)) + + (func $i32-i64 (type $i32-i64) (get_local 1)) + (func $i64-f64 (type $i64-f64) (get_local 1)) + (func $f32-i32 (type $f32-i32) (get_local 1)) + (func $f64-f32 (type $f64-f32) (get_local 1)) + + (func $over-i32-duplicate (type $over-i32-duplicate) (get_local 0)) + (func $over-i64-duplicate (type $over-i64-duplicate) (get_local 0)) + (func $over-f32-duplicate (type $over-f32-duplicate) (get_local 0)) + (func $over-f64-duplicate (type $over-f64-duplicate) (get_local 0)) + + (table anyfunc + (elem + $const-i32 $const-i64 $const-f32 $const-f64 + $id-i32 $id-i64 $id-f32 $id-f64 + $f32-i32 $i32-i64 $f64-f32 $i64-f64 + $fac $fac-acc $even $odd + $over-i32-duplicate $over-i64-duplicate + $over-f32-duplicate $over-f64-duplicate + ) + ) + + ;; Syntax + + (func + (return_call_indirect (i32.const 0)) + (return_call_indirect (param i64) (i64.const 0) (i32.const 0)) + (return_call_indirect (param i64) (param) (param f64 i32 i64) + (i64.const 0) (f64.const 0) (i32.const 0) (i64.const 0) (i32.const 0) + ) + (return_call_indirect (result) (i32.const 0)) + ) + + (func (result i32) + (return_call_indirect (result i32) (i32.const 0)) + (return_call_indirect (result i32) (result) (i32.const 0)) + (return_call_indirect (param i64) (result i32) (i64.const 0) (i32.const 0)) + (return_call_indirect + (param) (param i64) (param) (param f64 i32 i64) (param) (param) + (result) (result i32) (result) (result) + (i64.const 0) (f64.const 0) (i32.const 0) (i64.const 0) (i32.const 0) + ) + ) + + (func (result i64) + (return_call_indirect (type $over-i64) (param i64) (result i64) + (i64.const 0) (i32.const 0) + ) + ) + + ;; Typing + + (func (export "type-i32") (result i32) + (return_call_indirect (type $out-i32) (i32.const 0)) + ) + (func (export "type-i64") (result i64) + (return_call_indirect (type $out-i64) (i32.const 1)) + ) + (func (export "type-f32") (result f32) + (return_call_indirect (type $out-f32) (i32.const 2)) + ) + (func (export "type-f64") (result f64) + (return_call_indirect (type $out-f64) (i32.const 3)) + ) + + (func (export "type-index") (result i64) + (return_call_indirect (type $over-i64) (i64.const 100) (i32.const 5)) + ) + + (func (export "type-first-i32") (result i32) + (return_call_indirect (type $over-i32) (i32.const 32) (i32.const 4)) + ) + (func (export "type-first-i64") (result i64) + (return_call_indirect (type $over-i64) (i64.const 64) (i32.const 5)) + ) + (func (export "type-first-f32") (result f32) + (return_call_indirect (type $over-f32) (f32.const 1.32) (i32.const 6)) + ) + (func (export "type-first-f64") (result f64) + (return_call_indirect (type $over-f64) (f64.const 1.64) (i32.const 7)) + ) + + (func (export "type-second-i32") (result i32) + (return_call_indirect (type $f32-i32) + (f32.const 32.1) (i32.const 32) (i32.const 8) + ) + ) + (func (export "type-second-i64") (result i64) + (return_call_indirect (type $i32-i64) + (i32.const 32) (i64.const 64) (i32.const 9) + ) + ) + (func (export "type-second-f32") (result f32) + (return_call_indirect (type $f64-f32) + (f64.const 64) (f32.const 32) (i32.const 10) + ) + ) + (func (export "type-second-f64") (result f64) + (return_call_indirect (type $i64-f64) + (i64.const 64) (f64.const 64.1) (i32.const 11) + ) + ) + + ;; Dispatch + + (func (export "dispatch") (param i32 i64) (result i64) + (return_call_indirect (type $over-i64) (get_local 1) (get_local 0)) + ) + + (func (export "dispatch-structural") (param i32) (result i64) + (return_call_indirect (type $over-i64-duplicate) + (i64.const 9) (get_local 0) + ) + ) + + ;; Recursion + + (func $fac (export "fac") (type $over-i64) + (return_call_indirect (param i64 i64) (result i64) + (get_local 0) (i64.const 1) (i32.const 13) + ) + ) + + (func $fac-acc (param i64 i64) (result i64) + (if (result i64) (i64.eqz (get_local 0)) + (then (get_local 1)) + (else + (return_call_indirect (param i64 i64) (result i64) + (i64.sub (get_local 0) (i64.const 1)) + (i64.mul (get_local 0) (get_local 1)) + (i32.const 13) + ) + ) + ) + ) + + (func $even (export "even") (param i32) (result i32) + (if (result i32) (i32.eqz (get_local 0)) + (then (i32.const 44)) + (else + (return_call_indirect (type $over-i32) + (i32.sub (get_local 0) (i32.const 1)) + (i32.const 15) + ) + ) + ) + ) + (func $odd (export "odd") (param i32) (result i32) + (if (result i32) (i32.eqz (get_local 0)) + (then (i32.const 99)) + (else + (return_call_indirect (type $over-i32) + (i32.sub (get_local 0) (i32.const 1)) + (i32.const 14) + ) + ) + ) + ) +) + +(assert_return (invoke "type-i32") (i32.const 0x132)) +(assert_return (invoke "type-i64") (i64.const 0x164)) +(assert_return (invoke "type-f32") (f32.const 0xf32)) +(assert_return (invoke "type-f64") (f64.const 0xf64)) + +(assert_return (invoke "type-index") (i64.const 100)) + +(assert_return (invoke "type-first-i32") (i32.const 32)) +(assert_return (invoke "type-first-i64") (i64.const 64)) +(assert_return (invoke "type-first-f32") (f32.const 1.32)) +(assert_return (invoke "type-first-f64") (f64.const 1.64)) + +(assert_return (invoke "type-second-i32") (i32.const 32)) +(assert_return (invoke "type-second-i64") (i64.const 64)) +(assert_return (invoke "type-second-f32") (f32.const 32)) +(assert_return (invoke "type-second-f64") (f64.const 64.1)) + +(assert_return (invoke "dispatch" (i32.const 5) (i64.const 2)) (i64.const 2)) +(assert_return (invoke "dispatch" (i32.const 5) (i64.const 5)) (i64.const 5)) +(assert_return (invoke "dispatch" (i32.const 12) (i64.const 5)) (i64.const 120)) +(assert_return (invoke "dispatch" (i32.const 17) (i64.const 2)) (i64.const 2)) +(assert_trap (invoke "dispatch" (i32.const 0) (i64.const 2)) "indirect call type mismatch") +(assert_trap (invoke "dispatch" (i32.const 15) (i64.const 2)) "indirect call type mismatch") +(assert_trap (invoke "dispatch" (i32.const 20) (i64.const 2)) "undefined element") +(assert_trap (invoke "dispatch" (i32.const -1) (i64.const 2)) "undefined element") +(assert_trap (invoke "dispatch" (i32.const 1213432423) (i64.const 2)) "undefined element") + +(assert_return (invoke "dispatch-structural" (i32.const 5)) (i64.const 9)) +(assert_return (invoke "dispatch-structural" (i32.const 5)) (i64.const 9)) +(assert_return (invoke "dispatch-structural" (i32.const 12)) (i64.const 362880)) +(assert_return (invoke "dispatch-structural" (i32.const 17)) (i64.const 9)) +(assert_trap (invoke "dispatch-structural" (i32.const 11)) "indirect call type mismatch") +(assert_trap (invoke "dispatch-structural" (i32.const 16)) "indirect call type mismatch") + +(assert_return (invoke "fac" (i64.const 0)) (i64.const 1)) +(assert_return (invoke "fac" (i64.const 1)) (i64.const 1)) +(assert_return (invoke "fac" (i64.const 5)) (i64.const 120)) +(assert_return (invoke "fac" (i64.const 25)) (i64.const 7034535277573963776)) + +(assert_return (invoke "even" (i32.const 0)) (i32.const 44)) +(assert_return (invoke "even" (i32.const 1)) (i32.const 99)) +(assert_return (invoke "even" (i32.const 100)) (i32.const 44)) +(assert_return (invoke "even" (i32.const 77)) (i32.const 99)) +(assert_return (invoke "even" (i32.const 100_000)) (i32.const 44)) +(assert_return (invoke "even" (i32.const 111_111)) (i32.const 99)) +(assert_return (invoke "odd" (i32.const 0)) (i32.const 99)) +(assert_return (invoke "odd" (i32.const 1)) (i32.const 44)) +(assert_return (invoke "odd" (i32.const 200)) (i32.const 99)) +(assert_return (invoke "odd" (i32.const 77)) (i32.const 44)) +(assert_return (invoke "odd" (i32.const 200_002)) (i32.const 99)) +(assert_return (invoke "odd" (i32.const 300_003)) (i32.const 44)) + + +;; Invalid syntax + +(assert_malformed + (module quote + "(type $sig (func (param i32) (result i32)))" + "(table 0 anyfunc)" + "(func (result i32)" + " (return_call_indirect (type $sig) (result i32) (param i32)" + " (i32.const 0) (i32.const 0)" + " )" + ")" + ) + "unexpected token" +) +(assert_malformed + (module quote + "(type $sig (func (param i32) (result i32)))" + "(table 0 anyfunc)" + "(func (result i32)" + " (return_call_indirect (param i32) (type $sig) (result i32)" + " (i32.const 0) (i32.const 0)" + " )" + ")" + ) + "unexpected token" +) +(assert_malformed + (module quote + "(type $sig (func (param i32) (result i32)))" + "(table 0 anyfunc)" + "(func (result i32)" + " (return_call_indirect (param i32) (result i32) (type $sig)" + " (i32.const 0) (i32.const 0)" + " )" + ")" + ) + "unexpected token" +) +(assert_malformed + (module quote + "(type $sig (func (param i32) (result i32)))" + "(table 0 anyfunc)" + "(func (result i32)" + " (return_call_indirect (result i32) (type $sig) (param i32)" + " (i32.const 0) (i32.const 0)" + " )" + ")" + ) + "unexpected token" +) +(assert_malformed + (module quote + "(type $sig (func (param i32) (result i32)))" + "(table 0 anyfunc)" + "(func (result i32)" + " (return_call_indirect (result i32) (param i32) (type $sig)" + " (i32.const 0) (i32.const 0)" + " )" + ")" + ) + "unexpected token" +) +(assert_malformed + (module quote + "(table 0 anyfunc)" + "(func (result i32)" + " (return_call_indirect (result i32) (param i32)" + " (i32.const 0) (i32.const 0)" + " )" + ")" + ) + "unexpected token" +) + +(assert_malformed + (module quote + "(table 0 anyfunc)" + "(func (return_call_indirect (param $x i32) (i32.const 0) (i32.const 0)))" + ) + "unexpected token" +) +(assert_malformed + (module quote + "(type $sig (func))" + "(table 0 anyfunc)" + "(func (result i32)" + " (return_call_indirect (type $sig) (result i32) (i32.const 0))" + ")" + ) + "inline function type" +) +(assert_malformed + (module quote + "(type $sig (func (param i32) (result i32)))" + "(table 0 anyfunc)" + "(func (result i32)" + " (return_call_indirect (type $sig) (result i32) (i32.const 0))" + ")" + ) + "inline function type" +) +(assert_malformed + (module quote + "(type $sig (func (param i32) (result i32)))" + "(table 0 anyfunc)" + "(func" + " (return_call_indirect (type $sig) (param i32)" + " (i32.const 0) (i32.const 0)" + " )" + ")" + ) + "inline function type" +) +(assert_malformed + (module quote + "(type $sig (func (param i32 i32) (result i32)))" + "(table 0 anyfunc)" + "(func (result i32)" + " (return_call_indirect (type $sig) (param i32) (result i32)" + " (i32.const 0) (i32.const 0)" + " )" + ")" + ) + "inline function type" +) + +;; Invalid typing + +(assert_invalid + (module + (type (func)) + (func $no-table (return_call_indirect (type 0) (i32.const 0))) + ) + "unknown table" +) + +(assert_invalid + (module + (type (func)) + (table 0 anyfunc) + (func $type-void-vs-num (i32.eqz (return_call_indirect (type 0) (i32.const 0)))) + ) + "type mismatch" +) +(assert_invalid + (module + (type (func (result i64))) + (table 0 anyfunc) + (func $type-num-vs-num (i32.eqz (return_call_indirect (type 0) (i32.const 0)))) + ) + "type mismatch" +) + +(assert_invalid + (module + (type (func (param i32))) + (table 0 anyfunc) + (func $arity-0-vs-1 (return_call_indirect (type 0) (i32.const 0))) + ) + "type mismatch" +) +(assert_invalid + (module + (type (func (param f64 i32))) + (table 0 anyfunc) + (func $arity-0-vs-2 (return_call_indirect (type 0) (i32.const 0))) + ) + "type mismatch" +) + +(module + (type (func)) + (table 0 anyfunc) + (func $arity-1-vs-0 (return_call_indirect (type 0) (i32.const 1) (i32.const 0))) +) + +(module + (type (func)) + (table 0 anyfunc) + (func $arity-2-vs-0 + (return_call_indirect (type 0) (f64.const 2) (i32.const 1) (i32.const 0)) + ) +) + +(assert_invalid + (module + (type (func (param i32))) + (table 0 anyfunc) + (func $type-func-void-vs-i32 (return_call_indirect (type 0) (i32.const 1) (nop))) + ) + "type mismatch" +) +(assert_invalid + (module + (type (func (param i32))) + (table 0 anyfunc) + (func $type-func-num-vs-i32 (return_call_indirect (type 0) (i32.const 0) (i64.const 1))) + ) + "type mismatch" +) + +(assert_invalid + (module + (type (func (param i32 i32))) + (table 0 anyfunc) + (func $type-first-void-vs-num + (return_call_indirect (type 0) (nop) (i32.const 1) (i32.const 0)) + ) + ) + "type mismatch" +) +(assert_invalid + (module + (type (func (param i32 i32))) + (table 0 anyfunc) + (func $type-second-void-vs-num + (return_call_indirect (type 0) (i32.const 1) (nop) (i32.const 0)) + ) + ) + "type mismatch" +) +(assert_invalid + (module + (type (func (param i32 f64))) + (table 0 anyfunc) + (func $type-first-num-vs-num + (return_call_indirect (type 0) (f64.const 1) (i32.const 1) (i32.const 0)) + ) + ) + "type mismatch" +) +(assert_invalid + (module + (type (func (param f64 i32))) + (table 0 anyfunc) + (func $type-second-num-vs-num + (return_call_indirect (type 0) (i32.const 1) (f64.const 1) (i32.const 0)) + ) + ) + "type mismatch" +) + + +;; Unbound type + +(assert_invalid + (module + (table 0 anyfunc) + (func $unbound-type (return_call_indirect (type 1) (i32.const 0))) + ) + "unknown type" +) +(assert_invalid + (module + (table 0 anyfunc) + (func $large-type (return_call_indirect (type 1012321300) (i32.const 0))) + ) + "unknown type" +) + + +;; Unbound function in table + +(assert_invalid + (module (table anyfunc (elem 0 0))) + "unknown function" +) diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/thread_proposal_fix_atomic_case.patch b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/thread_proposal_fix_atomic_case.patch new file mode 100644 index 00000000..a64dd178 --- /dev/null +++ b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/thread_proposal_fix_atomic_case.patch @@ -0,0 +1,49 @@ +diff --git a/test/core/atomic.wast b/test/core/atomic.wast +index 66ad0eb..40259a9 100644 +--- a/test/core/atomic.wast ++++ b/test/core/atomic.wast +@@ -324,7 +324,7 @@ + + (invoke "init" (i64.const 0x1111111111111111)) + (assert_return (invoke "i32.atomic.rmw8.cmpxchg_u" (i32.const 0) (i32.const 0x11111111) (i32.const 0xcdcdcdcd)) (i32.const 0x11)) +-(assert_return (invoke "i64.atomic.load" (i32.const 0)) (i64.const 0x1111111111111111)) ++(assert_return (invoke "i64.atomic.load" (i32.const 0)) (i64.const 0x11111111111111cd)) + + (invoke "init" (i64.const 0x1111111111111111)) + (assert_return (invoke "i32.atomic.rmw16.cmpxchg_u" (i32.const 0) (i32.const 0) (i32.const 0xcafecafe)) (i32.const 0x1111)) +@@ -332,7 +332,7 @@ + + (invoke "init" (i64.const 0x1111111111111111)) + (assert_return (invoke "i32.atomic.rmw16.cmpxchg_u" (i32.const 0) (i32.const 0x11111111) (i32.const 0xcafecafe)) (i32.const 0x1111)) +-(assert_return (invoke "i64.atomic.load" (i32.const 0)) (i64.const 0x1111111111111111)) ++(assert_return (invoke "i64.atomic.load" (i32.const 0)) (i64.const 0x111111111111cafe)) + + (invoke "init" (i64.const 0x1111111111111111)) + (assert_return (invoke "i64.atomic.rmw8.cmpxchg_u" (i32.const 0) (i64.const 0) (i64.const 0x4242424242424242)) (i64.const 0x11)) +@@ -340,7 +340,7 @@ + + (invoke "init" (i64.const 0x1111111111111111)) + (assert_return (invoke "i64.atomic.rmw8.cmpxchg_u" (i32.const 0) (i64.const 0x1111111111111111) (i64.const 0x4242424242424242)) (i64.const 0x11)) +-(assert_return (invoke "i64.atomic.load" (i32.const 0)) (i64.const 0x1111111111111111)) ++(assert_return (invoke "i64.atomic.load" (i32.const 0)) (i64.const 0x1111111111111142)) + + (invoke "init" (i64.const 0x1111111111111111)) + (assert_return (invoke "i64.atomic.rmw16.cmpxchg_u" (i32.const 0) (i64.const 0) (i64.const 0xbeefbeefbeefbeef)) (i64.const 0x1111)) +@@ -348,7 +348,7 @@ + + (invoke "init" (i64.const 0x1111111111111111)) + (assert_return (invoke "i64.atomic.rmw16.cmpxchg_u" (i32.const 0) (i64.const 0x1111111111111111) (i64.const 0xbeefbeefbeefbeef)) (i64.const 0x1111)) +-(assert_return (invoke "i64.atomic.load" (i32.const 0)) (i64.const 0x1111111111111111)) ++(assert_return (invoke "i64.atomic.load" (i32.const 0)) (i64.const 0x111111111111beef)) + + (invoke "init" (i64.const 0x1111111111111111)) + (assert_return (invoke "i64.atomic.rmw32.cmpxchg_u" (i32.const 0) (i64.const 0) (i64.const 0xcabba6e5cabba6e5)) (i64.const 0x11111111)) +@@ -356,7 +356,7 @@ + + (invoke "init" (i64.const 0x1111111111111111)) + (assert_return (invoke "i64.atomic.rmw32.cmpxchg_u" (i32.const 0) (i64.const 0x1111111111111111) (i64.const 0xcabba6e5cabba6e5)) (i64.const 0x11111111)) +-(assert_return (invoke "i64.atomic.load" (i32.const 0)) (i64.const 0x1111111111111111)) ++(assert_return (invoke "i64.atomic.load" (i32.const 0)) (i64.const 0x11111111cabba6e5)) + + ;; *.atomic.rmw*.cmpxchg (compare true) + diff --git a/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/thread_proposal_ignore_cases.patch b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/thread_proposal_ignore_cases.patch new file mode 100644 index 00000000..41a0d25b --- /dev/null +++ b/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/tests/wamr-test-suites/spec-test-script/thread_proposal_ignore_cases.patch @@ -0,0 +1,213 @@ +diff --git a/test/core/binary.wast b/test/core/binary.wast +index b9fa438c..a5711dd3 100644 +--- a/test/core/binary.wast ++++ b/test/core/binary.wast +@@ -45,7 +45,7 @@ + (assert_malformed (module binary "\00asm\00\00\00\01") "unknown binary version") + + ;; Invalid section id. +-(assert_malformed (module binary "\00asm" "\01\00\00\00" "\0c\00") "malformed section id") ++;; (assert_malformed (module binary "\00asm" "\01\00\00\00" "\0c\00") "malformed section id") + (assert_malformed (module binary "\00asm" "\01\00\00\00" "\7f\00") "malformed section id") + (assert_malformed (module binary "\00asm" "\01\00\00\00" "\80\00\01\00") "malformed section id") + (assert_malformed (module binary "\00asm" "\01\00\00\00" "\81\00\01\00") "malformed section id") +@@ -68,7 +68,7 @@ + "\01" ;; call_indirect reserved byte is not equal to zero! + "\0b" ;; end + ) +- "zero flag expected" ++ "zero byte expected" + ) + + ;; call_indirect reserved byte should not be a "long" LEB128 zero. +@@ -87,7 +87,7 @@ + "\80\00" ;; call_indirect reserved byte + "\0b" ;; end + ) +- "zero flag expected" ++ "zero byte expected" + ) + + ;; Same as above for 3, 4, and 5-byte zero encodings. +@@ -106,7 +106,7 @@ + "\80\80\00" ;; call_indirect reserved byte + "\0b" ;; end + ) +- "zero flag expected" ++ "zero byte expected" + ) + + (assert_malformed +@@ -124,7 +124,7 @@ + "\80\80\80\00" ;; call_indirect reserved byte + "\0b" ;; end + ) +- "zero flag expected" ++ "zero byte expected" + ) + + (assert_malformed +@@ -142,7 +142,7 @@ + "\80\80\80\80\00" ;; call_indirect reserved byte + "\0b" ;; end + ) +- "zero flag expected" ++ "zero byte expected" + ) + + ;; memory.grow reserved byte equal to zero. +@@ -162,7 +162,7 @@ + "\1a" ;; drop + "\0b" ;; end + ) +- "zero flag expected" ++ "zero byte expected" + ) + + ;; memory.grow reserved byte should not be a "long" LEB128 zero. +@@ -182,7 +182,7 @@ + "\1a" ;; drop + "\0b" ;; end + ) +- "zero flag expected" ++ "zero byte expected" + ) + + ;; Same as above for 3, 4, and 5-byte zero encodings. +@@ -202,7 +202,7 @@ + "\1a" ;; drop + "\0b" ;; end + ) +- "zero flag expected" ++ "zero byte expected" + ) + + (assert_malformed +@@ -221,7 +221,7 @@ + "\1a" ;; drop + "\0b" ;; end + ) +- "zero flag expected" ++ "zero byte expected" + ) + + (assert_malformed +@@ -240,7 +240,7 @@ + "\1a" ;; drop + "\0b" ;; end + ) +- "zero flag expected" ++ "zero byte expected" + ) + + ;; memory.size reserved byte equal to zero. +@@ -259,7 +259,7 @@ + "\1a" ;; drop + "\0b" ;; end + ) +- "zero flag expected" ++ "zero byte expected" + ) + + ;; memory.size reserved byte should not be a "long" LEB128 zero. +@@ -278,7 +278,7 @@ + "\1a" ;; drop + "\0b" ;; end + ) +- "zero flag expected" ++ "zero byte expected" + ) + + ;; Same as above for 3, 4, and 5-byte zero encodings. +@@ -297,7 +297,7 @@ + "\1a" ;; drop + "\0b" ;; end + ) +- "zero flag expected" ++ "zero byte expected" + ) + + (assert_malformed +@@ -315,7 +315,7 @@ + "\1a" ;; drop + "\0b" ;; end + ) +- "zero flag expected" ++ "zero byte expected" + ) + + (assert_malformed +@@ -333,7 +333,7 @@ + "\1a" ;; drop + "\0b" ;; end + ) +- "zero flag expected" ++ "zero byte expected" + ) + + ;; No more than 2^32 locals. +@@ -745,6 +745,7 @@ + ) + + ;; 2 elem segment declared, 1 given ++(; + (assert_malformed + (module binary + "\00asm" "\01\00\00\00" +@@ -761,6 +762,7 @@ + ) + "unexpected end" + ) ++;) + + ;; 1 elem segment declared, 2 given + (assert_malformed +diff --git a/test/core/elem.wast b/test/core/elem.wast +index 1ea2b061..8eded377 100644 +--- a/test/core/elem.wast ++++ b/test/core/elem.wast +@@ -12,10 +12,10 @@ + (elem 0x0 (i32.const 0) $f $f) + (elem 0x000 (offset (i32.const 0))) + (elem 0 (offset (i32.const 0)) $f $f) +- (elem $t (i32.const 0)) +- (elem $t (i32.const 0) $f $f) +- (elem $t (offset (i32.const 0))) +- (elem $t (offset (i32.const 0)) $f $f) ++ (elem (i32.const 0)) ++ (elem (i32.const 0) $f $f) ++ (elem (offset (i32.const 0))) ++ (elem (offset (i32.const 0)) $f $f) + ) + + ;; Basic use +@@ -354,6 +354,7 @@ + (assert_return (invoke $module1 "call-8") (i32.const 65)) + (assert_return (invoke $module1 "call-9") (i32.const 66)) + ++(; + (module $module2 + (type $out-i32 (func (result i32))) + (import "module1" "shared-table" (table 10 funcref)) +@@ -379,3 +380,4 @@ + (assert_return (invoke $module1 "call-7") (i32.const 67)) + (assert_return (invoke $module1 "call-8") (i32.const 69)) + (assert_return (invoke $module1 "call-9") (i32.const 70)) ++;) +diff --git a/test/core/thread.wast b/test/core/thread.wast +index c3456a61..83fc2815 100644 +--- a/test/core/thread.wast ++++ b/test/core/thread.wast +@@ -2,6 +2,7 @@ + (memory (export "shared") 1 1 shared) + ) + ++(; + (thread $T1 (shared (module $Mem)) + (register "mem" $Mem) + (module +@@ -26,3 +27,4 @@ + + (wait $T1) + (wait $T2) ++;) |