Debian Codegraph @

third_party/rust/audio-mixer/run_sanitizers.sh

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