Skip to content

Commit 3028864

Browse files
committed
Auto merge of rust-lang#3590 - RalfJung:miri-test-target, r=RalfJung
make MIRI_TEST_TARGET and RUSTC_BLESS entirely an internal thing They are just used to communicate between `./miri test`/`./x.py test miri` and the test harness, but should not be used by users.
2 parents 42d9b68 + cb44843 commit 3028864

File tree

7 files changed

+179
-146
lines changed

7 files changed

+179
-146
lines changed

src/tools/miri/CONTRIBUTING.md

+42-5
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ You can (cross-)run the entire test suite using:
7878
```
7979

8080
`./miri test FILTER` only runs those tests that contain `FILTER` in their filename (including the
81-
base directory, e.g. `./miri test fail` will run all compile-fail tests). Multiple filters
82-
are supported: `./miri test FILTER1 FILTER2`.
81+
base directory, e.g. `./miri test fail` will run all compile-fail tests). Multiple filters are
82+
supported: `./miri test FILTER1 FILTER2` runs all tests that contain either string.
8383

8484
#### Fine grained logging
8585

@@ -139,9 +139,8 @@ and then you can use it as if it was installed by `rustup` as a component of the
139139
in the `miri` toolchain's sysroot to prevent conflicts with other toolchains.
140140
The Miri binaries in the `cargo` bin directory (usually `~/.cargo/bin`) are managed by rustup.
141141

142-
There's a test for the cargo wrapper in the `test-cargo-miri` directory; run
143-
`./run-test.py` in there to execute it. Like `./miri test`, this respects the
144-
`MIRI_TEST_TARGET` environment variable to execute the test for another target.
142+
There's a test for the cargo wrapper in the `test-cargo-miri` directory; run `./run-test.py` in
143+
there to execute it. You can pass `--target` to execute the test for another target.
145144

146145
### Using a modified standard library
147146

@@ -287,3 +286,41 @@ https. Add the following to your `.gitconfig`:
287286
[url "git@github.com:"]
288287
pushInsteadOf = https://github.com/
289288
```
289+
290+
## Internal environment variables
291+
292+
The following environment variables are *internal* and must not be used by
293+
anyone but Miri itself. They are used to communicate between different Miri
294+
binaries, and as such worth documenting:
295+
296+
* `CARGO_EXTRA_FLAGS` is understood by `./miri` and passed to all host cargo invocations.
297+
* `MIRI_BE_RUSTC` can be set to `host` or `target`. It tells the Miri driver to
298+
actually not interpret the code but compile it like rustc would. With `target`, Miri sets
299+
some compiler flags to prepare the code for interpretation; with `host`, this is not done.
300+
This environment variable is useful to be sure that the compiled `rlib`s are compatible
301+
with Miri.
302+
* `MIRI_CALLED_FROM_SETUP` is set during the Miri sysroot build,
303+
which will re-invoke `cargo-miri` as the `rustc` to use for this build.
304+
* `MIRI_CALLED_FROM_RUSTDOC` when set to any value tells `cargo-miri` that it is
305+
running as a child process of `rustdoc`, which invokes it twice for each doc-test
306+
and requires special treatment, most notably a check-only build before interpretation.
307+
This is set by `cargo-miri` itself when running as a `rustdoc`-wrapper.
308+
* `MIRI_CWD` when set to any value tells the Miri driver to change to the given
309+
directory after loading all the source files, but before commencing
310+
interpretation. This is useful if the interpreted program wants a different
311+
working directory at run-time than at build-time.
312+
* `MIRI_LOCAL_CRATES` is set by `cargo-miri` to tell the Miri driver which
313+
crates should be given special treatment in diagnostics, in addition to the
314+
crate currently being compiled.
315+
* `MIRI_ORIG_RUSTDOC` is set and read by different phases of `cargo-miri` to remember the
316+
value of `RUSTDOC` from before it was overwritten.
317+
* `MIRI_REPLACE_LIBRS_IF_NOT_TEST` when set to any value enables a hack that helps bootstrap
318+
run the standard library tests in Miri.
319+
* `MIRI_TEST_TARGET` is set by `./miri test` (and `./x.py test miri`) to tell the test harness about
320+
the chosen target.
321+
* `MIRI_VERBOSE` when set to any value tells the various `cargo-miri` phases to
322+
perform verbose logging.
323+
* `MIRI_HOST_SYSROOT` is set by bootstrap to tell `cargo-miri` which sysroot to use for *host*
324+
operations.
325+
* `RUSTC_BLESS` is set by `./miri test` (and `./x.py test miri`) to indicate bless-mode to the test
326+
harness.

src/tools/miri/README.md

-36
Original file line numberDiff line numberDiff line change
@@ -463,50 +463,14 @@ by all intended entry points, i.e. `cargo miri` and `./miri {test,run}`):
463463
* `MIRI_SYSROOT` indicates the sysroot to use. When using `cargo miri`, this skips the automatic
464464
setup -- only set this if you do not want to use the automatically created sysroot. When invoking
465465
`cargo miri setup`, this indicates where the sysroot will be put.
466-
* `MIRI_TEST_TARGET` (recognized by `./miri {test,run}`) indicates which target
467-
architecture to test against. The `--target` flag may be used for the same
468-
purpose.
469466
* `MIRI_TEST_THREADS` (recognized by `./miri test`): set the number of threads to use for running tests.
470467
By default, the number of cores is used.
471468
* `MIRI_NO_STD` makes sure that the target's sysroot is built without libstd. This allows testing
472469
and running no_std programs. (Miri has a heuristic to detect no-std targets based on the target
473470
name; this environment variable is only needed when that heuristic fails.)
474-
* `RUSTC_BLESS` (recognized by `./miri test` and `cargo-miri-test/run-test.py`): overwrite all
475-
`stderr` and `stdout` files instead of checking whether the output matches.
476471
* `MIRI_SKIP_UI_CHECKS` (recognized by `./miri test`): don't check whether the
477472
`stderr` or `stdout` files match the actual output.
478473

479-
The following environment variables are *internal* and must not be used by
480-
anyone but Miri itself. They are used to communicate between different Miri
481-
binaries, and as such worth documenting:
482-
483-
* `MIRI_BE_RUSTC` can be set to `host` or `target`. It tells the Miri driver to
484-
actually not interpret the code but compile it like rustc would. With `target`, Miri sets
485-
some compiler flags to prepare the code for interpretation; with `host`, this is not done.
486-
This environment variable is useful to be sure that the compiled `rlib`s are compatible
487-
with Miri.
488-
* `MIRI_CALLED_FROM_SETUP` is set during the Miri sysroot build,
489-
which will re-invoke `cargo-miri` as the `rustc` to use for this build.
490-
* `MIRI_CALLED_FROM_RUSTDOC` when set to any value tells `cargo-miri` that it is
491-
running as a child process of `rustdoc`, which invokes it twice for each doc-test
492-
and requires special treatment, most notably a check-only build before interpretation.
493-
This is set by `cargo-miri` itself when running as a `rustdoc`-wrapper.
494-
* `MIRI_CWD` when set to any value tells the Miri driver to change to the given
495-
directory after loading all the source files, but before commencing
496-
interpretation. This is useful if the interpreted program wants a different
497-
working directory at run-time than at build-time.
498-
* `MIRI_LOCAL_CRATES` is set by `cargo-miri` to tell the Miri driver which
499-
crates should be given special treatment in diagnostics, in addition to the
500-
crate currently being compiled.
501-
* `MIRI_ORIG_RUSTDOC` is set and read by different phases of `cargo-miri` to remember the
502-
value of `RUSTDOC` from before it was overwritten.
503-
* `MIRI_REPLACE_LIBRS_IF_NOT_TEST` when set to any value enables a hack that helps bootstrap
504-
run the standard library tests in Miri.
505-
* `MIRI_VERBOSE` when set to any value tells the various `cargo-miri` phases to
506-
perform verbose logging.
507-
* `MIRI_HOST_SYSROOT` is set by bootstrap to tell `cargo-miri` which sysroot to use for *host*
508-
operations.
509-
510474
[testing-miri]: CONTRIBUTING.md#testing-the-miri-driver
511475

512476
## Miri `extern` functions

src/tools/miri/ci/ci.sh

+35-32
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,26 @@ time ./miri build --all-targets # the build that all the `./miri test` below wil
3131
endgroup
3232

3333
# Run tests. Recognizes these variables:
34-
# - MIRI_TEST_TARGET: the target to test. Empty for host target.
34+
# - TEST_TARGET: the target to test. Empty for host target.
3535
# - GC_STRESS: if non-empty, run the GC stress test for the main test suite.
3636
# - MIR_OPT: if non-empty, re-run test `pass` tests with mir-opt-level=4
3737
# - MANY_SEEDS: if set to N, run the "many-seeds" tests N times
3838
# - TEST_BENCH: if non-empty, check that the benchmarks all build
3939
# - CARGO_MIRI_ENV: if non-empty, set some env vars and config to potentially confuse cargo-miri
4040
function run_tests {
41-
if [ -n "${MIRI_TEST_TARGET-}" ]; then
42-
begingroup "Testing foreign architecture $MIRI_TEST_TARGET"
41+
if [ -n "${TEST_TARGET-}" ]; then
42+
begingroup "Testing foreign architecture $TEST_TARGET"
43+
TARGET_FLAG="--target $TEST_TARGET"
4344
else
4445
begingroup "Testing host architecture"
46+
TARGET_FLAG=""
4547
fi
4648

4749
## ui test suite
4850
if [ -n "${GC_STRESS-}" ]; then
49-
time MIRIFLAGS="${MIRIFLAGS-} -Zmiri-provenance-gc=1" ./miri test
51+
time MIRIFLAGS="${MIRIFLAGS-} -Zmiri-provenance-gc=1" ./miri test $TARGET_FLAG
5052
else
51-
time ./miri test
53+
time ./miri test $TARGET_FLAG
5254
fi
5355

5456
## advanced tests
@@ -59,17 +61,17 @@ function run_tests {
5961
# them. Also error locations change so we don't run the failing tests.
6062
# We explicitly enable debug-assertions here, they are disabled by -O but we have tests
6163
# which exist to check that we panic on debug assertion failures.
62-
time MIRIFLAGS="${MIRIFLAGS-} -O -Zmir-opt-level=4 -Cdebug-assertions=yes" MIRI_SKIP_UI_CHECKS=1 ./miri test tests/{pass,panic}
64+
time MIRIFLAGS="${MIRIFLAGS-} -O -Zmir-opt-level=4 -Cdebug-assertions=yes" MIRI_SKIP_UI_CHECKS=1 ./miri test $TARGET_FLAG tests/{pass,panic}
6365
fi
6466
if [ -n "${MANY_SEEDS-}" ]; then
6567
# Also run some many-seeds tests.
6668
time for FILE in tests/many-seeds/*.rs; do
67-
./miri run "--many-seeds=0..$MANY_SEEDS" "$FILE"
69+
./miri run "--many-seeds=0..$MANY_SEEDS" $TARGET_FLAG "$FILE"
6870
done
6971
fi
7072
if [ -n "${TEST_BENCH-}" ]; then
7173
# Check that the benchmarks build and run, but only once.
72-
time HYPERFINE="hyperfine -w0 -r1" ./miri bench
74+
time HYPERFINE="hyperfine -w0 -r1" ./miri bench $TARGET_FLAG
7375
fi
7476

7577
## test-cargo-miri
@@ -91,7 +93,7 @@ function run_tests {
9193
echo 'build.rustc-wrapper = "thisdoesnotexist"' > .cargo/config.toml
9294
fi
9395
# Run the actual test
94-
time ${PYTHON} test-cargo-miri/run-test.py
96+
time ${PYTHON} test-cargo-miri/run-test.py $TARGET_FLAG
9597
# Clean up
9698
unset RUSTC MIRI
9799
rm -rf .cargo
@@ -100,17 +102,18 @@ function run_tests {
100102
}
101103

102104
function run_tests_minimal {
103-
if [ -n "${MIRI_TEST_TARGET-}" ]; then
104-
begingroup "Testing MINIMAL foreign architecture $MIRI_TEST_TARGET: only testing $@"
105+
if [ -n "${TEST_TARGET-}" ]; then
106+
begingroup "Testing MINIMAL foreign architecture $TEST_TARGET: only testing $@"
107+
TARGET_FLAG="--target $TEST_TARGET"
105108
else
106-
echo "run_tests_minimal requires MIRI_TEST_TARGET to be set"
109+
echo "run_tests_minimal requires TEST_TARGET to be set"
107110
exit 1
108111
fi
109112

110-
time ./miri test "$@"
113+
time ./miri test $TARGET_FLAG "$@"
111114

112115
# Ensure that a small smoke test of cargo-miri works.
113-
time cargo miri run --manifest-path test-cargo-miri/no-std-smoke/Cargo.toml --target ${MIRI_TEST_TARGET-$HOST_TARGET}
116+
time cargo miri run --manifest-path test-cargo-miri/no-std-smoke/Cargo.toml $TARGET_FLAG
114117

115118
endgroup
116119
}
@@ -126,33 +129,33 @@ case $HOST_TARGET in
126129
# Extra tier 1
127130
# With reduced many-seed count to avoid spending too much time on that.
128131
# (All OSes and ABIs are run with 64 seeds at least once though via the macOS runner.)
129-
MANY_SEEDS=16 MIRI_TEST_TARGET=i686-unknown-linux-gnu run_tests
130-
MANY_SEEDS=16 MIRI_TEST_TARGET=aarch64-unknown-linux-gnu run_tests
131-
MANY_SEEDS=16 MIRI_TEST_TARGET=x86_64-apple-darwin run_tests
132-
MANY_SEEDS=16 MIRI_TEST_TARGET=x86_64-pc-windows-gnu run_tests
132+
MANY_SEEDS=16 TEST_TARGET=i686-unknown-linux-gnu run_tests
133+
MANY_SEEDS=16 TEST_TARGET=aarch64-unknown-linux-gnu run_tests
134+
MANY_SEEDS=16 TEST_TARGET=x86_64-apple-darwin run_tests
135+
MANY_SEEDS=16 TEST_TARGET=x86_64-pc-windows-gnu run_tests
133136
;;
134137
aarch64-apple-darwin)
135138
# Host (tier 2)
136139
GC_STRESS=1 MIR_OPT=1 MANY_SEEDS=64 TEST_BENCH=1 CARGO_MIRI_ENV=1 run_tests
137140
# Extra tier 1
138-
MANY_SEEDS=64 MIRI_TEST_TARGET=i686-pc-windows-gnu run_tests
139-
MANY_SEEDS=64 MIRI_TEST_TARGET=x86_64-pc-windows-msvc CARGO_MIRI_ENV=1 run_tests
141+
MANY_SEEDS=64 TEST_TARGET=i686-pc-windows-gnu run_tests
142+
MANY_SEEDS=64 TEST_TARGET=x86_64-pc-windows-msvc CARGO_MIRI_ENV=1 run_tests
140143
# Extra tier 2
141-
MIRI_TEST_TARGET=arm-unknown-linux-gnueabi run_tests
142-
MIRI_TEST_TARGET=s390x-unknown-linux-gnu run_tests # big-endian architecture of choice
144+
TEST_TARGET=arm-unknown-linux-gnueabi run_tests
145+
TEST_TARGET=s390x-unknown-linux-gnu run_tests # big-endian architecture of choice
143146
# Partially supported targets (tier 2)
144147
VERY_BASIC="integer vec string btreemap" # common things we test on all of them (if they have std), requires no target-specific shims
145148
BASIC="$VERY_BASIC hello hashmap alloc align" # ensures we have the shims for stdout and basic data structures
146-
MIRI_TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal $BASIC panic/panic concurrency/simple atomic threadname libc-mem libc-misc libc-random libc-time fs env num_cpus
147-
MIRI_TEST_TARGET=i686-unknown-freebsd run_tests_minimal $BASIC panic/panic concurrency/simple atomic threadname libc-mem libc-misc libc-random libc-time fs env num_cpus
148-
MIRI_TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $VERY_BASIC hello panic/panic concurrency/simple pthread-sync libc-mem libc-misc libc-random
149-
MIRI_TEST_TARGET=x86_64-pc-solaris run_tests_minimal $VERY_BASIC hello panic/panic concurrency/simple pthread-sync libc-mem libc-misc libc-random
150-
MIRI_TEST_TARGET=aarch64-linux-android run_tests_minimal $VERY_BASIC hello panic/panic
151-
MIRI_TEST_TARGET=wasm32-wasi run_tests_minimal $VERY_BASIC wasm
152-
MIRI_TEST_TARGET=wasm32-unknown-unknown run_tests_minimal $VERY_BASIC wasm
153-
MIRI_TEST_TARGET=thumbv7em-none-eabihf run_tests_minimal no_std
149+
TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal $BASIC panic/panic concurrency/simple atomic threadname libc-mem libc-misc libc-random libc-time fs env num_cpus
150+
TEST_TARGET=i686-unknown-freebsd run_tests_minimal $BASIC panic/panic concurrency/simple atomic threadname libc-mem libc-misc libc-random libc-time fs env num_cpus
151+
TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $VERY_BASIC hello panic/panic concurrency/simple pthread-sync libc-mem libc-misc libc-random
152+
TEST_TARGET=x86_64-pc-solaris run_tests_minimal $VERY_BASIC hello panic/panic concurrency/simple pthread-sync libc-mem libc-misc libc-random
153+
TEST_TARGET=aarch64-linux-android run_tests_minimal $VERY_BASIC hello panic/panic
154+
TEST_TARGET=wasm32-wasi run_tests_minimal $VERY_BASIC wasm
155+
TEST_TARGET=wasm32-unknown-unknown run_tests_minimal $VERY_BASIC wasm
156+
TEST_TARGET=thumbv7em-none-eabihf run_tests_minimal no_std
154157
# Custom target JSON file
155-
MIRI_TEST_TARGET=tests/avr.json MIRI_NO_STD=1 run_tests_minimal no_std
158+
TEST_TARGET=tests/avr.json MIRI_NO_STD=1 run_tests_minimal no_std
156159
;;
157160
i686-pc-windows-msvc)
158161
# Host
@@ -162,7 +165,7 @@ case $HOST_TARGET in
162165
# Extra tier 1
163166
# We really want to ensure a Linux target works on a Windows host,
164167
# and a 64bit target works on a 32bit host.
165-
MIRI_TEST_TARGET=x86_64-unknown-linux-gnu run_tests
168+
TEST_TARGET=x86_64-unknown-linux-gnu run_tests
166169
;;
167170
*)
168171
echo "FATAL: unknown host target: $HOST_TARGET"

0 commit comments

Comments
 (0)