Skip to content

Commit 180b642

Browse files
committed
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
1 parent 6253bd1 commit 180b642

File tree

24 files changed

+129
-340
lines changed

24 files changed

+129
-340
lines changed

.github/workflows/compilation_on_android_ubuntu.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,9 @@ jobs:
349349
uses: ./.github/actions/install-wasi-sdk-wabt
350350
with:
351351
os: ${{ matrix.os }}
352+
353+
- name: install llvm dependencies
354+
run: sudo apt update && sudo apt install -y libzstd-dev zlib1g-dev
352355

353356
- name: Build wamrc
354357
run: |

build-scripts/code_coverage.cmake

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright (C) 2019 Intel Corporation. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
function(check_ubuntu_version)
5+
# ubuntu 2204 is the recommended environment for collecting coverage data for now
6+
# otherwise, there will be ERRORs, when using 2404, like below and
7+
#
8+
# 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
9+
# (use "geninfo --ignore-errors mismatch,mismatch ..." to suppress this warning)
10+
# geninfo: ERROR: ('negative') Unexpected negative count '-3' for /workspaces/wasm-micro-runtime/core/iwasm/interpreter/wasm_interp_classic.c:5473.
11+
# Perhaps you need to compile with '-fprofile-update=atomic
12+
# (use "geninfo --ignore-errors negative,negative ..." to suppress this warning)
13+
#
14+
# For sure, `--ignore-errors` can be used to ignore these errors, but better to use the recommended environment.
15+
file(READ "/etc/os-release" OS_RELEASE_CONTENT)
16+
string(REGEX MATCH "VERSION_ID=\"([0-9]+)\\.([0-9]+)\"" _ ${OS_RELEASE_CONTENT})
17+
if(NOT DEFINED CMAKE_MATCH_1 OR NOT DEFINED CMAKE_MATCH_2)
18+
message(WARNING "Unable to detect Ubuntu version. Please ensure you are using Ubuntu 22.04.")
19+
return()
20+
endif()
21+
22+
set(UBUNTU_MAJOR_VERSION ${CMAKE_MATCH_1})
23+
set(UBUNTU_MINOR_VERSION ${CMAKE_MATCH_2})
24+
25+
if(NOT (UBUNTU_MAJOR_VERSION EQUAL 22 AND UBUNTU_MINOR_VERSION EQUAL 04))
26+
message(WARNING "Ubuntu ${UBUNTU_MAJOR_VERSION}.${UBUNTU_MINOR_VERSION} detected. Ubuntu 22.04 is recommended for collecting coverage data.")
27+
else()
28+
message(STATUS "Ubuntu 22.04 detected. Proceeding with coverage data collection.")
29+
endif()
30+
endfunction()
31+
32+
check_ubuntu_version()
33+
34+
# add compile options for code coverage globally
35+
add_compile_options(--coverage -O0 -g)
36+
link_libraries(gcov)
37+
add_definitions (-DCOLLECT_CODE_COVERAGE)

build-scripts/config_common.cmake

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,7 @@ if (WAMR_BUILD_GC_HEAP_VERIFY EQUAL 1)
603603
message (" GC heap verification enabled")
604604
endif ()
605605
if ("$ENV{COLLECT_CODE_COVERAGE}" STREQUAL "1" OR COLLECT_CODE_COVERAGE EQUAL 1)
606-
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
607-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
608-
add_definitions (-DCOLLECT_CODE_COVERAGE)
606+
include(${CMAKE_CURRENT_LIST_DIR}/code_coverage.cmake)
609607
message (" Collect code coverage enabled")
610608
endif ()
611609
if (WAMR_BUILD_STATIC_PGO EQUAL 1)

tests/unit/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ if (NOT WAMR_BUILD_TARGET STREQUAL "X86_32")
7676
add_subdirectory (compilation)
7777

7878
# Fast-JIT or mem64 is not supported on X86_32
79-
add_subdirectory (running-modes)
79+
# add_subdirectory (running-modes)
8080
add_subdirectory (memory64)
81-
add_subdirectory (shared-heap)
81+
# add_subdirectory (shared-heap)
8282

8383
# HW_BOUND_CHECK is not supported on X86_32
8484
add_subdirectory (runtime-common)

tests/unit/aot-stack-frame/CMakeLists.txt

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,10 @@ file (GLOB_RECURSE source_all ${CMAKE_CURRENT_SOURCE_DIR}/*.cc)
3232
set (UNIT_SOURCE ${source_all})
3333

3434
set (unit_test_sources
35-
${UNIT_SOURCE}
36-
${WAMR_RUNTIME_LIB_SOURCE}
37-
${UNCOMMON_SHARED_SOURCE}
38-
${SRC_LIST}
39-
${PLATFORM_SHARED_SOURCE}
40-
${UTILS_SHARED_SOURCE}
41-
${MEM_ALLOC_SHARED_SOURCE}
42-
${LIB_HOST_AGENT_SOURCE}
43-
${NATIVE_INTERFACE_SOURCE}
44-
${LIBC_BUILTIN_SOURCE}
45-
${IWASM_COMMON_SOURCE}
46-
${IWASM_INTERP_SOURCE}
47-
${IWASM_AOT_SOURCE}
48-
${IWASM_COMPL_SOURCE}
49-
${WASM_APP_LIB_SOURCE_ALL}
50-
)
35+
${UNIT_SOURCE}
36+
${WAMR_RUNTIME_LIB_SOURCE}
37+
${IWASM_COMPL_SOURCE}
38+
)
5139

5240
# Automatically build wasm-apps for this test
5341
add_subdirectory(wasm-apps)
@@ -59,4 +47,4 @@ add_dependencies (aot_stack_frame_test aot-stack-frame-test-wasm)
5947

6048
target_link_libraries (aot_stack_frame_test ${LLVM_AVAILABLE_LIBS} gtest_main )
6149

62-
#gtest_discover_tests(aot_stack_frame_test)
50+
gtest_discover_tests(aot_stack_frame_test)

tests/unit/aot/CMakeLists.txt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,6 @@ set (WAMR_BUILD_APP_FRAMEWORK 1)
1818

1919
include (../unit_common.cmake)
2020

21-
set (LLVM_SRC_ROOT "${WAMR_ROOT_DIR}/core/deps/llvm")
22-
if (NOT EXISTS "${LLVM_SRC_ROOT}/build")
23-
message (FATAL_ERROR "Cannot find LLVM dir: ${LLVM_SRC_ROOT}/build")
24-
endif ()
25-
set (CMAKE_PREFIX_PATH "${LLVM_SRC_ROOT}/build;${CMAKE_PREFIX_PATH}")
26-
find_package(LLVM REQUIRED CONFIG)
27-
include_directories(${LLVM_INCLUDE_DIRS})
28-
add_definitions(${LLVM_DEFINITIONS})
29-
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
30-
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
31-
3221
include (${IWASM_DIR}/compilation/iwasm_compl.cmake)
3322

3423
include_directories (${CMAKE_CURRENT_SOURCE_DIR})

tests/unit/compilation/CMakeLists.txt

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,6 @@ set (WAMR_BUILD_AOT 1)
2020

2121
include (../unit_common.cmake)
2222

23-
set (LLVM_SRC_ROOT "${WAMR_ROOT_DIR}/core/deps/llvm")
24-
if (NOT EXISTS "${LLVM_SRC_ROOT}/build")
25-
message (FATAL_ERROR "Cannot find LLVM dir: ${LLVM_SRC_ROOT}/build")
26-
endif ()
27-
set (CMAKE_PREFIX_PATH "${LLVM_SRC_ROOT}/build;${CMAKE_PREFIX_PATH}")
28-
find_package(LLVM REQUIRED CONFIG)
29-
include_directories(${LLVM_INCLUDE_DIRS})
30-
add_definitions(${LLVM_DEFINITIONS})
31-
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
32-
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
33-
3423
include (${IWASM_DIR}/compilation/iwasm_compl.cmake)
3524

3625
include_directories (${CMAKE_CURRENT_SOURCE_DIR})
@@ -40,22 +29,11 @@ file (GLOB_RECURSE source_all ${CMAKE_CURRENT_SOURCE_DIR}/*.cc)
4029
set (UNIT_SOURCE ${source_all})
4130

4231
set (unit_test_sources
43-
${UNIT_SOURCE}
44-
${WAMR_RUNTIME_LIB_SOURCE}
45-
${UNCOMMON_SHARED_SOURCE}
46-
${SRC_LIST}
47-
${PLATFORM_SHARED_SOURCE}
48-
${UTILS_SHARED_SOURCE}
49-
${MEM_ALLOC_SHARED_SOURCE}
50-
${LIB_HOST_AGENT_SOURCE}
51-
${NATIVE_INTERFACE_SOURCE}
52-
${LIBC_BUILTIN_SOURCE}
53-
${IWASM_COMMON_SOURCE}
54-
${IWASM_INTERP_SOURCE}
55-
${IWASM_AOT_SOURCE}
56-
${IWASM_COMPL_SOURCE}
57-
${WASM_APP_LIB_SOURCE_ALL}
58-
)
32+
${UNIT_SOURCE}
33+
${WAMR_RUNTIME_LIB_SOURCE}
34+
${IWASM_COMPL_SOURCE}
35+
${UNCOMMON_SHARED_SOURCE}
36+
)
5937

6038
# Now simply link against gtest or gtest_main as needed. Eg
6139
add_executable (compilation_test ${unit_test_sources})

tests/unit/custom-section/CMakeLists.txt

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,6 @@ set (WAMR_BUILD_LOAD_CUSTOM_SECTION 1)
2222

2323
include (../unit_common.cmake)
2424

25-
set (LLVM_SRC_ROOT "${WAMR_ROOT_DIR}/core/deps/llvm")
26-
if (NOT EXISTS "${LLVM_SRC_ROOT}/build")
27-
message (FATAL_ERROR "Cannot find LLVM dir: ${LLVM_SRC_ROOT}/build")
28-
endif ()
29-
set (CMAKE_PREFIX_PATH "${LLVM_SRC_ROOT}/build;${CMAKE_PREFIX_PATH}")
30-
find_package(LLVM REQUIRED CONFIG)
31-
include_directories(${LLVM_INCLUDE_DIRS})
32-
add_definitions(${LLVM_DEFINITIONS})
33-
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
34-
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
35-
3625
include (${IWASM_DIR}/compilation/iwasm_compl.cmake)
3726

3827
include_directories (${CMAKE_CURRENT_SOURCE_DIR})
@@ -42,17 +31,10 @@ file (GLOB_RECURSE source_all ${CMAKE_CURRENT_SOURCE_DIR}/*.cc)
4231
set (UNIT_SOURCE ${source_all})
4332

4433
set (unit_test_sources
45-
${UNIT_SOURCE}
46-
${PLATFORM_SHARED_SOURCE}
47-
${UTILS_SHARED_SOURCE}
48-
${MEM_ALLOC_SHARED_SOURCE}
49-
${NATIVE_INTERFACE_SOURCE}
50-
${IWASM_COMMON_SOURCE}
51-
${IWASM_INTERP_SOURCE}
52-
${IWASM_AOT_SOURCE}
53-
${IWASM_COMPL_SOURCE}
54-
${WASM_APP_LIB_SOURCE_ALL}
55-
)
34+
${UNIT_SOURCE}
35+
${WAMR_RUNTIME_LIB_SOURCE}
36+
${IWASM_COMPL_SOURCE}
37+
)
5638

5739
# Automatically build wasm-apps for this test
5840
add_subdirectory(wasm-apps)

tests/unit/gc/CMakeLists.txt

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,9 @@ file (GLOB_RECURSE source_all ${CMAKE_CURRENT_SOURCE_DIR}/*.cc)
2121
set (UNIT_SOURCE ${source_all})
2222

2323
set (unit_test_sources
24-
${UNIT_SOURCE}
25-
${WAMR_RUNTIME_LIB_SOURCE}
26-
${UNCOMMON_SHARED_SOURCE}
27-
${SRC_LIST}
28-
${PLATFORM_SHARED_SOURCE}
29-
${UTILS_SHARED_SOURCE}
30-
${MEM_ALLOC_SHARED_SOURCE}
31-
${LIB_HOST_AGENT_SOURCE}
32-
${NATIVE_INTERFACE_SOURCE}
33-
${LIBC_BUILTIN_SOURCE}
34-
${IWASM_COMMON_SOURCE}
35-
${IWASM_INTERP_SOURCE}
36-
${IWASM_AOT_SOURCE}
37-
${IWASM_COMPL_SOURCE}
38-
${WASM_APP_LIB_SOURCE_ALL}
24+
${UNIT_SOURCE}
25+
${WAMR_RUNTIME_LIB_SOURCE}
26+
${UNCOMMON_SHARED_SOURCE}
3927
)
4028

4129
add_executable (gc_test ${unit_test_sources})
@@ -48,4 +36,4 @@ add_custom_command(TARGET gc_test POST_BUILD
4836
COMMENT "Copy wasm files to directory ${CMAKE_CURRENT_BINARY_DIR}"
4937
)
5038

51-
#gtest_discover_tests(gc_test)
39+
gtest_discover_tests(gc_test)

tests/unit/interpreter/CMakeLists.txt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,9 @@ file (GLOB_RECURSE source_all ${CMAKE_CURRENT_SOURCE_DIR}/*.cc)
2424
set (UNIT_SOURCE ${source_all})
2525

2626
set (unit_test_sources
27-
${UNIT_SOURCE}
28-
${PLATFORM_SHARED_SOURCE}
29-
${UTILS_SHARED_SOURCE}
30-
${MEM_ALLOC_SHARED_SOURCE}
31-
${NATIVE_INTERFACE_SOURCE}
32-
${LIBC_BUILTIN_SOURCE}
33-
${IWASM_COMMON_SOURCE}
34-
${IWASM_INTERP_SOURCE}
35-
)
27+
${UNIT_SOURCE}
28+
${WAMR_RUNTIME_LIB_SOURCE}
29+
)
3630

3731
# Now simply link against gtest or gtest_main as needed. Eg
3832
add_executable (interpreter_test ${unit_test_sources})

0 commit comments

Comments
 (0)