Skip to content

Commit a2c72ce

Browse files
committed
Auto merge of rust-lang#123506 - RalfJung:miri-test-libstd, r=Mark-Simulacrum
check-aux: test core, alloc, std in Miri Let's see if this works, and how long it takes.
2 parents f65f84f + 596908b commit a2c72ce

File tree

10 files changed

+68
-12
lines changed

10 files changed

+68
-12
lines changed

library/alloc/benches/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// Disabling on android for the time being
22
// See https://github.com/rust-lang/rust/issues/73535#event-3477699747
33
#![cfg(not(target_os = "android"))]
4+
// Disabling in Miri as these would take too long.
5+
#![cfg(not(miri))]
46
#![feature(btree_extract_if)]
57
#![feature(iter_next_chunk)]
68
#![feature(repr_simd)]

library/alloc/src/sync.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,9 @@ impl<T, A: Allocator> Arc<T, A> {
10621062
///
10631063
/// // Create a long list and clone it
10641064
/// let mut x = LinkedList::new();
1065-
/// for i in 0..100000 {
1065+
/// let size = 100000;
1066+
/// # let size = if cfg!(miri) { 100 } else { size };
1067+
/// for i in 0..size {
10661068
/// x.push(i); // Adds i to the front of x
10671069
/// }
10681070
/// let y = x.clone();

library/core/benches/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// wasm32 does not support benches (no time).
22
#![cfg(not(target_arch = "wasm32"))]
3+
// Disabling in Miri as these would take too long.
4+
#![cfg(not(miri))]
35
#![feature(flt2dec)]
46
#![feature(test)]
57
#![feature(trusted_random_access)]

library/std/benches/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Disabling in Miri as these would take too long.
2+
#![cfg(not(miri))]
13
#![feature(test)]
24

35
extern crate test;

library/std/tests/process_spawning.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::str;
88
mod common;
99

1010
#[test]
11+
#[cfg_attr(miri, ignore)] // Process spawning not supported by Miri
1112
fn issue_15149() {
1213
// If we're the parent, copy our own binary to a new directory.
1314
let my_path = env::current_exe().unwrap();

library/std/tests/switch-stdout.rs

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ fn switch_stdout_to(file: OwnedHandle) -> OwnedHandle {
5151
}
5252

5353
#[test]
54+
#[cfg_attr(miri, ignore)] // dup/SetStdHandle not supported by Miri
5455
fn switch_stdout() {
5556
let temp = common::tmpdir();
5657
let path = temp.join("switch-stdout-output");

library/std/tests/thread.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use std::time::Duration;
55

66
#[test]
77
#[cfg_attr(target_os = "emscripten", ignore)]
8-
fn sleep() {
8+
#[cfg_attr(miri, ignore)] // Miri does not like the thread leak
9+
fn sleep_very_long() {
910
let finished = Arc::new(Mutex::new(false));
1011
let t_finished = finished.clone();
1112
thread::spawn(move || {

src/bootstrap/mk/Makefile.in

+30
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,36 @@ check-aux:
5252
src/tools/cargo \
5353
src/tools/cargotest \
5454
$(BOOTSTRAP_ARGS)
55+
# Run standard library tests in Miri.
56+
# We use a 64bit little-endian and a 32bit big-endian target for max coverage.
57+
$(Q)BOOTSTRAP_SKIP_TARGET_SANITY=1 \
58+
$(BOOTSTRAP) miri --stage 2 \
59+
--target x86_64-unknown-linux-gnu,mips-unknown-linux-gnu \
60+
library/core \
61+
library/alloc \
62+
--no-doc
63+
# Some doctests have intentional memory leaks.
64+
# Also, they work only on the host.
65+
$(Q)MIRIFLAGS="-Zmiri-ignore-leaks -Zmiri-disable-isolation" \
66+
$(BOOTSTRAP) miri --stage 2 \
67+
library/core \
68+
library/alloc \
69+
--doc
70+
# In `std` we cannot test everything.
71+
$(Q)MIRIFLAGS="-Zmiri-disable-isolation" BOOTSTRAP_SKIP_TARGET_SANITY=1 \
72+
$(BOOTSTRAP) miri --stage 2 library/std \
73+
--no-doc -- \
74+
--skip fs:: --skip net:: --skip process:: --skip sys::pal::
75+
$(Q)MIRIFLAGS="-Zmiri-ignore-leaks -Zmiri-disable-isolation" BOOTSTRAP_SKIP_TARGET_SANITY=1 \
76+
$(BOOTSTRAP) miri --stage 2 library/std \
77+
--doc -- \
78+
--skip fs:: --skip net:: --skip process:: --skip sys::pal::
79+
# Also test some very target-specific modules on other targets.
80+
$(Q)MIRIFLAGS="-Zmiri-disable-isolation" BOOTSTRAP_SKIP_TARGET_SANITY=1 \
81+
$(BOOTSTRAP) miri --stage 2 library/std \
82+
--target aarch64-apple-darwin,i686-pc-windows-gnu \
83+
--no-doc -- \
84+
time:: sync:: thread:: env::
5585
dist:
5686
$(Q)$(BOOTSTRAP) dist $(BOOTSTRAP_ARGS)
5787
distcheck:

src/bootstrap/src/core/build_steps/test.rs

+21-10
Original file line numberDiff line numberDiff line change
@@ -2689,16 +2689,27 @@ impl Step for Crate {
26892689

26902690
match mode {
26912691
Mode::Std => {
2692-
compile::std_cargo(builder, target, compiler.stage, &mut cargo);
2693-
// `std_cargo` actually does the wrong thing: it passes `--sysroot build/host/stage2`,
2694-
// but we want to use the force-recompile std we just built in `build/host/stage2-test-sysroot`.
2695-
// Override it.
2696-
if builder.download_rustc() && compiler.stage > 0 {
2697-
let sysroot = builder
2698-
.out
2699-
.join(compiler.host.triple)
2700-
.join(format!("stage{}-test-sysroot", compiler.stage));
2701-
cargo.env("RUSTC_SYSROOT", sysroot);
2692+
if builder.kind == Kind::Miri {
2693+
// We can't use `std_cargo` as that uses `optimized-compiler-builtins` which
2694+
// needs host tools for the given target. This is similar to what `compile::Std`
2695+
// does when `is_for_mir_opt_tests` is true. There's probably a chance for
2696+
// de-duplication here... `std_cargo` should support a mode that avoids needing
2697+
// host tools.
2698+
cargo
2699+
.arg("--manifest-path")
2700+
.arg(builder.src.join("library/sysroot/Cargo.toml"));
2701+
} else {
2702+
compile::std_cargo(builder, target, compiler.stage, &mut cargo);
2703+
// `std_cargo` actually does the wrong thing: it passes `--sysroot build/host/stage2`,
2704+
// but we want to use the force-recompile std we just built in `build/host/stage2-test-sysroot`.
2705+
// Override it.
2706+
if builder.download_rustc() && compiler.stage > 0 {
2707+
let sysroot = builder
2708+
.out
2709+
.join(compiler.host.triple)
2710+
.join(format!("stage{}-test-sysroot", compiler.stage));
2711+
cargo.env("RUSTC_SYSROOT", sysroot);
2712+
}
27022713
}
27032714
}
27042715
Mode::Rustc => {

src/ci/docker/host-x86_64/x86_64-gnu-aux/Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
2525
COPY scripts/sccache.sh /scripts/
2626
RUN sh /scripts/sccache.sh
2727

28+
# Miri is just too slow with full assertions
29+
ENV NO_DEBUG_ASSERTIONS=1
30+
ENV NO_OVERFLOW_CHECKS=1
31+
2832
ENV RUST_CONFIGURE_ARGS --build=x86_64-unknown-linux-gnu
2933
ENV RUST_CHECK_TARGET check-aux

0 commit comments

Comments
 (0)