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

Implement #85440 (Random test ordering) #89082

Merged
merged 5 commits into from
Oct 8, 2021
Merged

Conversation

smoelius
Copy link
Contributor

@smoelius smoelius commented Sep 18, 2021

This PR adds --shuffle and --shuffle-seed options to libtest. The options are similar to the -shuffle option 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?

@rust-highfive
Copy link
Collaborator

r? @kennytm

(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 Sep 18, 2021
@rust-log-analyzer

This comment has been minimized.

@smoelius smoelius changed the title Implement #85440 Implement #85440 (Random test ordering) Sep 18, 2021
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@smoelius
Copy link
Contributor Author

smoelius commented Sep 19, 2021

r? @ghost

@smoelius smoelius changed the title Implement #85440 (Random test ordering) WIP: Implement #85440 (Random test ordering) Sep 19, 2021
@smoelius
Copy link
Contributor Author

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),
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@smoelius
Copy link
Contributor Author

r? @kennytm

@smoelius
Copy link
Contributor Author

@kennytm I think you can start reviewing this whenever you are ready.

@smoelius smoelius changed the title WIP: Implement #85440 (Random test ordering) Implement #85440 (Random test ordering) Sep 20, 2021
library/test/src/cli.rs Outdated Show resolved Hide resolved
}

fn rand_u64(&mut self) -> u64 {
self.state = calculate_hash(&(self.state, self.extra));
Copy link
Member

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)

Copy link
Contributor Author

@smoelius smoelius Sep 20, 2021

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

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.)

@smoelius
Copy link
Contributor Author

@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.

@kennytm
Copy link
Member

kennytm commented Oct 3, 2021

please also update /src/doc/rustc/src/tests/index.md to document the new unstable option.

r=me after that.

@smoelius
Copy link
Contributor Author

smoelius commented Oct 4, 2021

@kennytm I added some documentation. Please let me know if it seems inadequate.

Thank you again for all of your trouble.

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@kennytm kennytm left a 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 🙃

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.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
unstable-options` flag.
unstable-options` flag. See [tracking issue
#85440](https://github.com/rust-lang/rust/issues/85440) for more
information.

variable.

⚠️ 🚧 This option is [unstable](#unstable-options), and requires the `-Z
unstable-options` flag.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
unstable-options` flag.
unstable-options` flag. See [tracking issue
#85440](https://github.com/rust-lang/rust/issues/85440) for more
information.

@joshtriplett
Copy link
Member

Might be worth looking at lld's --shuffle-sections for comparison.

@smoelius
Copy link
Contributor Author

smoelius commented Oct 6, 2021

basically I just want a link to a tracking issue.

or you could file a different issue for tracking if you like upside_down_face

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.

@kennytm
Copy link
Member

kennytm commented Oct 7, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Oct 7, 2021

📌 Commit ecf4741 has been approved by kennytm

@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 Oct 7, 2021
Manishearth added a commit to Manishearth/rust that referenced this pull request Oct 7, 2021
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?
Manishearth added a commit to Manishearth/rust that referenced this pull request Oct 8, 2021
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?
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 8, 2021
…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
@bors bors merged commit 37f17bc into rust-lang:master Oct 8, 2021
@rustbot rustbot added this to the 1.57.0 milestone Oct 8, 2021
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.

8 participants