forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lit] Fix some issues from --per-test-coverage (llvm#65242)
D154280 (landed in 64d1954 in July, 2023) implements `--per-test-coverage` (which can also be specified via `lit_config.per_test_coverage`). However, it has a few issues, which the current patch addresses: 1. D154280 implements `--per-test-coverage` only for the case that lit is configured to use an external shell. The current patch extends the implementation to lit's internal shell. 2. In the case that lit is configured to use an external shell, regardless of whether `--per-test-coverage` is actually specified, D154280 causes `%dbg(RUN: at line N)` to be expanded in RUN lines early and in a manner that is specific to sh-like shells. As a result, later code in lit that expands it in a shell-specific manner is useless as there's nothing left to expand. The current patch cleans up the implementation to avoid useless code. 3. Because of issue 2, D154280 corrupts support for windows `cmd` as an external shell (effectively comments out all RUN lines with `:`). The current patch happens to fix that particular corruption by addressing issue 2. However, D122569 (landed in 1041a96 in April, 2022) had already broken support for windows `cmd` as an external shell (discards RUN lines when expanding `%dbg(RUN: at line N)`). The current patch does not attempt to fix that bug. For further details, see the PR discussion of the current patch. The current patch addresses the above issues by implementing `--per-test-coverage` before selecting the shell (internal or external) and by leaving `%dbg(RUN: at line N)` unexpanded there. Thus, it is expanded later in a shell-specific manner, as before D154280. This patch introduces `buildPdbgCommand` into lit's implementation to encapsulate the process of building (or rebuilding in the case of the `--per-test-coverage` implementation) a full `%dbg(RUN: at line N) cmd` line and asserting that the result matches `kPdbgRegex`. It also cleans up that and all other uses of `kPdbgRegex` to operate on the full line with `re.fullmatch` not `re.match`. This change better reflects the intention in every case, but it is expected to be NFC because `kPdbgRegex` ends in `.*` and thus avoids the difference between `re.fullmatch` and `re.match`. The only caveat is that `.*` does not match newlines, but RUN lines cannot contain newlines currently, so this caveat currently shouldn't matter in practice. The original `--per-test-coverage` implementation avoided accumulating `export LLVM_PROFILE_FILE={profile}` insertions across retries (due to `ALLOW_RETRIES`) by skipping the insertion if `%dbg(RUN: at line N)` was not present and thus had already been expanded. However, the current patch makes sure the insertions also happen for commands without `%dbg(RUN: at line N)`, such as preamble commands or some commands from other lit test formats. Thus, the current patch implements a different mechanism to avoid accumulating those insertions (see code comments).
- Loading branch information
1 parent
4d03670
commit ff702f3
Showing
8 changed files
with
110 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,24 @@ | ||
# Test if lit_config.per_test_coverage in lit.cfg sets individual test case coverage. | ||
|
||
# RUN: %{lit} -a -v %{inputs}/per-test-coverage-by-lit-cfg/per-test-coverage-by-lit-cfg.py \ | ||
# RUN: | FileCheck -match-full-lines %s | ||
# | ||
# CHECK: PASS: per-test-coverage-by-lit-cfg :: per-test-coverage-by-lit-cfg.py ({{[^)]*}}) | ||
# RUN: %{lit} -a -vv -Dexecute_external=False \ | ||
# RUN: %{inputs}/per-test-coverage-by-lit-cfg/per-test-coverage-by-lit-cfg.py | \ | ||
# RUN: FileCheck -DOUT=stdout %s | ||
|
||
# RUN: %{lit} -a -vv -Dexecute_external=True \ | ||
# RUN: %{inputs}/per-test-coverage-by-lit-cfg/per-test-coverage-by-lit-cfg.py | \ | ||
# RUN: FileCheck -DOUT=stderr %s | ||
|
||
# CHECK: {{^}}PASS: per-test-coverage-by-lit-cfg :: per-test-coverage-by-lit-cfg.py ({{[^)]*}}) | ||
# CHECK: Command Output ([[OUT]]): | ||
# CHECK-NEXT: -- | ||
# CHECK: export | ||
# CHECK: LLVM_PROFILE_FILE=per-test-coverage-by-lit-cfg0.profraw | ||
# CHECK: per-test-coverage-by-lit-cfg.py | ||
# CHECK: {{RUN}}: at line 2 | ||
# CHECK: export | ||
# CHECK: LLVM_PROFILE_FILE=per-test-coverage-by-lit-cfg1.profraw | ||
# CHECK: per-test-coverage-by-lit-cfg.py | ||
# CHECK: {{RUN}}: at line 3 | ||
# CHECK: export | ||
# CHECK: LLVM_PROFILE_FILE=per-test-coverage-by-lit-cfg2.profraw | ||
# CHECK: per-test-coverage-by-lit-cfg.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,24 @@ | ||
# Test LLVM_PROFILE_FILE is set when --per-test-coverage is passed to command line. | ||
|
||
# RUN: %{lit} -a -v --per-test-coverage %{inputs}/per-test-coverage/per-test-coverage.py \ | ||
# RUN: | FileCheck -match-full-lines %s | ||
# | ||
# CHECK: PASS: per-test-coverage :: per-test-coverage.py ({{[^)]*}}) | ||
# RUN: %{lit} -a -vv --per-test-coverage -Dexecute_external=False \ | ||
# RUN: %{inputs}/per-test-coverage/per-test-coverage.py | \ | ||
# RUN: FileCheck -DOUT=stdout %s | ||
|
||
# RUN: %{lit} -a -vv --per-test-coverage -Dexecute_external=True \ | ||
# RUN: %{inputs}/per-test-coverage/per-test-coverage.py | \ | ||
# RUN: FileCheck -DOUT=stderr %s | ||
|
||
# CHECK: {{^}}PASS: per-test-coverage :: per-test-coverage.py ({{[^)]*}}) | ||
# CHECK: Command Output ([[OUT]]): | ||
# CHECK-NEXT: -- | ||
# CHECK: export | ||
# CHECK: LLVM_PROFILE_FILE=per-test-coverage0.profraw | ||
# CHECK: per-test-coverage.py | ||
# CHECK: {{RUN}}: at line 2 | ||
# CHECK: export | ||
# CHECK: LLVM_PROFILE_FILE=per-test-coverage1.profraw | ||
# CHECK: per-test-coverage.py | ||
# CHECK: {{RUN}}: at line 3 | ||
# CHECK: export | ||
# CHECK: LLVM_PROFILE_FILE=per-test-coverage2.profraw | ||
# CHECK: per-test-coverage.py |