-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Implement #85440 (Random test ordering) #89082
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
Conversation
r? @kennytm (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
r? @ghost |
Converting this to a WIP while I figure out this randomness situation. |
shuffle_seed = match env::var("RUST_TEST_SHUFFLE_SEED") { | ||
Ok(val) => match val.parse::<u64>() { | ||
Ok(n) => Some(n), | ||
Err(_) => panic!("RUST_TEST_SHUFFLE_SEED is `{}`, should be a number.", val), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the panic!
here instead of returning an Error as above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to be consistent with get_concurrency
: https://github.com/rust-lang/rust/blob/0a0688e6f51229d2860af6317adaef378f4b45a5/library/test/src/helpers/concurrency.rs#L9
But I don't have a strong opinion, and I would be happy to change this.
r? @kennytm |
@kennytm I think you can start reviewing this whenever you are ready. |
} | ||
|
||
fn rand_u64(&mut self) -> u64 { | ||
self.state = calculate_hash(&(self.state, self.extra)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use a proper RNG library like fastrand
or oorandom
or rand
there is no proof that state = sip13_hash((state, extra))
is a good RNG.
(and additionally rand_u64() % n
produces biased result)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we use a proper RNG library like
fastrand
oroorandom
orrand
I tried rand
and oorandom
actually. In both cases, I got can't find crate for core
errors.
My impression (based on this, this, and this) is that a crate has to go out of its way to be a dependency of a builtin library. And none of those crates seem to do that. (I could be misunderstanding though.)
Note that oorandom
barely uses core
, but it does use it for Range
(here).
there is no proof that
state = sip13_hash((state, extra))
is a good RNG.(and additionally
rand_u64() % n
produces biased result)
Your points are very well taken. However, I don't think this random number generator needs to be "strong." Put another way, I think the risk of an attacker trying to manipulate the test ordering is low. I am open to counterarguments though.
(Thanks for doing this, BTW.)
@kennytm Since we seem to have reached a pause, I took the opportunity to do some squashing. Please let me know if there is anything I can do to make reviewing this PR easier. |
please also update r=me after that. |
@kennytm I added some documentation. Please let me know if it seems inadequate. Thank you again for all of your trouble. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
basically I just want a link to a tracking issue.
or you could file a different issue for tracking if you like 🙃
src/doc/rustc/src/tests/index.md
Outdated
run the tests in random order sequentially, use `--shuffle --test-threads 1`. | ||
|
||
⚠️ 🚧 This option is [unstable](#unstable-options), and requires the `-Z | ||
unstable-options` flag. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unstable-options` flag. | |
unstable-options` flag. See [tracking issue | |
#85440](https://github.com/rust-lang/rust/issues/85440) for more | |
information. |
src/doc/rustc/src/tests/index.md
Outdated
variable. | ||
|
||
⚠️ 🚧 This option is [unstable](#unstable-options), and requires the `-Z | ||
unstable-options` flag. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unstable-options` flag. | |
unstable-options` flag. See [tracking issue | |
#85440](https://github.com/rust-lang/rust/issues/85440) for more | |
information. |
Might be worth looking at lld's --shuffle-sections for comparison. |
Sorry, I misunderstood how these things work. I opened a new issue so that I can edit it if I have to. Thanks again, @kennytm. |
@bors r+ |
📌 Commit ecf4741 has been approved by |
Implement rust-lang#85440 (Random test ordering) This PR adds `--shuffle` and `--shuffle-seed` options to `libtest`. The options are similar to the [`-shuffle` option](https://github.com/golang/go/blob/c894b442d1e5e150ad33fa3ce13dbfab1c037b3a/src/testing/testing.go#L1482-L1499) that was recently added to Go. Here are the relevant parts of the help message: ``` --shuffle Run tests in random order --shuffle-seed SEED Run tests in random order; seed the random number generator with SEED ... By default, the tests are run in alphabetical order. Use --shuffle or set RUST_TEST_SHUFFLE to run the tests in random order. Pass the generated "shuffle seed" to --shuffle-seed (or set RUST_TEST_SHUFFLE_SEED) to run the tests in the same order again. Note that --shuffle and --shuffle-seed do not affect whether the tests are run in parallel. ``` Is an RFC needed for this?
Implement rust-lang#85440 (Random test ordering) This PR adds `--shuffle` and `--shuffle-seed` options to `libtest`. The options are similar to the [`-shuffle` option](https://github.com/golang/go/blob/c894b442d1e5e150ad33fa3ce13dbfab1c037b3a/src/testing/testing.go#L1482-L1499) that was recently added to Go. Here are the relevant parts of the help message: ``` --shuffle Run tests in random order --shuffle-seed SEED Run tests in random order; seed the random number generator with SEED ... By default, the tests are run in alphabetical order. Use --shuffle or set RUST_TEST_SHUFFLE to run the tests in random order. Pass the generated "shuffle seed" to --shuffle-seed (or set RUST_TEST_SHUFFLE_SEED) to run the tests in the same order again. Note that --shuffle and --shuffle-seed do not affect whether the tests are run in parallel. ``` Is an RFC needed for this?
…ingjubilee Rollup of 8 pull requests Successful merges: - rust-lang#87918 (Enable AutoFDO.) - rust-lang#88137 (On macOS, make strip="symbols" not pass any options to strip) - rust-lang#88772 (Fixed confusing wording on Result::map_or_else.) - rust-lang#89025 (Implement `#[link_ordinal(n)]`) - rust-lang#89082 (Implement rust-lang#85440 (Random test ordering)) - rust-lang#89288 (Wrapper for `-Z gcc-ld=lld` to invoke rust-lld with the correct flavor) - rust-lang#89476 (Correct decoding of foreign expansions during incr. comp.) - rust-lang#89622 (Use correct edition for panic in [debug_]assert!().) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Like with rust-lang#139224, this is a documentation-only deprecation for now. Over time, we can - warn and then remove on use of unstable environment variables - warn on use of stable environment variables (no plan to remove due to compatibility) Longer term, we expect test runners, like `cargo test`, to provide the necessary mechanisms for environmental or persistent configuration (e.g. using cargo config which supports `.cargo/config.toml` as well as environment variables). This would include: - `RUST_TEST_THREADS` - `RUST_TEST_NOCAPTURE` - `RUST_TEST_SHUFFLE` (unstable) - `RUST_TEST_SHUFFLE_SEED` (unstable) The primary outcomes for this change are - Reducing the scope of what is expected for custom test harnesses to implement - Reduce the mechanisms that test runners, like `cargo test`, are expected to track when they are being bypassed to protect against negative interactions, e.g. `RUST_TEST_NOCAPTURE=1` when json output is being read. For testing-devex FCP, see rust-lang/testing-devex-team#10 Fixes rust-lang/testing-devex-team#10 History ------- At each step, I could not find evidence of design discussions on whether to support CLI, env, or both. The first env variable seems to come from the fact that it was being forked out of an existing env variable that had a much wider scope. At best, this seems like a way to offer a more persistent configuration for these flags but environment variables hidden away in libtest is a bit clunky and this seems like the wrong layer to handle this problem. **Originally:** `RUST_THREADS` was respected by the Rust runtime and libextra/test got this for free **2013:** rust-lang#7335 suggested splitting `RUST_TEST_TASKS` out of `RUST_THREADS`. In that issue and the implementation (rust-lang#8823). **2014:** rust-lang#13374 ask for support to disable capturing of stdout/stderr. `--nocapture` and `RUST_TEST_NOCAPTURE` were added together. **2015:** rust-lang#23525 renamed `RUST_TEST_TASKS` to `RUST_TEST_THREADS` **2016:** rust-lang#25636 asked to configure `RUST_TEST_THREADS` via `--test-threads` which was implemented in rust-lang#35414 **2021:** rust-lang#85440 asked for test randomization which was implemented in rust-lang#89082, adding `--shuffle` / RUST_TEST_SHUFFLE` and `--shuffle-seed SEED` / `RUST_TEST_SHUFFLE_SEED` Potentially relevant issues --------------------------- - rust-lang#74845
This PR adds
--shuffle
and--shuffle-seed
options tolibtest
. The options are similar to the-shuffle
option that was recently added to Go.Here are the relevant parts of the help message:
Is an RFC needed for this?