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

Put the core unit tests in a separate coretests package #135937

Merged
merged 4 commits into from
Jan 27, 2025

Conversation

bjorn3
Copy link
Member

@bjorn3 bjorn3 commented Jan 23, 2025

Having standard library tests in the same package as a standard library crate has bad side effects. It causes the test to have a dependency on a locally built standard library crate, while also indirectly depending on it through libtest. Currently this works out fine in the context of rust's build system as both copies are identical, but for example in cg_clif's tests I've found it basically impossible to compile both copies with the exact same compiler flags and thus the two copies would cause lang item conflicts.

This PR moves the tests of libcore to a separate package which doesn't depend on libcore, thus preventing the duplicate crates even when compiler flags don't exactly match between building the sysroot (for libtest) and building the test itself. The rest of the standard library crates do still have this issue however.

@rustbot
Copy link
Collaborator

rustbot commented Jan 23, 2025

r? @cjgillot

rustbot has assigned @cjgillot.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 23, 2025
@jieyouxu jieyouxu self-assigned this Jan 23, 2025
@jieyouxu
Copy link
Member

There's a libcore comment that should be updated:

// Since core defines many fundamental lang items, all tests live in a
// separate crate, libcoretest (library/core/tests), to avoid bizarre issues.

@rustbot
Copy link
Collaborator

rustbot commented Jan 23, 2025

These commits modify the library/Cargo.lock file. Unintentional changes to library/Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

@@ -45,7 +45,7 @@ impl Step for Std {
const DEFAULT: bool = true;

fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
run.crate_or_deps("sysroot").path("library")
run.crate_or_deps("sysroot").crate_or_deps("coretests").path("library")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @onur-ozkan: do you know if this invocation (and the one in test) is correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems right to me

@jieyouxu
Copy link
Member

FYI @rust-lang/libs since this is restructuring libcore tests

@jieyouxu
Copy link
Member

I'll do some more local testing tmrw.

@rust-log-analyzer

This comment has been minimized.

@jieyouxu
Copy link
Member

libs-nominating for awareness.
@rustbot label: +I-libs-nominated

@rustbot rustbot added the I-libs-nominated Nominated for discussion during a libs team meeting. label Jan 24, 2025
Copy link
Member

@jieyouxu jieyouxu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this, I believe this is definitely an improvement over the current setup. I did some local manual testing, and here are my findings:

With profile = "library"1:

  • Basic library/coretests test: ./x test library/coretests... OK
  • Basic library/coretests test (unmodified re-run): ./x test library/coretests... RERUNS TESTS
    • Is it expected to re-run all coretests tests even though nothing changed?
  • Alias: ./x test coretests... OK
  • Alias (unmodified re-run): ./x test coretests ... RERUNS TESTS
  • Basic test: ./x test core... OK2
  • Basic test (unmodified re-run): ./x test core... RERUNS TESTS
    • Is it expected to re-run all core tests even though nothing changed?

The test reruns here are not very problematic because they are very fast to run (at least on my
machine).

Unrelated sanity checks:

  • Basic doc: ./x doc core... OK
  • Basic build: ./x build library/core... OK
  • Basic build (unmodified re-run): ./x build library/core... OK

The bootstrap changes look good to me (even with the test re-run because they are really fast anyway) and @onur-ozkan, but I'll hand this PR off to a libs reviewer for final sign-off (to really make sure libs contributors are aware of the change).

Footnotes

  1. No modified coretests/core flows were tested because they already rerun anyway.

  2. This is also weird because ./x build core is not recognized as a registered step, but ./x test core tests stuff.

@jieyouxu
Copy link
Member

jieyouxu commented Jan 24, 2025

Note that unfortunately this also has a merge conflict against latest master because a bstr test was changed.

@bors rollup=never p=10 (conflict-prone, and also non-trivial coretests movement)

@jieyouxu
Copy link
Member

r? libs (for final sign-off)

@rustbot rustbot assigned tgross35 and unassigned cjgillot and jieyouxu Jan 24, 2025
@jieyouxu jieyouxu closed this Jan 24, 2025
@jieyouxu jieyouxu reopened this Jan 24, 2025
Copy link
Contributor

@tgross35 tgross35 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything looks correct to me from a technical perspective, but this definitely needs an ack from a few team members (was there a discussion on Zulip?)

@jieyouxu
Copy link
Member

jieyouxu commented Jan 24, 2025

Everything looks correct to me from a technical perspective, but this definitely needs an ack from a few team members (was there a discussion on Zulip?)

Opened a T-libs zulip thread: https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/topic/Moving.20libcore.20unit.20tests.20into.20dedicated.20.60coretests.60.20package.

Marking PR as waiting on T-libs consensus.

@jieyouxu jieyouxu added S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 24, 2025
@jieyouxu
Copy link
Member

There seems to be some consensus, so @rustbot review

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (633a3fe): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results (primary -2.4%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.4% [-3.6%, -1.3%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.4% [-3.6%, -1.3%] 2

Cycles

Results (primary 0.3%, secondary -1.2%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.7% [2.7%, 2.7%] 1
Regressions ❌
(secondary)
2.0% [2.0%, 2.0%] 1
Improvements ✅
(primary)
-2.0% [-2.0%, -2.0%] 1
Improvements ✅
(secondary)
-1.8% [-2.1%, -1.6%] 5
All ❌✅ (primary) 0.3% [-2.0%, 2.7%] 2

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 772.928s -> 773.067s (0.02%)
Artifact size: 328.22 MiB -> 328.21 MiB (-0.00%)

@bjorn3 bjorn3 deleted the separate_coretests_crate branch February 1, 2025 16:39
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Feb 14, 2025
…=cuviper

Put the alloc unit tests in a separate alloctests package

Same rationale as rust-lang#135937. This PR has some extra complexity though as a decent amount of tests are testing internal implementation details rather than the public api. As such I opted to include the modules containing the types under test using `#[path]` into the alloctests package. This means that those modules still need `#[cfg(test)]`, but the rest of liballoc no longer need it.
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 14, 2025
…try>

Put the alloc unit tests in a separate alloctests package

Same rationale as rust-lang#135937. This PR has some extra complexity though as a decent amount of tests are testing internal implementation details rather than the public api. As such I opted to include the modules containing the types under test using `#[path]` into the alloctests package. This means that those modules still need `#[cfg(test)]`, but the rest of liballoc no longer need it.

try-job: x86_64-gnu-aux
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 19, 2025
…try>

Put the alloc unit tests in a separate alloctests package

Same rationale as rust-lang#135937. This PR has some extra complexity though as a decent amount of tests are testing internal implementation details rather than the public api. As such I opted to include the modules containing the types under test using `#[path]` into the alloctests package. This means that those modules still need `#[cfg(test)]`, but the rest of liballoc no longer need it.

try-job: x86_64-gnu-aux
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 21, 2025
…try>

Put the alloc unit tests in a separate alloctests package

Same rationale as rust-lang#135937. This PR has some extra complexity though as a decent amount of tests are testing internal implementation details rather than the public api. As such I opted to include the modules containing the types under test using `#[path]` into the alloctests package. This means that those modules still need `#[cfg(test)]`, but the rest of liballoc no longer need it.

try-job: x86_64-gnu-aux
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Feb 22, 2025
…=cuviper

Put the alloc unit tests in a separate alloctests package

Same rationale as rust-lang#135937. This PR has some extra complexity though as a decent amount of tests are testing internal implementation details rather than the public api. As such I opted to include the modules containing the types under test using `#[path]` into the alloctests package. This means that those modules still need `#[cfg(test)]`, but the rest of liballoc no longer need it.
@RalfJung
Copy link
Member

RalfJung commented Feb 23, 2025

I just spent 15min trying to figure out why ./x miri library/core no longer runs any tests. ./x test library/core has the same issue it turns out, and it's caused by this PR. That's quite the footgun! I feel like such a fundamental change to how we interact with the compiler build should be communicated a bit more broadly. But communication probably is not enough, this PR is a serious regression for the UX of testing library changes and I think that needs to be addressed before the same scheme is applied to more crates.

@bjorn3
Copy link
Member Author

bjorn3 commented Feb 26, 2025

#137679 will fix both ./x.py test library/core and ./x.py miri library/core to test coretests too.

compiler-errors added a commit to compiler-errors/rust that referenced this pull request Mar 7, 2025
…=cuviper

Put the alloc unit tests in a separate alloctests package

Same rationale as rust-lang#135937. This PR has some extra complexity though as a decent amount of tests are testing internal implementation details rather than the public api. As such I opted to include the modules containing the types under test using `#[path]` into the alloctests package. This means that those modules still need `#[cfg(test)]`, but the rest of liballoc no longer need it.
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Mar 7, 2025
…=cuviper

Put the alloc unit tests in a separate alloctests package

Same rationale as rust-lang#135937. This PR has some extra complexity though as a decent amount of tests are testing internal implementation details rather than the public api. As such I opted to include the modules containing the types under test using `#[path]` into the alloctests package. This means that those modules still need `#[cfg(test)]`, but the rest of liballoc no longer need it.
jhpratt added a commit to jhpratt/rust that referenced this pull request Mar 8, 2025
…=cuviper

Put the alloc unit tests in a separate alloctests package

Same rationale as rust-lang#135937. This PR has some extra complexity though as a decent amount of tests are testing internal implementation details rather than the public api. As such I opted to include the modules containing the types under test using `#[path]` into the alloctests package. This means that those modules still need `#[cfg(test)]`, but the rest of liballoc no longer need it.
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 8, 2025
Rollup merge of rust-lang#136642 - bjorn3:separate_alloctest_crate, r=cuviper

Put the alloc unit tests in a separate alloctests package

Same rationale as rust-lang#135937. This PR has some extra complexity though as a decent amount of tests are testing internal implementation details rather than the public api. As such I opted to include the modules containing the types under test using `#[path]` into the alloctests package. This means that those modules still need `#[cfg(test)]`, but the rest of liballoc no longer need it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-testsuite Area: The testsuite used to check the correctness of rustc I-libs-nominated Nominated for discussion during a libs team meeting. merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants