Skip to content

Commit c80979a

Browse files
bzbarsky-applepull[bot]
authored andcommittedJul 22, 2023
Enable ThreadSanitizer in Darwin CI. (#26614)
* Enable ThreadSanitizer in Darwin CI. Unfortunately, "-enableAddressSanitizer NO" does not seem to override the scheme, and you can't do both AddressSanitizer and ThreadSanitizer at once, so this turns off AddressSanitizer in the scheme and manually enables it in the command line for the test. * Fix threading issue the new test caught.
1 parent 28764ad commit c80979a

File tree

4 files changed

+24
-8
lines changed

4 files changed

+24
-8
lines changed
 

‎.github/workflows/darwin.yaml

+7-4
Original file line numberDiff line numberDiff line change
@@ -136,23 +136,26 @@ jobs:
136136
run: defaults delete com.apple.dt.xctest.tool
137137
continue-on-error: true
138138
- name: Run Framework Tests
139-
timeout-minutes: 20
139+
timeout-minutes: 30
140140
# For now disable unguarded-availability-new warnings because we
141141
# internally use APIs that we are annotating as only available on
142142
# new enough versions. Maybe we should change out deployment
143143
# target versions instead?
144144
run: |
145145
mkdir -p /tmp/darwin/framework-tests
146146
../../../out/debug/chip-all-clusters-app --interface-id -1 > >(tee /tmp/darwin/framework-tests/all-cluster-app.log) 2> >(tee /tmp/darwin/framework-tests/all-cluster-app-err.log >&2) &
147-
# Make each ota-requestor is using a different port, discriminator, and KVS from
147+
# Make sure each ota-requestor is using a different port, discriminator, and KVS from
148148
# all-clusters-app and from other requestors.
149149
#
150150
# And a different port from the test harness too; the test harness uses port 5541.
151151
../../../out/debug/chip-ota-requestor-app --interface-id -1 --secured-device-port 5542 --discriminator 1111 --KVS /tmp/chip-ota-requestor-kvs1 --otaDownloadPath /tmp/chip-ota-requestor-downloaded-image1 --autoApplyImage > >(tee /tmp/darwin/framework-tests/ota-requestor-app-1.log) 2> >(tee /tmp/darwin/framework-tests/ota-requestor-app-err-1.log >&2) &
152152
../../../out/debug/chip-ota-requestor-app --interface-id -1 --secured-device-port 5543 --discriminator 1112 --KVS /tmp/chip-ota-requestor-kvs2 --otaDownloadPath /tmp/chip-ota-requestor-downloaded-image2 --autoApplyImage > >(tee /tmp/darwin/framework-tests/ota-requestor-app-2.log) 2> >(tee /tmp/darwin/framework-tests/ota-requestor-app-err-2.log >&2) &
153-
# UndefinedBehaviorSanitizer is enabled in the Xcode scheme, so the code in Matter.framework gets instrumented,
153+
# -enableUndefinedBehaviorSanitizer instruments the code in Matter.framework,
154154
# but to instrument the code in the underlying libCHIP we need to pass CHIP_IS_UBSAN=YES
155-
xcodebuild test -target "Matter" -scheme "Matter Framework Tests" -sdk macosx OTHER_CFLAGS='${inherited} -Werror -Wconversion -Wno-incomplete-umbrella -Wno-unguarded-availability-new' CHIP_IS_UBSAN=YES > >(tee /tmp/darwin/framework-tests/darwin-tests.log) 2> >(tee /tmp/darwin/framework-tests/darwin-tests-err.log >&2)
155+
TEST_RUNNER_ASAN_OPTIONS=__CURRENT_VALUE__:detect_stack_use_after_return=1 xcodebuild test -target "Matter" -scheme "Matter Framework Tests" -sdk macosx -enableAddressSanitizer YES -enableUndefinedBehaviorSanitizer YES OTHER_CFLAGS='${inherited} -Werror -Wconversion -Wno-incomplete-umbrella -Wno-unguarded-availability-new' CHIP_IS_UBSAN=YES > >(tee /tmp/darwin/framework-tests/darwin-tests-asan.log) 2> >(tee /tmp/darwin/framework-tests/darwin-tests-asan-err.log >&2)
156+
# -enableThreadSanitizer instruments the code in Matter.framework,
157+
# but to instrument the code in the underlying libCHIP we need to pass CHIP_IS_TSAN=YES
158+
xcodebuild test -target "Matter" -scheme "Matter Framework Tests" -sdk macosx -enableThreadSanitizer YES OTHER_CFLAGS='${inherited} -Werror -Wconversion -Wno-incomplete-umbrella -Wno-unguarded-availability-new' CHIP_IS_TSAN=YES > >(tee /tmp/darwin/framework-tests/darwin-tests-tsan.log) 2> >(tee /tmp/darwin/framework-tests/darwin-tests-tsan-err.log >&2)
156159
working-directory: src/darwin/Framework
157160
- name: Uploading log files
158161
uses: actions/upload-artifact@v3

‎src/darwin/Framework/CHIP/MTRAsyncCallbackWorkQueue.mm

+7-1
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,14 @@ - (instancetype)initWithContext:(id)context queue:(dispatch_queue_t)queue
6969

7070
- (NSString *)description
7171
{
72-
return [NSString
72+
os_unfair_lock_lock(&_lock);
73+
74+
auto * desc = [NSString
7375
stringWithFormat:@"MTRAsyncCallbackWorkQueue context: %@ items count: %lu", self.context, (unsigned long) self.items.count];
76+
77+
os_unfair_lock_unlock(&_lock);
78+
79+
return desc;
7480
}
7581

7682
- (void)enqueueWorkItem:(MTRAsyncCallbackQueueWorkItem *)item

‎src/darwin/Framework/Matter.xcodeproj/xcshareddata/xcschemes/Matter Framework Tests.xcscheme

+1-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
2929
shouldUseLaunchSchemeArgsEnv = "YES"
30-
enableAddressSanitizer = "YES"
31-
enableASanStackUseAfterReturn = "YES"
32-
enableUBSanitizer = "YES">
30+
enableASanStackUseAfterReturn = "YES">
3331
<Testables>
3432
<TestableReference
3533
skipped = "NO">

‎src/darwin/Framework/chip_xcode_build_connector.sh

+9
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,15 @@ declare -a args=(
139139
)
140140
}
141141

142+
[[ $CHIP_IS_TSAN == YES ]] && {
143+
args+=(
144+
'is_tsan=true'
145+
# The system stats stuff races on the stats in various ways,
146+
# so just disable it when using TSan.
147+
'chip_system_config_provide_statistics=false'
148+
)
149+
}
150+
142151
[[ $CHIP_IS_CLANG == YES ]] && {
143152
args+=(
144153
'is_clang=true'

0 commit comments

Comments
 (0)