Skip to content

Commit e657756

Browse files
authored
Run CI tests through AddressSanitizer (#10537)
This is similar to running tests in Valgrind (which we should perhaps also do...) but can be useful for catching use-after-free style bugs faster than when a process crashes. Given the unsafe nature of Wasmtime this is something we should have probably enabled awhile back but otherwise so long as it doesn't take too long to run on CI seems like an easy win of a boost-of-confidence. prtest:asan
1 parent 07c71ab commit e657756

File tree

11 files changed

+52
-6
lines changed

11 files changed

+52
-6
lines changed

.github/workflows/main.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,14 @@ jobs:
769769
touch ${{ runner.tool_cache }}/qemu/built
770770
if: matrix.qemu != ''
771771

772+
- name: Configure ASAN
773+
run: |
774+
echo CARGO_PROFILE_DEV_OPT_LEVEL=2 >> $GITHUB_ENV
775+
echo CARGO_PROFILE_TEST_OPT_LEVEL=2 >> $GITHUB_ENV
776+
echo RUSTFLAGS=-Zsanitizer=address >> $GITHUB_ENV
777+
echo RUSTDOCFLAGS=-Zsanitizer=address >> $GITHUB_ENV
778+
if: ${{ contains(matrix.name, 'ASAN') }}
779+
772780
# Record some CPU details; this is helpful information if tests fail due
773781
# to CPU-specific features.
774782
- name: CPU information

build.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ fn main() {
66
println!("cargo:rerun-if-changed=build.rs");
77

88
set_commit_info_for_rustc();
9+
10+
println!("cargo:rustc-check-cfg=cfg(asan)");
11+
match env::var("CARGO_CFG_SANITIZE") {
12+
Ok(s) if s == "address" => {
13+
println!("cargo:rustc-cfg=asan");
14+
}
15+
_ => {}
16+
}
917
}
1018

1119
fn set_commit_info_for_rustc() {

ci/build-test-matrix.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ const FULL_MATRIX = [
7171
"filter": "linux-x64",
7272
"isa": "x64"
7373
},
74+
{
75+
"os": ubuntu,
76+
"name": "Test Linux x86_64 with ASAN",
77+
"filter": "asan",
78+
"rust": "wasmtime-ci-pinned-nightly",
79+
"target": "x86_64-unknown-linux-gnu",
80+
},
7481
{
7582
"os": macos,
7683
"name": "Test macOS x86_64",

crates/fiber/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ mod tests {
343343
// TODO: see comments in `arm.rs` about how this seems to work
344344
// in gdb but not at runtime, unsure why at this time.
345345
|| cfg!(target_arch = "arm")
346+
// asan does weird things
347+
|| cfg!(asan)
346348
);
347349
}
348350

crates/wasmtime/src/runtime/vm/instance/allocator/pooling.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,13 @@ mod test {
743743
);
744744
}
745745

746-
#[cfg(all(unix, target_pointer_width = "64", feature = "async", not(miri)))]
746+
#[cfg(all(
747+
unix,
748+
target_pointer_width = "64",
749+
feature = "async",
750+
not(miri),
751+
not(asan)
752+
))]
747753
#[test]
748754
fn test_stack_zeroed() -> Result<()> {
749755
let config = PoolingInstanceAllocatorConfig {
@@ -777,7 +783,13 @@ mod test {
777783
Ok(())
778784
}
779785

780-
#[cfg(all(unix, target_pointer_width = "64", feature = "async", not(miri)))]
786+
#[cfg(all(
787+
unix,
788+
target_pointer_width = "64",
789+
feature = "async",
790+
not(miri),
791+
not(asan)
792+
))]
781793
#[test]
782794
fn test_stack_unzeroed() -> Result<()> {
783795
let config = PoolingInstanceAllocatorConfig {

crates/wasmtime/src/runtime/vm/instance/allocator/pooling/unix_stack_pool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl StackPool {
239239
}
240240
}
241241

242-
#[cfg(all(test, unix, feature = "async", not(miri)))]
242+
#[cfg(all(test, unix, feature = "async", not(miri), not(asan)))]
243243
mod tests {
244244
use super::*;
245245
use crate::runtime::vm::InstanceLimits;

crates/wasmtime/tests/host_segfault.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ enum StackOverflow {
8989
}
9090

9191
fn main() {
92-
if cfg!(miri) {
92+
if cfg!(miri) || cfg!(asan) {
9393
return;
9494
}
9595
// Skip this tests if it looks like we're in a cross-compiled situation and

tests/all/memory.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ fn offsets_static_dynamic_oh_my(config: &mut Config) -> Result<()> {
140140

141141
#[test]
142142
#[cfg_attr(miri, ignore)]
143+
#[cfg_attr(asan, ignore)]
143144
fn guards_present() -> Result<()> {
144145
const GUARD_SIZE: u64 = 65536;
145146

@@ -188,6 +189,7 @@ fn guards_present() -> Result<()> {
188189

189190
#[wasmtime_test]
190191
#[cfg_attr(miri, ignore)]
192+
#[cfg_attr(asan, ignore)]
191193
fn guards_present_pooling(config: &mut Config) -> Result<()> {
192194
const GUARD_SIZE: u64 = 65536;
193195

@@ -246,6 +248,7 @@ fn guards_present_pooling(config: &mut Config) -> Result<()> {
246248

247249
#[wasmtime_test]
248250
#[cfg_attr(miri, ignore)]
251+
#[cfg_attr(asan, ignore)]
249252
fn guards_present_pooling_mpk(config: &mut Config) -> Result<()> {
250253
if !wasmtime::PoolingAllocationConfig::are_memory_protection_keys_available() {
251254
println!("skipping `guards_present_pooling_mpk` test; mpk is not supported");

tests/all/stack_creator.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ fn config() -> (Store<()>, Arc<CustomStackCreator>) {
128128
}
129129

130130
#[tokio::test]
131+
#[cfg_attr(asan, ignore)]
131132
async fn called_on_custom_heap_stack() -> Result<()> {
132133
let (mut store, stack_creator) = config();
133134
let module = Module::new(

tests/all/wasi_testsuite.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ fn wasi_testsuite() -> Result<()> {
5555
WASI_COMMON_IGNORE_LIST,
5656
)?;
5757

58-
// Only run threaded tests on platforms that support threads.
59-
if crate::threads::engine().is_some() {
58+
// Only run threaded tests on platforms that support threads. Also skip
59+
// these tests with ASAN as it, rightfully, complains about a memory leak.
60+
// The memory leak at this time is that child threads aren't joined with the
61+
// main thread, meaning that allocations done on child threads are indeed
62+
// leaked.
63+
if crate::threads::engine().is_some() && !cfg!(asan) {
6064
run_all(
6165
"tests/wasi_testsuite/wasi-threads",
6266
&["-Sthreads", "-Wthreads"],

0 commit comments

Comments
 (0)