-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
testing: benchmark regexp doesn't filter top level benchmarks #20589
Comments
Note that this happens with tests too, using the same example but with tests instead of benchmarks:
I always thought this was by design, since one can do stuff like this to avoid all sub-tests:
In other words, I understood |
I'd like to more precisely define what we want. (Everything below applies to both tests and benchmarks.) Normalization of the '/'-separated pattern
Normalization of the test name
Intra-depth match If the test's root is at depth zero and the first subregex of the normalized pattern is at index zero, we can define an intra-depth match as the subregex at index Runnability of a test A subtest is runnable if there is a path from the root to infinity containing that subtest and every subtest in that path has an intra-depth match. Examples mentioned above, and whether they follow this definition
Do you agree with this definition? @josharian @ianlancetaylor (I'd like to work on this.) |
The comment by @meirf appears to be a full redesign of the matching semantics. I'm sorry, but that's simply not on the table. If there are specific changes you want to see, maybe we can talk about those, but I'd rather not start with something that requires me to mentally compare the current behavior and the proposed behavior to see how they differ. Make a list of differences, please. Also, regrettably, the focus above on "what we want" may not be terribly relevant. The design of the pattern matching is constrained by the fact that the hierarchy of tests and subtests (and also benchmarks and sub-benchmarks) is only discovered by executing the parent levels of the hierarchy. If you have -run=/Foo, then since the only way to find out which tests have a sub-test "Foo" is to run them, it follows that all the top-level tests match this. We could hide that fact by not reporting the test results, but the fact is that the tests would still run, consuming CPU and possibly generating non-t.Logged output. Better to be honest. In the case of benchmarks, we could potentially be more constraining, by forcing b.N to 0 during those top-level benchmarks when we're just exploring to find a sub-benchmark named Foo. Maybe we should do that, but note that the result would be necessarily inconsistent with the test situation. I would see defending the inconsistency as better than today, but it's important to realize the inconsistency. And again it is critically important to identify what you propose to change, not to construct a whole new semantics and require diffing it against the current one. |
Sorry for using new semantics and putting the diffing/parsing burden on the reader. The only difference I am aware between the status quo and the definition from my 1st comment is the one @rsc mentioned: "The design of the pattern matching is constrained... realize the inconsistency." Status quo The diff is more general than just the highest level test/benchmark (@josharian's complaint) - e.g. a matching subtest can be 10 levels deep and still be run despite the pattern at the 11th level not matching its subtest/it having no subtest. Resolution of Diff/New Proposal
This has the same issue @josharian brought up regarding benchmarks. Specifically, one would think that a test needs a match at every level of the pattern in order to be run. So for the short term, the resolution could be to change the documentation for both tests and benchmarks. If the benchmark code gets a change, that doc change for benchmarks can be reverted. I'd be happy upload a minor change to the language used in the docs if there are no objections. |
(I understand that the problem is general but let's keep using top-level vs sub-test in the discussion, with everyone understanding that we really mean the general problem and that any fixes must apply generally.) I now remember that we tried b.N=0 for probing like this, but it broke too many ordinary benchmarks that mishandled N=0 (they expected their loops to run at least once). So now we use N=1 for the probe but don't print benchmark output. So for benchmarks, I think things are working as best they can. For testing, as we've established, there's no way to avoid running the top-level test. So for testing, I also think things are working as best they can. Here's an example transcript. If you think anything should change, please explain how this would behave differently:
I sent a CL clarifying the docs and will let that CL mark this issue closed. |
CL https://golang.org/cl/46030 mentions this issue. |
One minor improvement would be to probe only once when |
Sorry, Russ, but even with your new wording, the original result looks wrong to me. Note that |
Thanks Josh. I see what happened and will update the code to match the description. Re your next-to-last comment, the probe already only happens once regardless of -count. |
/cc @mpvl, CL on the way for you shortly. This is the context. |
CL https://golang.org/cl/46031 mentions this issue. |
The docs for
-bench
say:So I expected only benchmarks matching Map in the first part and C in the second part to match--namely BenchmarkMapB/C. But I got BenchmarkMapA as well.
This arose because I wanted to run only the runtime map sub-benchmarks named "Int64" and the natural command
go test -bench="Map/Int64" -run=NONE runtime
did not work.cc @mpvl
The text was updated successfully, but these errors were encountered: