Add unit tests for the tid allocator (#2519)
Add simple infrastructure to add more unit tests in the future. At the moment tests are only executed on Linux, but can be extended to other platforms if needed. Use https://github.com/google/googletest/ as a framework.
This commit is contained in:
51
tests/unit/CMakeLists.txt
Normal file
51
tests/unit/CMakeLists.txt
Normal file
@ -0,0 +1,51 @@
|
||||
# Copyright (C) 2023 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
cmake_minimum_required (VERSION 3.14)
|
||||
|
||||
project (wamr_unit_tests)
|
||||
|
||||
include (CTest)
|
||||
|
||||
if (NOT DEFINED WAMR_BUILD_INTERP)
|
||||
# Enable Interpreter by default
|
||||
set (WAMR_BUILD_INTERP 1)
|
||||
endif ()
|
||||
|
||||
if (NOT DEFINED WAMR_BUILD_PLATFORM)
|
||||
string (TOLOWER ${CMAKE_HOST_SYSTEM_NAME} WAMR_BUILD_PLATFORM)
|
||||
endif ()
|
||||
|
||||
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
|
||||
include (${WAMR_ROOT_DIR}/build-scripts/runtime_lib.cmake)
|
||||
add_library (vmlib ${WAMR_RUNTIME_LIB_SOURCE})
|
||||
|
||||
include (FetchContent)
|
||||
FetchContent_Declare (
|
||||
googletest
|
||||
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
|
||||
)
|
||||
# For Windows: Prevent overriding the parent project's compiler/linker settings
|
||||
set (gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||
FetchContent_MakeAvailable (googletest)
|
||||
|
||||
include (GoogleTest)
|
||||
|
||||
add_library (wamr_gtest_main main.cpp)
|
||||
target_link_libraries (wamr_gtest_main PUBLIC gtest vmlib)
|
||||
|
||||
function (create_wamr_unit_test test_name)
|
||||
set (sources ${ARGN})
|
||||
add_executable (${test_name} ${sources})
|
||||
target_link_libraries (
|
||||
${test_name}
|
||||
wamr_gtest_main
|
||||
vmlib
|
||||
${LLVM_AVAILABLE_LIBS}
|
||||
)
|
||||
gtest_discover_tests (${test_name})
|
||||
endfunction ()
|
||||
|
||||
if (WAMR_BUILD_LIB_WASI_THREADS EQUAL 1)
|
||||
include (${IWASM_DIR}/libraries/lib-wasi-threads/unit-test/lib_wasi_threads_unit_tests.cmake)
|
||||
endif ()
|
||||
21
tests/unit/main.cpp
Normal file
21
tests/unit/main.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Amazon.com Inc. or its affiliates. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
#include <gtest/gtest.h>
|
||||
#include "wasm_runtime_common.h"
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
if (!wasm_runtime_init()) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ret = RUN_ALL_TESTS();
|
||||
wasm_runtime_destroy();
|
||||
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user