2023-02-27 12:28:37 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#
|
|
|
|
# Copyright (C) 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
|
|
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#
|
|
|
|
|
2023-09-22 00:57:48 +00:00
|
|
|
THIS_DIR=$(cd $(dirname $0) && pwd -P)
|
|
|
|
|
2023-02-27 12:28:37 +00:00
|
|
|
readonly MODE=$1
|
|
|
|
readonly TARGET=$2
|
2023-11-06 11:24:06 +00:00
|
|
|
readonly TEST_FILTER=$3
|
2023-02-27 12:28:37 +00:00
|
|
|
|
|
|
|
readonly WORK_DIR=$PWD
|
2023-08-23 02:51:30 +00:00
|
|
|
|
|
|
|
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then
|
|
|
|
readonly PLATFORM=windows
|
|
|
|
readonly PYTHON_EXE=python
|
|
|
|
# see https://github.com/pypa/virtualenv/commit/993ba1316a83b760370f5a3872b3f5ef4dd904c1
|
|
|
|
readonly VENV_BIN_DIR=Scripts
|
|
|
|
readonly IWASM_EXE=$(cygpath -m "${WORK_DIR}/../../../../product-mini/platforms/${PLATFORM}/build/RelWithDebInfo/iwasm.exe")
|
|
|
|
else
|
|
|
|
readonly PLATFORM=$(uname -s | tr A-Z a-z)
|
|
|
|
readonly VENV_BIN_DIR=bin
|
|
|
|
readonly PYTHON_EXE=python3
|
|
|
|
readonly IWASM_EXE="${WORK_DIR}/../../../../product-mini/platforms/${PLATFORM}/build/iwasm"
|
|
|
|
fi
|
|
|
|
|
2023-03-09 01:03:16 +00:00
|
|
|
readonly WAMR_DIR="${WORK_DIR}/../../../.."
|
2023-08-23 02:51:30 +00:00
|
|
|
readonly IWASM_CMD="${IWASM_EXE} \
|
2023-07-30 11:34:09 +00:00
|
|
|
--allow-resolve=google-public-dns-a.google.com \
|
|
|
|
--addr-pool=::1/128,127.0.0.1/32"
|
2023-08-17 02:31:05 +00:00
|
|
|
|
2023-08-30 11:01:44 +00:00
|
|
|
readonly IWASM_CMD_STRESS="${IWASM_CMD} --max-threads=12"
|
2023-02-27 12:28:37 +00:00
|
|
|
readonly WAMRC_CMD="${WORK_DIR}/../../../../wamr-compiler/build/wamrc"
|
2023-03-16 00:22:03 +00:00
|
|
|
readonly C_TESTS="tests/c/testsuite/"
|
2023-10-06 12:12:08 +00:00
|
|
|
readonly RUST_TESTS="tests/rust/testsuite/"
|
2023-03-16 00:22:03 +00:00
|
|
|
readonly ASSEMBLYSCRIPT_TESTS="tests/assemblyscript/testsuite/"
|
|
|
|
readonly THREAD_PROPOSAL_TESTS="tests/proposals/wasi-threads/"
|
|
|
|
readonly THREAD_INTERNAL_TESTS="${WAMR_DIR}/core/iwasm/libraries/lib-wasi-threads/test/"
|
2023-08-30 11:01:44 +00:00
|
|
|
readonly THREAD_STRESS_TESTS="${WAMR_DIR}/core/iwasm/libraries/lib-wasi-threads/stress-test/"
|
2023-03-16 00:22:03 +00:00
|
|
|
readonly LIB_SOCKET_TESTS="${WAMR_DIR}/core/iwasm/libraries/lib-socket/test/"
|
|
|
|
|
2024-02-28 03:02:42 +00:00
|
|
|
add_env_key_to_test_config_file() {
|
|
|
|
filepath="tests/$2/testsuite/$3.json"
|
|
|
|
modified_contents=$(jq ".env.$1 = 1" "$filepath")
|
|
|
|
echo "$modified_contents" > "$filepath"
|
|
|
|
}
|
|
|
|
|
2023-03-16 00:22:03 +00:00
|
|
|
run_aot_tests () {
|
2023-11-06 11:24:06 +00:00
|
|
|
local -n tests=$1
|
|
|
|
local -n excluded_tests=$2
|
|
|
|
|
2023-03-16 00:22:03 +00:00
|
|
|
for test_wasm in ${tests[@]}; do
|
2023-11-06 11:24:06 +00:00
|
|
|
# get the base file name from the filepath
|
|
|
|
local test_name=${test_wasm##*/}
|
|
|
|
test_name=${test_name%.wasm}
|
|
|
|
|
|
|
|
for excluded_test in "${excluded_tests[@]}"; do
|
|
|
|
if [[ $excluded_test == "\"$test_name\"" ]]; then
|
|
|
|
echo "Skipping test $test_name"
|
|
|
|
continue 2
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2023-08-30 11:01:44 +00:00
|
|
|
local iwasm="${IWASM_CMD}"
|
|
|
|
if [[ $test_wasm =~ "stress" ]]; then
|
|
|
|
iwasm="${IWASM_CMD_STRESS}"
|
|
|
|
fi
|
2023-08-01 09:38:37 +00:00
|
|
|
|
2023-03-16 00:22:03 +00:00
|
|
|
test_aot="${test_wasm%.wasm}.aot"
|
|
|
|
test_json="${test_wasm%.wasm}.json"
|
|
|
|
|
|
|
|
if [ -f ${test_wasm} ]; then
|
|
|
|
expected=$(jq .exit_code ${test_json})
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Compiling $test_wasm to $test_aot"
|
|
|
|
${WAMRC_CMD} --enable-multi-thread ${target_option} \
|
|
|
|
-o ${test_aot} ${test_wasm}
|
|
|
|
|
|
|
|
echo "Running $test_aot"
|
|
|
|
expected=0
|
2023-07-30 11:34:09 +00:00
|
|
|
if [ -f ${test_json} ]; then
|
2023-03-16 00:22:03 +00:00
|
|
|
expected=$(jq .exit_code ${test_json})
|
|
|
|
fi
|
2023-07-30 11:34:09 +00:00
|
|
|
|
2023-10-08 07:03:35 +00:00
|
|
|
$PYTHON_EXE ${THIS_DIR}/pipe.py | ${iwasm} $test_aot
|
2023-09-23 02:28:18 +00:00
|
|
|
ret=${PIPESTATUS[1]}
|
2023-03-16 00:22:03 +00:00
|
|
|
|
|
|
|
echo "expected=$expected, actual=$ret"
|
|
|
|
if [[ $expected != "" ]] && [[ $expected != $ret ]];then
|
|
|
|
exit_code=1
|
|
|
|
fi
|
|
|
|
done
|
2023-07-30 11:34:09 +00:00
|
|
|
}
|
2023-02-27 12:28:37 +00:00
|
|
|
|
|
|
|
if [[ $MODE != "aot" ]];then
|
2023-08-23 02:51:30 +00:00
|
|
|
$PYTHON_EXE -m venv wasi-env && source wasi-env/${VENV_BIN_DIR}/activate
|
|
|
|
$PYTHON_EXE -m pip install -r test-runner/requirements.txt
|
2023-08-01 09:38:37 +00:00
|
|
|
|
2023-09-22 00:57:48 +00:00
|
|
|
export TEST_RUNTIME_EXE="${IWASM_CMD}"
|
2023-11-06 11:24:06 +00:00
|
|
|
|
2024-02-28 03:02:42 +00:00
|
|
|
# Some of the WASI test assertions can be controlled via environment
|
|
|
|
# variables. The following ones are set on Windows so that the tests pass.
|
|
|
|
if [ "$PLATFORM" == "windows" ]; then
|
|
|
|
add_env_key_to_test_config_file NO_DANGLING_FILESYSTEM rust symlink_loop
|
|
|
|
add_env_key_to_test_config_file NO_DANGLING_FILESYSTEM rust dangling_symlink
|
|
|
|
add_env_key_to_test_config_file ERRNO_MODE_WINDOWS rust path_open_preopen
|
|
|
|
add_env_key_to_test_config_file NO_RENAME_DIR_TO_EMPTY_DIR rust path_rename
|
|
|
|
fi
|
|
|
|
|
2023-11-06 11:24:06 +00:00
|
|
|
TEST_OPTIONS="-r adapters/wasm-micro-runtime.py \
|
|
|
|
-t \
|
|
|
|
${C_TESTS} \
|
|
|
|
${RUST_TESTS} \
|
|
|
|
${ASSEMBLYSCRIPT_TESTS} \
|
|
|
|
${THREAD_PROPOSAL_TESTS} \
|
|
|
|
${THREAD_INTERNAL_TESTS} \
|
|
|
|
${LIB_SOCKET_TESTS}"
|
|
|
|
|
|
|
|
if [ -n "$TEST_FILTER" ]; then
|
|
|
|
TEST_OPTIONS="${TEST_OPTIONS} --exclude-filter ${TEST_FILTER}"
|
|
|
|
fi
|
|
|
|
|
2023-11-09 02:13:59 +00:00
|
|
|
$PYTHON_EXE ${THIS_DIR}/pipe.py | TSAN_OPTIONS=${TSAN_OPTIONS} $PYTHON_EXE test-runner/wasi_test_runner.py $TEST_OPTIONS
|
2023-08-01 09:38:37 +00:00
|
|
|
|
2023-09-23 02:28:18 +00:00
|
|
|
ret=${PIPESTATUS[1]}
|
2023-08-30 11:01:44 +00:00
|
|
|
|
2023-11-09 02:13:59 +00:00
|
|
|
TEST_RUNTIME_EXE="${IWASM_CMD_STRESS}" TSAN_OPTIONS=${TSAN_OPTIONS} $PYTHON_EXE test-runner/wasi_test_runner.py \
|
2023-08-30 11:01:44 +00:00
|
|
|
-r adapters/wasm-micro-runtime.py \
|
|
|
|
-t \
|
|
|
|
${THREAD_STRESS_TESTS}
|
|
|
|
|
|
|
|
if [ "${ret}" -eq 0 ]; then
|
|
|
|
ret=${PIPESTATUS[0]}
|
2023-08-01 09:38:37 +00:00
|
|
|
fi
|
2023-11-09 02:13:59 +00:00
|
|
|
|
2023-08-30 11:01:44 +00:00
|
|
|
exit_code=${ret}
|
2023-11-09 02:13:59 +00:00
|
|
|
|
2023-02-27 12:28:37 +00:00
|
|
|
deactivate
|
|
|
|
else
|
|
|
|
target_option=""
|
|
|
|
if [[ $TARGET == "X86_32" ]];then
|
|
|
|
target_option="--target=i386"
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit_code=0
|
2023-08-30 11:01:44 +00:00
|
|
|
for testsuite in ${THREAD_STRESS_TESTS} ${THREAD_PROPOSAL_TESTS} ${THREAD_INTERNAL_TESTS}; do
|
2023-03-16 00:22:03 +00:00
|
|
|
tests=$(ls ${testsuite}*.wasm)
|
|
|
|
tests_array=($tests)
|
2023-11-06 11:24:06 +00:00
|
|
|
|
|
|
|
if [ -n "$TEST_FILTER" ]; then
|
|
|
|
readarray -t excluded_tests_array < <(jq -c \
|
|
|
|
--slurpfile testsuite_manifest $testsuite/manifest.json \
|
|
|
|
'.[$testsuite_manifest[0].name] // {} | keys[]' \
|
|
|
|
$TEST_FILTER)
|
|
|
|
else
|
|
|
|
excluded_tests_array=()
|
|
|
|
fi
|
|
|
|
|
|
|
|
run_aot_tests tests_array excluded_tests_array
|
2023-02-27 12:28:37 +00:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
2023-08-23 09:05:19 +00:00
|
|
|
exit ${exit_code}
|