Skip to content
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

Update github workflow to upload test coverage reports #759

Merged
merged 33 commits into from
Jan 6, 2023

Conversation

Chralt98
Copy link
Member

@Chralt98 Chralt98 commented Aug 17, 2022

@Chralt98
Copy link
Member Author

Chralt98 commented Aug 17, 2022

@sea212 @lsaether Is it okay to use and sign up on https://docs.codecov.com/docs#step-1-sign-up-for-codecov ? I have no admin access to the repository to integrate Codecov.

If you are signing up via GitHub, you may need to request access from an admin to authorize Codecov as a third-party application. For more information see GitHub OAuth Admin Authorization or follow our video guide.

@Chralt98 Chralt98 self-assigned this Aug 17, 2022
@Chralt98 Chralt98 marked this pull request as ready for review August 17, 2022 13:20
@Chralt98 Chralt98 added the s:review-needed The pull request requires reviews label Aug 17, 2022
@codecov-commenter
Copy link

codecov-commenter commented Aug 17, 2022

Codecov Report

❗ No coverage uploaded for pull request base (main@48ba93b). Click here to learn what that means.
The diff coverage is n/a.

@@           Coverage Diff           @@
##             main     #759   +/-   ##
=======================================
  Coverage        ?   92.23%           
=======================================
  Files           ?       80           
  Lines           ?    14062           
  Branches        ?        0           
=======================================
  Hits            ?    12970           
  Misses          ?     1092           
  Partials        ?        0           
Flag Coverage Δ
tests 92.23% <0.00%> (?)

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

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

vivekvpandya
vivekvpandya previously approved these changes Aug 18, 2022
Copy link
Contributor

@vivekvpandya vivekvpandya left a comment

Choose a reason for hiding this comment

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

It looks fine to me. I hope total turn around time is not increased much. Also I am wondering why grcov is used instead of llvm-cov. llvm-cov is available and it makes commands much simple with this cargo wrapper https://github.com/taiki-e/cargo-llvm-cov
however I am not able to find any comparison of grcov vs llvm-cov , only thing is that grcov is written in rust.

@maltekliemann
Copy link
Member

maltekliemann commented Aug 18, 2022

Just a dumb question: The report says 92.37% coverage. What exactly does that number mean? There seem to be two different workflows running, one for unit tests and one for fuzz tests, so I would have expected at least two numbers... right?

Also, doesn't this number seem surprisingly high? Can we get a complete list of lines of code reached/not reached?

Copy link
Member

@sea212 sea212 left a comment

Choose a reason for hiding this comment

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

Does CodeCov still need access to our repository?

Comment on lines 41 to 45
- name: Download grcov
run: |
mkdir -p "${HOME}/.local/bin"
curl -sL https://github.com/mozilla/grcov/releases/download/v0.8.11/grcov-x86_64-unknown-linux-gnu.tar.bz2 | tar jxf - -C "${HOME}/.local/bin"
echo "$HOME/.local/bin" >> $GITHUB_PATH
Copy link
Member

Choose a reason for hiding this comment

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

Can we use the grcov GH action instead?

Copy link
Member Author

@Chralt98 Chralt98 Sep 12, 2022

Choose a reason for hiding this comment

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

I tried it. When running the grcov github action it always returns the following error.

Error: Unable to find any coverage files, was `cargo test` executed correctly?

Although I executed cargo test as step before the grcov github action. I don't really know how to solve this.

In the example they use a github action for cargo test, but we use a script instead. But shouldn't be the result the same?

Copy link
Member Author

Choose a reason for hiding this comment

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

I couldn't find an example for grcov GH action for source-based coverage.

.github/workflows/rust.yml Outdated Show resolved Hide resolved
- name: Upload to codecov.io
uses: codecov/codecov-action@v3
with:
files: /misc/tests.lcov
Copy link
Member

Choose a reason for hiding this comment

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

Might want to use /tmp/tests.lcov instead to avoid potential permission issues.

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed in eb06f35

@Chralt98 Chralt98 added s:in-progress The pull requests is currently being worked on and removed s:review-needed The pull request requires reviews labels Sep 12, 2022
@Chralt98
Copy link
Member Author

Does CodeCov still need access to our repository?

That's a good question. I don't really know. I would assume no, because Codecov could comment on this PR, so I think it has been already added by Logan.

@Chralt98
Copy link
Member Author

Chralt98 commented Sep 12, 2022

The report says 92.37% coverage. What exactly does that number mean?

@maltekliemann I did use the lcov file and produced a html website out of it. And correct me if I am wrong, but I think we reached a code coverage of that level for our tests. I try to get another message from codecov, in which you can click on the report to see the code coverage for the different crates. The current message of Codecov is not correct at the moment. I wonder if this happens, when codecov is not initialised on the main branch. I need investigation time for that.

I would assume, that we need codecov on main, because of the error message from the codecov comment.

No coverage uploaded for pull request base (main@0e27079).

@Chralt98 Chralt98 added s:review-needed The pull request requires reviews s:in-progress The pull requests is currently being worked on and removed s:in-progress The pull requests is currently being worked on s:review-needed The pull request requires reviews labels Sep 13, 2022
@Chralt98 Chralt98 dismissed stale reviews from sea212 and vivekvpandya via 6d58521 September 26, 2022 11:53
@Chralt98
Copy link
Member Author

Chralt98 commented Sep 26, 2022

https://rust-fuzz.github.io/book/cargo-fuzz/coverage.html

Fuzz test coverage is extremely slow with the current version. I don't know how to solve this.

The fuzz coverage is outdated. Unfortunately I can't append my own compiler flags to get the result of code coverage for fuzz tests. rust-fuzz/cargo-fuzz#320

For the fuzz tests, the proposed way of cargo-fuzz always produces an empty lcov file. So the coverage doesn't seem to work at least for fuzz tests.

When I run cargo fuzz coverage --release --fuzz-dir zrml/swaps/fuzz pool_join for each fuzz target, then it takes extremely long to finish, because each corpus element runs. Even in release mode it takes so long.

For the normal tests I think the result is reasonable. I know, that there are some bugs like you Malte found out, but I think it's the fault of the current Substrate environment. At least we can detect paths, which are not covered at all from the tests. That's useful.

@@ -15,5 +15,6 @@ test_package_with_feature() {
local features=$2

/bin/echo -e "\e[0;33m***** Testing '$package' with features '$features' *****\e[0m\n"
cargo test --features $features --manifest-path $package/Cargo.toml --no-default-features --release
Copy link
Member Author

@Chralt98 Chralt98 Sep 27, 2022

Choose a reason for hiding this comment

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

We should avoid profile release for tests, so that debug_assert! macros are activated and we can see, that something is not as expected.

https://doc.rust-lang.org/cargo/reference/profiles.html#release

@Chralt98
Copy link
Member Author

Chralt98 commented Sep 27, 2022

I tried https://github.com/taiki-e/cargo-llvm-cov out @vivekvpandya . It had exactly the same result as we got with the current solution. Thanks for your investigation! I think it's fine as it is. With using cargo-llvm-cov (because it's a wrapper around cargo test) it's not so clear what actually happens (so the future maintainers would need to look up cargo-llsm-cov to understand that it's basically cargo test with code coverage and grcov).

@Chralt98 Chralt98 added s:review-needed The pull request requires reviews and removed s:in-progress The pull requests is currently being worked on labels Sep 27, 2022
@Chralt98
Copy link
Member Author

We got a slightly better time for the current fuzz workflow. It's now 56 minutes instead of on the main branch 66 minutes. This is because of the --release profile for the swaps fuzz tests. Just in case if somebody asks about if compile time with dev (debug) beats the speed of --release.

@maltekliemann maltekliemann removed their request for review October 2, 2022 16:06
@sea212 sea212 added s:accepted This pull request is ready for merge and removed s:review-needed The pull request requires reviews labels Jan 6, 2023
@Chralt98 Chralt98 merged commit 85cefa6 into main Jan 6, 2023
@Chralt98 Chralt98 deleted the chralt98-code-coverage branch January 6, 2023 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s:accepted This pull request is ready for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Analytics] Extend test workflow to generate and commit coverage reports
5 participants