Skip to content

Extend code-coverage to integration test #2103

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 6 commits into from
Mar 27, 2023

Conversation

cmaglie
Copy link
Member

@cmaglie cmaglie commented Mar 9, 2023

Please check if the PR fulfills these requirements

See how to contribute

  • The PR has no duplicates (please search among the Pull Requests
    before creating one)
  • The PR follows
    our contributing guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)
  • UPGRADING.md has been updated with a migration guide (for breaking changes)
  • configuration.schema.json updated if new parameters are added.

What kind of change does this PR introduce?

It's a tentative implementation of the solution described here: https://go.dev/blog/integration-test-coverage

Starting from golang >=1.20 go build supports the -cover* flags, so, not only the tests, but even the actual executable may be instrumented to produce code-coverage output, BTW there are some non-trivial interesting aspects:

  1. To produce the coverage output, the instrumented executable must be run with a GOCOVERDIR environment variable set to an existing directory path where the coverage data will be written. To accomplish this, I've added to the integration test the support for another env var INTEGRATION_GOCOVERDIR, the content of this variable will be passed to the arduino-cli run as GOCOVERDIR. We can not use GOCOVERDIR directly because it is overwritten by the go test ... command.
  2. The coverage data is output in binary form and we must convert it to text to be digested by CodeCov. This is done with the command tool covdata textfmt -i=coverage_data -o coverage_integration.txt that picks the content of the coverage_data directory and transforms it in a coverage_integration.txt.
  3. To upload the coverage data to CodeCov we must transfer the coverage output from each integration test job to the upload job. To accomplish this we exploit the upload_artifact capability to "add" files to an artifact, so it's just a matter of renaming the coverage_integration.txt file with a name that is unique among all integration test jobs. The current solution is: mv coverage_integration.txt coverage_integration_${{ matrix.operating-system }}_${{ matrix.tests }}.txt
  4. Finally we merge all the coverage artifacts together to obtain a single coverage.txt file to send to CodeCov. This is required because the CodeCov upload action apparently does not support globs like coverate_integration*.txt (or at least I wasn't able to make it work). To do this I've used the very good gocovmerge tool.

What is the current behavior?

Code-coverage is calculated only for unit tests.

What is the new behavior?

Code-coverage is calculated on unit test and integration tests, reaching a whooping total of 61.78%!

Does this PR introduce a breaking change, and is titled accordingly?

No

Other information

Fix #1829

@cmaglie cmaglie self-assigned this Mar 9, 2023
@codecov
Copy link

codecov bot commented Mar 9, 2023

Codecov Report

Patch coverage has no change and project coverage change: +26.79 🎉

Comparison is base (245e84c) 35.05% compared to head (eacd81c) 61.85%.

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #2103       +/-   ##
===========================================
+ Coverage   35.05%   61.85%   +26.79%     
===========================================
  Files         232      232               
  Lines       20480    19576      -904     
===========================================
+ Hits         7180    12108     +4928     
+ Misses      12455     6380     -6075     
- Partials      845     1088      +243     
Flag Coverage Δ
unit 61.85% <ø> (+26.79%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

see 166 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@cmaglie cmaglie force-pushed the increase_coverage branch 3 times, most recently from a525c3a to 50d6e3c Compare March 10, 2023 00:11
@cmaglie cmaglie marked this pull request as ready for review March 10, 2023 09:34
@cmaglie cmaglie force-pushed the increase_coverage branch from f4a894c to 0e3a9c9 Compare March 11, 2023 15:52
cmaglie added 6 commits March 14, 2023 09:43
The error was due to an increased git security constraints

  ...
  go: downloading github.com/xanzy/ssh-agent v0.2.1
  go: downloading gopkg.in/warnings.v0 v0.1.2
  error obtaining VCS status: exit status 128
	Use -buildvcs=false to disable VCS stamping.
  Error: failed building for darwin/amd64: exit status 1
  failed building for darwin/amd64: exit status 1
  task: Failed to run task "dist:macOS_64bit": exit status 1

To fix this I followed the suggestion here elastic/golang-crossbuild#232
Otherwise the process will not outut the coverage data.
@cmaglie cmaglie force-pushed the increase_coverage branch from 0e3a9c9 to eacd81c Compare March 14, 2023 11:13
@cmaglie cmaglie merged commit 5a5ae94 into arduino:master Mar 27, 2023
@cmaglie cmaglie deleted the increase_coverage branch March 27, 2023 13:36
@per1234 per1234 added type: enhancement Proposed improvement topic: infrastructure Related to project infrastructure labels Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: infrastructure Related to project infrastructure type: enhancement Proposed improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal to investigate: Increase test coverage using integration tests
3 participants