-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Implement #85440 (Random test ordering) #89082
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
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?