From 199af21557d109d86a9a2b805f989a0521699e70 Mon Sep 17 00:00:00 2001 From: "liang.he@intel.com" Date: Sun, 7 Sep 2025 13:49:49 +0000 Subject: [PATCH 01/10] refactor: streamline CMake configurations and improve code coverage collection - only unit/CMakeLists.txt fetches googletest - only unit/unit_common.cmake find LLVM dependencies - use `WAMR_RUNTIME_LIB_SOURCE` to replace a long list --- .../compilation_on_android_ubuntu.yml | 3 ++ build-scripts/code_coverage.cmake | 37 +++++++++++++ build-scripts/config_common.cmake | 4 +- tests/unit/CMakeLists.txt | 4 +- tests/unit/aot-stack-frame/CMakeLists.txt | 22 ++------ tests/unit/aot/CMakeLists.txt | 11 ---- tests/unit/compilation/CMakeLists.txt | 32 ++--------- tests/unit/custom-section/CMakeLists.txt | 26 ++------- tests/unit/gc/CMakeLists.txt | 20 ++----- tests/unit/interpreter/CMakeLists.txt | 12 ++--- tests/unit/libc-builtin/CMakeLists.txt | 8 ++- tests/unit/linear-memory-aot/CMakeLists.txt | 20 ++----- tests/unit/linear-memory-wasm/CMakeLists.txt | 12 ----- tests/unit/linux-perf/CMakeLists.txt | 11 ---- tests/unit/memory64/CMakeLists.txt | 24 ++------- tests/unit/running-modes/CMakeLists.txt | 28 ++-------- tests/unit/runtime-common/CMakeLists.txt | 16 ------ tests/unit/shared-heap/CMakeLists.txt | 24 ++------- tests/unit/shared-utils/CMakeLists.txt | 4 +- tests/unit/unit_common.cmake | 45 +++++----------- tests/unit/wasm-c-api/CMakeLists.txt | 53 ++----------------- tests/unit/wasm-vm/CMakeLists.txt | 19 ++----- .../spec-test-script/collect_coverage.sh | 6 ++- tests/wamr-test-suites/test_wamr.sh | 27 ++++++---- 24 files changed, 129 insertions(+), 339 deletions(-) create mode 100644 build-scripts/code_coverage.cmake diff --git a/.github/workflows/compilation_on_android_ubuntu.yml b/.github/workflows/compilation_on_android_ubuntu.yml index 01356dc66e..89fa54743d 100644 --- a/.github/workflows/compilation_on_android_ubuntu.yml +++ b/.github/workflows/compilation_on_android_ubuntu.yml @@ -350,6 +350,9 @@ jobs: uses: ./.github/actions/install-wasi-sdk-wabt with: os: ${{ matrix.os }} + + - name: install llvm dependencies + run: sudo apt update && sudo apt install -y libzstd-dev zlib1g-dev - name: Build wamrc run: | diff --git a/build-scripts/code_coverage.cmake b/build-scripts/code_coverage.cmake new file mode 100644 index 0000000000..e122201df0 --- /dev/null +++ b/build-scripts/code_coverage.cmake @@ -0,0 +1,37 @@ +# Copyright (C) 2019 Intel Corporation. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +function(check_ubuntu_version) +# ubuntu 2204 is the recommended environment for collecting coverage data for now +# otherwise, there will be ERRORs, when using 2404, like below and +# +# geninfo: ERROR: ('mismatch') mismatched end line for _ZN63compilation_aot_emit_memory_test_aot_check_memory_overflow_Test8TestBodyEv at /workspaces/wasm-micro-runtime/tests/unit/compilation/aot_emit_memory_test.cc:96: 96 -> 106 +# (use "geninfo --ignore-errors mismatch,mismatch ..." to suppress this warning) +# geninfo: ERROR: ('negative') Unexpected negative count '-3' for /workspaces/wasm-micro-runtime/core/iwasm/interpreter/wasm_interp_classic.c:5473. +# Perhaps you need to compile with '-fprofile-update=atomic +# (use "geninfo --ignore-errors negative,negative ..." to suppress this warning) +# +# For sure, `--ignore-errors` can be used to ignore these errors, but better to use the recommended environment. + file(READ "/etc/os-release" OS_RELEASE_CONTENT) + string(REGEX MATCH "VERSION_ID=\"([0-9]+)\\.([0-9]+)\"" _ ${OS_RELEASE_CONTENT}) + if(NOT DEFINED CMAKE_MATCH_1 OR NOT DEFINED CMAKE_MATCH_2) + message(WARNING "Unable to detect Ubuntu version. Please ensure you are using Ubuntu 22.04.") + return() + endif() + + set(UBUNTU_MAJOR_VERSION ${CMAKE_MATCH_1}) + set(UBUNTU_MINOR_VERSION ${CMAKE_MATCH_2}) + + if(NOT (UBUNTU_MAJOR_VERSION EQUAL 22 AND UBUNTU_MINOR_VERSION EQUAL 04)) + message(WARNING "Ubuntu ${UBUNTU_MAJOR_VERSION}.${UBUNTU_MINOR_VERSION} detected. Ubuntu 22.04 is recommended for collecting coverage data.") + else() + message(STATUS "Ubuntu 22.04 detected. Proceeding with coverage data collection.") + endif() +endfunction() + +check_ubuntu_version() + +# add compile options for code coverage globally +add_compile_options(--coverage -O0 -g) +link_libraries(gcov) +add_definitions (-DCOLLECT_CODE_COVERAGE) diff --git a/build-scripts/config_common.cmake b/build-scripts/config_common.cmake index 52c6d94afa..c087a0e673 100644 --- a/build-scripts/config_common.cmake +++ b/build-scripts/config_common.cmake @@ -640,9 +640,7 @@ if (WAMR_BUILD_GC_HEAP_VERIFY EQUAL 1) message (" GC heap verification enabled") endif () if ("$ENV{COLLECT_CODE_COVERAGE}" STREQUAL "1" OR COLLECT_CODE_COVERAGE EQUAL 1) - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage") - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") - add_definitions (-DCOLLECT_CODE_COVERAGE) + include(${CMAKE_CURRENT_LIST_DIR}/code_coverage.cmake) message (" Collect code coverage enabled") endif () if (WAMR_BUILD_STATIC_PGO EQUAL 1) diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index b726f83a12..9c8caa7d42 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -76,9 +76,9 @@ if (NOT WAMR_BUILD_TARGET STREQUAL "X86_32") add_subdirectory (compilation) # Fast-JIT or mem64 is not supported on X86_32 - add_subdirectory (running-modes) + # add_subdirectory (running-modes) add_subdirectory (memory64) - add_subdirectory (shared-heap) + # add_subdirectory (shared-heap) # HW_BOUND_CHECK is not supported on X86_32 add_subdirectory (runtime-common) diff --git a/tests/unit/aot-stack-frame/CMakeLists.txt b/tests/unit/aot-stack-frame/CMakeLists.txt index 90a61aea76..01ea6578ea 100644 --- a/tests/unit/aot-stack-frame/CMakeLists.txt +++ b/tests/unit/aot-stack-frame/CMakeLists.txt @@ -32,22 +32,10 @@ file (GLOB_RECURSE source_all ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) set (UNIT_SOURCE ${source_all}) set (unit_test_sources - ${UNIT_SOURCE} - ${WAMR_RUNTIME_LIB_SOURCE} - ${UNCOMMON_SHARED_SOURCE} - ${SRC_LIST} - ${PLATFORM_SHARED_SOURCE} - ${UTILS_SHARED_SOURCE} - ${MEM_ALLOC_SHARED_SOURCE} - ${LIB_HOST_AGENT_SOURCE} - ${NATIVE_INTERFACE_SOURCE} - ${LIBC_BUILTIN_SOURCE} - ${IWASM_COMMON_SOURCE} - ${IWASM_INTERP_SOURCE} - ${IWASM_AOT_SOURCE} - ${IWASM_COMPL_SOURCE} - ${WASM_APP_LIB_SOURCE_ALL} - ) + ${UNIT_SOURCE} + ${WAMR_RUNTIME_LIB_SOURCE} + ${IWASM_COMPL_SOURCE} +) # Automatically build wasm-apps for this test add_subdirectory(wasm-apps) @@ -59,4 +47,4 @@ add_dependencies (aot_stack_frame_test aot-stack-frame-test-wasm) target_link_libraries (aot_stack_frame_test ${LLVM_AVAILABLE_LIBS} gtest_main ) -#gtest_discover_tests(aot_stack_frame_test) \ No newline at end of file +gtest_discover_tests(aot_stack_frame_test) \ No newline at end of file diff --git a/tests/unit/aot/CMakeLists.txt b/tests/unit/aot/CMakeLists.txt index bb2216bddf..dbf9ad3842 100644 --- a/tests/unit/aot/CMakeLists.txt +++ b/tests/unit/aot/CMakeLists.txt @@ -18,17 +18,6 @@ set (WAMR_BUILD_APP_FRAMEWORK 1) include (../unit_common.cmake) -set (LLVM_SRC_ROOT "${WAMR_ROOT_DIR}/core/deps/llvm") -if (NOT EXISTS "${LLVM_SRC_ROOT}/build") - message (FATAL_ERROR "Cannot find LLVM dir: ${LLVM_SRC_ROOT}/build") -endif () -set (CMAKE_PREFIX_PATH "${LLVM_SRC_ROOT}/build;${CMAKE_PREFIX_PATH}") -find_package(LLVM REQUIRED CONFIG) -include_directories(${LLVM_INCLUDE_DIRS}) -add_definitions(${LLVM_DEFINITIONS}) -message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") -message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") - include (${IWASM_DIR}/compilation/iwasm_compl.cmake) include_directories (${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/tests/unit/compilation/CMakeLists.txt b/tests/unit/compilation/CMakeLists.txt index 65a9dfbdaa..8f1b85f003 100644 --- a/tests/unit/compilation/CMakeLists.txt +++ b/tests/unit/compilation/CMakeLists.txt @@ -20,17 +20,6 @@ set (WAMR_BUILD_AOT 1) include (../unit_common.cmake) -set (LLVM_SRC_ROOT "${WAMR_ROOT_DIR}/core/deps/llvm") -if (NOT EXISTS "${LLVM_SRC_ROOT}/build") - message (FATAL_ERROR "Cannot find LLVM dir: ${LLVM_SRC_ROOT}/build") -endif () -set (CMAKE_PREFIX_PATH "${LLVM_SRC_ROOT}/build;${CMAKE_PREFIX_PATH}") -find_package(LLVM REQUIRED CONFIG) -include_directories(${LLVM_INCLUDE_DIRS}) -add_definitions(${LLVM_DEFINITIONS}) -message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") -message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") - include (${IWASM_DIR}/compilation/iwasm_compl.cmake) include_directories (${CMAKE_CURRENT_SOURCE_DIR}) @@ -40,22 +29,11 @@ file (GLOB_RECURSE source_all ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) set (UNIT_SOURCE ${source_all}) set (unit_test_sources - ${UNIT_SOURCE} - ${WAMR_RUNTIME_LIB_SOURCE} - ${UNCOMMON_SHARED_SOURCE} - ${SRC_LIST} - ${PLATFORM_SHARED_SOURCE} - ${UTILS_SHARED_SOURCE} - ${MEM_ALLOC_SHARED_SOURCE} - ${LIB_HOST_AGENT_SOURCE} - ${NATIVE_INTERFACE_SOURCE} - ${LIBC_BUILTIN_SOURCE} - ${IWASM_COMMON_SOURCE} - ${IWASM_INTERP_SOURCE} - ${IWASM_AOT_SOURCE} - ${IWASM_COMPL_SOURCE} - ${WASM_APP_LIB_SOURCE_ALL} - ) + ${UNIT_SOURCE} + ${WAMR_RUNTIME_LIB_SOURCE} + ${IWASM_COMPL_SOURCE} + ${UNCOMMON_SHARED_SOURCE} +) # Now simply link against gtest or gtest_main as needed. Eg add_executable (compilation_test ${unit_test_sources}) diff --git a/tests/unit/custom-section/CMakeLists.txt b/tests/unit/custom-section/CMakeLists.txt index 747a8b1263..1953146519 100644 --- a/tests/unit/custom-section/CMakeLists.txt +++ b/tests/unit/custom-section/CMakeLists.txt @@ -22,17 +22,6 @@ set (WAMR_BUILD_LOAD_CUSTOM_SECTION 1) include (../unit_common.cmake) -set (LLVM_SRC_ROOT "${WAMR_ROOT_DIR}/core/deps/llvm") -if (NOT EXISTS "${LLVM_SRC_ROOT}/build") - message (FATAL_ERROR "Cannot find LLVM dir: ${LLVM_SRC_ROOT}/build") -endif () -set (CMAKE_PREFIX_PATH "${LLVM_SRC_ROOT}/build;${CMAKE_PREFIX_PATH}") -find_package(LLVM REQUIRED CONFIG) -include_directories(${LLVM_INCLUDE_DIRS}) -add_definitions(${LLVM_DEFINITIONS}) -message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") -message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") - include (${IWASM_DIR}/compilation/iwasm_compl.cmake) include_directories (${CMAKE_CURRENT_SOURCE_DIR}) @@ -42,17 +31,10 @@ file (GLOB_RECURSE source_all ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) set (UNIT_SOURCE ${source_all}) set (unit_test_sources - ${UNIT_SOURCE} - ${PLATFORM_SHARED_SOURCE} - ${UTILS_SHARED_SOURCE} - ${MEM_ALLOC_SHARED_SOURCE} - ${NATIVE_INTERFACE_SOURCE} - ${IWASM_COMMON_SOURCE} - ${IWASM_INTERP_SOURCE} - ${IWASM_AOT_SOURCE} - ${IWASM_COMPL_SOURCE} - ${WASM_APP_LIB_SOURCE_ALL} - ) + ${UNIT_SOURCE} + ${WAMR_RUNTIME_LIB_SOURCE} + ${IWASM_COMPL_SOURCE} +) # Automatically build wasm-apps for this test add_subdirectory(wasm-apps) diff --git a/tests/unit/gc/CMakeLists.txt b/tests/unit/gc/CMakeLists.txt index 6d9670dfe5..c8b865a384 100644 --- a/tests/unit/gc/CMakeLists.txt +++ b/tests/unit/gc/CMakeLists.txt @@ -21,21 +21,9 @@ file (GLOB_RECURSE source_all ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) set (UNIT_SOURCE ${source_all}) set (unit_test_sources - ${UNIT_SOURCE} - ${WAMR_RUNTIME_LIB_SOURCE} - ${UNCOMMON_SHARED_SOURCE} - ${SRC_LIST} - ${PLATFORM_SHARED_SOURCE} - ${UTILS_SHARED_SOURCE} - ${MEM_ALLOC_SHARED_SOURCE} - ${LIB_HOST_AGENT_SOURCE} - ${NATIVE_INTERFACE_SOURCE} - ${LIBC_BUILTIN_SOURCE} - ${IWASM_COMMON_SOURCE} - ${IWASM_INTERP_SOURCE} - ${IWASM_AOT_SOURCE} - ${IWASM_COMPL_SOURCE} - ${WASM_APP_LIB_SOURCE_ALL} + ${UNIT_SOURCE} + ${WAMR_RUNTIME_LIB_SOURCE} + ${UNCOMMON_SHARED_SOURCE} ) add_executable (gc_test ${unit_test_sources}) @@ -48,4 +36,4 @@ add_custom_command(TARGET gc_test POST_BUILD COMMENT "Copy wasm files to directory ${CMAKE_CURRENT_BINARY_DIR}" ) -#gtest_discover_tests(gc_test) \ No newline at end of file +gtest_discover_tests(gc_test) \ No newline at end of file diff --git a/tests/unit/interpreter/CMakeLists.txt b/tests/unit/interpreter/CMakeLists.txt index f0a1d5e22a..c5e1018f4a 100644 --- a/tests/unit/interpreter/CMakeLists.txt +++ b/tests/unit/interpreter/CMakeLists.txt @@ -24,15 +24,9 @@ file (GLOB_RECURSE source_all ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) set (UNIT_SOURCE ${source_all}) set (unit_test_sources - ${UNIT_SOURCE} - ${PLATFORM_SHARED_SOURCE} - ${UTILS_SHARED_SOURCE} - ${MEM_ALLOC_SHARED_SOURCE} - ${NATIVE_INTERFACE_SOURCE} - ${LIBC_BUILTIN_SOURCE} - ${IWASM_COMMON_SOURCE} - ${IWASM_INTERP_SOURCE} - ) + ${UNIT_SOURCE} + ${WAMR_RUNTIME_LIB_SOURCE} +) # Now simply link against gtest or gtest_main as needed. Eg add_executable (interpreter_test ${unit_test_sources}) diff --git a/tests/unit/libc-builtin/CMakeLists.txt b/tests/unit/libc-builtin/CMakeLists.txt index f39ed44444..2eaaa8b006 100644 --- a/tests/unit/libc-builtin/CMakeLists.txt +++ b/tests/unit/libc-builtin/CMakeLists.txt @@ -7,8 +7,6 @@ project (test-libc-builtin) add_definitions (-DRUN_ON_LINUX) -set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - set (WAMR_BUILD_LIBC_WASI 0) set (WAMR_BUILD_APP_FRAMEWORK 0) @@ -21,9 +19,9 @@ file (GLOB_RECURSE source_all ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) set (UNIT_SOURCE ${source_all}) set (unit_test_sources - ${UNIT_SOURCE} - ${WAMR_RUNTIME_LIB_SOURCE} - ) + ${UNIT_SOURCE} + ${WAMR_RUNTIME_LIB_SOURCE} +) add_executable (libc_builtin_test ${unit_test_sources}) diff --git a/tests/unit/linear-memory-aot/CMakeLists.txt b/tests/unit/linear-memory-aot/CMakeLists.txt index 02e96c6d10..eab9a49eca 100644 --- a/tests/unit/linear-memory-aot/CMakeLists.txt +++ b/tests/unit/linear-memory-aot/CMakeLists.txt @@ -22,21 +22,11 @@ file (GLOB_RECURSE source_all ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) set (UNIT_SOURCE ${source_all}) set (unit_test_sources - ${UNIT_SOURCE} - ${WAMR_RUNTIME_LIB_SOURCE} - ${UNCOMMON_SHARED_SOURCE} - ${SRC_LIST} - ${PLATFORM_SHARED_SOURCE} - ${UTILS_SHARED_SOURCE} - ${MEM_ALLOC_SHARED_SOURCE} - ${LIB_HOST_AGENT_SOURCE} - ${NATIVE_INTERFACE_SOURCE} - ${LIBC_BUILTIN_SOURCE} - ${IWASM_COMMON_SOURCE} - ${IWASM_INTERP_SOURCE} - ${IWASM_AOT_SOURCE} - ${IWASM_COMPL_SOURCE} - ${WASM_APP_LIB_SOURCE_ALL} + ${UNIT_SOURCE} + ${WAMR_RUNTIME_LIB_SOURCE} + ${UNCOMMON_SHARED_SOURCE} + ${IWASM_COMPL_SOURCE} + ${WASM_APP_LIB_SOURCE_ALL} ) # Test case: .aot file with hardware bound check. diff --git a/tests/unit/linear-memory-wasm/CMakeLists.txt b/tests/unit/linear-memory-wasm/CMakeLists.txt index a899b8fbe4..084d0c0942 100644 --- a/tests/unit/linear-memory-wasm/CMakeLists.txt +++ b/tests/unit/linear-memory-wasm/CMakeLists.txt @@ -25,18 +25,6 @@ set (unit_test_sources ${UNIT_SOURCE} ${WAMR_RUNTIME_LIB_SOURCE} ${UNCOMMON_SHARED_SOURCE} - ${SRC_LIST} - ${PLATFORM_SHARED_SOURCE} - ${UTILS_SHARED_SOURCE} - ${MEM_ALLOC_SHARED_SOURCE} - ${LIB_HOST_AGENT_SOURCE} - ${NATIVE_INTERFACE_SOURCE} - ${LIBC_BUILTIN_SOURCE} - ${IWASM_COMMON_SOURCE} - ${IWASM_INTERP_SOURCE} - ${IWASM_AOT_SOURCE} - ${IWASM_COMPL_SOURCE} - ${WASM_APP_LIB_SOURCE_ALL} ) # Test case: .wasm file with hardware bound check. diff --git a/tests/unit/linux-perf/CMakeLists.txt b/tests/unit/linux-perf/CMakeLists.txt index 572a087050..0dca75bd55 100644 --- a/tests/unit/linux-perf/CMakeLists.txt +++ b/tests/unit/linux-perf/CMakeLists.txt @@ -22,17 +22,6 @@ set (WAMR_BUILD_DUMP_CALL_STACK 1) include (../unit_common.cmake) -set (LLVM_SRC_ROOT "${WAMR_ROOT_DIR}/core/deps/llvm") -if (NOT EXISTS "${LLVM_SRC_ROOT}/build") - message (FATAL_ERROR "Cannot find LLVM dir: ${LLVM_SRC_ROOT}/build") -endif () -set (CMAKE_PREFIX_PATH "${LLVM_SRC_ROOT}/build;${CMAKE_PREFIX_PATH}") -find_package(LLVM REQUIRED CONFIG) -include_directories(${LLVM_INCLUDE_DIRS}) -add_definitions(${LLVM_DEFINITIONS}) -message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") -message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") - include (${IWASM_DIR}/compilation/iwasm_compl.cmake) add_executable (linux_perf_test test_sort_func_ptrs.cc) diff --git a/tests/unit/memory64/CMakeLists.txt b/tests/unit/memory64/CMakeLists.txt index f3629a7c40..f85c68cf54 100644 --- a/tests/unit/memory64/CMakeLists.txt +++ b/tests/unit/memory64/CMakeLists.txt @@ -22,19 +22,6 @@ set(WAMR_BUILD_SHARED_MEMORY 1) # include(GoogleTest) include(../unit_common.cmake) -set(LLVM_SRC_ROOT "${WAMR_ROOT_DIR}/core/deps/llvm") - -if (NOT EXISTS "${LLVM_SRC_ROOT}/build") - message(FATAL_ERROR "Cannot find LLVM dir: ${LLVM_SRC_ROOT}/build") -endif () - -set(CMAKE_PREFIX_PATH "${LLVM_SRC_ROOT}/build;${CMAKE_PREFIX_PATH}") -find_package(LLVM REQUIRED CONFIG) -include_directories(${LLVM_INCLUDE_DIRS}) -add_definitions(${LLVM_DEFINITIONS}) -message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") -message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") - include(${IWASM_DIR}/compilation/iwasm_compl.cmake) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) @@ -43,14 +30,11 @@ file(GLOB_RECURSE source_all ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) set(UNIT_SOURCE ${source_all}) -aux_source_directory(. SRC_LIST) - set(unit_test_sources - ${UNIT_SOURCE} - ${WAMR_RUNTIME_LIB_SOURCE} - ${UNCOMMON_SHARED_SOURCE} - ${SRC_LIST} - ) + ${UNIT_SOURCE} + ${WAMR_RUNTIME_LIB_SOURCE} + ${UNCOMMON_SHARED_SOURCE} +) # Now simply link against gtest or gtest_main as needed. Eg add_executable(memory64_test ${unit_test_sources}) diff --git a/tests/unit/running-modes/CMakeLists.txt b/tests/unit/running-modes/CMakeLists.txt index 5fc6a80bce..df6798cf1a 100644 --- a/tests/unit/running-modes/CMakeLists.txt +++ b/tests/unit/running-modes/CMakeLists.txt @@ -18,35 +18,17 @@ set(WAMR_BUILD_FAST_JIT 1) # if only load this CMake other than load it as subdirectory include(../unit_common.cmake) -set(LLVM_SRC_ROOT "${WAMR_ROOT_DIR}/core/deps/llvm") - -if (NOT EXISTS "${LLVM_SRC_ROOT}/build") - message(FATAL_ERROR "Cannot find LLVM dir: ${LLVM_SRC_ROOT}/build") -endif () - -set(CMAKE_PREFIX_PATH "${LLVM_SRC_ROOT}/build;${CMAKE_PREFIX_PATH}") -find_package(LLVM REQUIRED CONFIG) -include_directories(${LLVM_INCLUDE_DIRS}) -add_definitions(${LLVM_DEFINITIONS}) -message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") -message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") - include(${IWASM_DIR}/compilation/iwasm_compl.cmake) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -file(GLOB_RECURSE source_all ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) - -set(UNIT_SOURCE ${source_all}) - -aux_source_directory(. SRC_LIST) +aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} SRC_LIST) set(unit_test_sources - ${UNIT_SOURCE} - ${WAMR_RUNTIME_LIB_SOURCE} - ${UNCOMMON_SHARED_SOURCE} - ${SRC_LIST} - ) + ${WAMR_RUNTIME_LIB_SOURCE} + ${UNCOMMON_SHARED_SOURCE} + ${SRC_LIST} +) # Now simply link against gtest or gtest_main as needed. Eg add_executable(wasm_running_modes_test ${unit_test_sources}) diff --git a/tests/unit/runtime-common/CMakeLists.txt b/tests/unit/runtime-common/CMakeLists.txt index 21e5a917f2..7aeaae829d 100644 --- a/tests/unit/runtime-common/CMakeLists.txt +++ b/tests/unit/runtime-common/CMakeLists.txt @@ -12,32 +12,16 @@ set(WAMR_BUILD_APP_FRAMEWORK 0) include(../unit_common.cmake) -set(LLVM_SRC_ROOT "${WAMR_ROOT_DIR}/core/deps/llvm") - -if(NOT EXISTS "${LLVM_SRC_ROOT}/build") - message(FATAL_ERROR "Cannot find LLVM dir: ${LLVM_SRC_ROOT}/build") -endif() - -set(CMAKE_PREFIX_PATH "${LLVM_SRC_ROOT}/build;${CMAKE_PREFIX_PATH}") -find_package(LLVM REQUIRED CONFIG) -include_directories(${LLVM_INCLUDE_DIRS}) -add_definitions(${LLVM_DEFINITIONS}) -message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") -message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") - include_directories(${CMAKE_CURRENT_SOURCE_DIR}) file(GLOB_RECURSE source_all ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) set(UNIT_SOURCE ${source_all}) -aux_source_directory(. SRC_LIST) - set(unit_test_sources ${UNIT_SOURCE} ${WAMR_RUNTIME_LIB_SOURCE} ${UNCOMMON_SHARED_SOURCE} - ${SRC_LIST} ) add_executable(runtime_common_test ${unit_test_sources}) diff --git a/tests/unit/shared-heap/CMakeLists.txt b/tests/unit/shared-heap/CMakeLists.txt index fa7067918a..72f81d6a95 100644 --- a/tests/unit/shared-heap/CMakeLists.txt +++ b/tests/unit/shared-heap/CMakeLists.txt @@ -29,19 +29,6 @@ endif () # if only load this CMake other than load it as subdirectory include(../unit_common.cmake) -set(LLVM_SRC_ROOT "${WAMR_ROOT_DIR}/core/deps/llvm") - -if (NOT EXISTS "${LLVM_SRC_ROOT}/build") - message(FATAL_ERROR "Cannot find LLVM dir: ${LLVM_SRC_ROOT}/build") -endif () - -set(CMAKE_PREFIX_PATH "${LLVM_SRC_ROOT}/build;${CMAKE_PREFIX_PATH}") -find_package(LLVM REQUIRED CONFIG) -include_directories(${LLVM_INCLUDE_DIRS}) -add_definitions(${LLVM_DEFINITIONS}) -message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") -message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") - include(${IWASM_DIR}/compilation/iwasm_compl.cmake) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) @@ -50,14 +37,11 @@ file(GLOB_RECURSE source_all ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) set(UNIT_SOURCE ${source_all}) -aux_source_directory(. SRC_LIST) - set(unit_test_sources - ${UNIT_SOURCE} - ${WAMR_RUNTIME_LIB_SOURCE} - ${UNCOMMON_SHARED_SOURCE} - ${SRC_LIST} - ) + ${UNIT_SOURCE} + ${WAMR_RUNTIME_LIB_SOURCE} + ${UNCOMMON_SHARED_SOURCE} +) # Now simply link against gtest or gtest_main as needed. Eg add_executable(shared_heap_test ${unit_test_sources}) diff --git a/tests/unit/shared-utils/CMakeLists.txt b/tests/unit/shared-utils/CMakeLists.txt index 47b6b835ba..1826c8a7f9 100644 --- a/tests/unit/shared-utils/CMakeLists.txt +++ b/tests/unit/shared-utils/CMakeLists.txt @@ -19,8 +19,8 @@ file (GLOB_RECURSE source_all ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) set (UNIT_SOURCE ${source_all}) set (unit_test_sources - ${UNIT_SOURCE} - ${WAMR_RUNTIME_LIB_SOURCE} + ${UNIT_SOURCE} + ${WAMR_RUNTIME_LIB_SOURCE} ) add_executable (shared_utils_test ${unit_test_sources}) diff --git a/tests/unit/unit_common.cmake b/tests/unit/unit_common.cmake index 66c50b7e8c..ddc24aa651 100644 --- a/tests/unit/unit_common.cmake +++ b/tests/unit/unit_common.cmake @@ -1,13 +1,6 @@ # Copyright (C) 2019 Intel Corporation. All rights reserved. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# Yes. To solve the compatibility issue with CMAKE (>= 4.0), we need to update -# our `cmake_minimum_required()` to 3.5. However, there are CMakeLists.txt -# from 3rd parties that we should not alter. Therefore, in addition to -# changing the `cmake_minimum_required()`, we should also add a configuration -# here that is compatible with earlier versions. -set(CMAKE_POLICY_VERSION_MINIMUM 3.5 FORCE) - if (NOT DEFINED WAMR_BUILD_PLATFORM) set (WAMR_BUILD_PLATFORM "linux") endif () @@ -18,10 +11,6 @@ include_directories(${UNIT_ROOT_DIR}) enable_language (ASM) -# Reset default linker flags -set (CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") -set (CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") - # 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) @@ -71,11 +60,6 @@ if (NOT DEFINED WAMR_BUILD_APP_FRAMEWORK) set (WAMR_BUILD_APP_FRAMEWORK 1) endif () -if (COLLECT_CODE_COVERAGE EQUAL 1) - set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage") - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage") -endif () - set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -ffunction-sections -fdata-sections \ -Wall -Wno-unused-parameter -Wno-pedantic") @@ -90,23 +74,20 @@ include_directories (${SHARED_DIR}/include include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake) -if (NOT (GOOGLETEST_INCLUDED EQUAL 1)) -# Prevent overriding the parent project's compiler/linker -# settings on Windows -set (gtest_force_shared_crt ON CACHE BOOL "" FORCE) - -# Fetch Google test -include (FetchContent) -FetchContent_Declare ( - googletest - URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip -) -FetchContent_MakeAvailable (googletest) - -endif() - # Add helper classes include_directories(${CMAKE_CURRENT_LIST_DIR}/common) -message ("unit_common.cmake included") +# Involve LLVM for AOT and JIT +set(LLVM_SRC_ROOT "${WAMR_ROOT_DIR}/core/deps/llvm") +if (NOT EXISTS "${LLVM_SRC_ROOT}/build") + message(FATAL_ERROR "Cannot find LLVM dir: ${LLVM_SRC_ROOT}/build") +endif () +set (LLVM_DIR ${LLVM_SRC_ROOT}/build/lib/cmake/llvm) + +find_package(LLVM REQUIRED CONFIG) +include_directories(${LLVM_INCLUDE_DIRS}) +add_definitions(${LLVM_DEFINITIONS}) +message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") +message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") +message(STATUS "unit_common.cmake included") diff --git a/tests/unit/wasm-c-api/CMakeLists.txt b/tests/unit/wasm-c-api/CMakeLists.txt index 95cbfbd544..3150c93254 100644 --- a/tests/unit/wasm-c-api/CMakeLists.txt +++ b/tests/unit/wasm-c-api/CMakeLists.txt @@ -4,14 +4,8 @@ cmake_minimum_required (VERSION 3.14) project (wasm_c_api_test) -################ runtime settings ################ -set(CMAKE_BUILD_TYPE Debug) set(WAMR_BUILD_PLATFORM "linux") -# Resetdefault linker flags -set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") -set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "") - # WAMR features switch if (NOT DEFINED WAMR_BUILD_TARGET) set(WAMR_BUILD_TARGET "X86_64") @@ -23,49 +17,8 @@ set(WAMR_BUILD_LIBC_BUILTIN 1) set(WAMR_BUILD_LIBC_WASI 0) set(WAMR_BUILD_FAST_INTERP 0) -# compiling and linking flags -set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections -pie -fPIE") - -# build out vmlib -# hard code path here -set(WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../../..) -include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake) - -add_library(vmlib STATIC ${WAMR_RUNTIME_LIB_SOURCE}) -################################################ - -################ unit test related ################ - -# Yes. To solve the compatibility issue with CMAKE (>= 4.0), we need to update -# our `cmake_minimum_required()` to 3.5. However, there are CMakeLists.txt -# from 3rd parties that we should not alter. Therefore, in addition to -# changing the `cmake_minimum_required()`, we should also add a configuration -# here that is compatible with earlier versions. -set(CMAKE_POLICY_VERSION_MINIMUM 3.5 FORCE) - -# Add googletest directly to our build. This defines -# the gtest and gtest_main targets. - -if (NOT (GOOGLETEST_INCLUDED EQUAL 1)) -# Prevent overriding the parent project's compiler/linker -# settings on Windows -set (gtest_force_shared_crt ON CACHE BOOL "" FORCE) - -# Fetch Google test -include (FetchContent) -FetchContent_Declare ( - googletest - URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip -) -FetchContent_MakeAvailable (googletest) -endif() - -enable_testing() - -add_executable(wasm_c_api_test - basic.cc -) - -target_link_libraries(wasm_c_api_test vmlib gtest_main) +include (../unit_common.cmake) +add_executable(wasm_c_api_test basic.cc ${WAMR_RUNTIME_LIB_SOURCE}) +target_link_libraries(wasm_c_api_test gtest_main) gtest_discover_tests(wasm_c_api_test) diff --git a/tests/unit/wasm-vm/CMakeLists.txt b/tests/unit/wasm-vm/CMakeLists.txt index 6242a48b99..e7d3c757e6 100644 --- a/tests/unit/wasm-vm/CMakeLists.txt +++ b/tests/unit/wasm-vm/CMakeLists.txt @@ -22,21 +22,10 @@ file (GLOB_RECURSE source_all ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) set (UNIT_SOURCE ${source_all}) set (unit_test_sources - ${UNIT_SOURCE} - ${PLATFORM_SHARED_SOURCE} - ${UTILS_SHARED_SOURCE} - ${MEM_ALLOC_SHARED_SOURCE} - ${LIB_HOST_AGENT_SOURCE} - ${NATIVE_INTERFACE_SOURCE} - ${LIBC_BUILTIN_SOURCE} - ${LIBC_WASI_SOURCE} - ${IWASM_COMMON_SOURCE} - ${IWASM_INTERP_SOURCE} - ${IWASM_AOT_SOURCE} - ${IWASM_COMPL_SOURCE} - ${WASM_APP_LIB_SOURCE_ALL} - ${UNCOMMON_SHARED_SOURCE} - ) + ${UNIT_SOURCE} + ${WAMR_RUNTIME_LIB_SOURCE} + ${UNCOMMON_SHARED_SOURCE} +) # Now simply link against gtest or gtest_main as needed. Eg add_executable(wasm_vm_test ${unit_test_sources}) diff --git a/tests/wamr-test-suites/spec-test-script/collect_coverage.sh b/tests/wamr-test-suites/spec-test-script/collect_coverage.sh index 0091e76496..12bee733a4 100755 --- a/tests/wamr-test-suites/spec-test-script/collect_coverage.sh +++ b/tests/wamr-test-suites/spec-test-script/collect_coverage.sh @@ -28,10 +28,12 @@ echo "Start to collect code coverage of ${SRC_COV_DIR} .." pushd ${SRC_COV_DIR} > /dev/null 2>&1 # collect all code coverage data -lcov -q -o ${SRC_TEMP_COV_FILE} -c -d . --rc lcov_branch_coverage=1 +# for lcov 2.x: ignore-errors mismatch,negative +lcov -q -o ${SRC_TEMP_COV_FILE} -c -d . --rc lcov_branch_coverage=1 --rc geninfo_unexecuted_blocks=1 # extract code coverage data of WAMR source files +# for lcov 2.x: ignore-errors unused lcov -q -r ${SRC_TEMP_COV_FILE} -o ${SRC_TEMP_COV_FILE} \ - -rc lcov_branch_coverage=1 \ + -rc lcov_branch_coverage=1\ "*/usr/*" "*/_deps/*" "*/deps/*" "*/tests/unit/*" \ "*/llvm/include/*" "*/include/llvm/*" "*/samples/*" \ "*/test-tools/*" "*/tests/standalone/*" "*/tests/*" diff --git a/tests/wamr-test-suites/test_wamr.sh b/tests/wamr-test-suites/test_wamr.sh index 1edf363bcb..974db1d2c1 100755 --- a/tests/wamr-test-suites/test_wamr.sh +++ b/tests/wamr-test-suites/test_wamr.sh @@ -39,8 +39,8 @@ function help() echo "-F set the firmware path used by qemu" echo "-C enable code coverage collect" echo "-j set the platform to test" - echo "-T set the sanitizer(s) used during testing. It can be either a comma-separated list - (e.g., ubsan, asan) or a single option + echo "-T set the sanitizer(s) used during testing. It can be either a comma-separated list + (e.g., ubsan, asan) or a single option (e.g., ubsan, tsan, asan, posan)." echo "-A use the specified wamrc command instead of building it" echo "-N enable extended const expression feature" @@ -329,14 +329,14 @@ function unit_test() echo "Now start unit tests" cd ${WORK_DIR} - rm -fr unittest-build && mkdir unittest-build - cd unittest-build + rm -fr unittest-build echo "Build unit test" touch ${REPORT_DIR}/unit_test_report.txt - cmake ${WORK_DIR}/../../unit -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE} - make -j - make test | tee -a ${REPORT_DIR}/unit_test_report.txt + cmake -S ${WORK_DIR}/../../unit -B unittest-build \ + -DCOLLECT_CODE_COVERAGE=${COLLECT_CODE_COVERAGE} + cmake --build unittest-build + ctest --test-dir unittest-build --output-on-failure | tee -a ${REPORT_DIR}/unit_test_report.txt echo "Finish unit tests" } @@ -503,7 +503,7 @@ function spec_test() git reset --hard 8d4f6aa2b00a8e7c0174410028625c6a176db8a1 # ignore import table cases git apply --ignore-whitespace ../../spec-test-script/extended_const.patch || exit 1 - + elif [[ ${ENABLE_MEMORY64} == 1 ]]; then echo "checkout spec for memory64 proposal" @@ -1187,7 +1187,15 @@ function trigger() } # if collect code coverage, ignore -s, test all test cases. -if [[ $TEST_CASE_ARR ]];then +if [[ $TEST_CASE_ARR == "unit" ]];then + # unit test cases are designed with specific compilation flags + # and run under specific modes. + # There is no need to loop through all running modes in this script. + unit_test || (echo "TEST FAILED"; exit 1) + collect_coverage unit + echo "JUST SKIP UNIT TEST NOW" +elif [[ $TEST_CASE_ARR == "spec" ]];then + # loop through all running modes trigger || (echo "TEST FAILED"; exit 1) else # test all suite, ignore polybench and libsodium because of long time cost @@ -1200,6 +1208,7 @@ else TEST_CASE_ARR+=("libsodium") fi ' + # loop through all running modes trigger || (echo "TEST FAILED"; exit 1) # Add more suites here fi From b16050ec509bcf6a034f0dea28c8226e803b6f65 Mon Sep 17 00:00:00 2001 From: "liang.he@intel.com" Date: Tue, 9 Sep 2025 01:06:21 +0000 Subject: [PATCH 02/10] refactor: enable LLVM support across various CMake configurations --- tests/unit/CMakeLists.txt | 12 ++-- tests/unit/aot-stack-frame/CMakeLists.txt | 3 +- tests/unit/aot/CMakeLists.txt | 5 ++ tests/unit/compilation/CMakeLists.txt | 4 ++ tests/unit/custom-section/CMakeLists.txt | 3 +- tests/unit/interpreter/CMakeLists.txt | 5 +- tests/unit/libc-builtin/CMakeLists.txt | 5 ++ tests/unit/linear-memory-aot/CMakeLists.txt | 8 ++- tests/unit/linux-perf/CMakeLists.txt | 5 +- tests/unit/running-modes/CMakeLists.txt | 18 +++++- .../running-modes/wasm-apps/CMakeLists.txt | 33 +++------- tests/unit/runtime-common/CMakeLists.txt | 10 ++- tests/unit/shared-heap/CMakeLists.txt | 3 +- tests/unit/shared-utils/CMakeLists.txt | 4 ++ tests/unit/unit_common.cmake | 61 +------------------ tests/unit/wasm-vm/CMakeLists.txt | 5 ++ 16 files changed, 81 insertions(+), 103 deletions(-) diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 9c8caa7d42..d11cf095f7 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -30,13 +30,8 @@ if(WAMR_BUILD_TARGET STREQUAL "X86_32") set(CMAKE_LIBRARY_ARCHITECTURE "i386-linux-gnu" CACHE STRING "" FORCE) endif() -# Prevent overriding the parent project's compiler/linker -# settings on Windows -set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - # Fetch Google test include (FetchContent) - if(${CMAKE_VERSION} VERSION_GREATER_EQUAL "3.24") FetchContent_Declare ( googletest @@ -50,10 +45,11 @@ else() ) endif() +# Prevent overriding the parent project's compiler/linker +# settings on Windows +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) FetchContent_MakeAvailable(googletest) -SET(GOOGLETEST_INCLUDED 1) - include(GoogleTest) enable_testing() @@ -76,7 +72,7 @@ if (NOT WAMR_BUILD_TARGET STREQUAL "X86_32") add_subdirectory (compilation) # Fast-JIT or mem64 is not supported on X86_32 - # add_subdirectory (running-modes) + add_subdirectory (running-modes) add_subdirectory (memory64) # add_subdirectory (shared-heap) diff --git a/tests/unit/aot-stack-frame/CMakeLists.txt b/tests/unit/aot-stack-frame/CMakeLists.txt index 01ea6578ea..7eb2583ded 100644 --- a/tests/unit/aot-stack-frame/CMakeLists.txt +++ b/tests/unit/aot-stack-frame/CMakeLists.txt @@ -9,7 +9,8 @@ add_definitions (-DRUN_ON_LINUX) set (WAMR_BUILD_AOT 1) set (WAMR_BUILD_INTERP 0) -set (WAMR_BUILD_JIT 0) +# to involve LLVM +set (WAMR_BUILD_JIT 1) set (WAMR_BUILD_SIMD 1) set (WAMR_BUILD_REF_TYPES 1) set (WAMR_BUILD_LIBC_WASI 0) diff --git a/tests/unit/aot/CMakeLists.txt b/tests/unit/aot/CMakeLists.txt index dbf9ad3842..31abc5d1fd 100644 --- a/tests/unit/aot/CMakeLists.txt +++ b/tests/unit/aot/CMakeLists.txt @@ -13,6 +13,11 @@ add_definitions (-DWASM_ENABLE_WAMR_COMPILER=1) add_definitions (-DWASM_ENABLE_DUMP_CALL_STACK=1) add_definitions (-DWASM_ENABLE_AOT_STACK_FRAME=1) +set (WAMR_BUILD_AOT 1) +set (WAMR_BUILD_FAST_INTERP 0) +set (WAMR_BUILD_INTERP 0) +# to involve LLVM +set (WAMR_BUILD_JIT 1) set (WAMR_BUILD_LIBC_WASI 0) set (WAMR_BUILD_APP_FRAMEWORK 1) diff --git a/tests/unit/compilation/CMakeLists.txt b/tests/unit/compilation/CMakeLists.txt index 8f1b85f003..554aaa9395 100644 --- a/tests/unit/compilation/CMakeLists.txt +++ b/tests/unit/compilation/CMakeLists.txt @@ -17,6 +17,10 @@ set (WAMR_BUILD_LIBC_WASI 0) set (WAMR_BUILD_APP_FRAMEWORK 0) set (WAMR_BUILD_THREAD_MGR 1) set (WAMR_BUILD_AOT 1) +set (WAMR_BUILD_FAST_INTERP 0) +set (WAMR_BUILD_INTERP 0) +# to involve LLVM +set (WAMR_BUILD_JIT 1) include (../unit_common.cmake) diff --git a/tests/unit/custom-section/CMakeLists.txt b/tests/unit/custom-section/CMakeLists.txt index 1953146519..13db56e0ce 100644 --- a/tests/unit/custom-section/CMakeLists.txt +++ b/tests/unit/custom-section/CMakeLists.txt @@ -9,7 +9,8 @@ add_definitions (-DRUN_ON_LINUX) set (WAMR_BUILD_LIBC_WASI 0) set (WAMR_BUILD_LIBC_BUILTIN 0) -set (WAMR_BUILD_JIT 0) +# to involve LLVM +set (WAMR_BUILD_JIT 1) set (WAMR_BUILD_LAZY_JIT 0) set (WAMR_BUILD_AOT 1) diff --git a/tests/unit/interpreter/CMakeLists.txt b/tests/unit/interpreter/CMakeLists.txt index c5e1018f4a..7dc14ebff9 100644 --- a/tests/unit/interpreter/CMakeLists.txt +++ b/tests/unit/interpreter/CMakeLists.txt @@ -11,9 +11,12 @@ add_definitions (-Dattr_container_malloc=malloc) add_definitions (-Dattr_container_free=free) # add_definitions (-DWASM_ENABLE_WAMR_COMPILER=1) +set(WAMR_BUILD_AOT 0) +set(WAMR_BUILD_FAST_INTERP 0) +set(WAMR_BUILD_INTERP 1) +set(WAMR_BUILD_JIT 0) set (WAMR_BUILD_LIBC_WASI 0) set (WAMR_BUILD_APP_FRAMEWORK 1) -set (WAMR_BUILD_AOT 0) include (../unit_common.cmake) diff --git a/tests/unit/libc-builtin/CMakeLists.txt b/tests/unit/libc-builtin/CMakeLists.txt index 2eaaa8b006..8e6b905ddb 100644 --- a/tests/unit/libc-builtin/CMakeLists.txt +++ b/tests/unit/libc-builtin/CMakeLists.txt @@ -7,6 +7,11 @@ project (test-libc-builtin) add_definitions (-DRUN_ON_LINUX) +set (WAMR_BUILD_AOT 0) +set (WAMR_BUILD_FAST_INTERP 0) +set (WAMR_BUILD_INTERP 1) +set (WAMR_BUILD_JIT 0) +set (WAMR_BUILD_LIBC_BUILTIN 1) set (WAMR_BUILD_LIBC_WASI 0) set (WAMR_BUILD_APP_FRAMEWORK 0) diff --git a/tests/unit/linear-memory-aot/CMakeLists.txt b/tests/unit/linear-memory-aot/CMakeLists.txt index eab9a49eca..8133e1c743 100644 --- a/tests/unit/linear-memory-aot/CMakeLists.txt +++ b/tests/unit/linear-memory-aot/CMakeLists.txt @@ -12,6 +12,9 @@ set (WAMR_BUILD_APP_FRAMEWORK 0) set (WAMR_BUILD_MEMORY_PROFILING 1) set (WAMR_BUILD_INTERP 0) set (WAMR_BUILD_AOT 1) +set (WAMR_BUILD_FAST_INTERP 0) +# to involve LLVM +set (WAMR_BUILD_JIT 1) include (../unit_common.cmake) @@ -26,12 +29,11 @@ set (unit_test_sources ${WAMR_RUNTIME_LIB_SOURCE} ${UNCOMMON_SHARED_SOURCE} ${IWASM_COMPL_SOURCE} - ${WASM_APP_LIB_SOURCE_ALL} ) # Test case: .aot file with hardware bound check. add_executable (linear_memory_test_aot ${unit_test_sources}) -target_link_libraries (linear_memory_test_aot gtest_main) +target_link_libraries (linear_memory_test_aot ${LLVM_AVAILABLE_LIBS} gtest_main) gtest_discover_tests(linear_memory_test_aot) target_compile_definitions(linear_memory_test_aot PRIVATE WAMR_DISABLE_HW_BOUND_CHECK=0) @@ -63,6 +65,6 @@ add_custom_command(TARGET linear_memory_test_aot POST_BUILD # Test case: .aot file with no hardware bound check. add_executable (linear_memory_test_aot_no_hw_bound ${unit_test_sources}) -target_link_libraries (linear_memory_test_aot_no_hw_bound gtest_main) +target_link_libraries (linear_memory_test_aot_no_hw_bound ${LLVM_AVAILABLE_LIBS} gtest_main) gtest_discover_tests(linear_memory_test_aot_no_hw_bound) target_compile_definitions(linear_memory_test_aot_no_hw_bound PRIVATE WAMR_DISABLE_HW_BOUND_CHECK=1) diff --git a/tests/unit/linux-perf/CMakeLists.txt b/tests/unit/linux-perf/CMakeLists.txt index 0dca75bd55..45d323e884 100644 --- a/tests/unit/linux-perf/CMakeLists.txt +++ b/tests/unit/linux-perf/CMakeLists.txt @@ -9,7 +9,8 @@ add_definitions (-DRUN_ON_LINUX) set (WAMR_BUILD_LIBC_WASI 0) set (WAMR_BUILD_LIBC_BUILTIN 0) -set (WAMR_BUILD_JIT 0) +# to involve LLVM +set (WAMR_BUILD_JIT 1) set (WAMR_BUILD_LAZY_JIT 0) set (WAMR_BUILD_AOT 1) set (WAMR_BUILD_MULTI_MODULE 0) @@ -26,7 +27,7 @@ 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 gtest_main ) +target_link_libraries(linux_perf_test ${LLVM_AVAILABLE_LIBS} gtest_main ) target_link_options(linux_perf_test PUBLIC LINKER:--unresolved-symbols=ignore-all diff --git a/tests/unit/running-modes/CMakeLists.txt b/tests/unit/running-modes/CMakeLists.txt index df6798cf1a..05a3cf9c97 100644 --- a/tests/unit/running-modes/CMakeLists.txt +++ b/tests/unit/running-modes/CMakeLists.txt @@ -5,8 +5,20 @@ cmake_minimum_required(VERSION 3.14) project(test-running-modes) -# 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") + +include(ExternalProject) +ExternalProject_Add( + test-running-modes-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} +) add_definitions(-DRUN_ON_LINUX) @@ -32,7 +44,7 @@ set(unit_test_sources # Now simply link against gtest or gtest_main as needed. Eg add_executable(wasm_running_modes_test ${unit_test_sources}) - target_link_libraries(wasm_running_modes_test ${LLVM_AVAILABLE_LIBS} gtest_main) +add_dependencies(wasm_running_modes_test test-running-modes-wasm-apps) gtest_discover_tests(wasm_running_modes_test) diff --git a/tests/unit/running-modes/wasm-apps/CMakeLists.txt b/tests/unit/running-modes/wasm-apps/CMakeLists.txt index b2f1e9c0c5..7aec214bab 100644 --- a/tests/unit/running-modes/wasm-apps/CMakeLists.txt +++ b/tests/unit/running-modes/wasm-apps/CMakeLists.txt @@ -4,32 +4,19 @@ 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 () - -set(CMAKE_C_FLAGS "-nostdlib -pthread -Qunused-arguments") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -z stack-size=8192 -nostdlib") -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" - ) +# set(CMAKE_C_FLAGS "-nostdlib -pthread -Qunused-arguments") +# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -z stack-size=8192 -nostdlib") add_executable(mytest.wasm mytest.c) target_link_libraries(mytest.wasm) +target_compile_options(mytest.wasm PRIVATE + -pthread +) +target_link_options(mytest.wasm PRIVATE + LINKER:--allow-undefined + LINKER:--export-all + LINKER:--no-entry +) add_executable(hello.wasm hello.c) target_link_libraries(hello.wasm) diff --git a/tests/unit/runtime-common/CMakeLists.txt b/tests/unit/runtime-common/CMakeLists.txt index 7aeaae829d..f5691b9a51 100644 --- a/tests/unit/runtime-common/CMakeLists.txt +++ b/tests/unit/runtime-common/CMakeLists.txt @@ -7,8 +7,14 @@ project(test-runtime-common) add_definitions(-DRUN_ON_LINUX) -set(WAMR_BUILD_LIBC_WASI 0) -set(WAMR_BUILD_APP_FRAMEWORK 0) +set (WAMR_BUILD_AOT 1) +set (WAMR_BUILD_FAST_INTERP 0) +set (WAMR_BUILD_INTERP 0) +# to involve LLVM +set (WAMR_BUILD_JIT 1) +set (WAMR_BUILD_LIBC_WASI 0) +set (WAMR_BUILD_APP_FRAMEWORK 0) +set (WAMR_BUILD_MULTI_MODULE 1) include(../unit_common.cmake) diff --git a/tests/unit/shared-heap/CMakeLists.txt b/tests/unit/shared-heap/CMakeLists.txt index 72f81d6a95..ce7ae00364 100644 --- a/tests/unit/shared-heap/CMakeLists.txt +++ b/tests/unit/shared-heap/CMakeLists.txt @@ -11,7 +11,8 @@ set(WAMR_BUILD_APP_FRAMEWORK 0) set(WAMR_BUILD_AOT 1) set(WAMR_BUILD_INTERP 1) set(WAMR_BUILD_FAST_INTERP 1) -set(WAMR_BUILD_JIT 0) +# to involve LLVM +set(WAMR_BUILD_JIT 1) if(WAMR_BUILD_TARGET STREQUAL "X86_32") set(WAMR_BUILD_MEMORY64 0) else() diff --git a/tests/unit/shared-utils/CMakeLists.txt b/tests/unit/shared-utils/CMakeLists.txt index 1826c8a7f9..c6f250e6df 100644 --- a/tests/unit/shared-utils/CMakeLists.txt +++ b/tests/unit/shared-utils/CMakeLists.txt @@ -7,6 +7,10 @@ project (test-shared-utils) add_definitions (-DRUN_ON_LINUX) +set (WAMR_BUILD_AOT 0) +set (WAMR_BUILD_FAST_INTERP 0) +set (WAMR_BUILD_INTERP 1) +set (WAMR_BUILD_JIT 0) set (WAMR_BUILD_LIBC_WASI 0) set (WAMR_BUILD_APP_FRAMEWORK 0) diff --git a/tests/unit/unit_common.cmake b/tests/unit/unit_common.cmake index ddc24aa651..b9b9bb92eb 100644 --- a/tests/unit/unit_common.cmake +++ b/tests/unit/unit_common.cmake @@ -5,12 +5,11 @@ if (NOT DEFINED WAMR_BUILD_PLATFORM) set (WAMR_BUILD_PLATFORM "linux") endif () -set (UNIT_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}) - -include_directories(${UNIT_ROOT_DIR}) - 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) @@ -23,47 +22,6 @@ if (NOT DEFINED WAMR_BUILD_TARGET) endif () endif () -if (NOT CMAKE_BUILD_TYPE) - set (CMAKE_BUILD_TYPE Debug) -endif () - -if (NOT DEFINED WAMR_BUILD_INTERP) - # Enable Interpreter by default - set (WAMR_BUILD_INTERP 1) -endif () - -if (NOT DEFINED WAMR_BUILD_AOT) - # Enable AOT by default. - set (WAMR_BUILD_AOT 1) -endif () - -if (NOT DEFINED WAMR_BUILD_JIT) - # Disable JIT by default. - set (WAMR_BUILD_JIT 0) -endif () - -if (NOT DEFINED WAMR_BUILD_LIBC_BUILTIN) - # Enable libc builtin support by default - set (WAMR_BUILD_LIBC_BUILTIN 1) -endif () - -if (NOT DEFINED WAMR_BUILD_LIBC_WASI) - # Enable libc wasi support by default - set (WAMR_BUILD_LIBC_WASI 1) -endif () - -if (NOT DEFINED WAMR_BUILD_MULTI_MODULE) - set (WAMR_BUILD_MULTI_MODULE 1) -endif() - -if (NOT DEFINED WAMR_BUILD_APP_FRAMEWORK) - set (WAMR_BUILD_APP_FRAMEWORK 1) -endif () - -set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--gc-sections") -set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -ffunction-sections -fdata-sections \ - -Wall -Wno-unused-parameter -Wno-pedantic") - set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..) # include the build config template file @@ -77,17 +35,4 @@ include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake) # Add helper classes include_directories(${CMAKE_CURRENT_LIST_DIR}/common) -# Involve LLVM for AOT and JIT -set(LLVM_SRC_ROOT "${WAMR_ROOT_DIR}/core/deps/llvm") -if (NOT EXISTS "${LLVM_SRC_ROOT}/build") - message(FATAL_ERROR "Cannot find LLVM dir: ${LLVM_SRC_ROOT}/build") -endif () -set (LLVM_DIR ${LLVM_SRC_ROOT}/build/lib/cmake/llvm) - -find_package(LLVM REQUIRED CONFIG) -include_directories(${LLVM_INCLUDE_DIRS}) -add_definitions(${LLVM_DEFINITIONS}) -message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}") -message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}") - message(STATUS "unit_common.cmake included") diff --git a/tests/unit/wasm-vm/CMakeLists.txt b/tests/unit/wasm-vm/CMakeLists.txt index e7d3c757e6..eeda532570 100644 --- a/tests/unit/wasm-vm/CMakeLists.txt +++ b/tests/unit/wasm-vm/CMakeLists.txt @@ -7,6 +7,11 @@ project (test-wasm-vm) add_definitions (-DRUN_ON_LINUX) +set(WAMR_BUILD_AOT 0) +set(WAMR_BUILD_FAST_INTERP 0) +set(WAMR_BUILD_INTERP 1) +set(WAMR_BUILD_JIT 0) + add_definitions (-Dattr_container_malloc=malloc) add_definitions (-Dattr_container_free=free) From 7b248cf03244d3c652850ea51e6d164a752f9468 Mon Sep 17 00:00:00 2001 From: "liang.he@intel.com" Date: Tue, 9 Sep 2025 01:28:23 +0000 Subject: [PATCH 03/10] fix: remove redundant LLVM dependency installation and add i386 support for libraries --- .github/workflows/compilation_on_android_ubuntu.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/compilation_on_android_ubuntu.yml b/.github/workflows/compilation_on_android_ubuntu.yml index 89fa54743d..9dc528b6d5 100644 --- a/.github/workflows/compilation_on_android_ubuntu.yml +++ b/.github/workflows/compilation_on_android_ubuntu.yml @@ -351,9 +351,6 @@ jobs: with: os: ${{ matrix.os }} - - name: install llvm dependencies - run: sudo apt update && sudo apt install -y libzstd-dev zlib1g-dev - - name: Build wamrc run: | mkdir build && cd build @@ -364,8 +361,9 @@ jobs: - name: Install dependencies for X86_32 if: matrix.build_target == 'X86_32' run: | + sudo dpkg --add-architecture i386 sudo apt-get update - sudo apt-get install -y g++-multilib + sudo apt-get install -y g++-multilib libzstd-dev:i386 zlib1g-dev:i386 - name: Build and run unit tests run: | From c247d3ef3e37bb0fa3331f5bc576c27de8f53303 Mon Sep 17 00:00:00 2001 From: "liang.he@intel.com" Date: Tue, 9 Sep 2025 02:53:29 +0000 Subject: [PATCH 04/10] refactor: enhance CMake configurations for better build output and module support --- .../compilation_on_android_ubuntu.yml | 4 +- tests/unit/compilation/CMakeLists.txt | 2 + tests/unit/libc-builtin/CMakeLists.txt | 2 + tests/unit/running-modes/CMakeLists.txt | 7 +++- .../running-modes/wasm-apps/CMakeLists.txt | 39 +++++++++---------- tests/unit/runtime-common/CMakeLists.txt | 1 + tests/unit/wasm-vm/CMakeLists.txt | 1 + 7 files changed, 31 insertions(+), 25 deletions(-) diff --git a/.github/workflows/compilation_on_android_ubuntu.yml b/.github/workflows/compilation_on_android_ubuntu.yml index 9dc528b6d5..acaa4d0553 100644 --- a/.github/workflows/compilation_on_android_ubuntu.yml +++ b/.github/workflows/compilation_on_android_ubuntu.yml @@ -369,8 +369,8 @@ jobs: run: | mkdir build && cd build cmake .. -DWAMR_BUILD_TARGET=${{ matrix.build_target }} - cmake --build . --config Release --parallel 4 - ctest + cmake --build . --parallel 4 + ctest --output-on-failure working-directory: tests/unit build_regression_tests: diff --git a/tests/unit/compilation/CMakeLists.txt b/tests/unit/compilation/CMakeLists.txt index 554aaa9395..fd044b8692 100644 --- a/tests/unit/compilation/CMakeLists.txt +++ b/tests/unit/compilation/CMakeLists.txt @@ -14,6 +14,8 @@ add_definitions (-DWASM_ENABLE_DUMP_CALL_STACK=1) add_definitions (-DWASM_ENABLE_AOT_STACK_FRAME=1) set (WAMR_BUILD_LIBC_WASI 0) +set (WAMR_BUILD_LIBC_BUILTIN 1) +set (WAMR_BUILD_MULTI_MODULE 1) set (WAMR_BUILD_APP_FRAMEWORK 0) set (WAMR_BUILD_THREAD_MGR 1) set (WAMR_BUILD_AOT 1) diff --git a/tests/unit/libc-builtin/CMakeLists.txt b/tests/unit/libc-builtin/CMakeLists.txt index 8e6b905ddb..789018c3bc 100644 --- a/tests/unit/libc-builtin/CMakeLists.txt +++ b/tests/unit/libc-builtin/CMakeLists.txt @@ -14,6 +14,8 @@ set (WAMR_BUILD_JIT 0) set (WAMR_BUILD_LIBC_BUILTIN 1) set (WAMR_BUILD_LIBC_WASI 0) set (WAMR_BUILD_APP_FRAMEWORK 0) +# FIXME: if removed, LibcBuiltinTest.calloc will be failed +set (WAMR_BUILD_MULTI_MODULE 1) include (../unit_common.cmake) diff --git a/tests/unit/running-modes/CMakeLists.txt b/tests/unit/running-modes/CMakeLists.txt index 05a3cf9c97..1e52929bfe 100644 --- a/tests/unit/running-modes/CMakeLists.txt +++ b/tests/unit/running-modes/CMakeLists.txt @@ -16,16 +16,19 @@ ExternalProject_Add( 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 + BUILD_COMMAND ${CMAKE_COMMAND} --build build --verbose INSTALL_COMMAND ${CMAKE_COMMAND} --install build --prefix ${CMAKE_CURRENT_BINARY_DIR} ) add_definitions(-DRUN_ON_LINUX) -set(WAMR_BUILD_LIBC_WASI 1) +set(WAMR_BUILD_LIBC_BUILTIN 1) +set(WAMR_BUILD_MULTI_MODULE 0) +set(WAMR_BUILD_LIBC_WASI 0) set(WAMR_BUILD_APP_FRAMEWORK 0) set(WAMR_BUILD_JIT 1) set(WAMR_BUILD_FAST_JIT 1) +set(WAMR_BUILD_REF_TYPES 1) # if only load this CMake other than load it as subdirectory include(../unit_common.cmake) diff --git a/tests/unit/running-modes/wasm-apps/CMakeLists.txt b/tests/unit/running-modes/wasm-apps/CMakeLists.txt index 7aec214bab..c840169379 100644 --- a/tests/unit/running-modes/wasm-apps/CMakeLists.txt +++ b/tests/unit/running-modes/wasm-apps/CMakeLists.txt @@ -4,33 +4,30 @@ cmake_minimum_required(VERSION 3.14) project(wasm-apps) -# set(CMAKE_C_FLAGS "-nostdlib -pthread -Qunused-arguments") -# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -z stack-size=8192 -nostdlib") - add_executable(mytest.wasm mytest.c) -target_link_libraries(mytest.wasm) -target_compile_options(mytest.wasm PRIVATE - -pthread -) +target_compile_options(mytest.wasm PUBLIC -nostdlib) target_link_options(mytest.wasm PRIVATE + -nostdlib LINKER:--allow-undefined LINKER:--export-all + LINKER:--initial-memory=131072 LINKER:--no-entry ) add_executable(hello.wasm hello.c) -target_link_libraries(hello.wasm) - -add_custom_command(TARGET hello.wasm POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_BINARY_DIR}/hello.wasm - ${CMAKE_CURRENT_BINARY_DIR}/../ - COMMENT "Copy hello.wasm to the same directory of google test" - ) +target_compile_options(hello.wasm PUBLIC -nostdlib) +target_link_options(hello.wasm PRIVATE + -nostdlib + LINKER:--allow-undefined + LINKER:--export-all + LINKER:--initial-memory=131072 + LINKER:--no-entry +) -add_custom_command(TARGET mytest.wasm POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_BINARY_DIR}/mytest.wasm - ${CMAKE_CURRENT_BINARY_DIR}/../ - COMMENT "Copy mytest.wasm to the same directory of google test" - ) +# install .wasm +set( + WASM_FILES + ${CMAKE_CURRENT_BINARY_DIR}/hello.wasm + ${CMAKE_CURRENT_BINARY_DIR}/mytest.wasm +) +install(FILES ${WASM_FILES} DESTINATION .) diff --git a/tests/unit/runtime-common/CMakeLists.txt b/tests/unit/runtime-common/CMakeLists.txt index f5691b9a51..3252e1929c 100644 --- a/tests/unit/runtime-common/CMakeLists.txt +++ b/tests/unit/runtime-common/CMakeLists.txt @@ -13,6 +13,7 @@ set (WAMR_BUILD_INTERP 0) # to involve LLVM set (WAMR_BUILD_JIT 1) set (WAMR_BUILD_LIBC_WASI 0) +set (WAMR_BUILD_LIBC_BUILTIN 1) set (WAMR_BUILD_APP_FRAMEWORK 0) set (WAMR_BUILD_MULTI_MODULE 1) diff --git a/tests/unit/wasm-vm/CMakeLists.txt b/tests/unit/wasm-vm/CMakeLists.txt index eeda532570..15264b7f1d 100644 --- a/tests/unit/wasm-vm/CMakeLists.txt +++ b/tests/unit/wasm-vm/CMakeLists.txt @@ -11,6 +11,7 @@ set(WAMR_BUILD_AOT 0) set(WAMR_BUILD_FAST_INTERP 0) set(WAMR_BUILD_INTERP 1) set(WAMR_BUILD_JIT 0) +set(WAMR_BUILD_LIBC_BUILTIN 1) add_definitions (-Dattr_container_malloc=malloc) add_definitions (-Dattr_container_free=free) From 0d46878e51f0deee03033d9ef8f9eb1dd211840f Mon Sep 17 00:00:00 2001 From: "liang.he@intel.com" Date: Tue, 9 Sep 2025 12:54:18 +0000 Subject: [PATCH 05/10] remove few wrong mocks from wasm_runtime_common_test_suite --- .../wasm_runtime_common_test.cc | 33 ------------------- 1 file changed, 33 deletions(-) diff --git a/tests/unit/runtime-common/wasm_runtime_common_test.cc b/tests/unit/runtime-common/wasm_runtime_common_test.cc index 15a02673b2..01a7b5aa49 100644 --- a/tests/unit/runtime-common/wasm_runtime_common_test.cc +++ b/tests/unit/runtime-common/wasm_runtime_common_test.cc @@ -360,39 +360,6 @@ TEST_F(wasm_runtime_common_test_suite, functions_on_wasm_module) exception_test = wasm_runtime_get_exception(wasm_module_inst); EXPECT_NE(nullptr, exception_test); - WASMFunctionInstance func_test_1; - WASMFunction wasm_func_test; - WASMType wasm_type_test; - wasm_func_test.func_type = &wasm_type_test; - func_test_1.u.func = &wasm_func_test; - func_test_1.u.func->func_type->param_count = 1; - func_test_1.u.func->func_type->param_cell_num = 2; - func_test_1.u.func->func_type->types[0] = VALUE_TYPE_I64; - func_test_1.u.func->max_stack_cell_num = 10; - EXPECT_EQ(false, wasm_runtime_call_wasm_v( - exec_env, (WASMFunctionInstanceCommon *)(&func_test_1), - 0, nullptr, 1, arguments)); - func_test_1.u.func->func_type->types[0] = VALUE_TYPE_F32; - EXPECT_EQ(false, wasm_runtime_call_wasm_v( - exec_env, (WASMFunctionInstanceCommon *)(&func_test_1), - 0, nullptr, 1, arguments)); - func_test_1.u.func->func_type->types[0] = VALUE_TYPE_F64; - EXPECT_EQ(false, wasm_runtime_call_wasm_v( - exec_env, (WASMFunctionInstanceCommon *)(&func_test_1), - 0, nullptr, 1, arguments)); - -#if 0 - WASMFunctionInstance func_test; - WASMFunctionImport func_import_test; - WASMType *func_type_1 = nullptr; - func_import_test.func_type = func_type; - func_test.u.func_import = &func_import_test; - func_test.is_import_func = true; - func_type_1 = wasm_runtime_get_function_type(&func_test, - wasm_module_inst->module_type); - EXPECT_NE(func_type_1, nullptr); -#endif - EXPECT_EQ(true, wasm_runtime_create_exec_env_singleton(wasm_module_inst)); EXPECT_NE(nullptr, wasm_runtime_get_exec_env_singleton(wasm_module_inst)); From e4faae7eb85d32ec9eda3633b380ea7d304250f0 Mon Sep 17 00:00:00 2001 From: "liang.he@intel.com" Date: Tue, 9 Sep 2025 13:15:32 +0000 Subject: [PATCH 06/10] refactor: update CMake configurations for custom section tests and wasm-apps build process --- tests/unit/custom-section/CMakeLists.txt | 19 +++++++++++++---- .../custom-section/wasm-apps/CMakeLists.txt | 21 ++++++++++++------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/tests/unit/custom-section/CMakeLists.txt b/tests/unit/custom-section/CMakeLists.txt index 13db56e0ce..4921355ef6 100644 --- a/tests/unit/custom-section/CMakeLists.txt +++ b/tests/unit/custom-section/CMakeLists.txt @@ -2,9 +2,23 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception cmake_minimum_required(VERSION 3.14) - project (test-custom-section) +set(WASI_SDK_DIR "/opt/wasi-sdk") +set(WASISDK_TOOLCHAIN "${WASI_SDK_DIR}/share/cmake/wasi-sdk.cmake") + +include(ExternalProject) +ExternalProject_Add( + custom-section-test-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 --verbose + INSTALL_COMMAND ${CMAKE_COMMAND} --install build --prefix ${CMAKE_CURRENT_BINARY_DIR}/wasm-apps +) + add_definitions (-DRUN_ON_LINUX) set (WAMR_BUILD_LIBC_WASI 0) @@ -37,9 +51,6 @@ set (unit_test_sources ${IWASM_COMPL_SOURCE} ) -# Automatically build wasm-apps for this test -add_subdirectory(wasm-apps) - # Now simply link against gtest or gtest_main as needed. Eg add_executable (custom_section_test ${unit_test_sources}) diff --git a/tests/unit/custom-section/wasm-apps/CMakeLists.txt b/tests/unit/custom-section/wasm-apps/CMakeLists.txt index 6455db554d..6f80d6968a 100644 --- a/tests/unit/custom-section/wasm-apps/CMakeLists.txt +++ b/tests/unit/custom-section/wasm-apps/CMakeLists.txt @@ -2,13 +2,20 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception cmake_minimum_required(VERSION 3.14) +project(wasm-apps) -project(wasm-apps-custom-section) +add_executable(app.wasm app.c) +target_compile_options(app.wasm PUBLIC -g -nostdlib) +target_link_options(app.wasm PRIVATE + -nostdlib + LINKER:--allow-undefined + LINKER:--export-all + LINKER:--no-entry +) -# Add -g option so there will be debugger related custom sections -add_custom_target(app.wasm ALL - COMMAND /opt/wasi-sdk/bin/clang -g -nostdlib - -Wl,--no-entry,--export-all - -o ${CMAKE_CURRENT_BINARY_DIR}/app.wasm - ${CMAKE_CURRENT_LIST_DIR}/app.c +# install .wasm +set( + WASM_FILES + ${CMAKE_CURRENT_BINARY_DIR}/app.wasm ) +install(FILES ${WASM_FILES} DESTINATION .) From bd8456b37f132090db282e2451b12059c080798a Mon Sep 17 00:00:00 2001 From: "liang.he@intel.com" Date: Wed, 10 Sep 2025 00:52:20 +0000 Subject: [PATCH 07/10] fix several reviewing comments --- tests/unit/CMakeLists.txt | 5 +++-- tests/unit/aot/CMakeLists.txt | 3 +-- tests/unit/linear-memory-aot/CMakeLists.txt | 6 ++---- tests/unit/memory64/CMakeLists.txt | 3 ++- tests/unit/running-modes/CMakeLists.txt | 2 +- tests/unit/runtime-common/CMakeLists.txt | 11 ++++------- tests/unit/shared-heap/CMakeLists.txt | 5 ++--- 7 files changed, 15 insertions(+), 20 deletions(-) diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index d11cf095f7..9c641049b4 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -60,12 +60,13 @@ add_subdirectory(libc-builtin) add_subdirectory(shared-utils) add_subdirectory(linear-memory-wasm) add_subdirectory(linear-memory-aot) -add_subdirectory(aot-stack-frame) add_subdirectory(linux-perf) add_subdirectory(gc) add_subdirectory(tid-allocator) if (NOT WAMR_BUILD_TARGET STREQUAL "X86_32") + add_subdirectory(aot-stack-frame) + # should enable 32-bit llvm when X86_32 add_subdirectory (aot) add_subdirectory (custom-section) @@ -74,7 +75,7 @@ if (NOT WAMR_BUILD_TARGET STREQUAL "X86_32") # Fast-JIT or mem64 is not supported on X86_32 add_subdirectory (running-modes) add_subdirectory (memory64) - # add_subdirectory (shared-heap) + add_subdirectory (shared-heap) # HW_BOUND_CHECK is not supported on X86_32 add_subdirectory (runtime-common) diff --git a/tests/unit/aot/CMakeLists.txt b/tests/unit/aot/CMakeLists.txt index 31abc5d1fd..7dafe00fba 100644 --- a/tests/unit/aot/CMakeLists.txt +++ b/tests/unit/aot/CMakeLists.txt @@ -16,10 +16,9 @@ add_definitions (-DWASM_ENABLE_AOT_STACK_FRAME=1) set (WAMR_BUILD_AOT 1) set (WAMR_BUILD_FAST_INTERP 0) set (WAMR_BUILD_INTERP 0) -# to involve LLVM set (WAMR_BUILD_JIT 1) set (WAMR_BUILD_LIBC_WASI 0) -set (WAMR_BUILD_APP_FRAMEWORK 1) +set (WAMR_BUILD_APP_FRAMEWORK 0) include (../unit_common.cmake) diff --git a/tests/unit/linear-memory-aot/CMakeLists.txt b/tests/unit/linear-memory-aot/CMakeLists.txt index 8133e1c743..b76881f7f3 100644 --- a/tests/unit/linear-memory-aot/CMakeLists.txt +++ b/tests/unit/linear-memory-aot/CMakeLists.txt @@ -13,8 +13,6 @@ set (WAMR_BUILD_MEMORY_PROFILING 1) set (WAMR_BUILD_INTERP 0) set (WAMR_BUILD_AOT 1) set (WAMR_BUILD_FAST_INTERP 0) -# to involve LLVM -set (WAMR_BUILD_JIT 1) include (../unit_common.cmake) @@ -33,7 +31,7 @@ set (unit_test_sources # Test case: .aot file with hardware bound check. add_executable (linear_memory_test_aot ${unit_test_sources}) -target_link_libraries (linear_memory_test_aot ${LLVM_AVAILABLE_LIBS} gtest_main) +target_link_libraries (linear_memory_test_aot gtest_main) gtest_discover_tests(linear_memory_test_aot) target_compile_definitions(linear_memory_test_aot PRIVATE WAMR_DISABLE_HW_BOUND_CHECK=0) @@ -65,6 +63,6 @@ add_custom_command(TARGET linear_memory_test_aot POST_BUILD # Test case: .aot file with no hardware bound check. add_executable (linear_memory_test_aot_no_hw_bound ${unit_test_sources}) -target_link_libraries (linear_memory_test_aot_no_hw_bound ${LLVM_AVAILABLE_LIBS} gtest_main) +target_link_libraries (linear_memory_test_aot_no_hw_bound gtest_main) gtest_discover_tests(linear_memory_test_aot_no_hw_bound) target_compile_definitions(linear_memory_test_aot_no_hw_bound PRIVATE WAMR_DISABLE_HW_BOUND_CHECK=1) diff --git a/tests/unit/memory64/CMakeLists.txt b/tests/unit/memory64/CMakeLists.txt index f85c68cf54..5873f9ba3a 100644 --- a/tests/unit/memory64/CMakeLists.txt +++ b/tests/unit/memory64/CMakeLists.txt @@ -13,7 +13,8 @@ set(WAMR_BUILD_APP_FRAMEWORK 0) set(WAMR_BUILD_AOT 0) set(WAMR_BUILD_INTERP 1) set(WAMR_BUILD_FAST_INTERP 0) -set(WAMR_BUILD_JIT 0) +# to involve LLVM +set(WAMR_BUILD_JIT 1) set(WAMR_BUILD_FAST_JIT 0) set(WAMR_BUILD_MEMORY64 1) set(WAMR_BUILD_SHARED_MEMORY 1) diff --git a/tests/unit/running-modes/CMakeLists.txt b/tests/unit/running-modes/CMakeLists.txt index 1e52929bfe..07c66203af 100644 --- a/tests/unit/running-modes/CMakeLists.txt +++ b/tests/unit/running-modes/CMakeLists.txt @@ -24,7 +24,7 @@ add_definitions(-DRUN_ON_LINUX) set(WAMR_BUILD_LIBC_BUILTIN 1) set(WAMR_BUILD_MULTI_MODULE 0) -set(WAMR_BUILD_LIBC_WASI 0) +set(WAMR_BUILD_LIBC_WASI 1) set(WAMR_BUILD_APP_FRAMEWORK 0) set(WAMR_BUILD_JIT 1) set(WAMR_BUILD_FAST_JIT 1) diff --git a/tests/unit/runtime-common/CMakeLists.txt b/tests/unit/runtime-common/CMakeLists.txt index 3252e1929c..4ee60864ec 100644 --- a/tests/unit/runtime-common/CMakeLists.txt +++ b/tests/unit/runtime-common/CMakeLists.txt @@ -36,11 +36,8 @@ add_executable(runtime_common_test ${unit_test_sources}) target_link_libraries(runtime_common_test ${LLVM_AVAILABLE_LIBS} gtest_main) # Ensure that aot compiled is completed before linear_memory_test_aot is built -set(dummy_output "${CMAKE_CURRENT_BINARY_DIR}/dummy_output") - -add_custom_command(OUTPUT ${dummy_output} +add_custom_command(OUTPUT ${CMAKE_CURRENT_LIST_DIR}/wasm-apps/main.aot COMMAND ./build_aot.sh - COMMAND ${CMAKE_COMMAND} -E touch ${dummy_output} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/build_aot.sh COMMENT "Executing script to compile aot files" @@ -49,15 +46,15 @@ add_custom_command(OUTPUT ${dummy_output} add_custom_target( BuildAot ALL - DEPENDS ${dummy_output} + DEPENDS ${CMAKE_CURRENT_LIST_DIR}/wasm-apps/main.aot ) add_dependencies(runtime_common_test BuildAot) add_custom_command(TARGET runtime_common_test POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy - ${CMAKE_CURRENT_LIST_DIR}/wasm-apps/main.wasm ${CMAKE_CURRENT_LIST_DIR}/wasm-apps/main.aot - ${CMAKE_CURRENT_BINARY_DIR} + ${CMAKE_CURRENT_LIST_DIR}/wasm-apps/main.wasm ${CMAKE_CURRENT_LIST_DIR}/wasm-apps/main.aot + ${CMAKE_CURRENT_BINARY_DIR} COMMENT "Copy main.wasm and main.aot to the directory: build/runtime-common." ) diff --git a/tests/unit/shared-heap/CMakeLists.txt b/tests/unit/shared-heap/CMakeLists.txt index ce7ae00364..e1e7a1a9a3 100644 --- a/tests/unit/shared-heap/CMakeLists.txt +++ b/tests/unit/shared-heap/CMakeLists.txt @@ -11,8 +11,7 @@ set(WAMR_BUILD_APP_FRAMEWORK 0) set(WAMR_BUILD_AOT 1) set(WAMR_BUILD_INTERP 1) set(WAMR_BUILD_FAST_INTERP 1) -# to involve LLVM -set(WAMR_BUILD_JIT 1) +set(WAMR_BUILD_JIT 0) if(WAMR_BUILD_TARGET STREQUAL "X86_32") set(WAMR_BUILD_MEMORY64 0) else() @@ -47,6 +46,6 @@ set(unit_test_sources # Now simply link against gtest or gtest_main as needed. Eg add_executable(shared_heap_test ${unit_test_sources}) -target_link_libraries(shared_heap_test ${LLVM_AVAILABLE_LIBS} gtest_main) +target_link_libraries(shared_heap_test gtest_main) gtest_discover_tests(shared_heap_test) From 4b4c16e2e4857607a71de5f8c995c050eaf1a0c2 Mon Sep 17 00:00:00 2001 From: "liang.he@intel.com" Date: Wed, 24 Sep 2025 05:20:21 +0000 Subject: [PATCH 08/10] Find llvm on demand --- tests/unit/aot-stack-frame/CMakeLists.txt | 9 ++++++--- tests/unit/aot/CMakeLists.txt | 19 ++++++++----------- tests/unit/compilation/CMakeLists.txt | 9 ++++++--- tests/unit/custom-section/CMakeLists.txt | 10 +++++++--- tests/unit/interpreter/CMakeLists.txt | 2 +- tests/unit/linux-perf/CMakeLists.txt | 10 +++++++--- tests/unit/memory64/CMakeLists.txt | 7 ++++--- tests/unit/running-modes/CMakeLists.txt | 4 +++- tests/unit/runtime-common/CMakeLists.txt | 9 ++++++--- tests/unit/unit_common.cmake | 13 +++++++++++++ tests/unit/wasm-vm/CMakeLists.txt | 7 ++++--- 11 files changed, 65 insertions(+), 34 deletions(-) diff --git a/tests/unit/aot-stack-frame/CMakeLists.txt b/tests/unit/aot-stack-frame/CMakeLists.txt index 7eb2583ded..b20bb67b9a 100644 --- a/tests/unit/aot-stack-frame/CMakeLists.txt +++ b/tests/unit/aot-stack-frame/CMakeLists.txt @@ -8,9 +8,8 @@ project (test-aot-stack-frame) add_definitions (-DRUN_ON_LINUX) set (WAMR_BUILD_AOT 1) -set (WAMR_BUILD_INTERP 0) -# to involve LLVM -set (WAMR_BUILD_JIT 1) +set (WAMR_BUILD_INTERP 1) +set (WAMR_BUILD_JIT 0) set (WAMR_BUILD_SIMD 1) set (WAMR_BUILD_REF_TYPES 1) set (WAMR_BUILD_LIBC_WASI 0) @@ -22,6 +21,10 @@ set (WAMR_BUILD_GC 1) include (../unit_common.cmake) +find_package(LLVM REQUIRED CONFIG) +include_directories(${LLVM_INCLUDE_DIRS}) +add_definitions(${LLVM_DEFINITIONS}) + include_directories (${CMAKE_CURRENT_SOURCE_DIR}) add_definitions (-DWASM_ENABLE_AOT_STACK_FRAME=1) diff --git a/tests/unit/aot/CMakeLists.txt b/tests/unit/aot/CMakeLists.txt index 7dafe00fba..e45d4c0032 100644 --- a/tests/unit/aot/CMakeLists.txt +++ b/tests/unit/aot/CMakeLists.txt @@ -15,13 +15,17 @@ add_definitions (-DWASM_ENABLE_AOT_STACK_FRAME=1) set (WAMR_BUILD_AOT 1) set (WAMR_BUILD_FAST_INTERP 0) -set (WAMR_BUILD_INTERP 0) -set (WAMR_BUILD_JIT 1) +set (WAMR_BUILD_INTERP 1) +set (WAMR_BUILD_JIT 0) set (WAMR_BUILD_LIBC_WASI 0) set (WAMR_BUILD_APP_FRAMEWORK 0) include (../unit_common.cmake) +find_package(LLVM REQUIRED CONFIG) +include_directories(${LLVM_INCLUDE_DIRS}) +add_definitions(${LLVM_DEFINITIONS}) + include (${IWASM_DIR}/compilation/iwasm_compl.cmake) include_directories (${CMAKE_CURRENT_SOURCE_DIR}) @@ -32,16 +36,9 @@ set (UNIT_SOURCE ${source_all}) set (unit_test_sources ${UNIT_SOURCE} - ${PLATFORM_SHARED_SOURCE} - ${UTILS_SHARED_SOURCE} - ${MEM_ALLOC_SHARED_SOURCE} - ${NATIVE_INTERFACE_SOURCE} - ${LIBC_BUILTIN_SOURCE} - ${IWASM_COMMON_SOURCE} - ${IWASM_INTERP_SOURCE} - ${IWASM_AOT_SOURCE} + ${WAMR_RUNTIME_LIB_SOURCE} ${IWASM_COMPL_SOURCE} - ) +) # Now simply link against gtest or gtest_main as needed. Eg add_executable (aot_test ${unit_test_sources}) diff --git a/tests/unit/compilation/CMakeLists.txt b/tests/unit/compilation/CMakeLists.txt index fd044b8692..f6912122d9 100644 --- a/tests/unit/compilation/CMakeLists.txt +++ b/tests/unit/compilation/CMakeLists.txt @@ -20,12 +20,15 @@ set (WAMR_BUILD_APP_FRAMEWORK 0) set (WAMR_BUILD_THREAD_MGR 1) set (WAMR_BUILD_AOT 1) set (WAMR_BUILD_FAST_INTERP 0) -set (WAMR_BUILD_INTERP 0) -# to involve LLVM -set (WAMR_BUILD_JIT 1) +set (WAMR_BUILD_INTERP 1) +set (WAMR_BUILD_JIT 0) include (../unit_common.cmake) +find_package(LLVM REQUIRED CONFIG) +include_directories(${LLVM_INCLUDE_DIRS}) +add_definitions(${LLVM_DEFINITIONS}) + include (${IWASM_DIR}/compilation/iwasm_compl.cmake) include_directories (${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/tests/unit/custom-section/CMakeLists.txt b/tests/unit/custom-section/CMakeLists.txt index 4921355ef6..3967e8d9e8 100644 --- a/tests/unit/custom-section/CMakeLists.txt +++ b/tests/unit/custom-section/CMakeLists.txt @@ -23,10 +23,10 @@ add_definitions (-DRUN_ON_LINUX) set (WAMR_BUILD_LIBC_WASI 0) set (WAMR_BUILD_LIBC_BUILTIN 0) -# to involve LLVM -set (WAMR_BUILD_JIT 1) -set (WAMR_BUILD_LAZY_JIT 0) set (WAMR_BUILD_AOT 1) +set (WAMR_BUILD_FAST_INTERP 0) +set (WAMR_BUILD_INTERP 1) +set (WAMR_BUILD_JIT 0) add_definitions(-DWASM_ENABLE_WAMR_COMPILER=1) add_definitions (-DWASM_ENABLE_DUMP_CALL_STACK=1) @@ -37,6 +37,10 @@ set (WAMR_BUILD_LOAD_CUSTOM_SECTION 1) include (../unit_common.cmake) +find_package(LLVM REQUIRED CONFIG) +include_directories(${LLVM_INCLUDE_DIRS}) +add_definitions(${LLVM_DEFINITIONS}) + include (${IWASM_DIR}/compilation/iwasm_compl.cmake) include_directories (${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/tests/unit/interpreter/CMakeLists.txt b/tests/unit/interpreter/CMakeLists.txt index 7dc14ebff9..ef65e443f7 100644 --- a/tests/unit/interpreter/CMakeLists.txt +++ b/tests/unit/interpreter/CMakeLists.txt @@ -34,6 +34,6 @@ set (unit_test_sources # Now simply link against gtest or gtest_main as needed. Eg add_executable (interpreter_test ${unit_test_sources}) -target_link_libraries (interpreter_test ${LLVM_AVAILABLE_LIBS} gtest_main ) +target_link_libraries (interpreter_test gtest_main ) gtest_discover_tests(interpreter_test) diff --git a/tests/unit/linux-perf/CMakeLists.txt b/tests/unit/linux-perf/CMakeLists.txt index 45d323e884..e5e2d56921 100644 --- a/tests/unit/linux-perf/CMakeLists.txt +++ b/tests/unit/linux-perf/CMakeLists.txt @@ -9,10 +9,10 @@ add_definitions (-DRUN_ON_LINUX) set (WAMR_BUILD_LIBC_WASI 0) set (WAMR_BUILD_LIBC_BUILTIN 0) -# to involve LLVM -set (WAMR_BUILD_JIT 1) -set (WAMR_BUILD_LAZY_JIT 0) +set (WAMR_BUILD_JIT 0) set (WAMR_BUILD_AOT 1) +set (WAMR_BUILD_FAST_INTERP 0) +set (WAMR_BUILD_INTERP 1) set (WAMR_BUILD_MULTI_MODULE 0) set (WAMR_BUILD_LINUX_PERF 1) @@ -23,6 +23,10 @@ set (WAMR_BUILD_DUMP_CALL_STACK 1) include (../unit_common.cmake) +find_package(LLVM REQUIRED CONFIG) +include_directories(${LLVM_INCLUDE_DIRS}) +add_definitions(${LLVM_DEFINITIONS}) + include (${IWASM_DIR}/compilation/iwasm_compl.cmake) add_executable (linux_perf_test test_sort_func_ptrs.cc) diff --git a/tests/unit/memory64/CMakeLists.txt b/tests/unit/memory64/CMakeLists.txt index 5873f9ba3a..b19c9d9cfa 100644 --- a/tests/unit/memory64/CMakeLists.txt +++ b/tests/unit/memory64/CMakeLists.txt @@ -13,8 +13,7 @@ set(WAMR_BUILD_APP_FRAMEWORK 0) set(WAMR_BUILD_AOT 0) set(WAMR_BUILD_INTERP 1) set(WAMR_BUILD_FAST_INTERP 0) -# to involve LLVM -set(WAMR_BUILD_JIT 1) +set(WAMR_BUILD_JIT 0) set(WAMR_BUILD_FAST_JIT 0) set(WAMR_BUILD_MEMORY64 1) set(WAMR_BUILD_SHARED_MEMORY 1) @@ -23,7 +22,9 @@ set(WAMR_BUILD_SHARED_MEMORY 1) # include(GoogleTest) include(../unit_common.cmake) -include(${IWASM_DIR}/compilation/iwasm_compl.cmake) +find_package(LLVM REQUIRED CONFIG) +include_directories(${LLVM_INCLUDE_DIRS}) +add_definitions(${LLVM_DEFINITIONS}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/tests/unit/running-modes/CMakeLists.txt b/tests/unit/running-modes/CMakeLists.txt index 07c66203af..d547f54044 100644 --- a/tests/unit/running-modes/CMakeLists.txt +++ b/tests/unit/running-modes/CMakeLists.txt @@ -33,7 +33,9 @@ set(WAMR_BUILD_REF_TYPES 1) # if only load this CMake other than load it as subdirectory include(../unit_common.cmake) -include(${IWASM_DIR}/compilation/iwasm_compl.cmake) +find_package(LLVM REQUIRED CONFIG) +include_directories(${LLVM_INCLUDE_DIRS}) +add_definitions(${LLVM_DEFINITIONS}) include_directories(${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/tests/unit/runtime-common/CMakeLists.txt b/tests/unit/runtime-common/CMakeLists.txt index 4ee60864ec..9ef07ff50c 100644 --- a/tests/unit/runtime-common/CMakeLists.txt +++ b/tests/unit/runtime-common/CMakeLists.txt @@ -9,9 +9,8 @@ add_definitions(-DRUN_ON_LINUX) set (WAMR_BUILD_AOT 1) set (WAMR_BUILD_FAST_INTERP 0) -set (WAMR_BUILD_INTERP 0) -# to involve LLVM -set (WAMR_BUILD_JIT 1) +set (WAMR_BUILD_INTERP 1) +set (WAMR_BUILD_JIT 0) set (WAMR_BUILD_LIBC_WASI 0) set (WAMR_BUILD_LIBC_BUILTIN 1) set (WAMR_BUILD_APP_FRAMEWORK 0) @@ -19,6 +18,10 @@ set (WAMR_BUILD_MULTI_MODULE 1) include(../unit_common.cmake) +find_package(LLVM REQUIRED CONFIG) +include_directories(${LLVM_INCLUDE_DIRS}) +add_definitions(${LLVM_DEFINITIONS}) + include_directories(${CMAKE_CURRENT_SOURCE_DIR}) file(GLOB_RECURSE source_all ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) diff --git a/tests/unit/unit_common.cmake b/tests/unit/unit_common.cmake index b9b9bb92eb..53e9ae50df 100644 --- a/tests/unit/unit_common.cmake +++ b/tests/unit/unit_common.cmake @@ -35,4 +35,17 @@ include (${SHARED_DIR}/utils/uncommon/shared_uncommon.cmake) # Add helper classes include_directories(${CMAKE_CURRENT_LIST_DIR}/common) +# config_common.cmake only sets up the llvm environment when +# JIT is enabled. but in unit tests, we need llvm environment +# for aot compilation. +if (NOT DEFINED LLVM_DIR) + set (LLVM_SRC_ROOT "${WAMR_ROOT_DIR}/core/deps/llvm") + set (LLVM_BUILD_ROOT "${LLVM_SRC_ROOT}/build") + if (NOT EXISTS "${LLVM_BUILD_ROOT}") + message (FATAL_ERROR "Cannot find LLVM dir: ${LLVM_BUILD_ROOT}") + endif () + set (CMAKE_PREFIX_PATH "${LLVM_BUILD_ROOT};${CMAKE_PREFIX_PATH}") + set (LLVM_DIR ${LLVM_BUILD_ROOT}/lib/cmake/llvm) +endif () + message(STATUS "unit_common.cmake included") diff --git a/tests/unit/wasm-vm/CMakeLists.txt b/tests/unit/wasm-vm/CMakeLists.txt index 15264b7f1d..431b945450 100644 --- a/tests/unit/wasm-vm/CMakeLists.txt +++ b/tests/unit/wasm-vm/CMakeLists.txt @@ -16,11 +16,12 @@ set(WAMR_BUILD_LIBC_BUILTIN 1) add_definitions (-Dattr_container_malloc=malloc) add_definitions (-Dattr_container_free=free) -set (WAMR_BUILD_APP_FRAMEWORK 1) -set (CMAKE_BUILD_TYPE Release) - include (../unit_common.cmake) +find_package(LLVM REQUIRED CONFIG) +include_directories(${LLVM_INCLUDE_DIRS}) +add_definitions(${LLVM_DEFINITIONS}) + include_directories (${CMAKE_CURRENT_SOURCE_DIR}) file (GLOB_RECURSE source_all ${CMAKE_CURRENT_SOURCE_DIR}/*.cc) From 028dd3ac06b4e89a66500e13f7be9e5aa39f24ca Mon Sep 17 00:00:00 2001 From: "liang.he@intel.com" Date: Thu, 25 Sep 2025 01:36:43 +0000 Subject: [PATCH 09/10] refactor: remove verbose flag from build command in CMakeLists.txt --- tests/unit/custom-section/CMakeLists.txt | 2 +- tests/unit/running-modes/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/custom-section/CMakeLists.txt b/tests/unit/custom-section/CMakeLists.txt index 3967e8d9e8..b57fb8bffb 100644 --- a/tests/unit/custom-section/CMakeLists.txt +++ b/tests/unit/custom-section/CMakeLists.txt @@ -15,7 +15,7 @@ ExternalProject_Add( 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 --verbose + BUILD_COMMAND ${CMAKE_COMMAND} --build build INSTALL_COMMAND ${CMAKE_COMMAND} --install build --prefix ${CMAKE_CURRENT_BINARY_DIR}/wasm-apps ) diff --git a/tests/unit/running-modes/CMakeLists.txt b/tests/unit/running-modes/CMakeLists.txt index d547f54044..3a5ca4745a 100644 --- a/tests/unit/running-modes/CMakeLists.txt +++ b/tests/unit/running-modes/CMakeLists.txt @@ -16,7 +16,7 @@ ExternalProject_Add( 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 --verbose + BUILD_COMMAND ${CMAKE_COMMAND} --build build INSTALL_COMMAND ${CMAKE_COMMAND} --install build --prefix ${CMAKE_CURRENT_BINARY_DIR} ) From 2a671e351cb522947d98cd30145c45ffe3dddbef Mon Sep 17 00:00:00 2001 From: "liang.he@intel.com" Date: Thu, 25 Sep 2025 01:37:41 +0000 Subject: [PATCH 10/10] add guidelines for creating a test suite in WAMR --- tests/unit/README.md | 194 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100644 tests/unit/README.md diff --git a/tests/unit/README.md b/tests/unit/README.md new file mode 100644 index 0000000000..1bacbb40d5 --- /dev/null +++ b/tests/unit/README.md @@ -0,0 +1,194 @@ +# Guide to Creating a Test Suite for a New Feature in WAMR + +This guide provides instructions for contributors on how to create a test suite for a new feature in the WAMR project. Follow these steps to ensure consistency and maintainability across the test framework. + +--- + +## General Guidelines + +- **Create a New Directory**: + Always create a dedicated directory for a new feature under the `tests/unit/` directory. + + - Reuse existing test cases and patch them when possible to avoid redundancy. + - Name the directory in lowercase with words separated by hyphens (e.g., `new-feature`). + +- **Avoid Committing `.wasm` Files**: + Do not commit precompiled `.wasm` files. Instead: + + - Generate `.wasm` files from `.wat` or `.c` source files. + - Use `ExternalProject` and the `wasi-sdk` toolchain to compile `.wasm` files during the build process. + +- **Keep Using `ctest` as the framework**: + Continue to use `ctest` for running the test cases, as it is already integrated into the existing test framework. + +--- + +## Writing `CMakeLists.txt` for the Test Suite + +When creating a `CMakeLists.txt` file for your test suite, follow these best practices: + +1. **Do Not Fetch Googletest Again**: + The root `unit/CMakeLists.txt` already fetches Googletest. Avoid including or fetching it again in your test suite. + +2. **Find LLVM on Demand**: + If your test suite requires LLVM, use `find_package` to locate LLVM components as needed. Do not include LLVM globally unless required. + +3. **Include `unit_common.cmake`**: + Always include `../unit_common.cmake` in your `CMakeLists.txt` to avoid duplicating common configurations and utilities. + + Example: + + ```cmake + include("../unit_common.cmake") + ``` + +4. **Use `WAMR_RUNTIME_LIB_SOURCE`**: + Replace long lists of runtime source files with the `WAMR_RUNTIME_LIB_SOURCE` variable to simplify your configuration. + + Example: + + ```cmake + target_sources(your_test_target PRIVATE ${WAMR_RUNTIME_LIB_SOURCE}) + ``` + +5. **Avoid Global Compilation Flags**: + Do not define global compilation flags in the `unit` directory. Each test case should specify its own compilation flags based on its unique requirements. + +--- + +## Generating `.wasm` Files + +- **Compile `.wasm` Files Dynamically**: + Use `ExternalProject` in your `CMakeLists.txt` to compile `.wasm` files from `.wat` or `.c` source files. + - Use the `wasi-sdk` toolchain for `.c` or `.cc` source files. + - Example configuration: + ```cmake + ExternalProject_Add( + generate_wasm + 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}/wasm-apps + ) + ``` +- **Example for `wasm-apps` Directory**: + Place your source files in a `wasm-apps/` subdirectory within your test suite directory. + + - Create a `CMakeLists.txt` in `wasm-apps/` to handle the compilation of these files. + - Example `CMakeLists.txt` for `wasm-apps/`: + + ```cmake + cmake_minimum_required(VERSION 3.13) + project(wasm_apps) + + add_executable(example example.c) + set_target_properties(example PROPERTIES SUFFIX .wasm) + install(TARGETS example DESTINATION .) + ``` + +--- + +## Compiling and Running Test Cases + +To compile and run the test cases, follow these steps: + +1. **Generate Build Files**: + + ```bash + cmake -S . -B build + ``` + +2. **Build the Test Suite**: + + ```bash + cmake --build build + ``` + +3. **Run the Tests**: + + ```bash + ctest --test-dir build --output-on-failure + ``` + + This will compile and execute all test cases in the test suite, displaying detailed output for any failures. + +4. **List all Tests**: + To see all available test cases, use: + + ```bash + ctest --test-dir build -N + ``` + +5. **Run a Specific Test**: + To run a specific test case, use: + ```bash + ctest --test-dir build -R --output-on-failure + ``` + +--- + +## Collecting Code Coverage Data + +To collect code coverage data using `lcov`, follow these steps: + +1. **Build with Coverage Flags**: + Ensure the test suite is built with coverage flags enabled: + + ```bash + cmake -S . -B build -DCOLLECT_CODE_COVERAGE=1 + cmake --build build + ``` + +2. **Run the Tests**: + Execute the test cases as described above. + +3. **Generate Coverage Report**: + Use `lcov` to collect and generate the coverage report: + + ```bash + lcov --capture --directory build --output-file coverage.all.info + lcov --extract coverage.all.info "*/core/iwasm/*" "*/core/shared/*" --output-file coverage.info + genhtml coverage.info --output-directory coverage-report + ``` + +4. **View the Report**: + Open the `index.html` file in the `coverage-report` directory to view the coverage results in your browser. + +5. **Summary of Coverage**: + To get a summary of the coverage data, use: + + ```bash + lcov --summary coverage.info + ``` + +--- + +## Example Directory Structure + +Here’s an example of how your test suite directory might look: + +``` +new-feature/ +├── CMakeLists.txt +├── new_feature_test.cc +├── wasm-apps/ +| ├── CMakeLists.txt +│ ├── example.c +│ └── example.wat +``` + +--- + +## Additional Notes + +- **Testing Framework**: Use Googletest for writing unit tests. Refer to existing test cases in the `tests/unit/` directory for examples. +- **Documentation**: Add comments in your test code to explain the purpose of each test case. +- **Edge Cases**: Ensure your test suite covers edge cases and potential failure scenarios. +- **Reuse Utilities**: Leverage existing utilities in `common/` (e.g., `mock_allocator.h`, `test_helper.h`) to simplify your test code. + +--- + +By following these guidelines, you can create a well-structured and maintainable test suite that integrates seamlessly with the WAMR testing framework.