Skip to content

Commit

Permalink
Correctly calculate coverage by calling blaze coverage on individua…
Browse files Browse the repository at this point in the history
…l tests (#565)
  • Loading branch information
tnek committed Aug 11, 2021
1 parent df4134c commit d517fb2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ - (void)testDenyOnTimeout {
.version = 4,
.event_type = ES_EVENT_TYPE_AUTH_UNLINK,
.event = event,
.mach_time = DISPATCH_TIME_NOW,
.mach_time = 1234,
.action_type = ES_ACTION_TYPE_AUTH,
.deadline = DISPATCH_TIME_NOW,
.deadline = 1234,
.process = &proc,
.seq_num = 1337,
};
Expand Down Expand Up @@ -164,7 +164,7 @@ - (void)testSkipOtherESEvents {
[expectation fulfill];
}];

es_file_t dbFile = {.path = MakeStringToken(kEventsDBPath)};
es_file_t dbFile = {.path = MakeStringToken(@"/some/other/path")};
es_file_t otherBinary = {.path = MakeStringToken(@"somebinary")};
es_process_t proc = {
.executable = &otherBinary,
Expand Down Expand Up @@ -198,7 +198,6 @@ - (void)testSkipOtherESEvents {
}];

XCTAssertEqual(got.result, ES_AUTH_RESULT_ALLOW);
XCTAssertEqual(got.shouldCache, false);
}

@end
24 changes: 13 additions & 11 deletions coverage/generate_cov.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,22 @@ PROFILE_PATH="$GIT_ROOT/CoverageData"
COV_FILE="$PROFILE_PATH/info.lcov"

function build() {
bazel coverage \
--test_env="LLVM_PROFILE_FILE=$PROFILE_PATH/default.profraw" \
--experimental_use_llvm_covmap \
--spawn_strategy=standalone \
--cache_test_results=no \
--test_env=LCOV_MERGER=/usr/bin/true \
--define=SANTA_BUILD_TYPE=ci \
//:unit_tests

xcrun llvm-profdata merge "$PROFILE_PATH/default.profraw" -output "$PROFILE_PATH/default.profdata"
tests=$(bazel query "tests(//:unit_tests)")
for t in $tests; do
profname=$(echo $t | shasum | awk '{print $1}')
bazel coverage \
--test_env="LLVM_PROFILE_FILE=$PROFILE_PATH/$profname.profraw" \
--experimental_use_llvm_covmap \
--spawn_strategy=standalone \
--cache_test_results=no \
--test_env=LCOV_MERGER=/usr/bin/true \
$t
done
xcrun llvm-profdata merge $PROFILE_PATH/*.profraw -output "$PROFILE_PATH/default.profdata"
}

function generate_lcov() {
object_files=$(find -L $(bazel info bazel-bin) -type f -exec file -L {} \; | grep "Mach-O" | sed 's,:.*,,')
object_files=$(find -L $(bazel info bazel-bin) -type f -exec file -L {} \; | grep "Mach-O" | sed 's,:.*,,' | grep -v 'testdata')
bazel_base=$(bazel info execution_root)

true > $COV_FILE
Expand Down

0 comments on commit d517fb2

Please sign in to comment.