blob: 7f73c2b9a002cc6bd58a1c7bdc4f076ac5437578 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# The option `Z` is only accepted on the nightly compiler
# so changing to nightly toolchain by `rustup default nightly` is required.
# See: https://github.com/rust-lang/rust/issues/39699 for more sanitizer support.
toolchain="$(rustup default)"
echo -e "\nUse Rust toolchain: $toolchain"
NIGHTLY_PREFIX="nightly"
if [ ! -z "${toolchain##$NIGHTLY_PREFIX*}" ]; then
echo -e "The sanitizer is only available on Rust Nightly only. Skip."
exit
fi
if [ -z "${toolchain##*windows*}" ]; then
echo -e "The sanitizer doesn't work on Windows platform yet"
exit
fi
# Display verbose backtrace for debugging if backtrace is unset
if [ -z "${RUST_BACKTRACE}" ]; then
export RUST_BACKTRACE=1
fi
echo -e "RUST_BACKTRACE is set to ${RUST_BACKTRACE}\n"
# {Address, Thread}Sanitizer cannot build with `criterion` crate, so `criterion` will be removed
# from the `Cargo.toml` temporarily during the sanitizer tests.
ORIGINAL_MANIFEST="Cargo_ori.toml"
mv Cargo.toml $ORIGINAL_MANIFEST
# Delete lines that contain a `criterion` from Cargo.toml.
sed '/criterion/d' $ORIGINAL_MANIFEST > Cargo.toml
sanitizers=("address" "leak" "memory" "thread")
for san in "${sanitizers[@]}"
do
San="$(tr '[:lower:]' '[:upper:]' <<< ${san:0:1})${san:1}"
echo -e "\n\nRun ${San}Sanitizer\n------------------------------"
if [ $san = "leak" ]; then
echo -e "Skip the test that panics. Leaking memory when the program drops out abnormally is ok."
options="-- --Z unstable-options --exclude-should-panic"
fi
if [ $san = "memory" ]; then
if [ -z "${toolchain##*darwin*}" ]; then
echo -e "Skip the MemorySanitizer on Mac OS since it doesn't works with $toolchain"
else
echo -e "Skip the MemorySanitizer since it fails to run custom build command for bitflags crate"
fi
continue
fi
RUSTFLAGS="-Z sanitizer=${san}" cargo test $options
done
mv $ORIGINAL_MANIFEST Cargo.toml
|