Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better support for running libcore tests with Miri #87255

Merged
merged 1 commit into from
Jul 23, 2021

Conversation

RalfJung
Copy link
Member

See rust-lang/miri-test-libstd#4 for a description of the problem that this fixes.
Thanks to @hyd-dev for suggesting this patch!

@rust-highfive
Copy link
Collaborator

r? @Mark-Simulacrum

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 18, 2021
@ghost
Copy link

ghost commented Jul 18, 2021

liballoc also defines some lang and diagnostic items. It might need the same #![cfg] (plus test).

@RalfJung
Copy link
Member Author

liballoc doesn't have the #![cfg(not(test))] though, so maybe there's something that makes it less of an issue there?

library/core/src/lib.rs Outdated Show resolved Hide resolved
@ghost
Copy link

ghost commented Jul 18, 2021

liballoc doesn't have the #![cfg(not(test))] though, so maybe there's something that makes it less of an issue there?

I found that many lang and diagnostic items in liballoc are #[cfg(not(test))] at module/item-level or in #[cfg_attr(not(test), ...)].

@RalfJung
Copy link
Member Author

I found that many lang and diagnostic items in liballoc are #[cfg(not(test))] at module/item-level or in #[cfg_attr(not(test), ...)].

Ah yes. The #! approach does not work there as that would disable unit tests (which liballoc has but libcore does not).

@ghost
Copy link

ghost commented Jul 18, 2021

I can indeed reproduce the issue in liballoc with this diff:

diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs
index e8bd4bcb..3634756a 100644
--- a/library/alloc/src/lib.rs
+++ b/library/alloc/src/lib.rs
@@ -55,6 +55,9 @@
 //! [`Cell`]: core::cell
 //! [`Rc`]: rc
 //! [`RefCell`]: core::cell
+//! ```
+//! match x {}
+//! ```
 
 #![allow(unused_attributes)]
 #![stable(feature = "alloc", since = "1.36.0")]
Output
failures:

---- ../liballoc/src/lib.rs - (line 58) stdout ----
error[E0425]: cannot find value `x` in this scope
 --> ../liballoc/src/lib.rs:59:7
  |
4 | match x {}
  |       ^ not found in this scope

error: duplicate lang item in crate `alloc_miri_test`: `str_alloc`.
  |
  = note: the lang item is first defined in crate `alloc` (which `std` depends on)
  = note: first definition in `alloc` loaded from /home/hyd-dev/.cache/miri/HOST/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-fd991b19f11a4e51.rmeta
  = note: second definition in `alloc_miri_test` loaded from /somewhere/miri-test-libstd/target/miri/x86_64-unknown-linux-gnu/debug/deps/liballoc_miri_test-b48d33359c7e89e2.rmeta

error: duplicate lang item in crate `alloc_miri_test`: `slice_alloc`.
  |
  = note: the lang item is first defined in crate `alloc` (which `std` depends on)
  = note: first definition in `alloc` loaded from /home/hyd-dev/.cache/miri/HOST/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-fd991b19f11a4e51.rmeta
  = note: second definition in `alloc_miri_test` loaded from /somewhere/miri-test-libstd/target/miri/x86_64-unknown-linux-gnu/debug/deps/liballoc_miri_test-b48d33359c7e89e2.rmeta

error: duplicate lang item in crate `alloc_miri_test`: `slice_u8_alloc`.
  |
  = note: the lang item is first defined in crate `alloc` (which `std` depends on)
  = note: first definition in `alloc` loaded from /home/hyd-dev/.cache/miri/HOST/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-fd991b19f11a4e51.rmeta
  = note: second definition in `alloc_miri_test` loaded from /somewhere/miri-test-libstd/target/miri/x86_64-unknown-linux-gnu/debug/deps/liballoc_miri_test-b48d33359c7e89e2.rmeta

error: duplicate lang item in crate `alloc_miri_test`: `exchange_malloc`.
  |
  = note: the lang item is first defined in crate `alloc` (which `std` depends on)
  = note: first definition in `alloc` loaded from /home/hyd-dev/.cache/miri/HOST/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-fd991b19f11a4e51.rmeta
  = note: second definition in `alloc_miri_test` loaded from /somewhere/miri-test-libstd/target/miri/x86_64-unknown-linux-gnu/debug/deps/liballoc_miri_test-b48d33359c7e89e2.rmeta

error: duplicate lang item in crate `alloc_miri_test`: `box_free`.
  |
  = note: the lang item is first defined in crate `alloc` (which `std` depends on)
  = note: first definition in `alloc` loaded from /home/hyd-dev/.cache/miri/HOST/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-fd991b19f11a4e51.rmeta
  = note: second definition in `alloc_miri_test` loaded from /somewhere/miri-test-libstd/target/miri/x86_64-unknown-linux-gnu/debug/deps/liballoc_miri_test-b48d33359c7e89e2.rmeta

error: duplicate lang item in crate `alloc_miri_test`: `owned_box`.
  |
  = note: the lang item is first defined in crate `alloc` (which `std` depends on)
  = note: first definition in `alloc` loaded from /home/hyd-dev/.cache/miri/HOST/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-fd991b19f11a4e51.rmeta
  = note: second definition in `alloc_miri_test` loaded from /somewhere/miri-test-libstd/target/miri/x86_64-unknown-linux-gnu/debug/deps/liballoc_miri_test-b48d33359c7e89e2.rmeta

error: aborting due to 7 previous errors

For more information about this error, try `rustc --explain E0425`.
Couldn't compile the test.

failures:
    ../liballoc/src/lib.rs - (line 58)

test result: FAILED. 581 passed; 1 failed; 1 ignored; 0 measured; 0 filtered out; finished in 60.56s

error: test failed, to rerun pass '--doc'

@RalfJung
Copy link
Member Author

RalfJung commented Jul 18, 2021

Does adding

#![cfg(any(not(feature = "miri-test"), test, doctest))]

in liballoc help? (I think this needs the test, otherwise there'll be no unit tests.)

@ghost
Copy link

ghost commented Jul 18, 2021

Yes, that helps, and I confirmed that unit tests are still run.

Doctest output
failures:

---- ../liballoc/src/lib.rs - (line 58) stdout ----
error[E0425]: cannot find value `x` in this scope
 --> ../liballoc/src/lib.rs:59:7
  |
4 | match x {}
  |       ^ not found in this scope

error: aborting due to previous error

For more information about this error, try `rustc --explain E0425`.
Couldn't compile the test.

failures:
    ../liballoc/src/lib.rs - (line 58)

test result: FAILED. 581 passed; 1 failed; 1 ignored; 0 measured; 0 filtered out; finished in 70.29s

error: test failed, to rerun pass '--doc'
Partial unit test output
## Testing alloc (symbolic alignment)

0.172678   A libstd for Miri is now available in `/home/hyd-dev/.cache/miri/HOST`.
0.237599      Compiling libc v0.2.98
0.000211      Compiling getrandom v0.1.16
0.000120      Compiling cfg-if v1.0.0
0.000112      Compiling ppv-lite86 v0.2.10
0.090269      Compiling alloc_miri_test v0.0.0 (/somewhere/Code/rust-lang/miri-test-libstd/alloc_miri_test)
2.198054      Compiling rand_core v0.5.1
0.217777      Compiling rand_chacha v0.2.2
0.000221      Compiling rand_xorshift v0.2.0
0.213803      Compiling rand v0.7.3
1.308381       Finished test [unoptimized + debuginfo] target(s) in 4.20s
0.001043        Running unittests (/somewhere/miri-test-libstd/target/miri/x86_64-unknown-linux-gnu/debug/deps/alloc_miri_test-6eee054372adb77e)
11.202184   
0.000072   running 254 tests
0.945389   test alloc::tests::alloc_owned_small ... ignored
0.280983   test alloc::tests::allocate_zeroed ... ok
0.200594   test collections::btree::borrow::tests::test_borrow ... ok
1.001750   test collections::btree::map::tests::test_append_12 ... ok
0.928070   test collections::btree::map::tests::test_append_14 ... ok

@RalfJung
Copy link
Member Author

Great, thanks for checking! I updated the PR.

@Mark-Simulacrum
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jul 23, 2021

📌 Commit 6cba798 has been approved by Mark-Simulacrum

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 23, 2021
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 23, 2021
Rollup of 14 pull requests

Successful merges:

 - rust-lang#86410 (VecMap::get_value_matching should return just one element)
 - rust-lang#86790 (Document iteration order of `retain` functions)
 - rust-lang#87171 (Remove Option from BufWriter)
 - rust-lang#87175 (Stabilize `into_parts()` and `into_error()`)
 - rust-lang#87185 (Fix panics on Windows when the build was cancelled)
 - rust-lang#87191 (Package LLVM libs for the target rather than the build host)
 - rust-lang#87255 (better support for running libcore tests with Miri)
 - rust-lang#87266 (Add testcase for 87076)
 - rust-lang#87283 (Add `--codegen-backends=foo,bar` configure flag)
 - rust-lang#87322 (fix: clarify suggestion that `&T` must refer to `T: Sync` for `&T: Send`)
 - rust-lang#87358 (Fix `--dry-run` when download-ci-llvm is set)
 - rust-lang#87380 (Don't default to `submodules = true` unless the rust repo has a .git directory)
 - rust-lang#87398 (Add test for fonts used for module items)
 - rust-lang#87412 (Add missing article)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 1a2b90b into rust-lang:master Jul 23, 2021
@rustbot rustbot added this to the 1.55.0 milestone Jul 23, 2021
@RalfJung RalfJung deleted the miri-test-libcore branch July 24, 2021 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants