From 118c734187c2d61922134f0d949ba41bfdbdf9cb Mon Sep 17 00:00:00 2001 From: lum1n0us Date: Tue, 20 Jan 2026 20:52:56 -0800 Subject: [PATCH 01/16] Fix a compilation error by clang-17 ``` variable-sized object may not be initialized ``` clang-17 is the default version on MacOS Tahoe(26.2) on AppleM1 --- tests/unit/shared-heap/shared_heap_test.cc | 214 ++++++++++++++++----- 1 file changed, 169 insertions(+), 45 deletions(-) diff --git a/tests/unit/shared-heap/shared_heap_test.cc b/tests/unit/shared-heap/shared_heap_test.cc index 4b5a8e991b..6aa933d0f1 100644 --- a/tests/unit/shared-heap/shared_heap_test.cc +++ b/tests/unit/shared-heap/shared_heap_test.cc @@ -11,6 +11,7 @@ #include "bh_platform.h" #include +#include class shared_heap_test : public testing::Test { @@ -195,10 +196,15 @@ TEST_F(shared_heap_test, test_preallocated_shared_heap_malloc_fail) SharedHeapInitArgs args = {}; WASMSharedHeap *shared_heap = nullptr; uint32 argv[1] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); /* create a preallocated shared heap */ - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; args.size = BUF_SIZE; shared_heap = wasm_runtime_create_shared_heap(&args); if (!shared_heap) { @@ -329,10 +335,15 @@ TEST_F(shared_heap_test, test_shared_heap_rmw) { WASMSharedHeap *shared_heap = nullptr; uint32 argv[2] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE] = {}; + uint8 *preallocated_buf_ptr = nullptr; uint32 start1, end1; - create_test_shared_heap(preallocated_buf, BUF_SIZE, &shared_heap); + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + + create_test_shared_heap(preallocated_buf_ptr, BUF_SIZE, &shared_heap); /* app addr for shared heap */ start1 = UINT32_MAX - BUF_SIZE + 1; @@ -368,11 +379,21 @@ TEST_F(shared_heap_test, test_shared_heap_chain_rmw) SharedHeapInitArgs args = {}; WASMSharedHeap *shared_heap_chain = nullptr; uint32 argv[2] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE] = {}, preallocated_buf2[BUF_SIZE] = {}; + uint8 *preallocated_buf_ptr = nullptr; + uint8 *preallocated_buf2_ptr = nullptr; uint32 start1, end1, start2, end2; - create_test_shared_heap_chain(preallocated_buf, BUF_SIZE, preallocated_buf2, - BUF_SIZE, &shared_heap_chain); + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + std::vector preallocated_buf2(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + preallocated_buf2_ptr = preallocated_buf2.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + ASSERT_NE(preallocated_buf2_ptr, nullptr); + + create_test_shared_heap_chain(preallocated_buf_ptr, BUF_SIZE, + preallocated_buf2_ptr, BUF_SIZE, + &shared_heap_chain); /* app addr for shared heap */ start1 = UINT32_MAX - 2 * BUF_SIZE + 1; @@ -416,11 +437,21 @@ TEST_F(shared_heap_test, test_shared_heap_chain_rmw_bulk_memory) SharedHeapInitArgs args = {}; WASMSharedHeap *shared_heap_chain = nullptr; uint32 argv[3] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE] = {}, preallocated_buf2[BUF_SIZE] = {}; + uint8 *preallocated_buf_ptr = nullptr; + uint8 *preallocated_buf2_ptr = nullptr; uint32 start1, end1, start2, end2; - create_test_shared_heap_chain(preallocated_buf, BUF_SIZE, preallocated_buf2, - BUF_SIZE, &shared_heap_chain); + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + std::vector preallocated_buf2(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + preallocated_buf2_ptr = preallocated_buf2.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + ASSERT_NE(preallocated_buf2_ptr, nullptr); + + create_test_shared_heap_chain(preallocated_buf_ptr, BUF_SIZE, + preallocated_buf2_ptr, BUF_SIZE, + &shared_heap_chain); /* app addr for shared heap */ start1 = UINT32_MAX - 2 * BUF_SIZE + 1; @@ -471,11 +502,21 @@ TEST_F(shared_heap_test, test_shared_heap_chain_rmw_bulk_memory_oob) SharedHeapInitArgs args = {}; WASMSharedHeap *shared_heap_chain = nullptr; uint32 argv[3] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE] = {}, preallocated_buf2[BUF_SIZE] = {}; + uint8 *preallocated_buf_ptr = nullptr; + uint8 *preallocated_buf2_ptr = nullptr; uint32 start1, end1, start2, end2; - create_test_shared_heap_chain(preallocated_buf, BUF_SIZE, preallocated_buf2, - BUF_SIZE, &shared_heap_chain); + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + std::vector preallocated_buf2(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + preallocated_buf2_ptr = preallocated_buf2.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + ASSERT_NE(preallocated_buf2_ptr, nullptr); + + create_test_shared_heap_chain(preallocated_buf_ptr, BUF_SIZE, + preallocated_buf2_ptr, BUF_SIZE, + &shared_heap_chain); /* app addr for shared heap */ start1 = UINT32_MAX - 2 * BUF_SIZE + 1; @@ -553,10 +594,19 @@ TEST_F(shared_heap_test, test_shared_heap_rmw_oob) { WASMSharedHeap *shared_heap = nullptr; uint32 argv[2] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE], preallocated_buf2[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + uint8 *preallocated_buf2_ptr = nullptr; uint32 start1, end1, start2, end2; - create_test_shared_heap(preallocated_buf, BUF_SIZE, &shared_heap); + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + std::vector preallocated_buf2(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + preallocated_buf2_ptr = preallocated_buf2.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + ASSERT_NE(preallocated_buf2_ptr, nullptr); + + create_test_shared_heap(preallocated_buf_ptr, BUF_SIZE, &shared_heap); /* app addr for shared heap */ start1 = UINT32_MAX - BUF_SIZE + 1; @@ -587,11 +637,21 @@ TEST_F(shared_heap_test, test_shared_heap_chain_rmw_oob) { WASMSharedHeap *shared_heap_chain = nullptr; uint32 argv[2] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE], preallocated_buf2[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + uint8 *preallocated_buf2_ptr = nullptr; uint32 start1, end1, start2, end2; - create_test_shared_heap_chain(preallocated_buf, BUF_SIZE, preallocated_buf2, - BUF_SIZE, &shared_heap_chain); + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + std::vector preallocated_buf2(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + preallocated_buf2_ptr = preallocated_buf2.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + ASSERT_NE(preallocated_buf2_ptr, nullptr); + + create_test_shared_heap_chain(preallocated_buf_ptr, BUF_SIZE, + preallocated_buf2_ptr, BUF_SIZE, + &shared_heap_chain); /* app addr for shared heap */ start1 = UINT32_MAX - 2 * BUF_SIZE + 1; @@ -620,11 +680,21 @@ TEST_F(shared_heap_test, test_shared_heap_chain_memory64_rmw) { WASMSharedHeap *shared_heap_chain = nullptr; uint32 argv[3] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE] = {}, preallocated_buf2[BUF_SIZE] = {}; + uint8 *preallocated_buf_ptr = nullptr; + uint8 *preallocated_buf2_ptr = nullptr; uint64 start1, end1, start2, end2; - create_test_shared_heap_chain(preallocated_buf, BUF_SIZE, preallocated_buf2, - BUF_SIZE, &shared_heap_chain); + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + std::vector preallocated_buf2(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + preallocated_buf2_ptr = preallocated_buf2.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + ASSERT_NE(preallocated_buf2_ptr, nullptr); + + create_test_shared_heap_chain(preallocated_buf_ptr, BUF_SIZE, + preallocated_buf2_ptr, BUF_SIZE, + &shared_heap_chain); /* app addr for shared heap */ start1 = UINT64_MAX - 2 * BUF_SIZE + 1; @@ -667,11 +737,21 @@ TEST_F(shared_heap_test, test_shared_heap_chain_memory64_rmw_oob) { WASMSharedHeap *shared_heap_chain = nullptr; uint32 argv[3] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE], preallocated_buf2[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + uint8 *preallocated_buf2_ptr = nullptr; uint64 start1, end1, start2, end2; - create_test_shared_heap_chain(preallocated_buf, BUF_SIZE, preallocated_buf2, - BUF_SIZE, &shared_heap_chain); + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + std::vector preallocated_buf2(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + preallocated_buf2_ptr = preallocated_buf2.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + ASSERT_NE(preallocated_buf2_ptr, nullptr); + + create_test_shared_heap_chain(preallocated_buf_ptr, BUF_SIZE, + preallocated_buf2_ptr, BUF_SIZE, + &shared_heap_chain); /* app addr for shared heap */ start1 = UINT64_MAX - 2 * BUF_SIZE + 1; @@ -759,7 +839,11 @@ TEST_F(shared_heap_test, test_addr_conv_pre_allocated_oob) WASMSharedHeap *shared_heap = nullptr; uint32 argv[1] = {}, BUF_SIZE = os_getpagesize(), app_addr = 0xFFFFFFFF - BUF_SIZE; - uint8 preallocated_buf[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); bool ret = false; /* create a preallocated shared heap */ @@ -769,7 +853,7 @@ TEST_F(shared_heap_test, test_addr_conv_pre_allocated_oob) FAIL() << "Failed to register natives"; } - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; args.size = BUF_SIZE; shared_heap = wasm_runtime_create_shared_heap(&args); if (!shared_heap) { @@ -799,7 +883,11 @@ TEST_F(shared_heap_test, test_shared_heap_chain) WASMSharedHeap *shared_heap = nullptr, *shared_heap2 = nullptr, *shared_heap_chain = nullptr; uint32 argv[1] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); bool ret = false; ret = wasm_native_register_natives("env", g_test_native_symbols, @@ -816,7 +904,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain) /* create a preallocated shared heap */ memset(&args, 0, sizeof(args)); - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; args.size = BUF_SIZE; shared_heap2 = wasm_runtime_create_shared_heap(&args); if (!shared_heap2) { @@ -865,7 +953,11 @@ TEST_F(shared_heap_test, test_shared_heap_chain_create_fail2) WASMSharedHeap *shared_heap = nullptr, *shared_heap2 = nullptr, *shared_heap_chain = nullptr; uint32 argv[1] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); struct ret_env tmp_module_env; args.size = 1024; @@ -875,7 +967,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain_create_fail2) } memset(&args, 0, sizeof(args)); - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; args.size = BUF_SIZE; shared_heap2 = wasm_runtime_create_shared_heap(&args); if (!shared_heap2) { @@ -907,7 +999,15 @@ TEST_F(shared_heap_test, test_shared_heap_chain_create_fail3) WASMSharedHeap *shared_heap = nullptr, *shared_heap2 = nullptr, *shared_heap3 = nullptr, *shared_heap_chain = nullptr; uint32 argv[1] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE], preallocated_buf2[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + uint8 *preallocated_buf2_ptr = nullptr; + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + std::vector preallocated_buf2(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + preallocated_buf2_ptr = preallocated_buf2.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + ASSERT_NE(preallocated_buf2_ptr, nullptr); args.size = 1024; shared_heap = wasm_runtime_create_shared_heap(&args); @@ -916,7 +1016,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain_create_fail3) } memset(&args, 0, sizeof(args)); - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; args.size = BUF_SIZE; shared_heap2 = wasm_runtime_create_shared_heap(&args); if (!shared_heap2) { @@ -930,7 +1030,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain_create_fail3) } memset(&args, 0, sizeof(args)); - args.pre_allocated_addr = preallocated_buf2; + args.pre_allocated_addr = preallocated_buf2_ptr; args.size = BUF_SIZE; shared_heap3 = wasm_runtime_create_shared_heap(&args); if (!shared_heap3) { @@ -952,7 +1052,15 @@ TEST_F(shared_heap_test, test_shared_heap_chain_unchain) WASMSharedHeap *shared_heap = nullptr, *shared_heap2 = nullptr, *shared_heap3 = nullptr, *shared_heap_chain = nullptr; uint32 argv[1] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE], preallocated_buf2[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + uint8 *preallocated_buf2_ptr = nullptr; + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + std::vector preallocated_buf2(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + preallocated_buf2_ptr = preallocated_buf2.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); + ASSERT_NE(preallocated_buf2_ptr, nullptr); args.size = 1024; shared_heap = wasm_runtime_create_shared_heap(&args); @@ -961,7 +1069,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain_unchain) } memset(&args, 0, sizeof(args)); - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; args.size = BUF_SIZE; shared_heap2 = wasm_runtime_create_shared_heap(&args); if (!shared_heap2) { @@ -975,7 +1083,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain_unchain) } memset(&args, 0, sizeof(args)); - args.pre_allocated_addr = preallocated_buf2; + args.pre_allocated_addr = preallocated_buf2_ptr; args.size = BUF_SIZE; shared_heap3 = wasm_runtime_create_shared_heap(&args); if (!shared_heap3) { @@ -1007,7 +1115,11 @@ TEST_F(shared_heap_test, test_shared_heap_chain_reset_runtime_managed) uint64 offset = 0, offset_after_reset = 0; void *native_ptr = nullptr, *native_ptr_after_reset = nullptr; uint32 argv[1] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); struct ret_env tmp_module_env; args.size = 4096; @@ -1017,7 +1129,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain_reset_runtime_managed) } args.size = BUF_SIZE; - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; shared_heap2 = wasm_runtime_create_shared_heap(&args); if (!shared_heap2) { FAIL() << "Failed to create second shared heap"; @@ -1085,17 +1197,21 @@ TEST_F(shared_heap_test, test_shared_heap_chain_reset_preallocated) SharedHeapInitArgs args = {}; WASMSharedHeap *shared_heap = nullptr; uint32 BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); uint8 set_val = 0xA5; - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; args.size = BUF_SIZE; shared_heap = wasm_runtime_create_shared_heap(&args); if (!shared_heap) { FAIL() << "Create preallocated shared heap failed.\n"; } - memset(preallocated_buf, set_val, BUF_SIZE); + memset(preallocated_buf_ptr, set_val, BUF_SIZE); for (uint32 i = 0; i < BUF_SIZE; i++) { EXPECT_EQ(set_val, preallocated_buf[i]); } @@ -1146,7 +1262,11 @@ TEST_F(shared_heap_test, test_shared_heap_chain_addr_conv) WASMSharedHeap *shared_heap = nullptr, *shared_heap2 = nullptr, *shared_heap_chain = nullptr; uint32 argv[1] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); bool ret = false; ret = wasm_native_register_natives("env", g_test_native_symbols, @@ -1163,7 +1283,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain_addr_conv) /* create a preallocated shared heap */ memset(&args, 0, sizeof(args)); - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; args.size = BUF_SIZE; shared_heap2 = wasm_runtime_create_shared_heap(&args); if (!shared_heap2) { @@ -1203,7 +1323,11 @@ TEST_F(shared_heap_test, test_shared_heap_chain_addr_conv_oob) WASMSharedHeap *shared_heap = nullptr, *shared_heap2 = nullptr, *shared_heap_chain = nullptr; uint32 argv[1] = {}, BUF_SIZE = os_getpagesize(); - uint8 preallocated_buf[BUF_SIZE]; + uint8 *preallocated_buf_ptr = nullptr; + ASSERT_GT(BUF_SIZE, 0u); + std::vector preallocated_buf(BUF_SIZE); + preallocated_buf_ptr = preallocated_buf.data(); + ASSERT_NE(preallocated_buf_ptr, nullptr); bool ret = false; ret = wasm_native_register_natives("env", g_test_native_symbols, @@ -1220,7 +1344,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain_addr_conv_oob) /* create a preallocated shared heap */ memset(&args, 0, sizeof(args)); - args.pre_allocated_addr = preallocated_buf; + args.pre_allocated_addr = preallocated_buf_ptr; args.size = BUF_SIZE; shared_heap2 = wasm_runtime_create_shared_heap(&args); if (!shared_heap2) { From 6db04d64964a684b5c39e9f0b0e04f774e3bf4bb Mon Sep 17 00:00:00 2001 From: lum1n0us Date: Mon, 2 Feb 2026 21:31:49 -0800 Subject: [PATCH 02/16] refactor: modernize wasm-apps CMakeLists.txt to target-specific options and install commands --- .../unit/shared-heap/wasm-apps/CMakeLists.txt | 129 +++++++----------- 1 file changed, 47 insertions(+), 82 deletions(-) diff --git a/tests/unit/shared-heap/wasm-apps/CMakeLists.txt b/tests/unit/shared-heap/wasm-apps/CMakeLists.txt index 985cf18aeb..f748c27675 100644 --- a/tests/unit/shared-heap/wasm-apps/CMakeLists.txt +++ b/tests/unit/shared-heap/wasm-apps/CMakeLists.txt @@ -5,8 +5,6 @@ cmake_minimum_required(VERSION 3.14) project(wasm-apps) set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../..) -set(WAMRC_ROOT_DIR ${WAMR_ROOT_DIR}/wamr-compiler/build) - set(CMAKE_SYSTEM_PROCESSOR wasm32) set(CMAKE_SYSROOT ${WAMR_ROOT_DIR}/wamr-sdk/app/libc-builtin-sysroot) @@ -14,96 +12,63 @@ if (NOT DEFINED WASI_SDK_DIR) set(WASI_SDK_DIR "/opt/wasi-sdk") endif () -set(CMAKE_C_FLAGS "-nostdlib -pthread -Qunused-arguments") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -z stack-size=8192 -nostdlib -O0") -set(CMAKE_C_COMPILER_TARGET "wasm32") -set(CMAKE_C_COMPILER "${WASI_SDK_DIR}/bin/clang") - -set(DEFINED_SYMBOLS - "${WAMR_ROOT_DIR}/wamr-sdk/app/libc-builtin-sysroot/share/defined-symbols.txt") - -set(CMAKE_EXE_LINKER_FLAGS - "-Wl,--no-entry \ - -Wl,--initial-memory=65536 \ - -Wl,--export-all \ - -Wl,--allow-undefined" - ) +# Find WAMRC +set(WAMRC_ROOT_DIR ${WAMR_ROOT_DIR}/wamr-compiler) +file(REAL_PATH ${WAMRC_ROOT_DIR}/build/wamrc WAMRC_BIN) +# Set architecture-specific WAMRC flags if (WAMR_BUILD_TARGET STREQUAL "X86_32") - set (WAMR_COMPILER_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-heap --target=i386) - set (WAMR_COMPILER_CHAIN_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-chain --target=i386) + set(WAMRC_SHARED_HEAP_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-heap --target=i386) + set(WAMRC_SHARED_HEAP_CHAIN_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-chain --target=i386) else () - set (WAMR_COMPILER_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-heap) - set (WAMR_COMPILER_CHAIN_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-chain) + set(WAMRC_SHARED_HEAP_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-heap) + set(WAMRC_SHARED_HEAP_CHAIN_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-chain) endif () -function(copy_wasm TARGET_NAME) - add_custom_command(TARGET ${TARGET_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME} - ${CMAKE_CURRENT_BINARY_DIR}/../ - COMMENT "Copy ${TARGET_NAME} to the same directory of google test" - ) -endfunction() - -function(compile_and_copy_aot_from TARGET_NAME) - string(REPLACE ".wasm" ".aot" AOT_TARGET ${TARGET_NAME}) - string(REPLACE ".wasm" "_chain.aot" AOT_CHAIN_TARGET ${TARGET_NAME}) - - add_custom_command(TARGET ${TARGET_NAME} POST_BUILD - COMMAND ${WAMRC_ROOT_DIR}/wamrc ${WAMR_COMPILER_FLAGS} - -o ${AOT_TARGET} - ${TARGET_NAME} - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_BINARY_DIR}/${AOT_TARGET} - ${CMAKE_CURRENT_BINARY_DIR}/../ - COMMAND ${WAMRC_ROOT_DIR}/wamrc ${WAMR_COMPILER_CHAIN_FLAGS} - -o ${AOT_CHAIN_TARGET} - ${TARGET_NAME} - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_BINARY_DIR}/${AOT_CHAIN_TARGET} - ${CMAKE_CURRENT_BINARY_DIR}/../ - COMMENT "Compile and copy ${AOT_TARGET} to the same directory of google test" - ) -endfunction() - add_executable(test.wasm test.c) -target_link_libraries(test.wasm) -copy_wasm(test.wasm) -compile_and_copy_aot_from(test.wasm) +target_compile_options(test.wasm PUBLIC -nostdlib -O0 -pthread) +target_link_options(test.wasm PRIVATE + -nostdlib + -z stack-size=8192 + LINKER:--no-entry + LINKER:--initial-memory=65536 + LINKER:--export-all + LINKER:--allow-undefined +) add_executable(test_addr_conv.wasm test_addr_conv.c) -target_link_libraries(test_addr_conv.wasm) -copy_wasm(test_addr_conv.wasm) -compile_and_copy_aot_from(test_addr_conv.wasm) - -# copy and compile aot for bulk memory test -set(SOURCE_WASM ${CMAKE_CURRENT_SOURCE_DIR}/bulk-memory/test_bulk_memory.wasm) -set(BUILD_WASM ${CMAKE_CURRENT_BINARY_DIR}/../test_bulk_memory.wasm) -set(OUTPUT_AOT ${CMAKE_CURRENT_BINARY_DIR}/../test_bulk_memory.aot) -set(OUTPUT_CHAIN_AOT ${CMAKE_CURRENT_BINARY_DIR}/../test_bulk_memory_chain.aot) - -add_custom_command( - OUTPUT ${BUILD_WASM} - COMMAND ${CMAKE_COMMAND} -E copy - ${SOURCE_WASM} - ${BUILD_WASM} - DEPENDS ${SOURCE_WASM} - COMMENT "Copying bulk memory WASM to build directory" +target_compile_options(test_addr_conv.wasm PUBLIC -nostdlib -O0 -pthread) +target_link_options(test_addr_conv.wasm PRIVATE + -nostdlib + -z stack-size=8192 + LINKER:--no-entry + LINKER:--initial-memory=65536 + LINKER:--export-all + LINKER:--allow-undefined ) -add_custom_command( - OUTPUT ${OUTPUT_AOT} - COMMAND ${WAMRC_ROOT_DIR}/wamrc ${WAMR_COMPILER_FLAGS} - -o ${OUTPUT_AOT} - ${BUILD_WASM} - COMMAND ${WAMRC_ROOT_DIR}/wamrc ${WAMR_COMPILER_CHAIN_FLAGS} - -o ${OUTPUT_CHAIN_AOT} - ${BUILD_WASM} - DEPENDS ${BUILD_WASM} - COMMENT "Compiling bulk memory AOT from copied WASM" +# Compile AOT files (combined target) +add_custom_target(compile_aot ALL + COMMAND ${WAMRC_BIN} ${WAMRC_SHARED_HEAP_FLAGS} -o test.aot test.wasm + COMMAND ${WAMRC_BIN} ${WAMRC_SHARED_HEAP_CHAIN_FLAGS} -o test_chain.aot test.wasm + COMMAND ${WAMRC_BIN} ${WAMRC_SHARED_HEAP_FLAGS} -o test_addr_conv.aot test_addr_conv.wasm + COMMAND ${WAMRC_BIN} ${WAMRC_SHARED_HEAP_CHAIN_FLAGS} -o test_addr_conv_chain.aot test_addr_conv.wasm + DEPENDS test.wasm test_addr_conv.wasm + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) -add_custom_target(compile_bulk_memory_aot ALL - DEPENDS ${OUTPUT_AOT} +# Install WASM files +set(WASM_FILES + ${CMAKE_CURRENT_BINARY_DIR}/test.wasm + ${CMAKE_CURRENT_BINARY_DIR}/test_addr_conv.wasm +) +install(FILES ${WASM_FILES} DESTINATION .) + +# Install AOT files +set(AOT_FILES + ${CMAKE_CURRENT_BINARY_DIR}/test.aot + ${CMAKE_CURRENT_BINARY_DIR}/test_chain.aot + ${CMAKE_CURRENT_BINARY_DIR}/test_addr_conv.aot + ${CMAKE_CURRENT_BINARY_DIR}/test_addr_conv_chain.aot ) +install(FILES ${AOT_FILES} DESTINATION .) From f6101c507c38c74b404478b254503b8c9a6b5412 Mon Sep 17 00:00:00 2001 From: lum1n0us Date: Mon, 2 Feb 2026 21:35:14 -0800 Subject: [PATCH 03/16] Fix spec compliance in wasm-apps CMakeLists.txt - Change WAMRC_BIN finding from file(REAL_PATH) to find_program() as per spec - Remove -z stack-size=8192 from test.wasm target_link_options - Remove -z stack-size=8192 from test_addr_conv.wasm target_link_options --- tests/unit/shared-heap/wasm-apps/CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/unit/shared-heap/wasm-apps/CMakeLists.txt b/tests/unit/shared-heap/wasm-apps/CMakeLists.txt index f748c27675..6e30b35e35 100644 --- a/tests/unit/shared-heap/wasm-apps/CMakeLists.txt +++ b/tests/unit/shared-heap/wasm-apps/CMakeLists.txt @@ -14,7 +14,7 @@ endif () # Find WAMRC set(WAMRC_ROOT_DIR ${WAMR_ROOT_DIR}/wamr-compiler) -file(REAL_PATH ${WAMRC_ROOT_DIR}/build/wamrc WAMRC_BIN) +find_program(WAMRC_BIN wamrc HINTS ${WAMRC_ROOT_DIR}/build REQUIRED) # Set architecture-specific WAMRC flags if (WAMR_BUILD_TARGET STREQUAL "X86_32") @@ -29,7 +29,6 @@ add_executable(test.wasm test.c) target_compile_options(test.wasm PUBLIC -nostdlib -O0 -pthread) target_link_options(test.wasm PRIVATE -nostdlib - -z stack-size=8192 LINKER:--no-entry LINKER:--initial-memory=65536 LINKER:--export-all @@ -40,7 +39,6 @@ add_executable(test_addr_conv.wasm test_addr_conv.c) target_compile_options(test_addr_conv.wasm PUBLIC -nostdlib -O0 -pthread) target_link_options(test_addr_conv.wasm PRIVATE -nostdlib - -z stack-size=8192 LINKER:--no-entry LINKER:--initial-memory=65536 LINKER:--export-all From ffe7829f0f5869f455582fa7360642dbc25daa54 Mon Sep 17 00:00:00 2001 From: lum1n0us Date: Mon, 2 Feb 2026 21:39:09 -0800 Subject: [PATCH 04/16] feat: add CMakeLists.txt for bulk-memory test --- .../wasm-apps/bulk-memory/CMakeLists.txt | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/unit/shared-heap/wasm-apps/bulk-memory/CMakeLists.txt diff --git a/tests/unit/shared-heap/wasm-apps/bulk-memory/CMakeLists.txt b/tests/unit/shared-heap/wasm-apps/bulk-memory/CMakeLists.txt new file mode 100644 index 0000000000..b917a94323 --- /dev/null +++ b/tests/unit/shared-heap/wasm-apps/bulk-memory/CMakeLists.txt @@ -0,0 +1,40 @@ +# Copyright (C) 2024 Xiaomi Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +cmake_minimum_required(VERSION 3.14) +project(wasm-apps-bulk-memory) + +# Find WAMRC +set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../..) +set(WAMRC_ROOT_DIR ${WAMR_ROOT_DIR}/wamr-compiler) +find_program(WAMRC_BIN wamrc HINTS ${WAMRC_ROOT_DIR}/build REQUIRED) + +# Set architecture-specific WAMRC flags +if (WAMR_BUILD_TARGET STREQUAL "X86_32") + set(WAMRC_SHARED_HEAP_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-heap --target=i386) + set(WAMRC_SHARED_HEAP_CHAIN_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-chain --target=i386) +else () + set(WAMRC_SHARED_HEAP_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-heap) + set(WAMRC_SHARED_HEAP_CHAIN_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-chain) +endif () + +# Compile AOT files (combined target) +add_custom_target(compile_aot ALL + COMMAND ${WAMRC_BIN} ${WAMRC_SHARED_HEAP_FLAGS} -o test_bulk_memory.aot test_bulk_memory.wasm + COMMAND ${WAMRC_BIN} ${WAMRC_SHARED_HEAP_CHAIN_FLAGS} -o test_bulk_memory_chain.aot test_bulk_memory.wasm + DEPENDS test_bulk_memory.wasm + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} +) + +# Install WASM file +set(WASM_FILES + ${CMAKE_CURRENT_SOURCE_DIR}/test_bulk_memory.wasm +) +install(FILES ${WASM_FILES} DESTINATION .) + +# Install AOT files +set(AOT_FILES + ${CMAKE_CURRENT_BINARY_DIR}/test_bulk_memory.aot + ${CMAKE_CURRENT_BINARY_DIR}/test_bulk_memory_chain.aot +) +install(FILES ${AOT_FILES} DESTINATION .) From afe127aa47c8da15d0677ee9f2f2d4c7b28a7c50 Mon Sep 17 00:00:00 2001 From: lum1n0us Date: Mon, 2 Feb 2026 21:41:24 -0800 Subject: [PATCH 05/16] refactor: modernize memory64 CMakeLists.txt to target-specific options and install commands --- .../wasm-apps/memory64/CMakeLists.txt | 84 ++++++++----------- 1 file changed, 35 insertions(+), 49 deletions(-) diff --git a/tests/unit/shared-heap/wasm-apps/memory64/CMakeLists.txt b/tests/unit/shared-heap/wasm-apps/memory64/CMakeLists.txt index a82788b586..4b59ccba26 100644 --- a/tests/unit/shared-heap/wasm-apps/memory64/CMakeLists.txt +++ b/tests/unit/shared-heap/wasm-apps/memory64/CMakeLists.txt @@ -14,55 +14,41 @@ if (NOT DEFINED WASI_SDK_DIR) set(WASI_SDK_DIR "/opt/wasi-sdk") endif () -set(CMAKE_C_FLAGS "-nostdlib -pthread -Qunused-arguments") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -z stack-size=8192 -nostdlib -O0 --target=wasm64") -set(CMAKE_C_COMPILER_TARGET "wasm64") -set(CMAKE_C_COMPILER "${WASI_SDK_DIR}/bin/clang") +# Find WAMRC +set(WAMRC_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../..) +find_program(WAMRC_BIN wamrc HINTS ${WAMRC_ROOT_DIR}/wamr-compiler/build REQUIRED) -set(DEFINED_SYMBOLS - "${WAMR_ROOT_DIR}/wamr-sdk/app/libc-builtin-sysroot/share/defined-symbols.txt") - -set(CMAKE_EXE_LINKER_FLAGS - "-Wl,--no-entry \ - -Wl,--initial-memory=65536 \ - -Wl,--export-all \ - -Wl,--allow-undefined" - ) - -set (WAMR_COMPILER_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-heap) -set (WAMR_COMPILER_CHAIN_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-chain) - -function(copy_wasm TARGET_NAME) - add_custom_command(TARGET ${TARGET_NAME} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_NAME} - ${CMAKE_CURRENT_BINARY_DIR}/../../ - COMMENT "Copy ${TARGET_NAME} to the same directory of google test" - ) -endfunction() - -function(compile_and_copy_aot_from TARGET_NAME) - string(REPLACE ".wasm" ".aot" AOT_TARGET ${TARGET_NAME}) - string(REPLACE ".wasm" "_chain.aot" AOT_CHAIN_TARGET ${TARGET_NAME}) - - add_custom_command(TARGET ${TARGET_NAME} POST_BUILD - COMMAND ${WAMRC_ROOT_DIR}/wamrc ${WAMR_COMPILER_FLAGS} - -o ${AOT_TARGET} - ${TARGET_NAME} - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_BINARY_DIR}/${AOT_TARGET} - ${CMAKE_CURRENT_BINARY_DIR}/../../ - COMMAND ${WAMRC_ROOT_DIR}/wamrc ${WAMR_COMPILER_CHAIN_FLAGS} - -o ${AOT_CHAIN_TARGET} - ${TARGET_NAME} - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_BINARY_DIR}/${AOT_CHAIN_TARGET} - ${CMAKE_CURRENT_BINARY_DIR}/../../ - COMMENT "Compile and copy ${AOT_TARGET} ${AOT_CHAIN_TARGET} to the same directory of google test" - ) -endfunction() +# Set WAMRC flags for memory64 +set(WAMRC_SHARED_HEAP_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-heap) +set(WAMRC_SHARED_HEAP_CHAIN_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-chain) add_executable(test64.wasm ../test.c) -target_link_libraries(test64.wasm) -copy_wasm(test64.wasm) -compile_and_copy_aot_from(test64.wasm) +target_compile_options(test64.wasm PUBLIC -nostdlib -O0 -pthread --target=wasm64) +target_link_options(test64.wasm PRIVATE + -nostdlib + LINKER:--no-entry + LINKER:--initial-memory=65536 + LINKER:--export-all + LINKER:--allow-undefined +) + +# Compile AOT files (combined target) +add_custom_target(compile_aot ALL + COMMAND ${WAMRC_BIN} ${WAMRC_SHARED_HEAP_FLAGS} -o test64.aot test64.wasm + COMMAND ${WAMRC_BIN} ${WAMRC_SHARED_HEAP_CHAIN_FLAGS} -o test64_chain.aot test64.wasm + DEPENDS test64.wasm + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} +) + +# Install WASM file +set(WASM_FILES + ${CMAKE_CURRENT_BINARY_DIR}/test64.wasm +) +install(FILES ${WASM_FILES} DESTINATION .) + +# Install AOT files +set(AOT_FILES + ${CMAKE_CURRENT_BINARY_DIR}/test64.aot + ${CMAKE_CURRENT_BINARY_DIR}/test64_chain.aot +) +install(FILES ${AOT_FILES} DESTINATION .) From f97671ab493b3f77f4eea069b2c3a7d19dd1875f Mon Sep 17 00:00:00 2001 From: lum1n0us Date: Tue, 3 Feb 2026 15:15:14 -0800 Subject: [PATCH 06/16] Enable Unit test on Mac(m1) - detecting host arch. and platform instead of hard-coding - fix few compilation errors because of stricter rules involve by appleclang --- tests/unit/CMakeLists.txt | 43 +++++++++++++++++-- .../linear_memory_wasm_test.cc | 4 +- tests/unit/linux-perf/CMakeLists.txt | 5 --- tests/unit/linux-perf/test_sort_func_ptrs.cc | 12 ++---- tests/unit/tid-allocator/CMakeLists.txt | 4 -- tests/unit/unit_common.cmake | 16 ------- tests/unit/wasm-c-api/CMakeLists.txt | 2 - 7 files changed, 44 insertions(+), 42 deletions(-) diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 9c1a4a5d53..562fa8789f 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -14,7 +14,30 @@ set(CMAKE_POLICY_VERSION_MINIMUM 3.5) SET(CMAKE_BUILD_TYPE Debug) -# add_definitions (-m32) +set(CMAKE_CXX_STANDARD 17) + +#TODO: modularization me +# Detect Hosting target info +string(TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM) +# Set WAMR_BUILD_TARGET, currently values supported: +# "X86_64", "AMD_64", "X86_32", "AARCH64[sub]", "ARM[sub]", "THUMB[sub]", +# "MIPS", "XTENSA", "RISCV64[sub]", "RISCV32[sub]" +if (NOT DEFINED WAMR_BUILD_TARGET) + if (CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm64|aarch64)") + set (WAMR_BUILD_TARGET "AARCH64") + elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "riscv64") + set (WAMR_BUILD_TARGET "RISCV64") + elseif (CMAKE_SIZEOF_VOID_P EQUAL 8) + # Build as X86_64 by default in 64-bit platform + set (WAMR_BUILD_TARGET "X86_64") + elseif (CMAKE_SIZEOF_VOID_P EQUAL 4) + # Build as X86_32 by default in 32-bit platform + set (WAMR_BUILD_TARGET "X86_32") + else () + message(SEND_ERROR "Unsupported build target platform!") + endif () +endif () + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}") @@ -65,8 +88,9 @@ add_subdirectory(gc) add_subdirectory(tid-allocator) add_subdirectory(unsupported-features) add_subdirectory(smart-tests) +add_subdirectory (running-modes) -if (NOT WAMR_BUILD_TARGET STREQUAL "X86_32") +if(WAMR_BUILD_TARGET STREQUAL "X86_64") add_subdirectory(aot-stack-frame) # should enable 32-bit llvm when X86_32 @@ -74,11 +98,22 @@ if (NOT WAMR_BUILD_TARGET STREQUAL "X86_32") add_subdirectory (custom-section) add_subdirectory (compilation) - # Fast-JIT or mem64 is not supported on X86_32 - add_subdirectory (running-modes) add_subdirectory (memory64) add_subdirectory (shared-heap) # HW_BOUND_CHECK is not supported on X86_32 + add_subdirectory (runtime-common) +endif() + +if(WAMR_BUILD_TARGET STREQUAL "AARCH64") + add_subdirectory(aot-stack-frame) + + add_subdirectory (aot) + add_subdirectory (custom-section) + add_subdirectory (compilation) + + add_subdirectory (memory64) + add_subdirectory (shared-heap) + add_subdirectory (runtime-common) endif () diff --git a/tests/unit/linear-memory-wasm/linear_memory_wasm_test.cc b/tests/unit/linear-memory-wasm/linear_memory_wasm_test.cc index a5db0e0335..b6db451a45 100644 --- a/tests/unit/linear-memory-wasm/linear_memory_wasm_test.cc +++ b/tests/unit/linear-memory-wasm/linear_memory_wasm_test.cc @@ -135,7 +135,7 @@ TEST_F(TEST_SUITE_NAME, test_wasm_mem_page_count) struct ret_env tmp_module_env; unsigned int num_normal_wasm = 9; unsigned int num_error_wasm = 10; - const char *wasm_file_normal[num_normal_wasm] = { + const char *wasm_file_normal[9] = { "/wasm_mem_page_01.wasm", "/wasm_mem_page_02.wasm", "/wasm_mem_page_05.wasm", "/wasm_mem_page_07.wasm", "/wasm_mem_page_08.wasm", "/wasm_mem_page_09.wasm", @@ -143,7 +143,7 @@ TEST_F(TEST_SUITE_NAME, test_wasm_mem_page_count) "/wasm_mem_page_14.wasm" }; - const char *wasm_file_error[num_error_wasm] = { + const char *wasm_file_error[10] = { "/wasm_mem_page_03.wasm", "/wasm_mem_page_04.wasm", "/wasm_mem_page_06.wasm", "/wasm_mem_page_11.wasm", "/wasm_mem_page_13.wasm", "/wasm_mem_page_15.wasm", diff --git a/tests/unit/linux-perf/CMakeLists.txt b/tests/unit/linux-perf/CMakeLists.txt index e5e2d56921..baf9863c27 100644 --- a/tests/unit/linux-perf/CMakeLists.txt +++ b/tests/unit/linux-perf/CMakeLists.txt @@ -32,9 +32,4 @@ include (${IWASM_DIR}/compilation/iwasm_compl.cmake) add_executable (linux_perf_test test_sort_func_ptrs.cc) target_compile_options(linux_perf_test PUBLIC -fpermissive) target_link_libraries(linux_perf_test ${LLVM_AVAILABLE_LIBS} gtest_main ) -target_link_options(linux_perf_test - PUBLIC - LINKER:--unresolved-symbols=ignore-all -) - gtest_discover_tests(linux_perf_test) diff --git a/tests/unit/linux-perf/test_sort_func_ptrs.cc b/tests/unit/linux-perf/test_sort_func_ptrs.cc index 68f4b850f0..45380267fc 100644 --- a/tests/unit/linux-perf/test_sort_func_ptrs.cc +++ b/tests/unit/linux-perf/test_sort_func_ptrs.cc @@ -33,7 +33,7 @@ sort_func_ptrs(const AOTModule *module, char *error_buf, uint32 error_buf_size) unsigned i; content_len = (uint64)sizeof(struct func_info) * module->func_count; - sorted_func_ptrs = wasm_runtime_malloc(content_len); + sorted_func_ptrs = (struct func_info *)wasm_runtime_malloc(content_len); if (!sorted_func_ptrs) { snprintf(error_buf, error_buf_size, "allocate memory failed when creating perf map"); @@ -63,23 +63,17 @@ wasm_runtime_free(void* ptr) return free(ptr); } -int -b_memcpy_s(void *s1, unsigned int s1max, const void *s2, unsigned int n) -{ - return memcpy(s1, s2, n); -} } TEST(TestSortFuncPtrs, qsort) { - void *p = sort_func_ptrs; - ASSERT_NE(p, nullptr); + ASSERT_NE(sort_func_ptrs, nullptr); void *funcs[5] = { (void *)0x1024, (void *)0x10, (void *)0x24, (void *)0x102, (void *)0x4, }; - AOTModule module = { 0 }; + AOTModule module = {}; module.func_count = 5; module.func_ptrs = &funcs[0]; diff --git a/tests/unit/tid-allocator/CMakeLists.txt b/tests/unit/tid-allocator/CMakeLists.txt index be62340a3c..87cf08654a 100644 --- a/tests/unit/tid-allocator/CMakeLists.txt +++ b/tests/unit/tid-allocator/CMakeLists.txt @@ -13,10 +13,6 @@ if (NOT DEFINED WAMR_BUILD_INTERP) set (WAMR_BUILD_INTERP 1) endif () -if (NOT DEFINED WAMR_BUILD_PLATFORM) - string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM) -endif () - include (../unit_common.cmake) add_library (tid_allocator_vmlib ${WAMR_RUNTIME_LIB_SOURCE}) diff --git a/tests/unit/unit_common.cmake b/tests/unit/unit_common.cmake index 53e9ae50df..b6692c62eb 100644 --- a/tests/unit/unit_common.cmake +++ b/tests/unit/unit_common.cmake @@ -1,27 +1,11 @@ # Copyright (C) 2019 Intel Corporation. All rights reserved. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -if (NOT DEFINED WAMR_BUILD_PLATFORM) - set (WAMR_BUILD_PLATFORM "linux") -endif () - enable_language (ASM) # Usually, test cases should identify their unique # complation flags to implement their test plan -# Set WAMR_BUILD_TARGET, currently values supported: -# "X86_64", "AMD_64", "X86_32", "ARM_32", "MIPS_32", "XTENSA_32" -if (NOT DEFINED WAMR_BUILD_TARGET) - if (CMAKE_SIZEOF_VOID_P EQUAL 8) - # Build as X86_64 by default in 64-bit platform - set (WAMR_BUILD_TARGET "X86_64") - else () - # Build as X86_32 by default in 32-bit platform - set (WAMR_BUILD_TARGET "X86_32") - endif () -endif () - set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) # include the build config template file diff --git a/tests/unit/wasm-c-api/CMakeLists.txt b/tests/unit/wasm-c-api/CMakeLists.txt index 3150c93254..d4d83d0ec3 100644 --- a/tests/unit/wasm-c-api/CMakeLists.txt +++ b/tests/unit/wasm-c-api/CMakeLists.txt @@ -4,8 +4,6 @@ cmake_minimum_required (VERSION 3.14) project (wasm_c_api_test) -set(WAMR_BUILD_PLATFORM "linux") - # WAMR features switch if (NOT DEFINED WAMR_BUILD_TARGET) set(WAMR_BUILD_TARGET "X86_64") From 00190db399b757ef18afe144b5f0cfa7206643b9 Mon Sep 17 00:00:00 2001 From: lum1n0us Date: Tue, 3 Feb 2026 15:18:25 -0800 Subject: [PATCH 07/16] Refactorying to generate aarch64 aot targets on M1 --- tests/unit/linear-memory-aot/build_aot.sh | 39 +++++++++++++++++++---- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/tests/unit/linear-memory-aot/build_aot.sh b/tests/unit/linear-memory-aot/build_aot.sh index 8f2b29edee..12c10c33f9 100755 --- a/tests/unit/linear-memory-aot/build_aot.sh +++ b/tests/unit/linear-memory-aot/build_aot.sh @@ -31,15 +31,42 @@ if [ ! -s "$WAST2WASM" ]; then echo "please install wabt first" && exit -1 fi +# Detect host architecture +HOST_ARCH=$(uname -m) +echo "Detected host architecture: $HOST_ARCH" + # Iterate over the files array -rm -r build +rm -r build 2>/dev/null mkdir build for file_name in "${file_names[@]}"; do # wast to wasm $WAST2WASM "${file_name}.wast" -o "build/${file_name}.wasm" - # compile the aot files, x86-64, x86-32, no_hw_bounds, no_hw_bounds_x32 - $WAMRC -o "build/${file_name}.aot" "build/${file_name}.wasm" - $WAMRC --target=i386 -o "build/${file_name}_32.aot" "build/${file_name}.wasm" - $WAMRC --bounds-checks=1 -o "build/${file_name}_no_hw_bounds.aot" "build/${file_name}.wasm" - $WAMRC --bounds-checks=1 --target=i386 -o "build/${file_name}_no_hw_bounds_32.aot" "build/${file_name}.wasm" + + # Determine compilation configurations based on host architecture + case "$HOST_ARCH" in + x86_64) + # x86-64 host: compile both x86-64 and x86-32 + $WAMRC -o "build/${file_name}.aot" "build/${file_name}.wasm" + $WAMRC --target=i386 -o "build/${file_name}_32.aot" "build/${file_name}.wasm" + $WAMRC --bounds-checks=1 -o "build/${file_name}_no_hw_bounds.aot" "build/${file_name}.wasm" + $WAMRC --bounds-checks=1 --target=i386 -o "build/${file_name}_no_hw_bounds_32.aot" "build/${file_name}.wasm" + ;; + i386|i686) + # x86-32 host: compile only x86-32 + $WAMRC -o "build/${file_name}.aot" "build/${file_name}.wasm" + $WAMRC --bounds-checks=1 -o "build/${file_name}_no_hw_bounds.aot" "build/${file_name}.wasm" + ;; + aarch64|arm64) + # ARM64 host: compile only aarch64 + $WAMRC -o "build/${file_name}.aot" "build/${file_name}.wasm" + $WAMRC --bounds-checks=1 -o "build/${file_name}_no_hw_bounds.aot" "build/${file_name}.wasm" + ;; + *) + echo "Warning: Unsupported architecture '$HOST_ARCH'. Using default target." + $WAMRC -o "build/${file_name}.aot" "build/${file_name}.wasm" + $WAMRC --bounds-checks=1 -o "build/${file_name}_no_hw_bounds.aot" "build/${file_name}.wasm" + ;; + esac done + +echo "AOT compilation completed for architecture: $HOST_ARCH" From a55239988cd18c008cf15462e0206e059d8e44ed Mon Sep 17 00:00:00 2001 From: lum1n0us Date: Wed, 4 Feb 2026 17:07:02 -0800 Subject: [PATCH 08/16] Update running-modes CMakeLists.txt: enable AOT and INTERP; JIT/FAST_JIT gating for x86_64. Fix typo in JIT section. --- tests/unit/running-modes/CMakeLists.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/unit/running-modes/CMakeLists.txt b/tests/unit/running-modes/CMakeLists.txt index 3a5ca4745a..d7ebaed095 100644 --- a/tests/unit/running-modes/CMakeLists.txt +++ b/tests/unit/running-modes/CMakeLists.txt @@ -26,8 +26,12 @@ set(WAMR_BUILD_LIBC_BUILTIN 1) set(WAMR_BUILD_MULTI_MODULE 0) set(WAMR_BUILD_LIBC_WASI 1) set(WAMR_BUILD_APP_FRAMEWORK 0) -set(WAMR_BUILD_JIT 1) -set(WAMR_BUILD_FAST_JIT 1) +set(WAMR_BUILD_AOT 1) +set(WAMR_BUILD_INTERP 1) +if(WAMR_BUILD_TARGET STREQUAL "x86_64") + set(WAMR_BUILD_JIT 1) + sset(WAMR_BUILD_FAST_JIT 1) +endif() set(WAMR_BUILD_REF_TYPES 1) # if only load this CMake other than load it as subdirectory From 61b0223d63a2517679211afed20bdaf167e28040 Mon Sep 17 00:00:00 2001 From: lum1n0us Date: Thu, 5 Feb 2026 15:40:37 -0800 Subject: [PATCH 09/16] refactor: update CMakeLists.txt for shared heap tests to use ExternalProject_Add and improve WASI SDK integration --- tests/unit/shared-heap/CMakeLists.txt | 30 +++++++++++++++---- .../unit/shared-heap/wasm-apps/CMakeLists.txt | 13 ++++---- .../wasm-apps/bulk-memory/CMakeLists.txt | 6 ++-- .../wasm-apps/memory64/CMakeLists.txt | 13 +++----- 4 files changed, 37 insertions(+), 25 deletions(-) diff --git a/tests/unit/shared-heap/CMakeLists.txt b/tests/unit/shared-heap/CMakeLists.txt index c275ac6385..5de15b4428 100644 --- a/tests/unit/shared-heap/CMakeLists.txt +++ b/tests/unit/shared-heap/CMakeLists.txt @@ -16,14 +16,34 @@ set(WAMR_BUILD_MEMORY64 0) set(WAMR_BUILD_SHARED_HEAP 1) # Compile wasm modules -add_subdirectory(wasm-apps) +set(WASI_SDK_DIR "/opt/wasi-sdk") +set(WASISDK_TOOLCHAIN "${WASI_SDK_DIR}/share/cmake/wasi-sdk.cmake") -if (WAMR_BUILD_MEMORY64 EQUAL 1) - add_subdirectory(wasm-apps/memory64) -endif () +include(ExternalProject) +ExternalProject_Add( + shared_heap_wasm_apps + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/wasm-apps + BUILD_ALWAYS YES + CONFIGURE_COMMAND ${CMAKE_COMMAND} -S ${CMAKE_CURRENT_SOURCE_DIR}/wasm-apps -B build + -DWASI_SDK_PREFIX=${WASI_SDK_DIR} + -DCMAKE_TOOLCHAIN_FILE=${WASISDK_TOOLCHAIN} + BUILD_COMMAND ${CMAKE_COMMAND} --build build + INSTALL_COMMAND ${CMAKE_COMMAND} --install build --prefix ${CMAKE_CURRENT_BINARY_DIR} +) + +ExternalProject_Add( + shared_heap_wasm_apps_bulk_memory + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/wasm-apps/bulk-memory + BUILD_ALWAYS YES + CONFIGURE_COMMAND ${CMAKE_COMMAND} -S ${CMAKE_CURRENT_SOURCE_DIR}/wasm-apps/bulk-memory -B build + -DWASI_SDK_PREFIX=${WASI_SDK_DIR} + -DCMAKE_TOOLCHAIN_FILE=${WASISDK_TOOLCHAIN} + BUILD_COMMAND ${CMAKE_COMMAND} --build build + INSTALL_COMMAND ${CMAKE_COMMAND} --install build --prefix ${CMAKE_CURRENT_BINARY_DIR} +) # if only load this CMake other than load it as subdirectory -include(../unit_common.cmake) +include(${CMAKE_CURRENT_SOURCE_DIR}/../unit_common.cmake) include(${IWASM_DIR}/compilation/iwasm_compl.cmake) diff --git a/tests/unit/shared-heap/wasm-apps/CMakeLists.txt b/tests/unit/shared-heap/wasm-apps/CMakeLists.txt index 6e30b35e35..9d5a619294 100644 --- a/tests/unit/shared-heap/wasm-apps/CMakeLists.txt +++ b/tests/unit/shared-heap/wasm-apps/CMakeLists.txt @@ -5,12 +5,6 @@ cmake_minimum_required(VERSION 3.14) project(wasm-apps) set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../..) -set(CMAKE_SYSTEM_PROCESSOR wasm32) -set(CMAKE_SYSROOT ${WAMR_ROOT_DIR}/wamr-sdk/app/libc-builtin-sysroot) - -if (NOT DEFINED WASI_SDK_DIR) - set(WASI_SDK_DIR "/opt/wasi-sdk") -endif () # Find WAMRC set(WAMRC_ROOT_DIR ${WAMR_ROOT_DIR}/wamr-compiler) @@ -25,14 +19,17 @@ else () set(WAMRC_SHARED_HEAP_CHAIN_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-chain) endif () +# +# C -> Wasm +# add_executable(test.wasm test.c) target_compile_options(test.wasm PUBLIC -nostdlib -O0 -pthread) target_link_options(test.wasm PRIVATE -nostdlib LINKER:--no-entry LINKER:--initial-memory=65536 - LINKER:--export-all LINKER:--allow-undefined + LINKER:--export-all ) add_executable(test_addr_conv.wasm test_addr_conv.c) @@ -41,8 +38,8 @@ target_link_options(test_addr_conv.wasm PRIVATE -nostdlib LINKER:--no-entry LINKER:--initial-memory=65536 - LINKER:--export-all LINKER:--allow-undefined + LINKER:--export-all ) # Compile AOT files (combined target) diff --git a/tests/unit/shared-heap/wasm-apps/bulk-memory/CMakeLists.txt b/tests/unit/shared-heap/wasm-apps/bulk-memory/CMakeLists.txt index b917a94323..8dd0deca7a 100644 --- a/tests/unit/shared-heap/wasm-apps/bulk-memory/CMakeLists.txt +++ b/tests/unit/shared-heap/wasm-apps/bulk-memory/CMakeLists.txt @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.14) project(wasm-apps-bulk-memory) # Find WAMRC -set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../..) +set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../..) set(WAMRC_ROOT_DIR ${WAMR_ROOT_DIR}/wamr-compiler) find_program(WAMRC_BIN wamrc HINTS ${WAMRC_ROOT_DIR}/build REQUIRED) @@ -20,8 +20,8 @@ endif () # Compile AOT files (combined target) add_custom_target(compile_aot ALL - COMMAND ${WAMRC_BIN} ${WAMRC_SHARED_HEAP_FLAGS} -o test_bulk_memory.aot test_bulk_memory.wasm - COMMAND ${WAMRC_BIN} ${WAMRC_SHARED_HEAP_CHAIN_FLAGS} -o test_bulk_memory_chain.aot test_bulk_memory.wasm + COMMAND ${WAMRC_BIN} ${WAMRC_SHARED_HEAP_FLAGS} -o test_bulk_memory.aot ${CMAKE_CURRENT_SOURCE_DIR}/test_bulk_memory.wasm + COMMAND ${WAMRC_BIN} ${WAMRC_SHARED_HEAP_CHAIN_FLAGS} -o test_bulk_memory_chain.aot ${CMAKE_CURRENT_SOURCE_DIR}/test_bulk_memory.wasm DEPENDS test_bulk_memory.wasm WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) diff --git a/tests/unit/shared-heap/wasm-apps/memory64/CMakeLists.txt b/tests/unit/shared-heap/wasm-apps/memory64/CMakeLists.txt index 4b59ccba26..912990a890 100644 --- a/tests/unit/shared-heap/wasm-apps/memory64/CMakeLists.txt +++ b/tests/unit/shared-heap/wasm-apps/memory64/CMakeLists.txt @@ -5,23 +5,18 @@ cmake_minimum_required(VERSION 3.14) project(wasm-apps-wasm64) set(WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../..) -set(WAMRC_ROOT_DIR ${WAMR_ROOT_DIR}/wamr-compiler/build) - -set(CMAKE_SYSTEM_PROCESSOR wasm64) -set(CMAKE_SYSROOT ${WAMR_ROOT_DIR}/wamr-sdk/app/libc-builtin-sysroot) - -if (NOT DEFINED WASI_SDK_DIR) - set(WASI_SDK_DIR "/opt/wasi-sdk") -endif () # Find WAMRC set(WAMRC_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../..) -find_program(WAMRC_BIN wamrc HINTS ${WAMRC_ROOT_DIR}/wamr-compiler/build REQUIRED) +find_program(WAMRC_BIN wamrc HINTS ${CMAKE_CURRENT_SOURCE_DIR}/../../../../wamr-compiler/build REQUIRED) # Set WAMRC flags for memory64 set(WAMRC_SHARED_HEAP_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-heap) set(WAMRC_SHARED_HEAP_CHAIN_FLAGS --opt-level=3 --bounds-checks=1 --enable-shared-chain) +# +# C -> Wasm +# add_executable(test64.wasm ../test.c) target_compile_options(test64.wasm PUBLIC -nostdlib -O0 -pthread --target=wasm64) target_link_options(test64.wasm PRIVATE From dfec0ad1745e718b975c4c70dd1b84f298a0460b Mon Sep 17 00:00:00 2001 From: "liang.he@intel.com" Date: Tue, 10 Feb 2026 07:30:34 +0800 Subject: [PATCH 10/16] Improve shared_heap test cases. Aligned allocation size can be significantly greater than the original size, and page size varies across platforms. > macOS on M1 (Apple Silicon) uses a memory page size of 16,384 bytes (16 KB). > This differs from the traditional 4 KB page size used on Intel Macs and many > other ARM64 systems, and is designed to improve performance by reducing page > table overhead and allowing for better cache utilization. --- tests/unit/shared-heap/shared_heap_test.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/shared-heap/shared_heap_test.cc b/tests/unit/shared-heap/shared_heap_test.cc index 6aa933d0f1..411b0a7504 100644 --- a/tests/unit/shared-heap/shared_heap_test.cc +++ b/tests/unit/shared-heap/shared_heap_test.cc @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +#include "platform_internal.h" #include "test_helper.h" #include "gtest/gtest.h" From 0cf434dc0c9823ac66ca38857cf21e25c7c77696 Mon Sep 17 00:00:00 2001 From: lum1n0us Date: Tue, 10 Feb 2026 14:55:43 -0800 Subject: [PATCH 11/16] fix: add stack size option to linker flags for wasm executables --- tests/unit/shared-heap/wasm-apps/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/unit/shared-heap/wasm-apps/CMakeLists.txt b/tests/unit/shared-heap/wasm-apps/CMakeLists.txt index 9d5a619294..b0482888f9 100644 --- a/tests/unit/shared-heap/wasm-apps/CMakeLists.txt +++ b/tests/unit/shared-heap/wasm-apps/CMakeLists.txt @@ -30,6 +30,7 @@ target_link_options(test.wasm PRIVATE LINKER:--initial-memory=65536 LINKER:--allow-undefined LINKER:--export-all + -z stack-size=1024 ) add_executable(test_addr_conv.wasm test_addr_conv.c) @@ -40,6 +41,7 @@ target_link_options(test_addr_conv.wasm PRIVATE LINKER:--initial-memory=65536 LINKER:--allow-undefined LINKER:--export-all + -z stack-size=1024 ) # Compile AOT files (combined target) From c4da04d6ecbbaf90e260f6da621e369b96192662 Mon Sep 17 00:00:00 2001 From: lum1n0us Date: Tue, 10 Feb 2026 14:55:55 -0800 Subject: [PATCH 12/16] fix: update wasm file paths in linear_memory_wasm_test to remove leading slashes --- .../linear_memory_wasm_test.cc | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/unit/linear-memory-wasm/linear_memory_wasm_test.cc b/tests/unit/linear-memory-wasm/linear_memory_wasm_test.cc index b6db451a45..12ab51f35d 100644 --- a/tests/unit/linear-memory-wasm/linear_memory_wasm_test.cc +++ b/tests/unit/linear-memory-wasm/linear_memory_wasm_test.cc @@ -136,27 +136,27 @@ TEST_F(TEST_SUITE_NAME, test_wasm_mem_page_count) unsigned int num_normal_wasm = 9; unsigned int num_error_wasm = 10; const char *wasm_file_normal[9] = { - "/wasm_mem_page_01.wasm", "/wasm_mem_page_02.wasm", - "/wasm_mem_page_05.wasm", "/wasm_mem_page_07.wasm", - "/wasm_mem_page_08.wasm", "/wasm_mem_page_09.wasm", - "/wasm_mem_page_10.wasm", "/wasm_mem_page_12.wasm", - "/wasm_mem_page_14.wasm" + "wasm_mem_page_01.wasm", "wasm_mem_page_02.wasm", + "wasm_mem_page_05.wasm", "wasm_mem_page_07.wasm", + "wasm_mem_page_08.wasm", "wasm_mem_page_09.wasm", + "wasm_mem_page_10.wasm", "wasm_mem_page_12.wasm", + "wasm_mem_page_14.wasm" }; const char *wasm_file_error[10] = { - "/wasm_mem_page_03.wasm", "/wasm_mem_page_04.wasm", - "/wasm_mem_page_06.wasm", "/wasm_mem_page_11.wasm", - "/wasm_mem_page_13.wasm", "/wasm_mem_page_15.wasm", - "/wasm_mem_page_16.wasm", "/wasm_mem_page_17.wasm", - "/wasm_mem_page_18.wasm", "/wasm_mem_page_19.wasm" + "wasm_mem_page_03.wasm", "wasm_mem_page_04.wasm", + "wasm_mem_page_06.wasm", "wasm_mem_page_11.wasm", + "wasm_mem_page_13.wasm", "wasm_mem_page_15.wasm", + "wasm_mem_page_16.wasm", "wasm_mem_page_17.wasm", + "wasm_mem_page_18.wasm", "wasm_mem_page_19.wasm" }; // Test normal wasm file. for (int i = 0; i < num_normal_wasm; i++) { #if UINTPTR_MAX != UINT64_MAX // 32 bit do not load this wasm. - if ((0 == strcmp("/wasm_mem_page_12.wasm", wasm_file_normal[i])) - || (0 == strcmp("/wasm_mem_page_14.wasm", wasm_file_normal[i]))) { + if ((0 == strcmp("wasm_mem_page_12.wasm", wasm_file_normal[i])) + || (0 == strcmp("wasm_mem_page_14.wasm", wasm_file_normal[i]))) { continue; } #endif @@ -189,13 +189,13 @@ TEST_F(TEST_SUITE_NAME, test_wasm_about_app_heap) struct ret_env tmp_module_env; // Test case: init_page_count = 65536, app heap size = 1. - tmp_module_env = load_wasm((char *)"/wasm_mem_page_03.wasm", 1); + tmp_module_env = load_wasm((char *)"wasm_mem_page_03.wasm", 1); EXPECT_EQ(0, strncmp("WASM module instantiate failed", (const char *)tmp_module_env.error_buf, 30)); destroy_module_env(tmp_module_env); // Test case: init_page_count = 65535, app heap size = 65537. - tmp_module_env = load_wasm((char *)"/wasm_mem_page_20.wasm", 65537); + tmp_module_env = load_wasm((char *)"wasm_mem_page_20.wasm", 65537); EXPECT_EQ(0, strncmp("WASM module instantiate failed", (const char *)tmp_module_env.error_buf, 30)); destroy_module_env(tmp_module_env); From ac8d9d18093666857d2d1307704099495f905992 Mon Sep 17 00:00:00 2001 From: lum1n0us Date: Mon, 23 Feb 2026 17:26:17 -0800 Subject: [PATCH 13/16] fix: replace deprecated get_binary_path function with get_test_binary_dir for improved portability --- tests/unit/common/test_helper.h | 14 +++++++++++++ tests/unit/compilation/aot_compiler_test.cc | 19 +----------------- .../compilation/aot_emit_aot_file_test.cc | 19 +----------------- .../unit/compilation/aot_emit_control_test.cc | 19 +----------------- .../compilation/aot_emit_function_test.cc | 19 +----------------- .../unit/compilation/aot_emit_memory_test.cc | 19 +----------------- .../compilation/aot_emit_numberic_test.cc | 19 +----------------- .../compilation/aot_emit_parametric_test.cc | 19 +----------------- tests/unit/compilation/aot_emit_table_test.cc | 19 +----------------- tests/unit/compilation/aot_llvm_test.cc | 19 +----------------- tests/unit/gc/gc_test.cc | 20 ++----------------- .../linear_memory_aot_test.cc | 19 +----------------- .../linear_memory_wasm_test.cc | 19 +----------------- .../running-modes/wasm_running_modes_test.cc | 18 +---------------- .../wasm_runtime_common_test.cc | 19 +----------------- .../runtime-common/wasm_runtime_init_test.cc | 19 +----------------- 16 files changed, 30 insertions(+), 269 deletions(-) diff --git a/tests/unit/common/test_helper.h b/tests/unit/common/test_helper.h index 4db465fc8d..8f54a592c0 100644 --- a/tests/unit/common/test_helper.h +++ b/tests/unit/common/test_helper.h @@ -11,6 +11,20 @@ #include #include #include +#include +#include +#include + +static inline std::string +get_test_binary_dir() +{ + char cwd[PATH_MAX] = { 0 }; + if (!getcwd(cwd, sizeof(cwd))) { + return std::string(); + } + + return std::string(cwd); +} template class WAMRRuntimeRAII diff --git a/tests/unit/compilation/aot_compiler_test.cc b/tests/unit/compilation/aot_compiler_test.cc index 6fbccbb176..51ba2fbf29 100644 --- a/tests/unit/compilation/aot_compiler_test.cc +++ b/tests/unit/compilation/aot_compiler_test.cc @@ -14,23 +14,6 @@ static std::string CWD; static std::string MAIN_WASM = "/main.wasm"; static char *WASM_FILE; -static std::string -get_binary_path() -{ - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); -} - extern "C" { char * aot_generate_tempfile_name(const char *prefix, const char *extension, @@ -50,7 +33,7 @@ class aot_compiler_test_suit : public testing::Test static void SetUpTestCase() { - CWD = get_binary_path(); + CWD = get_test_binary_dir(); WASM_FILE = strdup((CWD + MAIN_WASM).c_str()); } diff --git a/tests/unit/compilation/aot_emit_aot_file_test.cc b/tests/unit/compilation/aot_emit_aot_file_test.cc index 8b0f63a8ed..c94b15402e 100644 --- a/tests/unit/compilation/aot_emit_aot_file_test.cc +++ b/tests/unit/compilation/aot_emit_aot_file_test.cc @@ -14,23 +14,6 @@ static std::string CWD; static std::string MAIN_WASM = "/main.wasm"; static char *WASM_FILE; -static std::string -get_binary_path() -{ - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); -} - extern "C" { uint8 * aot_emit_aot_file_buf(AOTCompContext *comp_ctx, AOTCompData *comp_data, @@ -50,7 +33,7 @@ class aot_emit_aot_file_test_suite : public testing::Test static void SetUpTestCase() { - CWD = get_binary_path(); + CWD = get_test_binary_dir(); WASM_FILE = strdup((CWD + MAIN_WASM).c_str()); } diff --git a/tests/unit/compilation/aot_emit_control_test.cc b/tests/unit/compilation/aot_emit_control_test.cc index 849189c907..c8a47554cf 100644 --- a/tests/unit/compilation/aot_emit_control_test.cc +++ b/tests/unit/compilation/aot_emit_control_test.cc @@ -15,23 +15,6 @@ static std::string CWD; static std::string MAIN_WASM = "/main.wasm"; static char *WASM_FILE; -static std::string -get_binary_path() -{ - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); -} - class aot_emit_control_test_suite : public testing::Test { protected: @@ -45,7 +28,7 @@ class aot_emit_control_test_suite : public testing::Test static void SetUpTestCase() { - CWD = get_binary_path(); + CWD = get_test_binary_dir(); WASM_FILE = strdup((CWD + MAIN_WASM).c_str()); } diff --git a/tests/unit/compilation/aot_emit_function_test.cc b/tests/unit/compilation/aot_emit_function_test.cc index d10d639a15..db67c3b20a 100644 --- a/tests/unit/compilation/aot_emit_function_test.cc +++ b/tests/unit/compilation/aot_emit_function_test.cc @@ -14,23 +14,6 @@ static std::string CWD; static std::string MAIN_WASM = "/main.wasm"; static char *WASM_FILE; -static std::string -get_binary_path() -{ - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); -} - class aot_emit_function_test_suite : public testing::Test { protected: @@ -44,7 +27,7 @@ class aot_emit_function_test_suite : public testing::Test static void SetUpTestCase() { - CWD = get_binary_path(); + CWD = get_test_binary_dir(); WASM_FILE = strdup((CWD + MAIN_WASM).c_str()); } diff --git a/tests/unit/compilation/aot_emit_memory_test.cc b/tests/unit/compilation/aot_emit_memory_test.cc index 0e8e86f21d..840a30f6d9 100644 --- a/tests/unit/compilation/aot_emit_memory_test.cc +++ b/tests/unit/compilation/aot_emit_memory_test.cc @@ -16,29 +16,12 @@ static std::string CWD; static std::string MAIN_WASM = "/main.wasm"; static char *WASM_FILE; -static std::string -get_binary_path() -{ - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); -} - class compilation_aot_emit_memory_test : public testing::Test { protected: void SetUp() override { - CWD = get_binary_path(); + CWD = get_test_binary_dir(); WASM_FILE = strdup((CWD + MAIN_WASM).c_str()); AOTCompOption option = { 0 }; diff --git a/tests/unit/compilation/aot_emit_numberic_test.cc b/tests/unit/compilation/aot_emit_numberic_test.cc index 70f119f9e5..22a62505df 100644 --- a/tests/unit/compilation/aot_emit_numberic_test.cc +++ b/tests/unit/compilation/aot_emit_numberic_test.cc @@ -15,23 +15,6 @@ static std::string CWD; static std::string MAIN_WASM = "/main.wasm"; static char *WASM_FILE; -static std::string -get_binary_path() -{ - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); -} - class aot_emit_numberic_test_suite : public testing::Test { protected: @@ -45,7 +28,7 @@ class aot_emit_numberic_test_suite : public testing::Test static void SetUpTestCase() { - CWD = get_binary_path(); + CWD = get_test_binary_dir(); WASM_FILE = strdup((CWD + MAIN_WASM).c_str()); } diff --git a/tests/unit/compilation/aot_emit_parametric_test.cc b/tests/unit/compilation/aot_emit_parametric_test.cc index aa7b08df3a..4ecac1894f 100644 --- a/tests/unit/compilation/aot_emit_parametric_test.cc +++ b/tests/unit/compilation/aot_emit_parametric_test.cc @@ -14,23 +14,6 @@ static std::string CWD; static std::string MAIN_WASM = "/main.wasm"; static char *WASM_FILE; -static std::string -get_binary_path() -{ - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); -} - class aot_emit_parametric_test_suite : public testing::Test { protected: @@ -44,7 +27,7 @@ class aot_emit_parametric_test_suite : public testing::Test static void SetUpTestCase() { - CWD = get_binary_path(); + CWD = get_test_binary_dir(); WASM_FILE = strdup((CWD + MAIN_WASM).c_str()); } diff --git a/tests/unit/compilation/aot_emit_table_test.cc b/tests/unit/compilation/aot_emit_table_test.cc index c77d16c6d1..457e1073ad 100644 --- a/tests/unit/compilation/aot_emit_table_test.cc +++ b/tests/unit/compilation/aot_emit_table_test.cc @@ -14,23 +14,6 @@ static std::string CWD; static std::string MAIN_WASM = "/main.wasm"; static char *WASM_FILE; -static std::string -get_binary_path() -{ - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); -} - class aot_emit_table_test_suite : public testing::Test { protected: @@ -44,7 +27,7 @@ class aot_emit_table_test_suite : public testing::Test static void SetUpTestCase() { - CWD = get_binary_path(); + CWD = get_test_binary_dir(); WASM_FILE = strdup((CWD + MAIN_WASM).c_str()); } diff --git a/tests/unit/compilation/aot_llvm_test.cc b/tests/unit/compilation/aot_llvm_test.cc index de4ab17c4a..83714130c5 100644 --- a/tests/unit/compilation/aot_llvm_test.cc +++ b/tests/unit/compilation/aot_llvm_test.cc @@ -14,23 +14,6 @@ static std::string CWD; static std::string MAIN_WASM = "/main.wasm"; static char *WASM_FILE; -static std::string -get_binary_path() -{ - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); -} - class aot_llvm_test_suite : public testing::Test { protected: @@ -44,7 +27,7 @@ class aot_llvm_test_suite : public testing::Test static void SetUpTestCase() { - CWD = get_binary_path(); + CWD = get_test_binary_dir(); WASM_FILE = strdup((CWD + MAIN_WASM).c_str()); } diff --git a/tests/unit/gc/gc_test.cc b/tests/unit/gc/gc_test.cc index 196ddba65a..971f2ecf4e 100644 --- a/tests/unit/gc/gc_test.cc +++ b/tests/unit/gc/gc_test.cc @@ -3,6 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +#include "test_helper.h" #include "gtest/gtest.h" #include "bh_platform.h" #include "bh_read_file.h" @@ -10,27 +11,10 @@ class WasmGCTest : public testing::Test { - private: - std::string get_binary_path() - { - char cwd[1024] = { 0 }; - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - return NULL; - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); - } - protected: void SetUp() { - CWD = get_binary_path(); + CWD = get_test_binary_dir(); memset(&init_args, 0, sizeof(RuntimeInitArgs)); diff --git a/tests/unit/linear-memory-aot/linear_memory_aot_test.cc b/tests/unit/linear-memory-aot/linear_memory_aot_test.cc index 198dfbc917..b365721fea 100644 --- a/tests/unit/linear-memory-aot/linear_memory_aot_test.cc +++ b/tests/unit/linear-memory-aot/linear_memory_aot_test.cc @@ -11,23 +11,6 @@ static std::string CWD; -static std::string -get_binary_path() -{ - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); -} - #if WASM_DISABLE_HW_BOUND_CHECK != 0 #define TEST_SUITE_NAME linear_memory_test_suite_aot_no_hw_bound #else @@ -45,7 +28,7 @@ class TEST_SUITE_NAME : public testing::Test // Otherwise, this can be skipped. virtual void SetUp() {} - static void SetUpTestCase() { CWD = get_binary_path(); } + static void SetUpTestCase() { CWD = get_test_binary_dir(); } // virtual void TearDown() will be called after each test is run. // You should define it if there is cleanup work to do. Otherwise, diff --git a/tests/unit/linear-memory-wasm/linear_memory_wasm_test.cc b/tests/unit/linear-memory-wasm/linear_memory_wasm_test.cc index 12ab51f35d..ac4c908828 100644 --- a/tests/unit/linear-memory-wasm/linear_memory_wasm_test.cc +++ b/tests/unit/linear-memory-wasm/linear_memory_wasm_test.cc @@ -11,23 +11,6 @@ static std::string CWD; -static std::string -get_binary_path() -{ - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); -} - #if WASM_DISABLE_HW_BOUND_CHECK != 0 #define TEST_SUITE_NAME linear_memory_test_suite_wasm_no_hw_bound #else @@ -45,7 +28,7 @@ class TEST_SUITE_NAME : public testing::Test // Otherwise, this can be skipped. virtual void SetUp() {} - static void SetUpTestCase() { CWD = get_binary_path(); } + static void SetUpTestCase() { CWD = get_test_binary_dir(); } // virtual void TearDown() will be called after each test is run. // You should define it if there is cleanup work to do. Otherwise, diff --git a/tests/unit/running-modes/wasm_running_modes_test.cc b/tests/unit/running-modes/wasm_running_modes_test.cc index 5f370dd649..5dc4803c02 100644 --- a/tests/unit/running-modes/wasm_running_modes_test.cc +++ b/tests/unit/running-modes/wasm_running_modes_test.cc @@ -39,22 +39,6 @@ std::vector running_mode_supported = { Mode_Interp, class wasm_running_modes_test_suite : public testing::TestWithParam { private: - std::string get_binary_path() - { - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); - } - bool load_wasm_file(const char *wasm_file) { const char *file; @@ -199,7 +183,7 @@ class wasm_running_modes_test_suite : public testing::TestWithParam // Otherwise, this can be skipped. virtual void SetUp() { - CWD = get_binary_path(); + CWD = get_test_binary_dir(); WASM_FILE_1 = strdup((CWD + TEST_WASM1).c_str()); WASM_FILE_2 = strdup((CWD + TEST_WASM2).c_str()); diff --git a/tests/unit/runtime-common/wasm_runtime_common_test.cc b/tests/unit/runtime-common/wasm_runtime_common_test.cc index b1282091c5..3e2fb1429a 100644 --- a/tests/unit/runtime-common/wasm_runtime_common_test.cc +++ b/tests/unit/runtime-common/wasm_runtime_common_test.cc @@ -36,23 +36,6 @@ static std::string MAIN_AOT = "/main.aot"; static char *WASM_FILE_1; static char *AOT_FILE_1; -static std::string -get_binary_path() -{ - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); -} - class wasm_runtime_common_test_suite : public testing::Test { protected: @@ -66,7 +49,7 @@ class wasm_runtime_common_test_suite : public testing::Test static void SetUpTestCase() { - CWD = get_binary_path(); + CWD = get_test_binary_dir(); WASM_FILE_1 = strdup((CWD + MAIN_WASM).c_str()); AOT_FILE_1 = strdup((CWD + MAIN_AOT).c_str()); } diff --git a/tests/unit/runtime-common/wasm_runtime_init_test.cc b/tests/unit/runtime-common/wasm_runtime_init_test.cc index f7ff26ae44..5632ca4cfe 100644 --- a/tests/unit/runtime-common/wasm_runtime_init_test.cc +++ b/tests/unit/runtime-common/wasm_runtime_init_test.cc @@ -48,23 +48,6 @@ static NativeSymbol native_symbols[] = { { "(ii)i" // the function prototype signature } }; -static std::string -get_binary_path() -{ - char cwd[1024]; - memset(cwd, 0, 1024); - - if (readlink("/proc/self/exe", cwd, 1024) <= 0) { - } - - char *path_end = strrchr(cwd, '/'); - if (path_end != NULL) { - *path_end = '\0'; - } - - return std::string(cwd); -} - class wasm_runtime_init_test_suite : public testing::Test { protected: @@ -78,7 +61,7 @@ class wasm_runtime_init_test_suite : public testing::Test static void SetUpTestCase() { - CWD = get_binary_path(); + CWD = get_test_binary_dir(); WASM_FILE_1 = strdup((CWD + MAIN_WASM).c_str()); AOT_FILE_1 = strdup((CWD + MAIN_AOT).c_str()); } From 9bc75ca1fdee788d3deac53335328387f31319c3 Mon Sep 17 00:00:00 2001 From: lum1n0us Date: Mon, 23 Feb 2026 17:28:32 -0800 Subject: [PATCH 14/16] Revert "fix: update wasm file paths in linear_memory_wasm_test to remove leading slashes" This reverts commit c4da04d6ecbbaf90e260f6da621e369b96192662. --- .../linear_memory_wasm_test.cc | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/tests/unit/linear-memory-wasm/linear_memory_wasm_test.cc b/tests/unit/linear-memory-wasm/linear_memory_wasm_test.cc index ac4c908828..d55f1926ff 100644 --- a/tests/unit/linear-memory-wasm/linear_memory_wasm_test.cc +++ b/tests/unit/linear-memory-wasm/linear_memory_wasm_test.cc @@ -119,27 +119,27 @@ TEST_F(TEST_SUITE_NAME, test_wasm_mem_page_count) unsigned int num_normal_wasm = 9; unsigned int num_error_wasm = 10; const char *wasm_file_normal[9] = { - "wasm_mem_page_01.wasm", "wasm_mem_page_02.wasm", - "wasm_mem_page_05.wasm", "wasm_mem_page_07.wasm", - "wasm_mem_page_08.wasm", "wasm_mem_page_09.wasm", - "wasm_mem_page_10.wasm", "wasm_mem_page_12.wasm", - "wasm_mem_page_14.wasm" + "/wasm_mem_page_01.wasm", "/wasm_mem_page_02.wasm", + "/wasm_mem_page_05.wasm", "/wasm_mem_page_07.wasm", + "/wasm_mem_page_08.wasm", "/wasm_mem_page_09.wasm", + "/wasm_mem_page_10.wasm", "/wasm_mem_page_12.wasm", + "/wasm_mem_page_14.wasm" }; const char *wasm_file_error[10] = { - "wasm_mem_page_03.wasm", "wasm_mem_page_04.wasm", - "wasm_mem_page_06.wasm", "wasm_mem_page_11.wasm", - "wasm_mem_page_13.wasm", "wasm_mem_page_15.wasm", - "wasm_mem_page_16.wasm", "wasm_mem_page_17.wasm", - "wasm_mem_page_18.wasm", "wasm_mem_page_19.wasm" + "/wasm_mem_page_03.wasm", "/wasm_mem_page_04.wasm", + "/wasm_mem_page_06.wasm", "/wasm_mem_page_11.wasm", + "/wasm_mem_page_13.wasm", "/wasm_mem_page_15.wasm", + "/wasm_mem_page_16.wasm", "/wasm_mem_page_17.wasm", + "/wasm_mem_page_18.wasm", "/wasm_mem_page_19.wasm" }; // Test normal wasm file. for (int i = 0; i < num_normal_wasm; i++) { #if UINTPTR_MAX != UINT64_MAX // 32 bit do not load this wasm. - if ((0 == strcmp("wasm_mem_page_12.wasm", wasm_file_normal[i])) - || (0 == strcmp("wasm_mem_page_14.wasm", wasm_file_normal[i]))) { + if ((0 == strcmp("/wasm_mem_page_12.wasm", wasm_file_normal[i])) + || (0 == strcmp("/wasm_mem_page_14.wasm", wasm_file_normal[i]))) { continue; } #endif @@ -172,13 +172,13 @@ TEST_F(TEST_SUITE_NAME, test_wasm_about_app_heap) struct ret_env tmp_module_env; // Test case: init_page_count = 65536, app heap size = 1. - tmp_module_env = load_wasm((char *)"wasm_mem_page_03.wasm", 1); + tmp_module_env = load_wasm((char *)"/wasm_mem_page_03.wasm", 1); EXPECT_EQ(0, strncmp("WASM module instantiate failed", (const char *)tmp_module_env.error_buf, 30)); destroy_module_env(tmp_module_env); // Test case: init_page_count = 65535, app heap size = 65537. - tmp_module_env = load_wasm((char *)"wasm_mem_page_20.wasm", 65537); + tmp_module_env = load_wasm((char *)"/wasm_mem_page_20.wasm", 65537); EXPECT_EQ(0, strncmp("WASM module instantiate failed", (const char *)tmp_module_env.error_buf, 30)); destroy_module_env(tmp_module_env); From 68ea3a97193295fa0613461b08f91be543fc973d Mon Sep 17 00:00:00 2001 From: lum1n0us Date: Tue, 24 Feb 2026 14:51:04 -0800 Subject: [PATCH 15/16] fix: update shared_heap_test to use os_getpagesize for memory size calculations --- tests/unit/shared-heap/shared_heap_test.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/shared-heap/shared_heap_test.cc b/tests/unit/shared-heap/shared_heap_test.cc index 411b0a7504..a66cfc68b1 100644 --- a/tests/unit/shared-heap/shared_heap_test.cc +++ b/tests/unit/shared-heap/shared_heap_test.cc @@ -263,7 +263,7 @@ TEST_F(shared_heap_test, test_preallocated_shared_runtime_api) } size = (uint64_t)UINT32_MAX + 0x2000; - printf("offset %lx size: %lx\n", offset, size); + printf("offset %llx size: %llx\n", offset, size); ASSERT_EQ(false, wasm_runtime_validate_app_addr( tmp_module_env.wasm_module_inst, offset, size)); @@ -1337,7 +1337,7 @@ TEST_F(shared_heap_test, test_shared_heap_chain_addr_conv_oob) FAIL() << "Failed to register natives"; } - args.size = 4096; + args.size = os_getpagesize(); shared_heap = wasm_runtime_create_shared_heap(&args); if (!shared_heap) { FAIL() << "Failed to create shared heap"; @@ -1359,14 +1359,14 @@ TEST_F(shared_heap_test, test_shared_heap_chain_addr_conv_oob) } /* test wasm */ - argv[0] = 0xFFFFFFFF - BUF_SIZE - 4096; + argv[0] = 0xFFFFFFFF - BUF_SIZE - os_getpagesize(); EXPECT_NONFATAL_FAILURE(test_shared_heap(shared_heap_chain, "test_addr_conv.wasm", "test_preallocated", 1, argv), "Exception: out of bounds memory access"); /* test aot */ - argv[0] = 0xFFFFFFFF - BUF_SIZE - 4096; + argv[0] = 0xFFFFFFFF - BUF_SIZE - os_getpagesize(); EXPECT_NONFATAL_FAILURE(test_shared_heap(shared_heap_chain, "test_addr_conv_chain.aot", "test_preallocated", 1, argv), From e6227315d66c690c86d1fb59d0499088c6f405d3 Mon Sep 17 00:00:00 2001 From: lum1n0us Date: Tue, 24 Feb 2026 15:05:44 -0800 Subject: [PATCH 16/16] fix: adjust size_level test cases for aarch64 architecture compatibility --- tests/unit/compilation/aot_compiler_test.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/unit/compilation/aot_compiler_test.cc b/tests/unit/compilation/aot_compiler_test.cc index 51ba2fbf29..7c5df9c34a 100644 --- a/tests/unit/compilation/aot_compiler_test.cc +++ b/tests/unit/compilation/aot_compiler_test.cc @@ -100,8 +100,13 @@ TEST_F(aot_compiler_test_suit, aot_emit_object_file) // Test size_level in range from 0 to 3. option.opt_level = 3; - for (i = 0; i <= 3; i++) { - option.size_level = i; +#if defined(__aarch64__) || defined(_M_ARM64) + std::vector size_levels = { 0, 3 }; +#else + std::vector size_levels = { 0, 1, 2, 3 }; +#endif + for (auto size_level : size_levels) { + option.size_level = size_level; test_aot_emit_object_file_with_option(&option); }