Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bytecodealliance
GitHub Repository: bytecodealliance/wasmtime
Path: blob/main/crates/c-api/tests/CMakeLists.txt
1692 views
1
include(FetchContent)
2
FetchContent_Declare(
3
googletest
4
URL https://github.com/google/googletest/archive/refs/tags/release-1.12.1.zip
5
)
6
# For Windows: Prevent overriding the parent project's compiler/linker settings
7
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
8
FetchContent_MakeAvailable(googletest)
9
10
include(GoogleTest)
11
12
function(add_capi_test name)
13
cmake_parse_arguments(PARSE_ARGV 1 arg "" "" "FILES")
14
add_executable(test-${name} ${arg_FILES})
15
target_link_libraries(test-${name} PRIVATE wasmtime-cpp gtest_main)
16
gtest_discover_tests(test-${name}
17
# GitHub Actions on Windows is pretty slow, let's give it lots more time
18
# than the default 5 seconds.
19
DISCOVERY_TIMEOUT 60)
20
endfunction()
21
22
add_capi_test(tests FILES
23
simple.cc
24
types.cc
25
memory_type.cc
26
val_type.cc
27
global_type.cc
28
table_type.cc
29
func_type.cc
30
import_type.cc
31
export_type.cc
32
extern_type.cc
33
func.cc
34
component/instantiate.cc
35
component/define_module.cc
36
component/lookup_func.cc
37
component/call_func.cc
38
component/values.cc
39
error.cc
40
config.cc
41
wat.cc
42
module.cc
43
engine.cc
44
trap.cc
45
wasi.cc
46
store.cc
47
val.cc
48
table.cc
49
global.cc
50
memory.cc
51
instance.cc
52
linker.cc
53
wasip2.cc
54
)
55
56
# Create a list of all wasmtime headers with `GLOB_RECURSE`, then emit a file
57
# into the current binary directory which tests that if the header is included
58
# that the file compiles correctly.
59
#
60
# Gather everything into a list and then create a test which links all these
61
# compilations together. This binary doesn't actually run any tests itself but
62
# it does test that all headers compile in isolation at least. Not perfect but
63
# hopefully at least something.
64
cmake_path(APPEND CMAKE_CURRENT_SOURCE_DIR "../include" OUTPUT_VARIABLE header_root)
65
file(GLOB_RECURSE cpp_headers "${header_root}/*.h*")
66
foreach(header IN LISTS cpp_headers)
67
cmake_path(GET header EXTENSION header_extension)
68
if(header_extension STREQUAL ".h.in")
69
continue()
70
endif()
71
cmake_path(GET header FILENAME header_filename)
72
cmake_path(APPEND CMAKE_CURRENT_BINARY_DIR "header-test" "${header_filename}.cc"
73
OUTPUT_VARIABLE test_filename)
74
list(APPEND header_tests ${test_filename})
75
76
cmake_path(
77
RELATIVE_PATH header
78
BASE_DIRECTORY ${header_root}
79
OUTPUT_VARIABLE rel_header)
80
file(WRITE ${test_filename} "#include <${rel_header}>")
81
endforeach()
82
add_capi_test(standalone-headers FILES ${header_tests})
83
84
# Add a custom test where two files include `wasmtime.hh` and are compiled into
85
# the same executable (basically makes sure any defined functions in the header
86
# are tagged with `inline`).
87
add_capi_test(test-double-include FILES double-include-a.cc double-include-b.cc)
88
89