From 25a120b3d04f09e9918450992f4cda62e0fdb264 Mon Sep 17 00:00:00 2001 From: samedson Date: Thu, 3 Oct 2024 11:24:12 -0400 Subject: [PATCH 1/4] Fix Performance Unit Tests requiring Swizzling --- .../Sources/Instrumentation/FPRSelectorInstrumentor.m | 4 ++-- FirebasePerformance/Tests/Unit/FPRClassInstrumentorTest.m | 4 ---- FirebasePerformance/Tests/Unit/FPRInstrumentTest.m | 4 ---- .../Tests/Unit/Instruments/FPRNSURLConnectionInstrumentTest.m | 4 ---- .../Tests/Unit/Instruments/FPRNSURLSessionInstrumentTest.m | 4 ---- .../Unit/Instruments/FPRUIViewControllerInstrumentTest.m | 3 --- Package.swift | 4 ++++ 7 files changed, 6 insertions(+), 21 deletions(-) diff --git a/FirebasePerformance/Sources/Instrumentation/FPRSelectorInstrumentor.m b/FirebasePerformance/Sources/Instrumentation/FPRSelectorInstrumentor.m index 0f474e5436a..29ac3ff0edf 100644 --- a/FirebasePerformance/Sources/Instrumentation/FPRSelectorInstrumentor.m +++ b/FirebasePerformance/Sources/Instrumentation/FPRSelectorInstrumentor.m @@ -17,7 +17,7 @@ #import "FirebasePerformance/Sources/Common/FPRDiagnostics.h" #import -#ifdef UNSWIZZLE_AVAILABLE +#ifdef FPR_UNSWIZZLE_AVAILABLE #import #endif @@ -76,7 +76,7 @@ - (void)swizzle { - (void)unswizzle { _swizzled = NO; -#ifdef UNSWIZZLE_AVAILABLE +#ifdef FPR_UNSWIZZLE_AVAILABLE [GULSwizzler unswizzleClass:_class selector:_selector isClassSelector:_isClassSelector]; #else NSAssert(NO, @"Unswizzling is disabled."); diff --git a/FirebasePerformance/Tests/Unit/FPRClassInstrumentorTest.m b/FirebasePerformance/Tests/Unit/FPRClassInstrumentorTest.m index 5e07dd9a3ea..0b72ea5cd9a 100644 --- a/FirebasePerformance/Tests/Unit/FPRClassInstrumentorTest.m +++ b/FirebasePerformance/Tests/Unit/FPRClassInstrumentorTest.m @@ -57,8 +57,6 @@ - (void)testCannotInstrumentSameSelectorTwice { #pragma mark - Unswizzle based tests -#if !SWIFT_PACKAGE - /** Tests swizzling an instance selector. */ - (void)testSwizzleInstanceSelector { FPRClassInstrumentor *classInstrumentor = @@ -158,6 +156,4 @@ - (void)testVoidReturnClassSelector { [classInstrumentor unswizzle]; } -#endif // SWIFT_PACKAGE - @end diff --git a/FirebasePerformance/Tests/Unit/FPRInstrumentTest.m b/FirebasePerformance/Tests/Unit/FPRInstrumentTest.m index 245d0ac0d47..82a2af6f64b 100644 --- a/FirebasePerformance/Tests/Unit/FPRInstrumentTest.m +++ b/FirebasePerformance/Tests/Unit/FPRInstrumentTest.m @@ -65,8 +65,6 @@ - (void)testRegisterAlreadyRegisteredClassInstrumentor { #pragma mark - Unswizzle based tests -#if !SWIFT_PACKAGE - - (void)testDeregisterInstrumentors { FPRInstrument *instrument = [[FPRInstrument alloc] init]; FPRClassInstrumentor *classInstrumentor = @@ -86,6 +84,4 @@ - (void)testDeregisterInstrumentors { [classInstrumentor unswizzle]; } -#endif // SWIFT_PACKAGE - @end diff --git a/FirebasePerformance/Tests/Unit/Instruments/FPRNSURLConnectionInstrumentTest.m b/FirebasePerformance/Tests/Unit/Instruments/FPRNSURLConnectionInstrumentTest.m index bb3e3520f39..c6c9f65bf2b 100644 --- a/FirebasePerformance/Tests/Unit/Instruments/FPRNSURLConnectionInstrumentTest.m +++ b/FirebasePerformance/Tests/Unit/Instruments/FPRNSURLConnectionInstrumentTest.m @@ -14,8 +14,6 @@ #pragma mark - Unswizzle based tests -#if !SWIFT_PACKAGE - #import "FirebasePerformance/Tests/Unit/Instruments/FPRNSURLConnectionInstrumentTestDelegates.h" #import @@ -519,5 +517,3 @@ - (void)testDownloadDelegateCompletionAPIGetsCalledEvenIfDataDelegateIsImplement } @end - -#endif // SWIFT_PACKAGE diff --git a/FirebasePerformance/Tests/Unit/Instruments/FPRNSURLSessionInstrumentTest.m b/FirebasePerformance/Tests/Unit/Instruments/FPRNSURLSessionInstrumentTest.m index ffffbe17c17..33866ad20e4 100644 --- a/FirebasePerformance/Tests/Unit/Instruments/FPRNSURLSessionInstrumentTest.m +++ b/FirebasePerformance/Tests/Unit/Instruments/FPRNSURLSessionInstrumentTest.m @@ -14,8 +14,6 @@ #pragma mark - Unswizzle based tests -#ifndef SWIFT_PACKAGE - #import "FirebasePerformance/Tests/Unit/Instruments/FPRNSURLSessionInstrumentTestDelegates.h" #import @@ -836,5 +834,3 @@ - (void)testMutableRequestURLs { } @end - -#endif // SWIFT_PACKAGE diff --git a/FirebasePerformance/Tests/Unit/Instruments/FPRUIViewControllerInstrumentTest.m b/FirebasePerformance/Tests/Unit/Instruments/FPRUIViewControllerInstrumentTest.m index 005818f63a0..ac840257cfe 100644 --- a/FirebasePerformance/Tests/Unit/Instruments/FPRUIViewControllerInstrumentTest.m +++ b/FirebasePerformance/Tests/Unit/Instruments/FPRUIViewControllerInstrumentTest.m @@ -14,8 +14,6 @@ #pragma mark - Unswizzle based tests -#if !SWIFT_PACKAGE - #import "FirebasePerformance/Sources/Instrumentation/UIKit/FPRUIViewControllerInstrument.h" #import @@ -173,4 +171,3 @@ - (void)testViewDidAppearInvokesPreviousViewDidDisappear { @end -#endif // SWIFT_PACKAGE diff --git a/Package.swift b/Package.swift index 4bfb5a9b228..2e7ce1facdc 100644 --- a/Package.swift +++ b/Package.swift @@ -884,6 +884,7 @@ let package = Package( .product(name: "GoogleDataTransport", package: "GoogleDataTransport"), .product(name: "GULEnvironment", package: "GoogleUtilities"), .product(name: "GULMethodSwizzler", package: "GoogleUtilities"), + .product(name: "GULSwizzlerTestHelpers", package: "GoogleUtilities"), .product(name: "GULUserDefaults", package: "GoogleUtilities"), .product(name: "nanopb", package: "nanopb"), ], @@ -895,6 +896,7 @@ let package = Package( .define("PB_NO_PACKED_STRUCTS", to: "1"), .define("PB_ENABLE_MALLOC", to: "1"), .define("FIRPerformance_LIB_VERSION", to: firebaseVersion), + .define("FPR_UNSWIZZLE_AVAILABLE", to: "1"), ], linkerSettings: [ .linkedFramework("MobileCoreServices", .when(platforms: [.iOS, .tvOS])), @@ -907,6 +909,8 @@ let package = Package( "FirebasePerformanceTarget", "SharedTestUtilities", "GCDWebServer", + .product(name: "GULMethodSwizzler", package: "GoogleUtilities"), + .product(name: "GULSwizzlerTestHelpers", package: "GoogleUtilities"), .product(name: "OCMock", package: "ocmock"), ], path: "FirebasePerformance/Tests/Unit", From 62db6a99c6ab03580e3ac5d08224cde0218d5c9c Mon Sep 17 00:00:00 2001 From: samedson Date: Thu, 3 Oct 2024 11:58:23 -0400 Subject: [PATCH 2/4] Remove assertion around swizzling --- .../Sources/Instrumentation/FPRSelectorInstrumentor.m | 10 ++-------- Package.swift | 3 +-- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/FirebasePerformance/Sources/Instrumentation/FPRSelectorInstrumentor.m b/FirebasePerformance/Sources/Instrumentation/FPRSelectorInstrumentor.m index 29ac3ff0edf..63fe708d223 100644 --- a/FirebasePerformance/Sources/Instrumentation/FPRSelectorInstrumentor.m +++ b/FirebasePerformance/Sources/Instrumentation/FPRSelectorInstrumentor.m @@ -17,9 +17,6 @@ #import "FirebasePerformance/Sources/Common/FPRDiagnostics.h" #import -#ifdef FPR_UNSWIZZLE_AVAILABLE -#import -#endif @implementation FPRSelectorInstrumentor { // The class this instrumentor operates on. @@ -76,11 +73,8 @@ - (void)swizzle { - (void)unswizzle { _swizzled = NO; -#ifdef FPR_UNSWIZZLE_AVAILABLE - [GULSwizzler unswizzleClass:_class selector:_selector isClassSelector:_isClassSelector]; -#else - NSAssert(NO, @"Unswizzling is disabled."); -#endif + // For the SDK, we do not unswizzle, but this does run in unit tests, + // though it does not seem to have any effect } - (IMP)currentIMP { diff --git a/Package.swift b/Package.swift index 2e7ce1facdc..d5c9ae648da 100644 --- a/Package.swift +++ b/Package.swift @@ -884,7 +884,6 @@ let package = Package( .product(name: "GoogleDataTransport", package: "GoogleDataTransport"), .product(name: "GULEnvironment", package: "GoogleUtilities"), .product(name: "GULMethodSwizzler", package: "GoogleUtilities"), - .product(name: "GULSwizzlerTestHelpers", package: "GoogleUtilities"), .product(name: "GULUserDefaults", package: "GoogleUtilities"), .product(name: "nanopb", package: "nanopb"), ], @@ -896,7 +895,6 @@ let package = Package( .define("PB_NO_PACKED_STRUCTS", to: "1"), .define("PB_ENABLE_MALLOC", to: "1"), .define("FIRPerformance_LIB_VERSION", to: firebaseVersion), - .define("FPR_UNSWIZZLE_AVAILABLE", to: "1"), ], linkerSettings: [ .linkedFramework("MobileCoreServices", .when(platforms: [.iOS, .tvOS])), @@ -924,6 +922,7 @@ let package = Package( .define("PB_FIELD_32BIT", to: "1"), .define("PB_NO_PACKED_STRUCTS", to: "1"), .define("PB_ENABLE_MALLOC", to: "1"), + .define("FPR_UNSWIZZLE_AVAILABLE", to: "1"), ] ), From 235434e44a16081bebb3781a16ed38e2bb4722a2 Mon Sep 17 00:00:00 2001 From: samedson Date: Thu, 3 Oct 2024 11:59:28 -0400 Subject: [PATCH 3/4] Disable one test --- .../Unit/Instruments/FPRUIViewControllerInstrumentTest.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/FirebasePerformance/Tests/Unit/Instruments/FPRUIViewControllerInstrumentTest.m b/FirebasePerformance/Tests/Unit/Instruments/FPRUIViewControllerInstrumentTest.m index ac840257cfe..fba807116cf 100644 --- a/FirebasePerformance/Tests/Unit/Instruments/FPRUIViewControllerInstrumentTest.m +++ b/FirebasePerformance/Tests/Unit/Instruments/FPRUIViewControllerInstrumentTest.m @@ -52,6 +52,8 @@ - (void)setUp { originalViewDidDisappearInvoked = NO; } +#if !SWIFT_PACKAGE + /** Tests that the viewControllerDidAppear: of the FPRScreenTraceTracker sharedInstance is invoked * when a UIViewController's viewDidAppear: is invoked. */ @@ -75,6 +77,8 @@ - (void)testViewDidAppearInvokesViewControllerDidAppearOnScreenTraceTracker { [[testViewController view] removeFromSuperview]; } +#endif // SWIFT_PACKAGE + /** Tests that the viewControllerDidAppear: of the FPRScreenTraceTracker sharedInstance is invoked * when a UIViewController's viewDidAppear: is invoked. */ @@ -170,4 +174,3 @@ - (void)testViewDidAppearInvokesPreviousViewDidDisappear { } @end - From 152e2d4a53c704a34eb6095167d77010a80ef62b Mon Sep 17 00:00:00 2001 From: samedson Date: Thu, 3 Oct 2024 12:00:21 -0400 Subject: [PATCH 4/4] asfasfas --- Package.swift | 3 --- 1 file changed, 3 deletions(-) diff --git a/Package.swift b/Package.swift index d5c9ae648da..4bfb5a9b228 100644 --- a/Package.swift +++ b/Package.swift @@ -907,8 +907,6 @@ let package = Package( "FirebasePerformanceTarget", "SharedTestUtilities", "GCDWebServer", - .product(name: "GULMethodSwizzler", package: "GoogleUtilities"), - .product(name: "GULSwizzlerTestHelpers", package: "GoogleUtilities"), .product(name: "OCMock", package: "ocmock"), ], path: "FirebasePerformance/Tests/Unit", @@ -922,7 +920,6 @@ let package = Package( .define("PB_FIELD_32BIT", to: "1"), .define("PB_NO_PACKED_STRUCTS", to: "1"), .define("PB_ENABLE_MALLOC", to: "1"), - .define("FPR_UNSWIZZLE_AVAILABLE", to: "1"), ] ),