Skip to content

A lightweight WebAssembly runtime that is fast, secure, and standards-compliant

Run ASAN with C/C++ tests in CI (#11801)

Alex Crichtona70809d0caa4
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index af3c9e9240..619b653208 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -656,6 +656,11 @@ jobs:
- os: ubuntu-24.04
flags: -DBUILD_SHARED_LIBS=OFF -DBUILD_RUST_EXAMPLES=OFF
name: Linux (static linking)
+
+ # Run tests with ASAN for leak checking primarily.
+ - os: ubuntu-24.04
+ flags: -DCMAKE_C_FLAGS=-fsanitize=address -DCMAKE_CXX_FLAGS=-fsanitize=address -DBUILD_SHARED_LIBS=ON -DBUILD_TESTS=ON
+ name: Linux (ASAN)
steps:
- uses: actions/checkout@v4
with:
@@ -789,10 +794,10 @@ jobs:
# Enable environment variable to indicate SDE is being used
echo WASMTIME_TEST_SDE=1 >> $GITHUB_ENV
-
+
# Generic variable for skipping tests that are problematic under SDE (performance, compatibility, etc.)
echo WASMTIME_TEST_NO_SDE=1 >> $GITHUB_ENV
-
+
# Similar to QEMU, reduce memory usage during SDE emulation
echo WASMTIME_TEST_NO_HOG_MEMORY=1 >> $GITHUB_ENV
@@ -803,11 +808,11 @@ jobs:
curl --retry 5 --retry-all-errors -o sde.tar.xz \
https://downloadmirror.intel.com/859732/sde-external-${{ env.SDE_BUILD_VERSION }}-lin.tar.xz
-
+
mkdir -p ${{ runner.tool_cache }}/sde
tar xJf sde.tar.xz --strip-components=1 -C ${{ runner.tool_cache }}/sde
rm sde.tar.xz
-
+
chmod +x ${{ runner.tool_cache }}/sde/sde64
if: matrix.sde != ''
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index f338dd1856..f8494b9319 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -21,6 +21,10 @@ function(CREATE_TARGET TARGET TARGET_PATH)
target_compile_definitions(wasmtime-${TARGET} PRIVATE WASMTIME_TEST_ONLY)
endif()
+ if (CMAKE_C_FLAGS MATCHES ".*-fsanitize=address.*")
+ target_compile_definitions(wasmtime-${TARGET} PRIVATE WASMTIME_ASAN)
+ endif()
+
set_target_properties(wasmtime-${TARGET} PROPERTIES
OUTPUT_NAME wasmtime-${TARGET}
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/$<0:>
diff --git a/examples/multimemory.c b/examples/multimemory.c
index c0a705ee27..41cf16f67c 100644
--- a/examples/multimemory.c
+++ b/examples/multimemory.c
@@ -114,7 +114,7 @@ void check_trap2(wasmtime_context_t *store, wasmtime_func_t *func, int32_t arg1,
check_trap(store, func, args, 2, 0);
}
-int main(int argc, const char *argv[]) {
+int main() {
// Initialize.
printf("Initializing...\n");
diff --git a/examples/threads.cc b/examples/threads.cc
index f03b0b2f15..84793c13c2 100644
--- a/examples/threads.cc
+++ b/examples/threads.cc
@@ -31,8 +31,13 @@ std::string readFile(const char *name) {
return strStream.str();
}
+#if defined(WASMTIME_ASAN)
+const int N_THREADS = 1;
+const int N_REPS = 1;
+#else
const int N_THREADS = 10;
const int N_REPS = 3;
+#endif
std::mutex print_mutex;