-
Notifications
You must be signed in to change notification settings - Fork 736
Revamp code coverage tooling #30181
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
Merged
Merged
Revamp code coverage tooling #30181
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,106 @@ | ||
| --- | ||
| name: improve-coverage | ||
| description: Improve code coverage for a Bazel C++ test target or source file | ||
| user-invocable: true | ||
| --- | ||
|
|
||
| # Improve Code Coverage | ||
|
|
||
| Improve test coverage for a Bazel C++ test target or source file path. | ||
|
|
||
| ## Input Resolution | ||
|
|
||
| 1. **Bazel test target** (starts with `//`, e.g. `//src/v/bytes/tests:iobuf_test`): | ||
| use it directly. | ||
|
|
||
| 2. **Source file path** (e.g. `src/v/bytes/iobuf.cc`): find the test target: | ||
| ```bash | ||
| bazel query "kind('.*_test', rdeps(//src/v/..., //$(dirname $FILE):$(basename $FILE .cc), 1))" 2>/dev/null | ||
| ``` | ||
| If multiple targets match, pick the one in the closest `tests/` directory. | ||
| If none match, tell the user and stop. | ||
|
|
||
| ## Workflow | ||
|
|
||
| ### Step 1: Baseline Coverage | ||
|
|
||
| Run coverage and read the LLM report: | ||
|
|
||
| ```bash | ||
| tools/run-cov <target> -r llm | ||
| ``` | ||
|
|
||
| Note the **total line coverage percentage** — this is the baseline to beat. | ||
|
|
||
| Read the report and identify: | ||
| - **Uncovered functions** — highest impact. One test can cover many lines. | ||
| - **Partially covered functions** — uncovered branches indicate missing | ||
| error-path or edge-case tests. | ||
| - **Zero-coverage files in scope** — may need new test cases entirely. | ||
|
|
||
| ### Step 2: Understand the Code | ||
|
|
||
| Read the source files named in the report. Focus on: | ||
| - Uncovered functions: what they do, inputs, preconditions. | ||
| - The existing test file: patterns, fixtures, helpers. | ||
|
|
||
| Key codebase patterns: | ||
| - `redpanda_cc_gtest` targets use GTest (`TEST()`, `TEST_F()`). | ||
| `redpanda_cc_btest` targets use Seastar Boost test | ||
| (`SEASTAR_THREAD_TEST_CASE`). Match whichever the test file uses. | ||
| - Many functions are `ss::future<>` coroutines — test with | ||
| `SEASTAR_THREAD_TEST_CASE` or the Seastar GTest runner. | ||
| - Use `ss` namespace prefix for Seastar types. | ||
| - Use `EXPECT_*` for most checks, `ASSERT_*` only when continuing would crash. | ||
|
|
||
| ### Step 3: Write Tests | ||
|
|
||
| Prioritize by impact: | ||
| 1. **Uncovered functions** — call each one. A 20-line function = 20 lines covered. | ||
| 2. **Uncovered error paths** — trigger the uncovered branches in partially | ||
| covered functions. | ||
| 3. **Zero-coverage files** — add smoke tests if practical. | ||
|
|
||
| Rules: | ||
| - Add tests to the **existing test file**. Don't create new files or BUILD | ||
| targets unless necessary. | ||
| - Follow existing naming conventions in the file. | ||
| - One logical behavior per test case. | ||
| - Prefer deterministic tests — construct error conditions directly. | ||
| - Do NOT add comments that restate the code. | ||
|
|
||
| ### Step 4: Verify Build | ||
|
|
||
| ```bash | ||
| bazel build <target> | ||
| ``` | ||
|
|
||
| Fix compilation errors before proceeding. | ||
|
|
||
| ### Step 5: Verify Coverage | ||
|
|
||
| Re-run coverage: | ||
|
|
||
| ```bash | ||
| tools/run-cov <target> -r llm | ||
| ``` | ||
|
|
||
| Compare to the baseline. Report: | ||
|
|
||
| ``` | ||
| Coverage: X.Y% → A.B% (+N.N%) | ||
| New lines covered: <count> | ||
| ``` | ||
|
|
||
| If coverage did not improve, investigate: | ||
| - Build errors preventing the new tests from running? | ||
| - Code compiled out by preprocessor guards? | ||
| - Template instantiations not triggered by test types? | ||
|
|
||
| ### Step 6: Summary | ||
|
|
||
| Report: | ||
| - Which functions/paths are now covered | ||
| - What test cases were added | ||
| - Before/after coverage numbers | ||
| - Remaining significant gaps and suggestions |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -138,6 +138,7 @@ coverage.xml | |
| .hypothesis/ | ||
| .pytest_cache/ | ||
| genhtml/ | ||
| coverage-out/ | ||
|
|
||
| # Translations | ||
| *.mo | ||
|
|
||
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 copied these settings from another c++ project two years ago. i don't know how much of that is old bazel versions vs secret magic settings. in any case, with these simplified settings coverage passes the spot testing i've been doing.