diff --git a/.github/workflows/darwin.yaml b/.github/workflows/darwin.yaml index 1eddaec04a8667..99306feef42225 100644 --- a/.github/workflows/darwin.yaml +++ b/.github/workflows/darwin.yaml @@ -116,6 +116,8 @@ jobs: # -enableUndefinedBehaviorSanitizer instruments the code in Matter.framework, # but to instrument the code in the underlying libCHIP we need to pass CHIP_IS_UBSAN=YES 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-unguarded-availability-new' CHIP_IS_UBSAN=YES CHIP_IS_BLE=NO > >(tee /tmp/darwin/framework-tests/darwin-tests-asan.log) 2> >(tee /tmp/darwin/framework-tests/darwin-tests-asan-err.log >&2) + # And the same thing, but with MTR_PER_CONTROLLER_STORAGE_ENABLED turned on. + 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-unguarded-availability-new' CHIP_IS_UBSAN=YES CHIP_IS_BLE=NO GCC_PREPROCESSOR_DEFINITIONS='${inherited} MTR_PER_CONTROLLER_STORAGE_ENABLED=1' > >(tee /tmp/darwin/framework-tests/darwin-tests-asan-provisional.log) 2> >(tee /tmp/darwin/framework-tests/darwin-tests-asan-provisional-err.log >&2) # -enableThreadSanitizer instruments the code in Matter.framework, # but to instrument the code in the underlying libCHIP we need to pass CHIP_IS_TSAN=YES xcodebuild test -target "Matter" -scheme "Matter Framework Tests" -sdk macosx -enableThreadSanitizer YES OTHER_CFLAGS='${inherited} -Werror -Wconversion -Wno-unguarded-availability-new' CHIP_IS_TSAN=YES CHIP_IS_BLE=NO > >(tee /tmp/darwin/framework-tests/darwin-tests-tsan.log) 2> >(tee /tmp/darwin/framework-tests/darwin-tests-tsan-err.log >&2) diff --git a/src/darwin/Framework/CHIP/MTRDefines.h b/src/darwin/Framework/CHIP/MTRDefines.h index dab6250019e325..206ae4d856fcc5 100644 --- a/src/darwin/Framework/CHIP/MTRDefines.h +++ b/src/darwin/Framework/CHIP/MTRDefines.h @@ -53,12 +53,20 @@ #define MTR_NEWLY_AVAILABLE #endif -#if defined(MTR_ENABLE_PROVISIONAL) && MTR_ENABLE_PROVISIONAL +#if !defined(MTR_ENABLE_PROVISIONAL) +#define MTR_ENABLE_PROVISIONAL 0 +#endif + +#if MTR_ENABLE_PROVISIONAL #define MTR_PROVISIONALLY_AVAILABLE MTR_NEWLY_AVAILABLE #else #define MTR_PROVISIONALLY_AVAILABLE NS_UNAVAILABLE MTR_HIDDEN #endif +#ifndef MTR_PER_CONTROLLER_STORAGE_ENABLED +#define MTR_PER_CONTROLLER_STORAGE_ENABLED 0 +#endif + #pragma mark - Types typedef NSData * MTRTLVBytes; diff --git a/src/darwin/Framework/CHIP/MTRDeviceController.h b/src/darwin/Framework/CHIP/MTRDeviceController.h index 670e12bbd0caaf..d8636796707946 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController.h +++ b/src/darwin/Framework/CHIP/MTRDeviceController.h @@ -47,10 +47,12 @@ typedef void (^MTRDeviceConnectionCallback)(MTRBaseDevice * _Nullable device, NS */ @property (readonly, nonatomic, getter=isRunning) BOOL running; +#if MTR_PER_CONTROLLER_STORAGE_ENABLED /** * The ID assigned to this controller at creation time. */ @property (readonly, nonatomic) NSUUID * uniqueIdentifier MTR_NEWLY_AVAILABLE; +#endif // MTR_PER_CONTROLLER_STORAGE_ENABLED /** * Return the Node ID assigned to the controller. Will return nil if the diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerDataStore.h b/src/darwin/Framework/CHIP/MTRDeviceControllerDataStore.h index 8d10c7af3e810b..3abab9ea48adcc 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerDataStore.h +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerDataStore.h @@ -17,7 +17,11 @@ #import #import #import +#if MTR_PER_CONTROLLER_STORAGE_ENABLED #import +#else +#import "MTRDeviceControllerStorageDelegate_Wrapper.h" +#endif // MTR_PER_CONTROLLER_STORAGE_ENABLED #include diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.h b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.h index 6471db8b005ccb..5cb4b7c7fd188f 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.h +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.h @@ -22,7 +22,12 @@ #import #import +#import +#if MTR_PER_CONTROLLER_STORAGE_ENABLED #import +#else +@class MTRDeviceControllerStartupParameters; +#endif // MTR_PER_CONTROLLER_STORAGE_ENABLED NS_ASSUME_NONNULL_BEGIN @@ -93,12 +98,15 @@ API_AVAILABLE(ios(16.4), macos(13.3), watchos(9.4), tvos(16.4)) */ - (instancetype)initWithStorage:(id)storage; +#if MTR_PER_CONTROLLER_STORAGE_ENABLED /* * Initialize the device controller factory without storage. In this mode, * device controllers will need to have per-controller storage provided to allow * storing controller-specific information. */ - (instancetype)init MTR_NEWLY_AVAILABLE; +#endif // MTR_PER_CONTROLLER_STORAGE_ENABLED + @end API_AVAILABLE(ios(16.4), macos(13.3), watchos(9.4), tvos(16.4)) @@ -180,6 +188,7 @@ API_AVAILABLE(ios(16.4), macos(13.3), watchos(9.4), tvos(16.4)) - (MTRDeviceController * _Nullable)createControllerOnNewFabric:(MTRDeviceControllerStartupParams *)startupParams error:(NSError * __autoreleasing *)error; +#if MTR_PER_CONTROLLER_STORAGE_ENABLED /** * Create an MTRDeviceController. Returns nil on failure. * @@ -191,6 +200,7 @@ API_AVAILABLE(ios(16.4), macos(13.3), watchos(9.4), tvos(16.4)) */ - (MTRDeviceController * _Nullable)createController:(MTRDeviceControllerStartupParameters *)startupParameters error:(NSError * __autoreleasing *)error MTR_NEWLY_AVAILABLE; +#endif // MTR_PER_CONTROLLER_STORAGE_ENABLED @end diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm index 195fb61f5c7b6a..31b261ad74b79a 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerFactory.mm @@ -34,6 +34,9 @@ #import "MTRPersistentStorageDelegateBridge.h" #import "MTRSessionResumptionStorageBridge.h" #import "NSDataSpanConversion.h" +#if !MTR_PER_CONTROLLER_STORAGE_ENABLED +#import "MTRDeviceControllerStartupParameters_Wrapper.h" +#endif // MTR_PER_CONTROLLER_STORAGE_ENABLED #import diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerStartupParameters.h b/src/darwin/Framework/CHIP/MTRDeviceControllerStartupParameters.h index 0fca31906c2e3b..7b69f0f3d96531 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerStartupParameters.h +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerStartupParameters.h @@ -15,13 +15,22 @@ */ #import - #import + +#if defined(MTR_INTERNAL_INCLUDE) && defined(MTR_INCLUDED_FROM_UMBRELLA_HEADER) +#error Internal includes should not happen from the umbrella header +#endif + +#if MTR_PER_CONTROLLER_STORAGE_ENABLED || defined(MTR_INTERNAL_INCLUDE) + #import #import NS_ASSUME_NONNULL_BEGIN +#if !MTR_PER_CONTROLLER_STORAGE_ENABLED +MTR_HIDDEN +#endif MTR_NEWLY_AVAILABLE @interface MTRDeviceControllerStartupParameters : NSObject @@ -68,6 +77,9 @@ MTR_NEWLY_AVAILABLE @end +#if !MTR_PER_CONTROLLER_STORAGE_ENABLED +MTR_HIDDEN +#endif MTR_NEWLY_AVAILABLE @interface MTRDeviceControllerExternalCertificateStartupParameters : MTRDeviceControllerStartupParameters @@ -119,3 +131,5 @@ MTR_NEWLY_AVAILABLE @end NS_ASSUME_NONNULL_END + +#endif // MTR_PER_CONTROLLER_STORAGE_ENABLED || defined(MTR_INTERNAL_INCLUDE) diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerStartupParameters_Wrapper.h b/src/darwin/Framework/CHIP/MTRDeviceControllerStartupParameters_Wrapper.h new file mode 100644 index 00000000000000..537958dabf37fb --- /dev/null +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerStartupParameters_Wrapper.h @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2023 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#if MTR_PER_CONTROLLER_STORAGE_ENABLED +#error Should be including Matter/MTRDeviceControllerStartupParameters.h +#endif // MTR_PER_CONTROLLER_STORAGE_ENABLED + +#define MTR_INTERNAL_INCLUDE +#import +#undef MTR_INTERNAL_INCLUDE diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerStartupParams.mm b/src/darwin/Framework/CHIP/MTRDeviceControllerStartupParams.mm index 7bbcea96183035..3da8a906c0886d 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerStartupParams.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerStartupParams.mm @@ -23,7 +23,11 @@ #import "MTRP256KeypairBridge.h" #import "NSDataSpanConversion.h" +#if MTR_PER_CONTROLLER_STORAGE_ENABLED #import +#else +#import "MTRDeviceControllerStorageDelegate_Wrapper.h" +#endif // MTR_PER_CONTROLLER_STORAGE_ENABLED #include #include diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerStartupParams_Internal.h b/src/darwin/Framework/CHIP/MTRDeviceControllerStartupParams_Internal.h index 734197ef72d2d6..9d52067d510982 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerStartupParams_Internal.h +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerStartupParams_Internal.h @@ -20,7 +20,11 @@ #import #import #import +#if MTR_PER_CONTROLLER_STORAGE_ENABLED #import +#else +#import "MTRDeviceControllerStartupParameters_Wrapper.h" +#endif // MTR_PER_CONTROLLER_STORAGE_ENABLED #include #include diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerStorageDelegate.h b/src/darwin/Framework/CHIP/MTRDeviceControllerStorageDelegate.h index 1fee9c65ae460c..2a322eb07f799a 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceControllerStorageDelegate.h +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerStorageDelegate.h @@ -15,8 +15,15 @@ */ #import +#import #import +#if defined(MTR_INTERNAL_INCLUDE) && defined(MTR_INCLUDED_FROM_UMBRELLA_HEADER) +#error Internal includes should not happen from the umbrella header +#endif + +#if MTR_PER_CONTROLLER_STORAGE_ENABLED || defined(MTR_INTERNAL_INCLUDE) + NS_ASSUME_NONNULL_BEGIN typedef NS_ENUM(NSUInteger, MTRStorageSecurityLevel) { @@ -105,6 +112,13 @@ MTR_NEWLY_AVAILABLE @end // TODO: FIXME: Is this a sane place to put this API? -MTR_EXTERN MTR_NEWLY_AVAILABLE NSSet * MTRDeviceControllerStorageClasses(void); +#if MTR_PER_CONTROLLER_STORAGE_ENABLED +MTR_EXTERN +#else +MTR_HIDDEN +#endif // MTR_PER_CONTROLLER_STORAGE_ENABLED +MTR_NEWLY_AVAILABLE NSSet * MTRDeviceControllerStorageClasses(void); NS_ASSUME_NONNULL_END + +#endif // MTR_PER_CONTROLLER_STORAGE_ENABLED || defined(MTR_INTERNAL_INCLUDE) diff --git a/src/darwin/Framework/CHIP/MTRDeviceControllerStorageDelegate_Wrapper.h b/src/darwin/Framework/CHIP/MTRDeviceControllerStorageDelegate_Wrapper.h new file mode 100644 index 00000000000000..774fff9f48a179 --- /dev/null +++ b/src/darwin/Framework/CHIP/MTRDeviceControllerStorageDelegate_Wrapper.h @@ -0,0 +1,25 @@ +/** + * Copyright (c) 2023 Project CHIP Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#if MTR_PER_CONTROLLER_STORAGE_ENABLED +#error Should be including Matter/MTRDeviceControllerStorageDelegate.h +#endif // MTR_PER_CONTROLLER_STORAGE_ENABLED + +#define MTR_INTERNAL_INCLUDE +#import +#undef MTR_INTERNAL_INCLUDE diff --git a/src/darwin/Framework/CHIP/MTRDeviceController_Internal.h b/src/darwin/Framework/CHIP/MTRDeviceController_Internal.h index 6ff5843f622513..2f86a4edb88fec 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController_Internal.h +++ b/src/darwin/Framework/CHIP/MTRDeviceController_Internal.h @@ -32,7 +32,11 @@ #import "MTRDeviceControllerDataStore.h" #import +#if MTR_PER_CONTROLLER_STORAGE_ENABLED #import +#else +#import "MTRDeviceControllerStorageDelegate_Wrapper.h" +#endif // MTR_PER_CONTROLLER_STORAGE_ENABLED #import @class MTRDeviceControllerStartupParamsInternal; @@ -51,6 +55,13 @@ NS_ASSUME_NONNULL_BEGIN @interface MTRDeviceController () +#if !MTR_PER_CONTROLLER_STORAGE_ENABLED +/** + * The ID assigned to this controller at creation time. + */ +@property (readonly, nonatomic) NSUUID * uniqueIdentifier MTR_NEWLY_AVAILABLE; +#endif // MTR_PER_CONTROLLER_STORAGE_ENABLED + #pragma mark - MTRDeviceControllerFactory methods /** diff --git a/src/darwin/Framework/CHIP/Matter.h b/src/darwin/Framework/CHIP/Matter.h index 26c74cd80487d2..63c067f48d084d 100644 --- a/src/darwin/Framework/CHIP/Matter.h +++ b/src/darwin/Framework/CHIP/Matter.h @@ -17,6 +17,8 @@ #import +#define MTR_INCLUDED_FROM_UMBRELLA_HEADER + #import #import #import @@ -57,3 +59,5 @@ #import #import #import + +#undef MTR_INCLUDED_FROM_UMBRELLA_HEADER diff --git a/src/darwin/Framework/CHIPTests/MTRControllerAdvertisingTests.m b/src/darwin/Framework/CHIPTests/MTRControllerAdvertisingTests.m index 1276e0ce845bca..549d66ec3826a5 100644 --- a/src/darwin/Framework/CHIPTests/MTRControllerAdvertisingTests.m +++ b/src/darwin/Framework/CHIPTests/MTRControllerAdvertisingTests.m @@ -24,6 +24,8 @@ #import "MTRTestKeys.h" #import "MTRTestPerControllerStorage.h" +#if MTR_PER_CONTROLLER_STORAGE_ENABLED + static const uint16_t kTestVendorId = 0xFFF1u; static const uint16_t kTimeoutInSeconds = 3; @@ -295,3 +297,5 @@ - (void)test001_CheckAdvertisingAsExpected } @end + +#endif // MTR_PER_CONTROLLER_STORAGE_ENABLED diff --git a/src/darwin/Framework/CHIPTests/MTRPerControllerStorageTests.m b/src/darwin/Framework/CHIPTests/MTRPerControllerStorageTests.m index 894eb5f3893464..f81cc23af4e44e 100644 --- a/src/darwin/Framework/CHIPTests/MTRPerControllerStorageTests.m +++ b/src/darwin/Framework/CHIPTests/MTRPerControllerStorageTests.m @@ -25,6 +25,8 @@ #import "MTRTestPerControllerStorage.h" #import "MTRTestResetCommissioneeHelper.h" +#if MTR_PER_CONTROLLER_STORAGE_ENABLED + static const uint16_t kPairingTimeoutInSeconds = 10; static const uint16_t kTimeoutInSeconds = 3; static NSString * kOnboardingPayload = @"MT:-24J0AFN00KA0648G00"; @@ -1055,3 +1057,5 @@ - (void)test007_TestMultipleControllers } @end + +#endif // MTR_PER_CONTROLLER_STORAGE_ENABLED diff --git a/src/darwin/Framework/CHIPTests/TestHelpers/MTRTestPerControllerStorage.h b/src/darwin/Framework/CHIPTests/TestHelpers/MTRTestPerControllerStorage.h index b3052a9929a1af..427d537e07b485 100644 --- a/src/darwin/Framework/CHIPTests/TestHelpers/MTRTestPerControllerStorage.h +++ b/src/darwin/Framework/CHIPTests/TestHelpers/MTRTestPerControllerStorage.h @@ -17,6 +17,8 @@ #import #import +#if MTR_PER_CONTROLLER_STORAGE_ENABLED + NS_ASSUME_NONNULL_BEGIN @interface MTRTestPerControllerStorage : NSObject @@ -41,3 +43,5 @@ NS_ASSUME_NONNULL_BEGIN @end NS_ASSUME_NONNULL_END + +#endif // MTR_PER_CONTROLLER_STORAGE_ENABLED diff --git a/src/darwin/Framework/CHIPTests/TestHelpers/MTRTestPerControllerStorage.m b/src/darwin/Framework/CHIPTests/TestHelpers/MTRTestPerControllerStorage.m index 1898bd14832cf9..1a453d5eaec281 100644 --- a/src/darwin/Framework/CHIPTests/TestHelpers/MTRTestPerControllerStorage.m +++ b/src/darwin/Framework/CHIPTests/TestHelpers/MTRTestPerControllerStorage.m @@ -18,6 +18,8 @@ #import "MTRTestPerControllerStorage.h" +#if MTR_PER_CONTROLLER_STORAGE_ENABLED + @interface MTRTestPerControllerStorage () @property (nonatomic, readonly) NSMutableDictionary * storage; @end @@ -83,3 +85,5 @@ - (BOOL)controller:(MTRDeviceController *)controller } @end + +#endif // MTR_PER_CONTROLLER_STORAGE_ENABLED