Skip to content

Commit 0efc6b2

Browse files
authored
Merge pull request #429 from RalfJung/cargo-miri-test
Cargo miri test
2 parents ff0f856 + c4c8c60 commit 0efc6b2

File tree

3 files changed

+40
-34
lines changed

3 files changed

+40
-34
lines changed

.travis.yml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,38 @@ before_script:
2424
script:
2525
- set -e
2626
- |
27-
# get ourselves a MIR-ful libstd
28-
xargo/build.sh
29-
- |
30-
# Test plain miri
27+
# Test and install plain miri
3128
cargo build --release --all-features &&
3229
RUST_BACKTRACE=1 cargo test --release --all-features --all &&
3330
cargo install --all-features --force
31+
- |
32+
# test that the rustc_tests binary compiles
33+
cd rustc_tests &&
34+
cargo build --release &&
35+
cd ..
36+
- |
37+
# get ourselves a MIR-full libstd
38+
xargo/build.sh &&
39+
export MIRI_SYSROOT=~/.xargo/HOST
3440
- |
3541
# Test `cargo miri`
3642
cd cargo-miri-test &&
3743
if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
38-
MIRI_SYSROOT=~/.xargo/HOST cargo miri -q -- -Zmiri-start-fn
44+
cargo miri -q -- -Zmiri-start-fn
3945
else
40-
MIRI_SYSROOT=~/.xargo/HOST cargo miri -q -- -Zmiri-start-fn >stdout.real 2>stderr.real &&
46+
cargo miri -q -- -Zmiri-start-fn >stdout.real 2>stderr.real &&
4147
cat stdout.real stderr.real &&
4248
# Test `cargo miri` output. Not on mac because output redirecting doesn't
4349
# work. There is no error. It just stops CI.
4450
diff -u stdout.ref stdout.real &&
4551
diff -u stderr.ref stderr.real
4652
fi &&
4753
# Test `cargo miri test`
48-
#cargo miri test &&
54+
cargo miri test &&
4955
cd ..
5056
- |
5157
# and run all tests with full mir
52-
MIRI_SYSROOT=~/.xargo/HOST cargo test --release
53-
- |
54-
# test that the rustc_tests binary compiles
55-
cd rustc_tests &&
56-
cargo build --release &&
57-
cd ..
58+
cargo test --release
5859
notifications:
5960
email:
6061
on_success: never

README.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,33 @@ undergraduate research course at the [University of Saskatchewan][usask].
77

88
## Building Miri
99

10-
I recommend that you install [rustup][rustup] to obtain Rust. miri comes with a
10+
I recommend that you install [rustup][rustup] to obtain Rust. Miri comes with a
1111
`rust-toolchain` file so rustup will automatically pick a suitable nightly
1212
version. Then all you have to do is:
1313

1414
```sh
1515
cargo build
1616
```
1717

18-
## Running tests
18+
## Running Miri
1919

2020
```sh
2121
cargo run tests/run-pass/vecs.rs # Or whatever test you like.
2222
```
2323

24-
## Running miri on your own project('s test suite)
25-
26-
Install miri as a cargo subcommand with `cargo install --debug`.
27-
Then, inside your own project, use `cargo +nightly miri` to run your project, if it is
28-
a bin project, or run `cargo +nightly miri test` to run all tests in your project
29-
through miri.
30-
31-
## Running miri with full libstd
24+
## Running Miri with full libstd
3225

3326
Per default libstd does not contain the MIR of non-polymorphic functions. When
34-
miri hits a call to such a function, execution terminates. To fix this, it is
27+
Miri hits a call to such a function, execution terminates. To fix this, it is
3528
possible to compile libstd with full MIR:
3629

3730
```sh
3831
rustup component add rust-src
3932
cargo install xargo
40-
cd xargo/
41-
RUSTFLAGS='-Zalways-encode-mir' xargo build
33+
xargo/build.sh
4234
```
4335

44-
Now you can run miri against the libstd compiled by xargo:
36+
Now you can run Miri against the libstd compiled by xargo:
4537

4638
```sh
4739
MIRI_SYSROOT=~/.xargo/HOST cargo run tests/run-pass-fullmir/hashmap.rs
@@ -50,13 +42,23 @@ MIRI_SYSROOT=~/.xargo/HOST cargo run tests/run-pass-fullmir/hashmap.rs
5042
Notice that you will have to re-run the last step of the preparations above when
5143
your toolchain changes (e.g., when you update the nightly).
5244

53-
You can also set `-Zmiri-start-fn` to make miri start evaluation with the
45+
You can also set `-Zmiri-start-fn` to make Miri start evaluation with the
5446
`start_fn` lang item, instead of starting at the `main` function.
5547

48+
## Running Miri on your own project('s test suite)
49+
50+
Install Miri as a cargo subcommand with `cargo install --all-features`, and install
51+
a full libstd as described above.
52+
53+
Then, inside your own project, use `MIRI_SYSROOT=~/.xargo/HOST cargo +nightly
54+
miri` to run your project, if it is a bin project, or run
55+
`MIRI_SYSROOT=~/.xargo/HOST cargo +nightly miri test` to run all tests in your
56+
project through Miri.
57+
5658
## Development and Debugging
5759

58-
Since the heart of miri (the main interpreter engine) lives in rustc, working on
59-
miri will often require using a locally built rustc. This includes getting a
60+
Since the heart of Miri (the main interpreter engine) lives in rustc, working on
61+
Miri will often require using a locally built rustc. This includes getting a
6062
trace of the execution, as distributed rustc has `trace!` disabled.
6163

6264
The first-time setup for a local rustc looks as follows:
@@ -68,12 +70,12 @@ cp config.toml.example config.toml
6870
./x.py build src/rustc
6971
# You may have to change the architecture in the next command
7072
rustup toolchain link custom build/x86_64-unknown-linux-gnu/stage2
71-
# Now cd to your miri directory
73+
# Now cd to your Miri directory
7274
rustup override set custom
7375
```
7476
The `build` step can take 30 minutes and more.
7577

76-
Now you can `cargo build` miri, and you can `cargo test --tests`. (`--tests`
78+
Now you can `cargo build` Miri, and you can `cargo test --tests`. (`--tests`
7779
is needed to skip doctests because we have not built rustdoc for your custom
7880
toolchain.) You can also set `RUST_LOG=rustc_mir::interpret=trace` as
7981
environment variable to get a step-by-step trace.

xargo/Xargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
[dependencies]
2-
std = {features = ["panic_unwind", "jemalloc", "backtrace"]}
1+
[dependencies.std]
2+
features = ["panic_unwind", "jemalloc", "backtrace"]
3+
4+
[dependencies.test]
5+
stage = 1

0 commit comments

Comments
 (0)