From 4a6bf95f19448475fc05df2b124113a788616100 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Tue, 31 Oct 2017 21:30:43 +0100 Subject: [PATCH] add tsan test --- blacklist.txt | 6 ++++++ ci/install.sh | 4 ++++ ci/script.sh | 13 ++++++++++++- tests/tsan.rs | 20 ++++++++++++++++++++ 4 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 blacklist.txt create mode 100644 tests/tsan.rs diff --git a/blacklist.txt b/blacklist.txt new file mode 100644 index 00000000..7a73a277 --- /dev/null +++ b/blacklist.txt @@ -0,0 +1,6 @@ +# false positives from thread::spawn (?) +race:>::drop_slow +race:__GI___call_tls_dtors +race:alloc::heap::{{impl}}::dealloc +race:core::ptr::drop_in_place>>> +race:core::ptr::drop_in_place>> diff --git a/ci/install.sh b/ci/install.sh index 4d5d56a4..8724552d 100644 --- a/ci/install.sh +++ b/ci/install.sh @@ -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 } diff --git a/ci/script.sh b/ci/script.sh index e9ff7e38..5bf4a8b0 100644 --- a/ci/script.sh +++ b/ci/script.sh @@ -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 } diff --git a/tests/tsan.rs b/tests/tsan.rs new file mode 100644 index 00000000..edee9011 --- /dev/null +++ b/tests/tsan.rs @@ -0,0 +1,20 @@ +extern crate heapless; + +use std::thread; + +use heapless::RingBuffer; + +#[test] +fn tsan() { + static mut RB: RingBuffer = 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(); + }); +}