Skip to content

PROF-16533: Merged test coverage across CI-tested Linux platforms and JVMs - #948

Draft
zhengyu123 wants to merge 25 commits into
mainfrom
zgu/test-coverage-skill
Draft

zhengyu123 wants to merge 25 commits into
mainfrom
zgu/test-coverage-skill

Conversation

@zhengyu123

@zhengyu123 zhengyu123 commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?:

Adds a merged C++ and Java coverage report across the Linux platforms and JVMs that CI tests.

  • utils/run-containers-tests.sh --coverage-out=DIR runs :ddprof-lib:coverageReport -PenableCoverage for one container cell. It exports the reports, the JaCoCo .exec files, the classes they were recorded against and a cell.properties file (libc, arch, jdk, tests filter, commit, Gradle exit code).
  • coverageReport also writes a gcovr JSON tracefile, reports/coverage/cpp/coverage.json.
  • utils/merge-coverage.sh merges cells built from one commit into one gcovr report and one JaCoCo report, plus summary.md.
  • The test-coverage agent skill runs the CI matrix (test_workflow.yml): one worktree and one subagent per libc×arch, capped by container memory, then the merge.

Other changes to run-containers-tests.sh:

Change Why
Clone mode works from a git worktree The worktree's .git names a gitdir in the main repository; the script mounts that git dir read-only
JDK images carry a java-profiler.base-id label and are rebuilt when the base image changes A JDK image cached on an older base image hid the rebuilt base's gcovr, even after --rebuild-base on another JDK
--tests accepts only letters, digits and _ . * # , -, in every mode The pattern is spliced unquoted into a host-side eval; a quote in it could run commands on the host

With -Ptests, the coverage test tasks no longer fail on an empty match (ddprof-test/build.gradle.kts). A pattern usually matches tests of only one of testCoverage and testSlowCoverage.

Motivation:

One coverageReport run covers one libc, one architecture and one test JVM. Code that only runs elsewhere (aarch64 stack walking, musl paths, OpenJ9 and GraalVM support) shows as not covered. A merged report shows what the CI-tested matrix actually executes.

Additional Notes:

  • Behavior change for all users: --tests now rejects patterns with other characters, e.g. spaces, $ or ;. Such patterns could not work reliably before.
  • One-time cost: cached JDK images carry no base-id label, so each is rebuilt once on first use.
  • Not covered: CI's 8-orcl and 8-ibm (no container image) and macOS. The C++ report covers the -O0 -DDEBUG build only (see doc/building/CodeCoverage.md).
  • Merge host: needs a gcovr at least as new as the containers'. gcovr 8.6 rejects the format-0.15 tracefiles written by the containers' gcovr 8.8.
  • Agentic review: sphinx reviewed the full range, with 31 findings and none Critical or High. /code-review then re-reviewed each fix commit; the last pass was clean. Declined findings:
Finding Reason
Move orchestration into the script's matrix mode The skill's per-platform subagents and memory slots are the requested design
Narrow safe.directory "*" in worktree mode The ownership failure does not reproduce under podman; "*" applies only inside the throwaway container
--rebuild-base should not force a JDK image rebuild Keeps the script's documented behavior
Pin gcovr in the base images Left as a follow-up; the skill checks the host's gcovr version against the images' instead
Gradle-level tests for coverage.json and the empty-match filter No Gradle test harness exists for this; the real container run below exercised both

How to test the change?:

  • Hermetic: bash utils/tests/test_coverage_scripts.sh has 103 tests and runs in CI with utils/tests/*.sh. Stub podman, gcovr, java and curl programs record their arguments. The container command itself runs on the host against a stub Gradle and checks exit codes, cell.properties and the export.
  • Real run: 14 native aarch64 cells ran with tests=JavaProfilerTest: 9 glibc (HotSpot 17/21/25, OpenJ9 8/11/17, GraalVM 17/21/25) and 5 musl (8–25). All passed and merged into one report.
    • Merged C++ lines: 68.1%. glibc cells alone: 66.6%; musl cells alone: 65.6%.
    • The run used commit 0825b2dcb; the review fixes after it are covered by the hermetic tests only.
    • The x64 cells did not run: this host's container VM has memory for one cell at a time, and x64 runs emulated there.

For Datadog employees:

  • If this PR touches code that signs or publishes builds or packages, or handles
    credentials of any kind, I've requested a security review (run the dd:platform-security-review
    skill, or file a request via the PSEC review form).
    bewaire also runs automatically on every PR.
  • This PR doesn't touch any of that.
  • JIRA: PROF-16533

🤖 Generated with Claude Code

zhengyu123 and others added 7 commits November 6, 2026 10:10
Run :ddprof-lib:coverageReport for each CI-tested libc/arch/JVM cell in a
container and merge the results into one C++ and one Java report.

- run-containers-tests.sh: --coverage-out=DIR runs the coverage report for
  one cell and exports reports, JaCoCo data, classes and cell.properties;
  clone mode works from a git worktree
- coverageReport also writes a gcovr JSON tracefile
- merge-coverage.sh merges cells built from one commit
- hermetic tests for both scripts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Coverage test tasks do not fail on an empty -Ptests match, so a filter
  that matches only slow or only regular tests still reaches the reports
- run-containers-tests.sh labels each JDK image with its base image ID and
  rebuilds it when the base image changed
- test-coverage skill: memory preflight caps parallel cells at one per
  8 GB, checks base images for gcovr, and counts a killed Gradle daemon
  as blocked instead of failed

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- --coverage-out replaces the previous export, records the -Ptests
  filter, exits 70 when Gradle passed but the export failed, rejects an
  empty directory and creates it only for an accepted run
- --rebuild-base again forces the JDK image rebuild
- merge-coverage.sh replaces --out, rejects cells without a commit, marks
  per cell whether it is in the C++ and Java reports, flags filtered runs
  and checks the downloaded JaCoCo CLI against a pinned SHA-256
- tests run the container command with a stub Gradle and cover the new
  merge and image-reuse branches
- test-coverage skill clears a cell before each attempt, checks RUN
  against colima's $HOME share, and reports cells missing from a report

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- --coverage-out clears the previous export on the host before the run,
  so a run that dies before the export leaves no stale data, and rejects
  --tests patterns that would break the spliced container command
- merge-coverage.sh refuses an --out that is not empty or an earlier
  merge, and marks a cell in the Java column only when it contributed
  .exec files to a report that was written
- test-coverage skill: the $HOME check covers podman machine too, and the
  merge snippet sets the worktree it uses

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- run-containers-tests.sh accepts only letters, digits and _ . * # , - in
  --tests, in every mode: the pattern is spliced unquoted into the
  host-side eval and the container shell, so other characters could run
  commands on the host or inject cell.properties keys
- the host-side clearing of a previous export is best effort; with a
  rootful runtime the in-container export clears root-owned files
- merge-coverage.sh marks its output directory, so a merge that failed
  midway can be rerun into the same --out, and links a report in
  summary.md only when it was written

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zhengyu123
zhengyu123 requested a review from a team as a code owner November 6, 2026 20:34
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T21:35:07.451469Z ae6dca8 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@dd-octo-sts

dd-octo-sts Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Scan-Build Report

User:runner@runnervmwuk1x
Working Directory:/home/runner/work/java-profiler/java-profiler/ddprof-lib/src/test/make
Command Line:make -j4 all
Clang Version:Ubuntu clang version 21.1.8 (6ubuntu1)
Date:Wed Nov 11 21:30:11 2026

Bug Summary

Bug TypeQuantityDisplay?
All Bugs2
Logic error
Dereference of null pointer1
Unused code
Dead initialization1

Filter Results by File

Reports

Bug Group Bug Type ▾ File Function/Method Line Path Length
Unused codeDead initializationreferenceChains.cppapplyOomRamp4971
Logic errorDereference of null pointerperfEvents_linux.cppunregisterThread72026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9a545ac893

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ddprof-test/build.gradle.kts Resolved
Comment thread utils/merge-coverage.sh Resolved

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: FAIL

Two of the most critical issues are a Git mount/clone path overlap that causes every worktree coverage cell to fail before testing, and an unescaped eval of the coverage output path that allows shell injection and silently redirects exports to the wrong location. A separate gcovr version mismatch between the preflight-checked host and the unpinned container image can abort coverage merging after the full matrix completes.

Open Bits AI session

🤖 Bits Code Review · Commit 9a545ac

Comment thread utils/run-containers-tests.sh Resolved
Comment thread .agents/skills/test-coverage/SKILL.md Resolved
Comment thread utils/run-containers-tests.sh Resolved
@dd-octo-sts

dd-octo-sts Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

CI Test Results

Run: #43103255998 | Commit: 92b1fe3 | Duration: 20m 10s (longest job)

✅ All 32 test jobs passed

Status Overview

JDK glibc-aarch64/debug glibc-amd64/debug musl-aarch64/debug musl-amd64/debug
8 - ✅ - -
8-ibm - ✅ - -
8-j9 ✅ ✅ - -
8-librca - - ✅ ✅
8-orcl - ✅ - -
11 - ✅ - -
11-j9 ✅ ✅ - -
11-librca - - ✅ ✅
17 ✅ ✅ - -
17-graal ✅ ✅ - -
17-j9 ✅ ✅ - -
17-librca - - ✅ ✅
21 ✅ ✅ - -
21-graal ✅ ✅ - -
21-librca - - ✅ ✅
25 ✅ ✅ - -
25-graal ✅ ✅ - -
25-librca - - ✅ ✅

Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled

Summary: Total: 32 | Passed: 32 | Failed: 0


Updated: 2026-11-12 14:26:00 UTC

zhengyu123 and others added 4 commits November 9, 2026 09:06
- run-containers-tests.sh: shell-escape mount paths with %q; reject a worktree
  git dir that overlaps a container path
- ddprof-test: fail -Ptests runs where neither coverage task matched a test
- merge-coverage.sh: reject uncommitted changes under ddprof-lib/src/main
- test-coverage skill: recheck gcovr version on the final base images

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
jacocoTestReport is skipped when no .exec file exists, so a guard in its
actions never ran. Count executed tests from the result XML in
checkCoverageTestFailures instead.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Clear old result XML before the coverage tasks (the musl runner never does),
report deferred test failures before the no-match error, and count only
tests that ran (not skipped).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@dd-octo-sts

dd-octo-sts Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

✅ All 40 integration tests passed

📊 Dashboard · 👷 Pipeline · 📦 ae6dca81

Comment thread doc/building/CodeCoverage.md Resolved
Comment thread ddprof-test/build.gradle.kts Resolved
Comment thread utils/merge-coverage.sh Resolved
Comment thread utils/run-containers-tests.sh Resolved
Comment thread utils/run-containers-tests.sh Resolved
Comment thread .agents/skills/test-coverage/SKILL.md Resolved
zhengyu123 and others added 4 commits November 11, 2026 10:16
- Count skipped tests as matched when checking -Ptests, so a valid pattern
  gated off on one JVM does not fail the cell.
- Mark cells without exported classes "unverified (no classes)".
- Refuse a non-empty --coverage-out that is not an earlier export.
- Resolve the git common dir without --path-format; reject --mount from a worktree.
- Fetch all of origin before resolving the ref in the skill.
- Reword the JDK note in CodeCoverage.md.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- Re-mark "unverified (no classes)" cells when no cell exports classes.
- Create cell.properties before the export copies, so a partial export is
  still recognized as an export by the --coverage-out guard.
- Plant a valid earlier export in the script tests and test the guard.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The pattern was spliced into a command that is evaluated twice, so --tests
was restricted to a character allow-list that rejected valid filters such
as Outer$Inner. Pass it as TESTS_FILTER and quote the expansion in the
container; only a newline is still rejected.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: FAIL

The PR adds merged C++/Java coverage across Linux platforms and JVMs; post-build gcovr checks and intentional rejection of overlapping worktree paths address the earlier findings. One export-marker defect remains: incomplete exports can abort otherwise-valid merges, and interrupted rootful reruns can lose retry eligibility.

Open Bits AI session

🤖 Bits Code Review · Commit 4689429

Comment thread utils/run-containers-tests.sh Resolved
@datadog-official

datadog-official Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Pipelines

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: ae6dca8 | Docs | View more details | Give us feedback!

zhengyu123 and others added 2 commits November 11, 2026 10:46
- Skip the -Ptests no-match check when no coverage test task ran, so a
  gtest failure is not masked; read only each result XML's header.
- Merge Java coverage against the class tree most cells share.
- Reject a colon in mounted paths, and tracked changes in the source tree,
  for a coverage cell.
- Trust only the mounted git dirs in the container, not every path.
- Warn on an unverified JACOCO_CLI; add timeouts and retries to the download.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: FAIL

The PR merges Linux/JVM C++ and Java coverage, with earlier gcovr compatibility and worktree-path concerns addressed. Export-marker handling still lets incomplete cells abort merges and strands interrupted rootful retries; additionally, the new dirty-tree check rejects reruns when their own output is unignored inside the checkout.

Open Bits AI session

🤖 Bits Code Review · Commit 4da17f3

Comment thread utils/run-containers-tests.sh Resolved
zhengyu123 and others added 2 commits November 11, 2026 14:36
cell.properties was both the marker that lets a run reuse a non-empty
--coverage-out and the signal that a cell is ready to merge. A failed copy
left an empty one behind, which the merge then rejected. A host cleanup could
remove it while root-owned reports stayed, so the retry failed the guard.

The host now creates .coverage-cell, which nothing removes. The export writes
cell.properties last, through a rename, so it exists only after a complete
export. The source-cleanliness check also ignores a --coverage-out directory
inside the checkout, so a rerun can replace its own earlier export.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The skill deleted the whole cell directory before a retry, which also
removed .coverage-cell. On rootful Docker the root-owned export files
stayed behind, so the retry failed the --coverage-out guard. The skill
now removes only <cell>.exit, and the script clears the earlier export.

The in-checkout exclusion compares physical paths, so a symlinked alias of
the checkout is still recognised. The partial-export test is skipped as
root, which can read a mode-000 file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@datadog-official datadog-official Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

The PR merges C++/Java coverage across Linux/JVM cells, with earlier gcovr and worktree-path concerns addressed. Both remaining findings are fixed: incomplete exports stay out of merges, rootful retries retain their ownership marker, and generated output no longer makes an otherwise clean checkout fail.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit f0b5575

zhengyu123 and others added 4 commits November 11, 2026 15:19
One rejected tracefile aborted merge-coverage.sh under set -e. The Java
report and summary.md were not written, and the error did not name the
cell. On a failed gcovr merge the script now checks each tracefile on its
own and leaves the rejected cells out of the C++ report. It then merges the
rest, still writes the Java report and summary.md, and exits with 2.

A cell whose Gradle was killed by a signal (gradle_exit >= 128) still
exported partial data, and the merge counted it. merge-coverage.sh now
leaves such cells out of both reports. The skill merges only passed and
failed cells, because a daemon that disappears exits with 1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When gcovr rejects every tracefile, merge-coverage.sh now blames the host
gcovr, not each cell, and stops early when gcovr is missing. The per-cell
check uses the merge's function mode. When no single tracefile is rejected,
the merge is not run a second time. The closing line lists only the reports
that exist.

The skill records each cell's status in <cell>.status and merges the passed
and failed cells from those files, not from a hand-written list. The docs
describe exit 2 as an incomplete C++ report, with the reason per cell in
summary.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A missing gcovr stopped merge-coverage.sh before the Java report. It now
marks the C++ column "gcovr not found", still writes the Java report and
summary.md, and exits with 2. A rejected tracefile always names its cell.
The host-gcovr hint appears only when more than one tracefile was probed
and all were rejected.

The skill's merge snippet lists status files with find, which works in
bash and zsh, and warns on an unknown status. The docs say when there is no
C++ report at all.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zhengyu123
zhengyu123 requested a review from rkennke November 12, 2026 16:07
@zhengyu123
zhengyu123 marked this pull request as draft November 12, 2026 16:23

@kaahos kaahos left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, nothing blocking! I left 1 improvement suggestion.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants