From d517fb23915395554b2b060af05ab03461352dda Mon Sep 17 00:00:00 2001 From: Kent Ma Date: Wed, 11 Aug 2021 09:17:27 -0400 Subject: [PATCH] Correctly calculate coverage by calling `blaze coverage` on individual tests (#565) --- .../SNTEndpointSecurityManagerTest.mm | 7 +++--- coverage/generate_cov.sh | 24 ++++++++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Source/santad/EventProviders/SNTEndpointSecurityManagerTest.mm b/Source/santad/EventProviders/SNTEndpointSecurityManagerTest.mm index be9b80e33..d4027c3da 100644 --- a/Source/santad/EventProviders/SNTEndpointSecurityManagerTest.mm +++ b/Source/santad/EventProviders/SNTEndpointSecurityManagerTest.mm @@ -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, }; @@ -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, @@ -198,7 +198,6 @@ - (void)testSkipOtherESEvents { }]; XCTAssertEqual(got.result, ES_AUTH_RESULT_ALLOW); - XCTAssertEqual(got.shouldCache, false); } @end diff --git a/coverage/generate_cov.sh b/coverage/generate_cov.sh index a25d4130c..031f723ba 100755 --- a/coverage/generate_cov.sh +++ b/coverage/generate_cov.sh @@ -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