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

Allow panic = "abort" for benchmarks when harness = false. #11214

Open
Imberflur opened this issue Oct 11, 2022 · 5 comments · May be fixed by #11272
Open

Allow panic = "abort" for benchmarks when harness = false. #11214

Imberflur opened this issue Oct 11, 2022 · 5 comments · May be fixed by #11272
Labels
A-profiles Area: profiles C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@Imberflur
Copy link

Imberflur commented Oct 11, 2022

Problem

The panic setting is ignored for benchmarks since (by default) they link libtest which is compiled with panic = "unwind". This would otherwise lead to confusing errors at link time when "abort" is used (#3166, #3175).

However, it is possible to disable the default harness for a benchmark (which means libtest is no longer linked):

[[bench]]
name = "my_bench"
harness = false

(this is common when using external benchmarking frameworks such as criterion)

The ability to disable unwinding when benchmarking is useful since the inclusion of unwinding machinery can affect performance.

Proposed Solution

Allow panic = "abort" when harness = false.

Cargo currently always prints a warning when the bench profile contains panic = "abort". With this proposal that warning would only be printed when building/running a benchmark where the setting is ignored. (Note: currently running a benchmark with a different profile, e.g. cargo bench --profile release that has panic = "abort" will ignore the panic setting but not print any warning)

Notes

No response

@Imberflur Imberflur added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Oct 11, 2022
@weihanglo
Copy link
Member

weihanglo commented Oct 12, 2022

Hmm… really interesting! That is a limitation of libtest but it seems unnecessary to hinder custom test harnesses from adjusting the panic strategy. For myself, I'd like to see Cargo relax it a bit.

Haven't tracked its progress for a while, but there is -Z panic-abort-tests you might want to try out at this moment.

@weihanglo weihanglo added the A-profiles Area: profiles label Oct 12, 2022
@weihanglo
Copy link
Member

Sorry for pinging you folks. My little brain only remembers two custom test harnesses nextest-rs/nextest and bheisler/criterion.rs. @bheisler and @sunshowers, I'd love to know your opinions on relaxing panic strategy for custom harnesses. How would it help your awesome project if Cargo provides this flexibility?

@bheisler
Copy link

Well, I don't think I have too much to say except the obvious. Panicking in a benchmark would be very unusual, and an uncaught panic would be a bug the benchmark author should fix.

Production code sometimes changes the panic handler for performance or other reasons, and it would make sense for the panic handler of the benchmarks to match that of the production code (to make benchmark measurements more similar to, and thus more predictive of, the performance of that code in production).

I had never thought to change the panic handler for a benchmark suite, but now that someone has pointed out that we can't, it does seem like a very strange limitation.

I can't think of a way that Criterion-rs would directly make use of this feature - panics are mostly orthogonal to benchmarking. I can imagine Criterion-rs users - benchmark authors - wanting to change the panic handler and being surprised that they can't.

@sunshowers
Copy link
Contributor

Nextest isn't a custom test harness (it's a custom test runner) so I don't think there's any upside or downside of supporting this for nextest.

@weihanglo
Copy link
Member

Thank you for all the rapid and valuable feedback!. Seems it won't break things from your side. Pretty good!

The only breaking change I can think of is that tests with custom harness set to panic = abort suddenly work (which is exactly what we want to solve). Depending on the old behaviour sounds rare and is a mistake. The fix from the user side should also be an easy change on panic strategy. I'll bring this to the next meeting or do an FCP.

(and sorry for mistaking nextest for a test harness 🫣)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-profiles Area: profiles C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants