-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
libtest: Add --report-time flag to print test execution time #64663
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @TimNN (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
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've left some comments (I think it makes sense to start by allowing this only on nightly at first), but otherwise this LGTM.
I'm not sure about the exact formatting, but that is something that can be improved.
It's an unstable option now. Should its help message mention that it's unstable? (The help messages of the other unstable options don't mention it.) I had tried different formatting variants but couldn't decide which to choose. Eventually I just implemented the simplest one (with the precision proposed by the issue). |
No, I don't think this is necessary; trying to use it explains what to do.
Yes I saw that, I think this is fine for now. cc @rust-lang/compiler which I think is the team responsible for libtest? cc @Manishearth @alexcrichton |
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.
This LGTM now.
I don't believe there's a canonical owner of libtest right now, but this is all behind an unstable flag anyway, so seems fine to me to land in that regard. @bors: r+ |
📌 Commit d91b965 has been approved by |
libtest: Add --report-time flag to print test execution time Implements the flag `--report-time` to print the execution time of each executed (successful or failed) test. Closes rust-lang#46610 # Example `cargo test -- --report-time` produces the following output to stdout: ``` running 6 tests test tests::ignore ... ignored test tests::noop ... ok 0.000s test tests::should_panic ... ok 0.000s test tests::panic_after_10millis ... FAILED 0.010s test tests::sleep_100millis ... ok 0.100s test tests::sleep_10secs ... ok 10.001s failures: ---- tests::panic_after_10millis stdout ---- thread 'tests::panic_after_10millis' panicked at 'foo', src\lib.rs:31:9 failures: tests::panic_after_10millis test result: FAILED. 4 passed; 1 failed; 1 ignored; 0 measured; 0 filtered out ``` `cargo test -- --report-time -Z unstable-options --format=json` produces the following output to stdout: ``` { "type": "suite", "event": "started", "test_count": 6 } { "type": "test", "event": "started", "name": "tests::ignore" } { "type": "test", "event": "started", "name": "tests::noop" } { "type": "test", "event": "started", "name": "tests::panic_after_10millis" } { "type": "test", "event": "started", "name": "tests::should_panic" } { "type": "test", "name": "tests::ignore", "event": "ignored" } { "type": "test", "event": "started", "name": "tests::sleep_100millis" } { "type": "test", "name": "tests::noop", "event": "ok", "exec_time": "0.000s" } { "type": "test", "event": "started", "name": "tests::sleep_10secs" } { "type": "test", "name": "tests::should_panic", "event": "ok", "exec_time": "0.000s" } { "type": "test", "name": "tests::panic_after_10millis", "event": "failed", "exec_time": "0.010s", "stdout": "thread 'tests::panic_after_10millis' panicked at 'foo', src\\lib.rs:31:9\n" } { "type": "test", "name": "tests::sleep_100millis", "event": "ok", "exec_time": "0.101s" } { "type": "test", "name": "tests::sleep_10secs", "event": "ok", "exec_time": "10.000s" } { "type": "suite", "event": "failed", "passed": 4, "failed": 1, "allowed_fail": 0, "ignored": 1, "measured": 0, "filtered_out": 0 } ``` `cargo test -- --report-time --logfile foo.log` produces the following logfile: ``` ignored tests::ignore ok tests::noop 0.000s ok tests::should_panic 0.000s failed tests::panic_after_10millis 0.010s ok tests::sleep_100millis 0.100s ok tests::sleep_10secs 10.001s ```
libtest: Add --report-time flag to print test execution time Implements the flag `--report-time` to print the execution time of each executed (successful or failed) test. Closes #46610 # Example `cargo test -- --report-time` produces the following output to stdout: ``` running 6 tests test tests::ignore ... ignored test tests::noop ... ok 0.000s test tests::should_panic ... ok 0.000s test tests::panic_after_10millis ... FAILED 0.010s test tests::sleep_100millis ... ok 0.100s test tests::sleep_10secs ... ok 10.001s failures: ---- tests::panic_after_10millis stdout ---- thread 'tests::panic_after_10millis' panicked at 'foo', src\lib.rs:31:9 failures: tests::panic_after_10millis test result: FAILED. 4 passed; 1 failed; 1 ignored; 0 measured; 0 filtered out ``` `cargo test -- --report-time -Z unstable-options --format=json` produces the following output to stdout: ``` { "type": "suite", "event": "started", "test_count": 6 } { "type": "test", "event": "started", "name": "tests::ignore" } { "type": "test", "event": "started", "name": "tests::noop" } { "type": "test", "event": "started", "name": "tests::panic_after_10millis" } { "type": "test", "event": "started", "name": "tests::should_panic" } { "type": "test", "name": "tests::ignore", "event": "ignored" } { "type": "test", "event": "started", "name": "tests::sleep_100millis" } { "type": "test", "name": "tests::noop", "event": "ok", "exec_time": "0.000s" } { "type": "test", "event": "started", "name": "tests::sleep_10secs" } { "type": "test", "name": "tests::should_panic", "event": "ok", "exec_time": "0.000s" } { "type": "test", "name": "tests::panic_after_10millis", "event": "failed", "exec_time": "0.010s", "stdout": "thread 'tests::panic_after_10millis' panicked at 'foo', src\\lib.rs:31:9\n" } { "type": "test", "name": "tests::sleep_100millis", "event": "ok", "exec_time": "0.101s" } { "type": "test", "name": "tests::sleep_10secs", "event": "ok", "exec_time": "10.000s" } { "type": "suite", "event": "failed", "passed": 4, "failed": 1, "allowed_fail": 0, "ignored": 1, "measured": 0, "filtered_out": 0 } ``` `cargo test -- --report-time --logfile foo.log` produces the following logfile: ``` ignored tests::ignore ok tests::noop 0.000s ok tests::should_panic 0.000s failed tests::panic_after_10millis 0.010s ok tests::sleep_100millis 0.100s ok tests::sleep_10secs 10.001s ```
☀️ Test successful - checks-azure |
Enhance report-time option ## Short overview This PR is a follow-up to a previously closed #64714 PR. ## Changes introduced by this PR * `libtest` now retrieves the type of the test within `TestDesc` (available types are: `UnitTest`, `IntegrationTest`, `DocTest`, `Unknown`). * `--report-time` subcommand of the `libtest` now supports colored output (disabled by default). * Colorized output depends on the threshold values. Default values (proposed by @wesleywiser): - For unit-tests: 50ms warn/100ms critical, - For integration-tests: 500ms warn/1000ms critical, - For doctests: same as for integration tests, - For unknown tests: `TEST_WARN_TIMEOUT_S` warn/ `TEST_WARN_TIMEOUT_S * 2` critical (it will only applied single-threaded mode, because otherwise test will be interrupted after reaching `TEST_WARN_TIMEOUT_S`). - These values can be overrided by setting environment variables (since those thresholds are somewhat constant for every project, it's more flexible to use environment variables than command line arguments). * New optional flag `--ensure-test-time` for `libtest`. With this flag applied, exectuion time limit excesss will cause test failure. ## What have not been done There was a comment that it would be nice to have an entry in the Cargo book about it. However, changes introduced by this PR (and #64663 in which `report-time` flag was added) aren't related directly to `cargo`, it's more about `libtest` itself. I'm considering that [The Unstable Book](https://doc.rust-lang.org/unstable-book/) is more appropriate place, but not sure if I'm right (and if so, how exactly it should be described). As one possible option, this PR may be merged without denoting it in the documentation, and in the next PR adding support of this feature to the `cargo` itself, I'll add a note in the Cargo book. ## Scope of this PR Logical scope of this PR is `libtest` only. However, to get test types, I had to modify also `libsyntax_ext` and `librustdoc` for them to provide information about test type. ## Rationale Rationale for colored output was submitted in #64714 Providing the information about kind of test was also proposed in #64714, and as an additional benefit this information may be useful for the tools using `libtest` (e.g. `cargo`). Adding flag to treat time limits excess seems logical to me, so projects that do care about test execution time won't have to invent a wheel. ## Backward compatibility All the changes are completely backward compatible. ## Demo ![rustc_enhanced_time](https://user-images.githubusercontent.com/12111581/65818381-c04f6800-e219-11e9-9875-322463abe24f.gif) r? @wesleywiser
How do I run this?
|
@nkostoulas If |
Sorry I copied the wrong segment
Not sure what |
|
cheers! |
Note that nightly toolchain is not required for this, |
Could this be a bug? This is from
If I remember correctly nightly toolchain was needed when I made the PR. |
I wonder if we should have some kind of a tracking issue for this and #75752? I personally would love to see both of this stabilized sooner than later, as they are a tremendous help for large complicated projects with many engineers. |
Implements the flag
--report-time
to print the execution time of each executed (successful or failed) test.Closes #46610
Example
cargo test -- --report-time
produces the following output to stdout:cargo test -- --report-time -Z unstable-options --format=json
produces the following output to stdout:cargo test -- --report-time --logfile foo.log
produces the following logfile: