From de832d157ea99a4dacf379d789e6f43582179920 Mon Sep 17 00:00:00 2001 From: Qing Yang Date: Thu, 19 Oct 2023 11:37:30 -0700 Subject: [PATCH] coverage on crash --- README.md | 1 + testing/code_coverage/Test.swift | 4 ++++ testing/code_coverage/build_and_test.sh | 6 +++++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2cd8b7d..5ace1bd 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ This repo is mostly my study notes about low level iOS. * Testing * [Behind the scenes: iOS Testing](./articles/iOSTesting.md) * [Behind the scenes: Code Coverage](./articles/CodeCoverage.md) + * [Code Coverage on Test Crash](./articles/CodeCoverageOnTestCrash.md) * [Archived] [XCTest](./xctest) * Xcode * [Behind the scenes: SwiftUI Previews](./articles/SwiftUIPreview.md) diff --git a/testing/code_coverage/Test.swift b/testing/code_coverage/Test.swift index dc95841..211b93e 100644 --- a/testing/code_coverage/Test.swift +++ b/testing/code_coverage/Test.swift @@ -7,4 +7,8 @@ class Tests: XCTestCase { XCTAssert(foo.func1(a: 0) == 0) XCTAssert(foo.func1(a: 2) == 1) } + + // func testForceCrash() { + // assertionFailure("Crash") + // } } diff --git a/testing/code_coverage/build_and_test.sh b/testing/code_coverage/build_and_test.sh index 7322a0d..0e6439b 100755 --- a/testing/code_coverage/build_and_test.sh +++ b/testing/code_coverage/build_and_test.sh @@ -37,13 +37,17 @@ xcrun clang -bundle -o $TEST_BINARY build/Test.o \ PROFRAW_FILE="/tmp/test.profraw" PROFDATA_FILE="/tmp/test.profdata" -export SIMCTL_CHILD_LLVM_PROFILE_FILE="$PROFRAW_FILE" +# %c enables a mode in which profile counter updates are continuously synced to a file +export SIMCTL_CHILD_LLVM_PROFILE_FILE="$PROFRAW_FILE%c" rm -f $PROFRAW_FILE $PROFDATA_FILE +# Don't exit if test fails +set +e xcrun simctl spawn --arch=$ARCH --standalone "iPhone 14 Pro" \ "$PLATFORM_DIR/Developer/Library/Xcode/Agents/xctest" \ $PWD/build/Test.xctest +set -e xcrun llvm-profdata merge -sparse "$PROFRAW_FILE" -o "$PROFDATA_FILE"