-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Stabilize fn coverage by creating a clean room #7576
Conversation
scripts/coverage.sh
Outdated
echo "Reverting files" | ||
find target/cov -newer target/cov/build-finished -type f -print -delete | ||
echo "Reverting (empty) directories" | ||
find target/cov -newer target/cov/build-finished -type d -empty -print -delete |
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.
After quick googling, I bet -delete
and -newer
is available on macOS. Dunno why the current code uses print0-and-xargs trick needlessly.
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.
As a matter of fact, this can't be replaced with the trick because we want to recursively remove directories which might get empty while doing search & destroy. The trick is effectively a BFS, and this find
is effectively a DFS.
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.
Confirmed macOS find
has -delete
and -newer
Cool I hope this helps! 🤞 |
scripts/coverage.sh
Outdated
source ci/rust-version.sh nightly | ||
|
||
RUST_LOG=solana=trace _ cargo +$rust_nightly test --target-dir target/cov --no-run "${packages[@]}" | ||
touch target/cov/build-finished |
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.
The new logic is simpler: Remove 'em all files and directories written after the build including any coverage data and report file. Just all of them.
Codecov Report
@@ Coverage Diff @@
## master #7576 +/- ##
========================================
+ Coverage 71.8% 81.7% +9.8%
========================================
Files 244 244
Lines 56626 49807 -6819
========================================
+ Hits 40680 40706 +26
+ Misses 15946 9101 -6845 |
This has to be better than the full |
After painful trials, I've found pruning doesn't work. The somewhat-complete detailed investigation report is here. :) The excerpt for the pinned-down culprit of our diverged coverage reports:
As shown above, the bad coverage report double-counts the total number of functions. This seems to happen for many files, not alone this. This is caused by the existence of stale My guess is that multiple stale Simply removing them doesn't help as well. Removing would cause Ideally, So, drawing from these tearful and restraining findings, as the last resort, let's stash updated and relevant coverage data files into a newly-created empty dir... (Sorry bad explanation; I'm getting tired... :p) |
scripts/coverage.sh
Outdated
find target/cov -name \*.gcda -newer "$timing_file" | | ||
(while read -r gcda_file; do | ||
gcno_file="${gcda_file%.gcda}.gcno" | ||
ln -s "../../../$gcda_file" "$data_dir/$(basename "$gcda_file")" |
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 guess realpath
isn't available on macOS...
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.
yeah realpath is a GNU program that requires an extra install for macOS. We can require it if absolutely needed but that's not ideal (another barrier for entry)
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 suggest just removing the data_dir
variable and directly embedding target/cov/tmp
everywhere data_dir
is used. The two ln
command aren't generic enough to handle any modifications to data_dir
due to the ../../..
so the variable doesn't really help much (and in fact could hurt a future person who attempts to modify this file).
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 think you have a nice point!: 690a7b3
scripts/coverage.sh
Outdated
rm -rf "$data_dir" | ||
mkdir -p "$data_dir" | ||
|
||
find target/cov -name \*.gcda -newer "$timing_file" | |
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'm curious why you didn't go for a simple for loop:
for gcda_file in $(find target/cov -name \*.gcda -newer "$timing_file"); do
declare gcno_file="${gcda_file%.gcda}.gcno"
ln -s "../../../$gcda_file" "$data_dir/$(basename "$gcda_file")"
ln -s "../../../$gcno_file" "$data_dir/$(basename "$gcno_file")"
done
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.
No problem. :) That's a natural question. In short, I wanted to avoid another shellcheck exception. (SC2044). And among various alternative loop constructions, I ended to choose this particular one based on existing other uses of find
in this script after some enduring time for compat. thinking. ;)
As a bonus for this round of commenting, I've made it more robust: 97fe9d9.
Ideally, I wanted to write like this (but I can't due to the restriction of bash 3+) based on this:
ryoqun@ubuqun:~/work/solana/solana$ git diff
diff --git a/scripts/coverage.sh b/scripts/coverage.sh
index 7a0df653a..3b985712f 100755
--- a/scripts/coverage.sh
+++ b/scripts/coverage.sh
@@ -51,12 +51,14 @@ mkdir -p target/cov/tmp
# Can't use a simpler construct under the condition of SC2044 and bash 3
# (macOS's default). See: https://github.com/koalaman/shellcheck/wiki/SC2044
-find target/cov -name \*.gcda -newer "$timing_file" -print0 |
- (while IFS= read -r -d '' gcda_file; do
+(
+ shopt -s globstar nullglob
+ for gcda_file in target/cov/**/*.gcda; do
gcno_file="${gcda_file%.gcda}.gcno"
ln -s "../../../$gcda_file" "target/cov/tmp/$(basename "$gcda_file")"
ln -s "../../../$gcno_file" "target/cov/tmp/$(basename "$gcno_file")"
- done)
+ done
+)
_ grcov target/cov/tmp > target/cov/lcov-full.info
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.
Thank for chasing this down!
f18c324
to
97fe9d9
Compare
@@ -31,9 +31,12 @@ export RUST_MIN_STACK=8388608 | |||
|
|||
echo "--- remove old coverage results" | |||
if [[ -d target/cov ]]; then | |||
find target/cov -name \*.gcda -print0 | xargs -0 rm -f | |||
find target/cov -name \*.gcda -delete |
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.
Let's utilize our new findings: #7576 (comment)
Problem
Coverage report is lying (partly). So, increasing coverage isn't fun. ;)
Summary of Changes
Casual quick inspection and my hunch says, this might fix the issue. :p I'll add the findings as a comment later. First, let the CI spin. :)
Found in the middle of #7546