Skip to content

workflows/check: Add test code coverage#763

Draft
RobertZ2011 wants to merge 1 commit intoOpenDevicePartnership:v0.2.0from
RobertZ2011:test-coverage-report
Draft

workflows/check: Add test code coverage#763
RobertZ2011 wants to merge 1 commit intoOpenDevicePartnership:v0.2.0from
RobertZ2011:test-coverage-report

Conversation

@RobertZ2011
Copy link
Contributor

No description provided.

Copilot AI review requested due to automatic review settings March 25, 2026 23:44
@RobertZ2011 RobertZ2011 self-assigned this Mar 25, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends the existing CI “check” workflow by adding Rust test code coverage generation and uploading the resulting HTML report as a workflow artifact.

Changes:

  • Attempts to install LLVM coverage tooling for the Rust toolchain.
  • Runs cargo test with coverage instrumentation enabled.
  • Adds steps to merge raw profiles, generate an HTML coverage report via grcov, and upload it as an artifact.

submodules: true
- name: Install stable
uses: dtolnay/rust-toolchain@stable
components: llvm-tools
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

dtolnay/rust-toolchain step inputs must be under with:. As written, components: llvm-tools is not passed to the action, so the LLVM tools (and rust-profdata) likely won’t be installed and later coverage steps will fail. Move the component under with: (and ensure the correct rustup component name is used for rust-profdata).

Suggested change
components: llvm-tools
with:
components: llvm-tools-preview

Copilot uses AI. Check for mistakes.
Comment on lines 156 to +159
- name: cargo test
run: cargo test --locked
env:
RUSTFLAGS: '-C instrument-coverage'
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

Coverage instrumentation sets RUSTFLAGS=-C instrument-coverage, but LLVM_PROFILE_FILE isn’t set. Without a per-process filename pattern, test binaries can overwrite the same .profraw, producing incomplete/incorrect coverage data. Set LLVM_PROFILE_FILE to a unique pattern (e.g., including %p/%m) and preferably write it into a known directory under target/.

Copilot uses AI. Check for mistakes.
- name: Install rustfilt
run: cargo install rustfilt
- name : Merge raw profiles
run: rust-profdata merge -sparse *.profraw -o coverage.profdata
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

The merge step assumes .profraw files exist in the repo root (*.profraw). Depending on where the tests run and how profiling output is configured, the files may be emitted elsewhere (or not match the glob), causing this step to fail. Consider merging from the directory you configure via LLVM_PROFILE_FILE, or using find to collect the .profraw inputs robustly.

Suggested change
run: rust-profdata merge -sparse *.profraw -o coverage.profdata
run: rust-profdata merge -sparse $(find . -name '*.profraw' -print) -o coverage.profdata

Copilot uses AI. Check for mistakes.
Comment on lines +164 to +167
- name: Install grcov
run: cargo install grcov
- name: Install rustfilt
run: cargo install rustfilt
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

Installing grcov and rustfilt via cargo install without pinning versions makes CI non-reproducible and can break when upstream releases change. Prefer pinning --version (and --locked) or using an install action (e.g., taiki-e/install-action) to get consistent binaries and faster runs via caching.

Suggested change
- name: Install grcov
run: cargo install grcov
- name: Install rustfilt
run: cargo install rustfilt
- name: Install grcov and rustfilt
uses: taiki-e/install-action@v2
with:
tool: grcov,rustfilt
tool-version: 0.8.18,0.2.1

Copilot uses AI. Check for mistakes.
@RobertZ2011 RobertZ2011 force-pushed the test-coverage-report branch from 4bd6053 to 5e295dc Compare March 25, 2026 23:49
Copilot AI review requested due to automatic review settings March 25, 2026 23:56
@RobertZ2011 RobertZ2011 force-pushed the test-coverage-report branch from 5e295dc to e40955b Compare March 25, 2026 23:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.

run: rust-profdata merge -sparse *.profraw -o coverage.profdata
- name: Generate code coverage report
run: |
grcov . --binary-path ./target/debug/ -s . -t html --ignore-not-existing -o ./target/debug/coverage/ coverage.profdata
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

The grcov invocation is generating a report from an LLVM .profdata, but it doesn't pass LLVM-specific options and only points --binary-path at ./target/debug/ (test binaries usually live under target/debug/deps). As written this can produce an empty/incomplete report. Consider enabling LLVM mode in grcov and including the deps directory (or otherwise pointing grcov at the actual test binaries used to generate the profiles).

Suggested change
grcov . --binary-path ./target/debug/ -s . -t html --ignore-not-existing -o ./target/debug/coverage/ coverage.profdata
grcov . \
--binary-path ./target/debug/ \
--binary-path ./target/debug/deps/ \
-s . \
-t html \
--llvm \
--ignore-not-existing \
-o ./target/debug/coverage/ \
coverage.profdata

Copilot uses AI. Check for mistakes.
- name: cargo test
run: cargo test --locked
env:
RUSTFLAGS: '-C instrument-coverage'
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

-C instrument-coverage relies on LLVM profile output files; without setting LLVM_PROFILE_FILE to a unique pattern (e.g., including %p), parallel cargo test processes can overwrite/corrupt the same .profraw and make coverage flaky/incorrect. Set LLVM_PROFILE_FILE (and consider CARGO_INCREMENTAL=0) in this step's env so all profiles are written deterministically to a known directory.

Suggested change
RUSTFLAGS: '-C instrument-coverage'
RUSTFLAGS: '-C instrument-coverage'
LLVM_PROFILE_FILE: 'default-%p-%m.profraw'
CARGO_INCREMENTAL: '0'

Copilot uses AI. Check for mistakes.
Comment on lines +169 to +170
- name : Merge raw profiles
run: rust-profdata merge -sparse *.profraw -o coverage.profdata
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

This step installs llvm-tools-preview but merges profiles using rust-profdata. For clarity/portability across toolchains, prefer using the LLVM tool name (llvm-profdata) that is provided by the component, and make the input glob/path match wherever LLVM_PROFILE_FILE writes the .profraw files.

Copilot uses AI. Check for mistakes.
@RobertZ2011 RobertZ2011 force-pushed the test-coverage-report branch 2 times, most recently from 66036c8 to 950eb34 Compare March 26, 2026 00:04
Copilot AI review requested due to automatic review settings March 26, 2026 00:04
@RobertZ2011 RobertZ2011 force-pushed the test-coverage-report branch 2 times, most recently from 15d3fa4 to b4b6053 Compare March 26, 2026 00:17
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment on lines +171 to 173
name: code-coverage-report
path: ./target/debug/coverage/

Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

grcov typically needs LLVM mode enabled when consuming .profraw/.profdata generated by -C instrument-coverage; otherwise it may not interpret the profile data correctly and can produce an empty/incorrect report. Consider adding the appropriate LLVM flag(s) for grcov when generating the HTML report.

Copilot uses AI. Check for mistakes.
Comment on lines +169 to +170
uses: actions/upload-artifact@v4
with:
Copy link

Copilot AI Mar 26, 2026

Choose a reason for hiding this comment

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

Minor YAML style: this step uses - name : whereas the rest of the workflow uses - name:. Consider normalizing formatting for consistency/readability.

Copilot uses AI. Check for mistakes.
@RobertZ2011 RobertZ2011 force-pushed the test-coverage-report branch from b4b6053 to d8a8f6b Compare March 26, 2026 00:23
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.

2 participants