From c25207d8690a14c8d61aa215cd502d8ad581a0ea Mon Sep 17 00:00:00 2001 From: Jieyou Xu Date: Fri, 4 Apr 2025 10:46:13 +0800 Subject: [PATCH 1/3] bootstrap: only build `rust_test_helpers` for `{incremental,ui}` suites --- src/bootstrap/src/core/build_steps/test.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index 81f6b473c4593..8e42e845a8cb2 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -1624,9 +1624,6 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the builder.tool_exe(Tool::RunMakeSupport); } - // Also provide `rust_test_helpers` for the host. - builder.ensure(TestHelpers { target: compiler.host }); - // ensure that `libproc_macro` is available on the host. if suite == "mir-opt" { builder.ensure(compile::Std::new(compiler, compiler.host).is_for_mir_opt_tests(true)); @@ -1634,11 +1631,6 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the builder.ensure(compile::Std::new(compiler, compiler.host)); } - // As well as the target - if suite != "mir-opt" { - builder.ensure(TestHelpers { target }); - } - let mut cmd = builder.tool_cmd(Tool::Compiletest); if suite == "mir-opt" { @@ -1804,11 +1796,18 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the } let mut hostflags = flags.clone(); - hostflags.push(format!("-Lnative={}", builder.test_helpers_out(compiler.host).display())); hostflags.extend(linker_flags(builder, compiler.host, LldThreads::No, compiler.stage)); let mut targetflags = flags; - targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display())); + + // Provide `rust_test_helpers` for both host and target. + if suite == "ui" || suite == "incremental" { + builder.ensure(TestHelpers { target: compiler.host }); + builder.ensure(TestHelpers { target }); + hostflags + .push(format!("-Lnative={}", builder.test_helpers_out(compiler.host).display())); + targetflags.push(format!("-Lnative={}", builder.test_helpers_out(target).display())); + } for flag in hostflags { cmd.arg("--host-rustcflags").arg(flag); From 3af666ea915aa0a125f5d473e30b20600ca90f08 Mon Sep 17 00:00:00 2001 From: Thalia Archibald Date: Sat, 29 Mar 2025 15:23:58 -0700 Subject: [PATCH 2/3] tidy: Fix paths to coretests and alloctests Following `#135937` and `#136642`, tests for core and alloc are in coretests and alloctests. Fix tidy to lint for the new paths. Also, update comments referring to the old locations. Some context for changes which don't match that pattern: * library/std/src/thread/local/dynamic_tests.rs and library/std/src/sync/mpsc/sync_tests.rs were moved under library/std/tests/ in 332fb7e6f1d (Move std::thread_local unit tests to integration tests, 2025-01-17) and b8ae372e483 (Move std::sync unit tests to integration tests, 2025-01-17), respectively, so are no longer special cases. * There never was a library/core/tests/fmt.rs file. That comment previously referred to src/test/ui/ifmt.rs, which was folded into library/alloc/tests/fmt.rs in 949c96660c3 (move format! interface tests, 2020-09-08). --- library/core/src/fmt/mod.rs | 4 +-- library/coretests/tests/str.rs | 2 +- src/tools/tidy/src/unit_tests.rs | 51 ++++++++++++++++++++------------ 3 files changed, 35 insertions(+), 22 deletions(-) diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index 30fd2d7815f51..f1a9cec318fde 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -3016,6 +3016,6 @@ impl Debug for SyncUnsafeCell { } } -// If you expected tests to be here, look instead at the core/tests/fmt.rs file, +// If you expected tests to be here, look instead at coretests/tests/fmt/; // it's a lot easier than creating all of the rt::Piece structures here. -// There are also tests in the alloc crate, for those that need allocations. +// There are also tests in alloctests/tests/fmt.rs, for those that need allocations. diff --git a/library/coretests/tests/str.rs b/library/coretests/tests/str.rs index f5066343af20a..5e23e910f0aeb 100644 --- a/library/coretests/tests/str.rs +++ b/library/coretests/tests/str.rs @@ -1 +1 @@ -// All `str` tests live in library/alloc/tests/str.rs +// All `str` tests live in library/alloctests/tests/str.rs diff --git a/src/tools/tidy/src/unit_tests.rs b/src/tools/tidy/src/unit_tests.rs index 708e4ef808571..90ef36d5882da 100644 --- a/src/tools/tidy/src/unit_tests.rs +++ b/src/tools/tidy/src/unit_tests.rs @@ -1,11 +1,13 @@ -//! Tidy check to ensure `#[test]` and `#[bench]` are not used directly inside `core`. +//! Tidy check to ensure `#[test]` and `#[bench]` are not used directly inside +//! `core` or `alloc`. //! -//! `#![no_core]` libraries cannot be tested directly due to duplicating lang -//! items. All tests and benchmarks must be written externally in `core/{tests,benches}`. +//! `core` and `alloc` cannot be tested directly due to duplicating lang items. +//! All tests and benchmarks must be written externally in +//! `{coretests,alloctests}/{tests,benches}`. //! -//! Outside of core tests and benchmarks should be outlined into separate files -//! named `tests.rs` or `benches.rs`, or directories named `tests` or `benches` unconfigured -//! during normal build. +//! Outside of `core` and `alloc`, tests and benchmarks should be outlined into +//! separate files named `tests.rs` or `benches.rs`, or directories named +//! `tests` or `benches` unconfigured during normal build. use std::path::Path; @@ -14,40 +16,51 @@ use crate::walk::{filter_dirs, walk}; pub fn check(root_path: &Path, bad: &mut bool) { let core = root_path.join("core"); let core_copy = core.clone(); - let core_tests = core.join("tests"); - let core_benches = core.join("benches"); - let is_core = move |path: &Path| { - path.starts_with(&core) - && !(path.starts_with(&core_tests) || path.starts_with(&core_benches)) - }; + let is_core = move |path: &Path| path.starts_with(&core); + let alloc = root_path.join("alloc"); + let alloc_copy = alloc.clone(); + let is_alloc = move |path: &Path| path.starts_with(&alloc); let skip = move |path: &Path, is_dir| { let file_name = path.file_name().unwrap_or_default(); if is_dir { filter_dirs(path) || path.ends_with("src/doc") - || (file_name == "tests" || file_name == "benches") && !is_core(path) + || (file_name == "tests" || file_name == "benches") + && !is_core(path) + && !is_alloc(path) } else { let extension = path.extension().unwrap_or_default(); extension != "rs" - || (file_name == "tests.rs" || file_name == "benches.rs") && !is_core(path) - // UI tests with different names - || path.ends_with("src/thread/local/dynamic_tests.rs") - || path.ends_with("src/sync/mpsc/sync_tests.rs") + || (file_name == "tests.rs" || file_name == "benches.rs") + && !is_core(path) + && !is_alloc(path) + // Tests which use non-public internals and, as such, need to + // have the types in the same crate as the tests themselves. See + // the comment in alloctests/lib.rs. + || path.ends_with("library/alloc/src/collections/btree/borrow/tests.rs") + || path.ends_with("library/alloc/src/collections/btree/map/tests.rs") + || path.ends_with("library/alloc/src/collections/btree/node/tests.rs") + || path.ends_with("library/alloc/src/collections/btree/set/tests.rs") + || path.ends_with("library/alloc/src/collections/linked_list/tests.rs") + || path.ends_with("library/alloc/src/collections/vec_deque/tests.rs") + || path.ends_with("library/alloc/src/raw_vec/tests.rs") } }; walk(root_path, skip, &mut |entry, contents| { let path = entry.path(); let is_core = path.starts_with(&core_copy); + let is_alloc = path.starts_with(&alloc_copy); for (i, line) in contents.lines().enumerate() { let line = line.trim(); let is_test = || line.contains("#[test]") && !line.contains("`#[test]"); let is_bench = || line.contains("#[bench]") && !line.contains("`#[bench]"); if !line.starts_with("//") && (is_test() || is_bench()) { let explanation = if is_core { - "core unit tests and benchmarks must be placed into \ - `core/tests` or `core/benches`" + "`core` unit tests and benchmarks must be placed into `coretests`" + } else if is_alloc { + "`alloc` unit tests and benchmarks must be placed into `alloctests`" } else { "unit tests and benchmarks must be placed into \ separate files or directories named \ From f6afb35c6170ad3cadc6e6d7d41dc4dc3bd46556 Mon Sep 17 00:00:00 2001 From: Zalathar Date: Sun, 6 Apr 2025 12:33:22 +1000 Subject: [PATCH 3/3] Prevent a test from seeing forbidden numbers in the rustc version The final CHECK-NOT directive in this test was able to see past the end of the enclosing function, and find the substring 753 or 754 in the git hash in the rustc version number, causing false failures in CI. Adding an explicit check for `ret` prevents the CHECK-NOT directive from seeing past the end of the function. --- tests/codegen/issues/issue-122600-ptr-discriminant-update.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/codegen/issues/issue-122600-ptr-discriminant-update.rs b/tests/codegen/issues/issue-122600-ptr-discriminant-update.rs index fbea4ee8979fb..74bc824dbfefc 100644 --- a/tests/codegen/issues/issue-122600-ptr-discriminant-update.rs +++ b/tests/codegen/issues/issue-122600-ptr-discriminant-update.rs @@ -37,6 +37,8 @@ pub unsafe fn update(s: *mut State) { // CHECK-NOT: store // CHECK-NOT: memcpy // CHECK-NOT: 75{{3|4}} + + // CHECK: ret let State::A(v) = s.read() else { std::hint::unreachable_unchecked() }; s.write(State::B(v)); }