add tsan test

This commit is contained in:
Jorge Aparicio 2017-10-31 21:30:43 +01:00
parent 55f891e64f
commit 4a6bf95f19
4 changed files with 42 additions and 1 deletions

6
blacklist.txt Normal file
View File

@ -0,0 +1,6 @@
# false positives from thread::spawn (?)
race:<alloc::arc::Arc<T>>::drop_slow
race:__GI___call_tls_dtors
race:alloc::heap::{{impl}}::dealloc
race:core::ptr::drop_in_place<core::option::Option<core::result::Result<(), alloc::boxed::Box<Any>>>>
race:core::ptr::drop_in_place<core::result::Result<(), alloc::boxed::Box<Any>>>

View File

@ -11,7 +11,11 @@ main() {
rustup component list | grep 'rust-src.*installed' || \
rustup component add rust-src
;;
x86_64-unknown-linux-gnu)
;;
*)
# unhandled case
exit 1
;;
esac
}

View File

@ -5,8 +5,19 @@ main() {
thumb*m-none-eabi)
xargo check --target $TARGET
;;
*)
x86_64-unknown-linux-gnu)
cargo check --target $TARGET
cargo test --target $TARGET
export TSAN_OPTIONS="suppressions=$(pwd)/blacklist.txt"
export RUSTFLAGS="-Z sanitizer=thread"
cargo test --test tsan --target $TARGET
cargo test --test tsan --target $TARGET --release
;;
*)
# unhandled case
exit 1
;;
esac
}

20
tests/tsan.rs Normal file
View File

@ -0,0 +1,20 @@
extern crate heapless;
use std::thread;
use heapless::RingBuffer;
#[test]
fn tsan() {
static mut RB: RingBuffer<i32, [i32; 4]> = RingBuffer::new();
unsafe { RB.split() }.0.enqueue(0).unwrap();
thread::spawn(|| {
unsafe { RB.split() }.0.enqueue(1).unwrap();
});
thread::spawn(|| {
unsafe { RB.split() }.1.dequeue().unwrap();
});
}