Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move spec test to the last commit of Apr.3 #3293

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update spec test to latest commit
- update spec test to commit bc76fd79cfe61033d7f4ad4a7e8fc4f996dc5ba8 on Apr. 3
- upddate wabt binary to 1.0.34 to support newer spec cases
- Add comparision between table declared elem type and elem segment value type
- Add a function to decide whether to execute test cases in a running mode
- keep using interpreter in GC spec because wat2wasm in wabt can't compile if.wast w/o errors
- re-factoring threads spec test case processing
- since wabt 1.0.34 release isn't compatible with ubuntu 20.04, compile
  from source code
  • Loading branch information
lum1n0us committed May 14, 2024
commit 494d7e7902ec0e47e82d8eaa2c9cb734534390d3
18 changes: 11 additions & 7 deletions .github/workflows/compilation_on_sgx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -269,23 +269,24 @@ jobs:
strategy:
matrix:
running_mode: ["classic-interp", "fast-interp", "aot", "fast-jit"]
test_option: ["-x -p -s spec -b -P", "-x -p -s spec -S -b -P", "-x -p -s spec -X -b -P"]
# FIXME: use binary release(adding -b) instead of building from source after upgrading to 22.04
test_option: ["-x -p -s spec -P", "-x -p -s spec -S -P", "-x -p -s spec -X -P"]
llvm_cache_key: ["${{ needs.build_llvm_libraries.outputs.cache_key }}"]
exclude:
# classic-interp, fast-interp and fast-jit don't support simd
- running_mode: "classic-interp"
test_option: "-x -p -s spec -S -b -P"
test_option: "-x -p -s spec -S -P"
- running_mode: "fast-interp"
test_option: "-x -p -s spec -S -b -P"
test_option: "-x -p -s spec -S -P"
- running_mode: "fast-jit"
test_option: "-x -p -s spec -S -b -P"
test_option: "-x -p -s spec -S -P"
# classic-interp, fast-interp and fast jit don't support XIP
- running_mode: "classic-interp"
test_option: "-x -p -s spec -X -b -P"
test_option: "-x -p -s spec -X -P"
- running_mode: "fast-interp"
test_option: "-x -p -s spec -X -b -P"
test_option: "-x -p -s spec -X -P"
- running_mode: "fast-jit"
test_option: "-x -p -s spec -X -b -P"
test_option: "-x -p -s spec -X -P"

steps:
- name: checkout
Expand Down Expand Up @@ -320,6 +321,9 @@ jobs:
sudo apt update
sudo apt install -y libsgx-launch libsgx-urts

- name: install for wabt compilation
run: sudo apt update && sudo apt install -y ninja-build

- name: run spec tests
run: |
source /opt/intel/sgxsdk/environment
Expand Down
12 changes: 8 additions & 4 deletions .github/workflows/nightly_run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ env:
LLVM_EAGER_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_FAST_JIT=0 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=0"
MULTI_TIER_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=1 -DWAMR_BUILD_FAST_JIT=1 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=1"
# For Spec Test
DEFAULT_TEST_OPTIONS: "-s spec -b -P"
MULTI_MODULES_TEST_OPTIONS: "-s spec -b -M -P"
SIMD_TEST_OPTIONS: "-s spec -b -S -P"
THREADS_TEST_OPTIONS: "-s spec -b -p -P"
# FIXME: use binary release(adding -b) instead of building from source after upgrading to 22.04
DEFAULT_TEST_OPTIONS: "-s spec -P"
MULTI_MODULES_TEST_OPTIONS: "-s spec -M -P"
SIMD_TEST_OPTIONS: "-s spec -S -P"
THREADS_TEST_OPTIONS: "-s spec -p -P"
X86_32_TARGET_TEST_OPTIONS: "-m x86_32 -P"
WASI_TEST_OPTIONS: "-s wasi_certification -w"

Expand Down Expand Up @@ -719,6 +720,9 @@ jobs:
if: matrix.running_mode == 'aot' && matrix.test_option == '$WASI_TEST_OPTIONS'
run: sudo apt-get update && sudo apt install -y jq

- name: install for wabt compilation
run: sudo apt update && sudo apt install -y ninja-build

- name: Build WASI thread tests
if: matrix.test_option == '$WASI_TEST_OPTIONS'
run: bash build.sh --sysroot "$SYSROOT_PATH"
Expand Down
23 changes: 12 additions & 11 deletions core/iwasm/aot/aot_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ check_global_init_expr(const AOTModule *module, uint32 global_index,
return false;
}

#if WASM_ENABLE_GC == 0
/**
* Currently, constant expressions occurring as initializers of
* globals are further constrained in that contained global.get
Expand All @@ -129,24 +128,26 @@ check_global_init_expr(const AOTModule *module, uint32 global_index,
* And initializer expression cannot reference a mutable global.
*/
if (global_index >= module->import_global_count
|| module->import_globals->type.is_mutable) {
set_error_buf(error_buf, error_buf_size,
"constant expression required");
return false;
}
#else
if (global_index >= module->import_global_count + module->global_count) {
/* make spec test happy */
#if WASM_ENABLE_GC != 0
+ module->global_count
#endif
) {
set_error_buf_v(error_buf, error_buf_size, "unknown global %u",
global_index);
return false;
}
if (global_index < module->import_global_count
&& module->import_globals[global_index].type.is_mutable) {

if (
/* make spec test happy */
#if WASM_ENABLE_GC != 0
global_index < module->import_global_count &&
#endif
module->import_globals[global_index].type.is_mutable) {
set_error_buf(error_buf, error_buf_size,
"constant expression required");
return false;
}
#endif

return true;
}
Expand Down
101 changes: 77 additions & 24 deletions core/iwasm/interpreter/wasm_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -830,39 +830,35 @@ load_init_expr(WASMModule *module, const uint8 **p_buf, const uint8 *buf_end,
read_leb_uint32(p, p_end, cur_value.global_index);
global_idx = cur_value.global_index;

#if WASM_ENABLE_GC == 0
if (global_idx >= module->import_global_count) {
/**
* Currently, constant expressions occurring as initializers
* of globals are further constrained in that contained
* global.get instructions are
* only allowed to refer to imported globals.
*/
/*
* Currently, constant expressions occurring as initializers
* of globals are further constrained in that contained
* global.get instructions are
* only allowed to refer to imported globals.
*
* https://webassembly.github.io/spec/core/valid/instructions.html#constant-expressions
*/
if (global_idx >= module->import_global_count
/* make spec test happy */
#if WASM_ENABLE_GC != 0
+ module->global_count
#endif
) {
set_error_buf_v(error_buf, error_buf_size,
"unknown global %u", global_idx);
goto fail;
}
if (module->import_globals[global_idx]
if (
/* make spec test happy */
#if WASM_ENABLE_GC != 0
global_idx < module->import_global_count &&
#endif
module->import_globals[global_idx]
.u.global.type.is_mutable) {
set_error_buf_v(error_buf, error_buf_size,
"constant expression required");
goto fail;
}
#else
if (global_idx
>= module->import_global_count + module->global_count) {
set_error_buf_v(error_buf, error_buf_size,
"unknown global %u", global_idx);
goto fail;
}
if (global_idx < module->import_global_count
&& module->import_globals[global_idx]
.u.global.type.is_mutable) {
set_error_buf_v(error_buf, error_buf_size,
"constant expression required");
goto fail;
}
#endif

if (global_idx < module->import_global_count) {
global_type = module->import_globals[global_idx]
Expand Down Expand Up @@ -4244,6 +4240,43 @@ load_table_index(const uint8 **p_buf, const uint8 *buf_end, WASMModule *module,
return false;
}

/* Element segments must match element type of table */
static bool
check_table_elem_type(WASMModule *module, uint32 table_index,
uint32 type_from_elem_seg, char *error_buf,
uint32 error_buf_size)
{
uint32 table_declared_elem_type;

if (table_index < module->import_table_count)
table_declared_elem_type =
module->import_tables[table_index].u.table.elem_type;
else
table_declared_elem_type = (module->tables + table_index)->elem_type;

if (table_declared_elem_type == type_from_elem_seg)
return true;

#if WASM_ENABLE_GC != 0
/*
* balance in: anyref, funcref, (ref.null func) and (ref.func)
*/
if (table_declared_elem_type == REF_TYPE_ANYREF)
return true;

if (table_declared_elem_type == VALUE_TYPE_FUNCREF
&& type_from_elem_seg == REF_TYPE_HT_NON_NULLABLE)
return true;

if (table_declared_elem_type == REF_TYPE_HT_NULLABLE
&& type_from_elem_seg == REF_TYPE_HT_NON_NULLABLE)
return true;
#endif

set_error_buf(error_buf, error_buf_size, "type mismatch");
return false;
}

#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0
static bool
load_elem_type(WASMModule *module, const uint8 **p_buf, const uint8 *buf_end,
Expand Down Expand Up @@ -4479,6 +4512,12 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end,
return false;
}

if (!check_table_elem_type(module,
table_segment->table_index,
table_segment->elem_type,
error_buf, error_buf_size))
return false;

break;
}
/* elemkind + passive/declarative */
Expand Down Expand Up @@ -4530,6 +4569,13 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end,
error_buf_size))
return false;
}

if (!check_table_elem_type(module,
table_segment->table_index,
table_segment->elem_type,
error_buf, error_buf_size))
return false;

break;
case 5:
case 7:
Expand Down Expand Up @@ -4566,6 +4612,13 @@ load_table_segment_section(const uint8 *buf, const uint8 *buf_end,
if (!load_func_index_vec(&p, p_end, module, table_segment,
error_buf, error_buf_size))
return false;

table_segment->elem_type = VALUE_TYPE_FUNCREF;

if (!check_table_elem_type(module, table_segment->table_index,
table_segment->elem_type, error_buf,
error_buf_size))
return false;
#endif /* end of WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 */

#if WASM_ENABLE_WAMR_COMPILER != 0
Expand Down
8 changes: 8 additions & 0 deletions core/iwasm/libraries/libc-builtin/libc_builtin_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,12 @@ print_i32_wrapper(wasm_exec_env_t exec_env, int32 i32)
os_printf("in specttest.print_i32(%" PRId32 ")\n", i32);
}

static void
print_i64_wrapper(wasm_exec_env_t exec_env, int64 i64)
{
os_printf("in specttest.print_i64(%" PRId32 ")\n", i64);
}

static void
print_i32_f32_wrapper(wasm_exec_env_t exec_env, int32 i32, float f32)
{
Expand Down Expand Up @@ -1091,6 +1097,7 @@ static NativeSymbol native_symbols_libc_builtin[] = {
static NativeSymbol native_symbols_spectest[] = {
REG_NATIVE_FUNC(print, "()"),
REG_NATIVE_FUNC(print_i32, "(i)"),
REG_NATIVE_FUNC(print_i64, "(I)"),
REG_NATIVE_FUNC(print_i32_f32, "(if)"),
REG_NATIVE_FUNC(print_f64_f64, "(FF)"),
REG_NATIVE_FUNC(print_f32, "(f)"),
Expand Down Expand Up @@ -1136,6 +1143,7 @@ static WASMNativeGlobalDef native_global_defs[] = {
{ "test", "global-f32", VALUE_TYPE_F32, false, .value.f32 = 0 },
{ "test", "global-mut-i32", VALUE_TYPE_I32, true, .value.i32 = 0 },
{ "test", "global-mut-i64", VALUE_TYPE_I64, true, .value.i64 = 0 },
{ "test", "g", VALUE_TYPE_I32, true, .value.i32 = 0 },
#if WASM_ENABLE_GC != 0
{ "G", "g", VALUE_TYPE_I32, false, .value.i32 = 4 },
{ "M", "g", REF_TYPE_HT_NON_NULLABLE, false, .value.gc_obj = 0 },
Expand Down
19 changes: 6 additions & 13 deletions tests/wamr-test-suites/spec-test-script/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def get_iwasm_cmd(platform: str) -> str:
IWASM_SGX_CMD = "../../../product-mini/platforms/linux-sgx/enclave-sample/iwasm"
IWASM_QEMU_CMD = "iwasm"
SPEC_TEST_DIR = "spec/test/core"
EXCE_HANDLING_DIR = "exception-handling/test/core"
WAST2WASM_CMD = exe_file_path("./wabt/out/gcc/Release/wat2wasm")
SPEC_INTERPRETER_CMD = "spec/interpreter/wasm"
WAMRC_CMD = "../../../wamr-compiler/build/wamrc"
Expand Down Expand Up @@ -87,7 +86,7 @@ def ignore_the_case(
if case_name in ["comments", "inline-module", "names"]:
return True

if not multi_module_flag and case_name in ["imports", "linking"]:
if not multi_module_flag and case_name in ["imports", "linking", "simd_linking"]:
return True

# Note: x87 doesn't preserve sNaN and makes some relevant tests fail.
Expand Down Expand Up @@ -143,10 +142,6 @@ def preflight_check(aot_flag, eh_flag):
print(f"Can not find {WAMRC_CMD}")
return False

if eh_flag and not pathlib.Path(EXCE_HANDLING_DIR).resolve().exists():
print(f"Can not find {EXCE_HANDLING_DIR}")
return False

return True


Expand All @@ -171,7 +166,7 @@ def test_case(
):
CMD = [sys.executable, "runtest.py"]
CMD.append("--wast2wasm")
CMD.append(WAST2WASM_CMD if not gc_flag and not memory64_flag else SPEC_INTERPRETER_CMD)
CMD.append(WAST2WASM_CMD if not gc_flag else SPEC_INTERPRETER_CMD)
CMD.append("--interpreter")
if sgx_flag:
CMD.append(IWASM_SGX_CMD)
Expand Down Expand Up @@ -310,11 +305,7 @@ def test_suite(
case_list.extend(gc_case_list)

if eh_flag:
eh_path = pathlib.Path(EXCE_HANDLING_DIR).resolve()
if not eh_path.exists():
print(f"can not find spec test cases at {eh_path}")
return False
eh_case_list = sorted(eh_path.glob("*.wast"))
eh_case_list = sorted(suite_path.glob("*.wast"))
eh_case_list_include = [test for test in eh_case_list if test.stem in ["throw", "tag", "try_catch", "rethrow", "try_delegate"]]
case_list.extend(eh_case_list_include)

Expand All @@ -337,7 +328,9 @@ def test_suite(
qemu_flag,
):
filtered_case_list.append(case_path)
print(f"---> {len(case_list)} --filter--> {len(filtered_case_list)}")
else:
print(f"---> skip {case_name}")
print(f"---> {len(case_list)} ---filter--> {len(filtered_case_list)}")
case_list = filtered_case_list

case_count = len(case_list)
Expand Down
Loading
Loading