about summary refs log tree commit diff
path: root/tests/coverage
AgeCommit message (Collapse)AuthorLines
2024-05-14coverage: Simplify counter expressions using simple algebraZalathar-1305/+804
Some of these cases currently don't occur in practice, but are included for completeness, and to avoid having to add them later as branch coverage and MC/DC coverage start building more complex expressions.
2024-05-07Auto merge of #124223 - Zalathar:conditional-let, r=compiler-errorsbors-10/+34
coverage: Branch coverage support for let-else and if-let This PR adds branch coverage instrumentation for let-else and if-let, including let-chains. This lifts two of the limitations listed at #124118.
2024-05-03Auto merge of #123602 - cjgillot:gvn-borrowed, r=oli-obkbors-14/+14
Account for immutably borrowed locals in MIR copy-prop and GVN For the most part, we consider that immutably borrowed `Freeze` locals still fulfill SSA conditions. As the borrow is immutable, any use of the local will have the value given by the single assignment, and there can be no surprise. This allows copy-prop to merge a non-borrowed local with a borrowed local. We chose to keep copy-classes heads unborrowed, as those may be easier to optimize in later passes. This also allows to GVN the value behind an immutable borrow. If a SSA local is borrowed, dereferencing that borrow is equivalent to copying the local's value: re-executing the assignment between the borrow and the dereference would be UB. r? `@ghost` for perf
2024-04-30coverage: Add branch coverage support for if-let and let-chainsZalathar-7/+25
2024-04-30coverage: Add branch coverage support for let-elseZalathar-3/+9
2024-04-29Auto merge of #124255 - RenjiSann:renji/mcdc-nested-expressions, r=Zalatharbors-0/+506
MCDC coverage: support nested decision coverage #123409 provided the initial MCDC coverage implementation. As referenced in #124144, it does not currently support "nested" decisions, like the following example : ```rust fn nested_if_in_condition(a: bool, b: bool, c: bool) { if a && if b || c { true } else { false } { say("yes"); } else { say("no"); } } ``` Note that there is an if-expression (`if b || c ...`) embedded inside a boolean expression in the decision of an outer if-expression. This PR proposes a workaround for this cases, by introducing a Decision context stack, and by handing several `temporary condition bitmaps` instead of just one. When instrumenting boolean expressions, if the current node is a leaf condition (i.e. not a `||`/`&&` logical operator nor a `!` not operator), we insert a new decision context, such that if there are more boolean expressions inside the condition, they are handled as separate expressions. On the codegen LLVM side, we allocate as many `temp_cond_bitmap`s as necessary to handle the maximum encountered decision depth.
2024-04-29tests(mcdc-coverage): Add tests for nested decision structures in ↵Dorian Péron-0/+506
mcdc_nested_if.rs
2024-04-24Error on using `yield` without also using `#[coroutine]` on the closureOli Scherer-16/+16
And suggest adding the `#[coroutine]` to the closure
2024-04-22coverage: Branch coverage tests for match armsZalathar-0/+401
2024-04-22coverage: Branch coverage test for if-let and let-chainsZalathar-0/+161
2024-04-22coverage: Branch coverage test for let-elseZalathar-0/+90
2024-04-20Rollup merge of #124053 - Zalathar:lazy-boolean, r=Mark-Simulacrum许杰友 Jieyou Xu (Joe)-15/+385
coverage: Branch coverage tests for lazy boolean operators The current branch coverage implementation already supports the `&&` and `||` operators (even outside of an `if` condition), as a natural consequence of how they are desugared/lowered, but we didn't have any specific tests for them. This PR adds some appropriate tests. I've also moved the existing branch coverage tests into a `coverage/branch` subdirectory, so that they don't become unwieldy as I add more branch coverage tests. ``@rustbot`` label +A-code-coverage
2024-04-20Dereference immutable borrows in GVN.Camille GILLOT-14/+14
2024-04-20coverage. Add basic tests for MC/DCzhuyunxing-0/+583
2024-04-17coverage: Branch coverage tests for lazy boolean operatorsZalathar-0/+370
2024-04-17coverage: Move branch coverage tests into a subdirectoryZalathar-15/+15
2024-03-27Eliminate `UbCheck` for non-standard librariesDianQK-6/+6
2024-03-26coverage: Re-enable `UnreachablePropagation` for coverage buildsZalathar-3/+3
2024-03-20coverage: Remove incorrect assertions from counter allocationZalathar-2/+2
These assertions detect situations where a BCB node would have both a physical counter and one or more in-edge counters/expressions. For most BCBs that situation would indicate an implementation bug. However, it's perfectly fine in the case of a BCB having an edge that loops back to itself. Given the complexity and risk involved in fixing the assertions, and the fact that nothing relies on them actually being true, this patch just removes them instead.
2024-03-20coverage: Regression test for ICE triggered by self-loopsZalathar-0/+98
2024-03-14coverage: Enable branch coverage in the branch coverage testsZalathar-116/+272
2024-03-13coverage: Add branch coverage tests (with branch coverage disabled)Zalathar-0/+707
2024-03-13coverage: Remove all unstable values of `-Cinstrument-coverage`Zalathar-20/+10
2024-02-22[AUTO_GENERATED] Migrate compiletest to use `ui_test`-style `//@` directives许杰友 Jieyou Xu (Joe)-112/+112
2024-02-21coverage: Eagerly deduplicate covspans with the same spanZalathar-10/+8
2024-02-18Update coverage-run testsVadim Petrochenkov-5/+5
2024-02-18macro_rules: Preserve all metavariable spans in a global side tableVadim Petrochenkov-0/+20
2024-02-16coverage: Discard spans that fill the entire function bodyZalathar-29/+20
When we try to extract coverage-relevant spans from MIR, sometimes we see MIR statements/terminators whose spans cover the entire function body. Those spans tend to be unhelpful for coverage purposes, because they often represent compiler-inserted code, e.g. the implicit return value of `()`.
2024-02-16coverage: Regression test for a span extraction inconsistencyZalathar-0/+93
2024-02-09Enable by default.Camille GILLOT-178/+139
2024-02-05coverage: Make unexpansion of closure bodies more preciseZalathar-32/+48
This improves the coverage instrumentation of closures declared in macros, as seen in `closure_macro.rs` and `closure_macro_async.rs`.
2024-02-05coverage: Add a test for `#[coverage(..)]` on closuresZalathar-0/+119
2024-02-05coverage: Test for closure body that is a single bang-macroZalathar-0/+51
2024-02-02coverage: Use normal `edition:` headers in coverage testsZalathar-40/+40
Some of these tests were originally written as part of a custom `run-make` test, so at that time they weren't able to use the normal compiletest header directive parser. Now that they're properly integrated, there's no need for them to use `compile-flags` to specify the edition, since they can use `edition` instead.
2024-01-24Rollup merge of #120185 - Zalathar:auto-derived, r=wesleywiserLeón Orell Valerian Liehr-94/+4
coverage: Don't instrument `#[automatically_derived]` functions This PR makes the coverage instrumentor detect and skip functions that have [`#[automatically_derived]`](https://doc.rust-lang.org/reference/attributes/derive.html#the-automatically_derived-attribute) on their enclosing impl block. Most notably, this means that methods generated by built-in derives (e.g. `Clone`, `Debug`, `PartialEq`) are now ignored by coverage instrumentation, and won't appear as executed or not-executed in coverage reports. This is a noticeable change in user-visible behaviour, but overall I think it's a net improvement. For example, we've had a few user requests for this sort of change (e.g. #105055, https://github.com/rust-lang/rust/issues/84605#issuecomment-1902069040), and I believe it's the behaviour that most users will expect/prefer by default. It's possible to imagine situations where users would want to instrument these derived implementations, but I think it's OK to treat that as an opportunity to consider adding more fine-grained option flags to control the details of coverage instrumentation, while leaving this new behaviour as the default. (Also note that while `-Cinstrument-coverage` is a stable feature, the exact details of coverage instrumentation are allowed to change. So we *can* make this change; the main question is whether we *should*.) Fixes #105055.
2024-01-22coverage: Don't instrument `#[automatically_derived]` functionsZalathar-94/+4
2024-01-21Add `#[coverage(off)]` to closures introduced by `#[test]`/`#[bench]`Zalathar-18/+2
2024-01-21coverage: Add a test that uses `#[bench]`Zalathar-0/+33
2024-01-21Rollup merge of #120015 - Zalathar:format, r=dtolnayNadrieril-218/+282
coverage: Format all coverage tests with `rustfmt` As suggested by <https://github.com/rust-lang/rust/pull/119984#discussion_r1452856806>. Test files in `tests/` are normally ignored by `x fmt`, but sometimes those files end up being run through `rustfmt` anyway, either by `rust-analyzer` or by hand. When that happens, it's annoying to have to manually revert formatting changes that are unrelated to the actual changes being made. So it's helpful for the tests in the repository to already have standard formatting beforehand. However, there are several coverage tests that deliberately use non-standard formatting, so that line counts reveal more information about where code regions begin and end. In those cases, we can use `#[rustfmt::skip]` to prevent that code from being disturbed. ``@rustbot`` label +A-code-coverage
2024-01-18coverage: Format all remaining testsZalathar-54/+70
These tests can simply be reformatted as normal, because the resulting changes are unimportant.
2024-01-17Remove unnecessary `let`s and borrowing from `Waker::noop()` usage.Kevin Reid-16/+8
`Waker::noop()` now returns a `&'static Waker` reference, so it can be passed directly to `Context` creation with no temporary lifetime issue.
2024-01-16coverage: Tweak individual tests to be unaffected by `rustfmt`Zalathar-22/+34
Some of these tests use non-standard formatting that we can simulate by strategically adding `//` line comments. One contains `where` clauses that would be split across multiple lines, which we can keep on one line by moving the bounds to the generic type instead.
2024-01-16coverage: Add `#[rustfmt::skip]` to tests with non-standard formattingZalathar-142/+178
These tests deliberately use non-standard formatting, so that the line execution counts reported by `llvm-cov` reveal additional information about where code regions begin and end.
2024-01-08coverage: `llvm-cov` expects column numbers to be bytes, not code pointsZalathar-12/+52
2024-01-08coverage: Test for column numbers involving non-ASCII charactersZalathar-0/+89
2024-01-05Rollup merge of #119208 - Zalathar:hoist, r=WaffleLapkin,SwatinemMichael Goulet-27/+21
coverage: Hoist some complex code out of the main span refinement loop The span refinement loop in `spans.rs` takes the spans that have been extracted from MIR, and modifies them to produce more helpful output in coverage reports. It is also one of the most complicated pieces of code in the coverage instrumentor. It has an abundance of moving pieces that make it difficult to understand, and most attempts to modify it end up accidentally changing its behaviour in unacceptable ways. This PR nevertheless tries to make a dent in it by hoisting two pieces of special-case logic out of the main loop, and into separate preprocessing passes. Coverage tests show that the resulting mappings are *almost* identical, with all known differences being unimportant. This should hopefully unlock further simplifications to the refinement loop, since it now has fewer edge cases to worry about.
2024-01-05Allow coverage tests to enable `llvm-cov --use-color`Zalathar-0/+24
2024-01-05Allow tests to ignore individual test modesZalathar-0/+18
Normally, each test in `tests/coverage` is automatically run in both `coverage-map` mode and `coverage-run` mode. This new family of directives allows an individual test to specify that it should not be run in a particular mode.
2024-01-05coverage: Hoist the splitting of visible macro invocationsZalathar-24/+18
2024-01-05coverage: Overhaul how "visible macros" are determinedZalathar-3/+3