]> git.lizzy.rs Git - rust.git/blob - src/tools/miri/ci.sh
Rollup merge of #103521 - chenyukang:yukang/fix-103451-avoid-hang, r=jackh726,wesleywiser
[rust.git] / src / tools / miri / ci.sh
1 #!/bin/bash
2 set -euo pipefail
3 set -x
4
5 # Determine configuration for installed build
6 echo "Installing release version of Miri"
7 export RUSTFLAGS="-D warnings"
8 export CARGO_INCREMENTAL=0
9 ./miri install # implicitly locked
10
11 # Prepare debug build for direct `./miri` invocations
12 echo "Building debug version of Miri"
13 export CARGO_EXTRA_FLAGS="--locked"
14 ./miri check --no-default-features # make sure this can be built
15 ./miri check --all-features # and this, too
16 ./miri build --all-targets # the build that all the `./miri test` below will use
17 echo
18
19 # Test
20 function run_tests {
21   if [ -n "${MIRI_TEST_TARGET+exists}" ]; then
22     echo "Testing foreign architecture $MIRI_TEST_TARGET"
23   else
24     echo "Testing host architecture"
25   fi
26
27   ## ui test suite
28   ./miri test
29   if [ -z "${MIRI_TEST_TARGET+exists}" ]; then
30     # Only for host architecture: tests with optimizations (`-O` is what cargo passes, but crank MIR
31     # optimizations up all the way).
32     # Optimizations change diagnostics (mostly backtraces), so we don't check them
33     #FIXME(#2155): we want to only run the pass and panic tests here, not the fail tests.
34     MIRIFLAGS="${MIRIFLAGS:-} -O -Zmir-opt-level=4" MIRI_SKIP_UI_CHECKS=1 ./miri test -- tests/{pass,panic}
35   fi
36
37   ## test-cargo-miri
38   # On Windows, there is always "python", not "python3" or "python2".
39   if command -v python3 > /dev/null; then
40     PYTHON=python3
41   else
42     PYTHON=python
43   fi
44   # Some environment setup that attempts to confuse the heck out of cargo-miri.
45   if [ "$HOST_TARGET" = x86_64-unknown-linux-gnu ]; then
46     # These act up on Windows (`which miri` produces a filename that does not exist?!?),
47     # so let's do this only on Linux. Also makes sure things work without these set.
48     export RUSTC=$(which rustc)
49     export MIRI=$(which miri)
50   fi
51   mkdir -p .cargo
52   echo 'build.rustc-wrapper = "thisdoesnotexist"' > .cargo/config.toml
53   # Run the actual test
54   ${PYTHON} test-cargo-miri/run-test.py
55   echo
56   # Clean up
57   unset RUSTC MIRI
58   rm -rf .cargo
59
60   # Ensure that our benchmarks all work, but only on Linux hosts.
61   if [ -z "${MIRI_TEST_TARGET+exists}" ] && [ "$HOST_TARGET" = x86_64-unknown-linux-gnu ] ; then
62     for BENCH in $(ls "bench-cargo-miri"); do
63       cargo miri run --manifest-path bench-cargo-miri/$BENCH/Cargo.toml
64     done
65   fi
66 }
67
68 function run_tests_minimal {
69   if [ -n "${MIRI_TEST_TARGET+exists}" ]; then
70     echo "Testing MINIMAL foreign architecture $MIRI_TEST_TARGET: only testing $@"
71   else
72     echo "Testing MINIMAL host architecture: only testing $@"
73   fi
74
75   ./miri test -- "$@"
76 }
77
78 # host
79 run_tests
80
81 case $HOST_TARGET in
82   x86_64-unknown-linux-gnu)
83     MIRI_TEST_TARGET=i686-unknown-linux-gnu run_tests
84     MIRI_TEST_TARGET=aarch64-apple-darwin run_tests
85     MIRI_TEST_TARGET=i686-pc-windows-msvc run_tests
86     MIRI_TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal hello integer vec panic/panic concurrency/simple atomic data_race env/var
87     MIRI_TEST_TARGET=aarch64-linux-android run_tests_minimal hello integer vec panic/panic
88     MIRI_TEST_TARGET=thumbv7em-none-eabihf MIRI_NO_STD=1 run_tests_minimal no_std # no_std embedded architecture
89     ;;
90   x86_64-apple-darwin)
91     MIRI_TEST_TARGET=mips64-unknown-linux-gnuabi64 run_tests # big-endian architecture
92     MIRI_TEST_TARGET=x86_64-pc-windows-msvc run_tests
93     ;;
94   i686-pc-windows-msvc)
95     MIRI_TEST_TARGET=x86_64-unknown-linux-gnu run_tests
96     MIRI_TEST_TARGET=x86_64-pc-windows-gnu run_tests
97     ;;
98   *)
99     echo "FATAL: unknown OS"
100     exit 1
101     ;;
102 esac