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