Skip to content

Commit ea7767a

Browse files
HeyImChristom-un
authored andcommitted
Add memory management and concurrency tests plans to our fork of Reac… (#186)
* Add memory management and concurrency tests plans to our fork of React Native * temporarily disable a few more tests that are failing for us * reenable tests that are building/testing again * Build break fix: when running parallized xctestplan builds, non-deterministic errors can occur in the header maps of RCTText. Fix by forward declaring @protocols in headers, and #import the necessary headers in the .m files that need them. * ASAN testing revealed that RCTMessageThread can be deleted before the RunLoop has executed a block during shutdown, which results in this->m_shutdown being deferenced to deallocated memory. Capture a shared_ptr to this instead of a raw `this` in the lambdas.
1 parent 925a76d commit ea7767a

File tree

8 files changed

+96
-23
lines changed

8 files changed

+96
-23
lines changed

Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
#import "RCTBackedTextInputViewProtocol.h"
9-
#import "RCTBackedTextInputDelegate.h"
108
#import "../RCTTextUIKit.h" // TODO(macOS ISS#2323203)
119

1210
NS_ASSUME_NONNULL_BEGIN
1311

1412
#pragma mark - RCTBackedTextFieldDelegateAdapter (for UITextField)
1513

14+
@protocol RCTBackedTextInputViewProtocol; // TODO(OSS Candidate ISS#2710739)
15+
@protocol RCTBackedTextInputDelegate; // TODO(OSS Candidate ISS#2710739)
16+
1617
@interface RCTBackedTextFieldDelegateAdapter : NSObject
1718

1819
- (instancetype)initWithTextField:(UITextField<RCTBackedTextInputViewProtocol> *)backedTextInputView;

Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*/
77

88
#import "RCTBackedTextInputDelegateAdapter.h"
9+
#import "RCTBackedTextInputViewProtocol.h" // TODO(OSS Candidate ISS#2710739)
10+
#import "RCTBackedTextInputDelegate.h" // TODO(OSS Candidate ISS#2710739)
911
#import "../RCTTextUIKit.h" // TODO(macOS ISS#2323203)
1012

1113
#pragma mark - RCTBackedTextFieldDelegateAdapter (for UITextField)

Libraries/Text/TextInput/Singleline/RCTUITextField.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#import <React/UIView+React.h>
1212

1313
#import "RCTBackedTextInputDelegateAdapter.h"
14+
#import "RCTBackedTextInputDelegate.h" // TODO(OSS Candidate ISS#2710739)
1415
#import "RCTTextAttributes.h"
1516

1617
#if TARGET_OS_OSX // [TODO(macOS ISS#2323203)

RNTester/RNTester.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,7 @@
915915
8385CF031B87479200C6273E /* RCTImageLoaderHelpers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTImageLoaderHelpers.m; sourceTree = "<group>"; };
916916
8385CF051B8747A000C6273E /* RCTImageLoaderHelpers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTImageLoaderHelpers.h; sourceTree = "<group>"; };
917917
9F1534BD233AB44F006DFE44 /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/System/Library/Frameworks/JavaScriptCore.framework; sourceTree = DEVELOPER_DIR; };
918+
9F1C4D00236CB06B0022EC0D /* RNTesterTestPlan_iOS.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = RNTesterTestPlan_iOS.xctestplan; sourceTree = "<group>"; };
918919
9F5C1923230F46CB00E3E5A7 /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/JavaScriptCore.framework; sourceTree = DEVELOPER_DIR; };
919920
9FBFA513233C7E4C003D9A8D /* RNTesterBundle-macOS.bundle */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "RNTesterBundle-macOS.bundle"; sourceTree = BUILT_PRODUCTS_DIR; };
920921
9FBFA515233C7E4C003D9A8D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -1452,6 +1453,7 @@
14521453
3D13F83F1D6F6AE000E69E0E /* RNTesterBundle */ = {
14531454
isa = PBXGroup;
14541455
children = (
1456+
9F1C4D00236CB06B0022EC0D /* RNTesterTestPlan_iOS.xctestplan */,
14551457
3D13F8401D6F6AE000E69E0E /* Info.plist */,
14561458
3D13F8441D6F6AF200E69E0E /* ImageInBundle.png */,
14571459
3D13F8451D6F6AF200E69E0E /* OtherImages.xcassets */,

RNTester/RNTester.xcodeproj/xcshareddata/xcschemes/RNTester.xcscheme

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
33
LastUpgradeVersion = "0940"
4-
version = "1.3">
4+
version = "1.7">
55
<BuildAction
66
parallelizeBuildables = "NO"
77
buildImplicitDependencies = "YES">
@@ -83,6 +83,21 @@
8383
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
8484
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
8585
shouldUseLaunchSchemeArgsEnv = "YES">
86+
<MacroExpansion>
87+
<BuildableReference
88+
BuildableIdentifier = "primary"
89+
BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
90+
BuildableName = "RNTester.app"
91+
BlueprintName = "RNTester"
92+
ReferencedContainer = "container:RNTester.xcodeproj">
93+
</BuildableReference>
94+
</MacroExpansion>
95+
<TestPlans>
96+
<TestPlanReference
97+
reference = "container:RNTester/RNTesterBundle/RNTesterTestPlan_iOS.xctestplan"
98+
default = "YES">
99+
</TestPlanReference>
100+
</TestPlans>
86101
<Testables>
87102
<TestableReference
88103
skipped = "NO">
@@ -110,17 +125,6 @@
110125
</SkippedTests>
111126
</TestableReference>
112127
</Testables>
113-
<MacroExpansion>
114-
<BuildableReference
115-
BuildableIdentifier = "primary"
116-
BlueprintIdentifier = "13B07F861A680F5B00A75B9A"
117-
BuildableName = "RNTester.app"
118-
BlueprintName = "RNTester"
119-
ReferencedContainer = "container:RNTester.xcodeproj">
120-
</BuildableReference>
121-
</MacroExpansion>
122-
<AdditionalOptions>
123-
</AdditionalOptions>
124128
</TestAction>
125129
<LaunchAction
126130
buildConfiguration = "Debug"
@@ -154,8 +158,6 @@
154158
isEnabled = "YES">
155159
</EnvironmentVariable>
156160
</EnvironmentVariables>
157-
<AdditionalOptions>
158-
</AdditionalOptions>
159161
</LaunchAction>
160162
<ProfileAction
161163
buildConfiguration = "Release"
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
{
2+
"configurations" : [
3+
{
4+
"id" : "37D31EEF-8FEF-4078-89E7-6BA48A640995",
5+
"name" : "Memory Checking",
6+
"options" : {
7+
"addressSanitizer" : {
8+
"detectStackUseAfterReturn" : true,
9+
"enabled" : true
10+
},
11+
"nsZombieEnabled" : true
12+
}
13+
},
14+
{
15+
"id" : "B79DCEC6-8538-44AF-B29F-2F45036E8EE2",
16+
"name" : "Concurrency",
17+
"options" : {
18+
"testExecutionOrdering" : "random",
19+
"undefinedBehaviorSanitizerEnabled" : true
20+
}
21+
}
22+
],
23+
"defaultOptions" : {
24+
"environmentVariableEntries" : [
25+
{
26+
"key" : "CI_USE_PACKAGER",
27+
"value" : "1"
28+
},
29+
{
30+
"key" : "RN_BUNDLE_PREFIX",
31+
"value" : ""
32+
}
33+
],
34+
"targetForVariableExpansion" : {
35+
"containerPath" : "container:RNTester.xcodeproj",
36+
"identifier" : "13B07F861A680F5B00A75B9A",
37+
"name" : "RNTester"
38+
}
39+
},
40+
"testTargets" : [
41+
{
42+
"parallelizable" : true,
43+
"target" : {
44+
"containerPath" : "container:RNTester.xcodeproj",
45+
"identifier" : "004D289D1AAF61C70097A701",
46+
"name" : "RNTesterUnitTests"
47+
}
48+
},
49+
{
50+
"parallelizable" : true,
51+
"skippedTests" : [
52+
"RNTesterIntegrationTests\/testAccessibilityManagerTest"
53+
],
54+
"target" : {
55+
"containerPath" : "container:RNTester.xcodeproj",
56+
"identifier" : "143BC5941B21E3E100462512",
57+
"name" : "RNTesterIntegrationTests"
58+
}
59+
}
60+
],
61+
"version" : 1
62+
}

React/CxxBridge/RCTMessageThread.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
namespace facebook {
1616
namespace react {
1717

18-
class RCTMessageThread : public MessageQueueThread {
18+
class RCTMessageThread : public MessageQueueThread, public std::enable_shared_from_this<RCTMessageThread> { // TODO(OSS Candidate ISS#2710739)
1919
public:
2020
RCTMessageThread(NSRunLoop *runLoop, RCTJavaScriptCompleteBlock errorBlock);
2121
~RCTMessageThread() override;

React/CxxBridge/RCTMessageThread.mm

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@
6767
return;
6868
}
6969

70-
runAsync([this, func=std::make_shared<std::function<void()>>(std::move(func))] {
71-
if (!m_shutdown) {
72-
tryFunc(*func);
70+
auto sharedThis = shared_from_this(); // TODO(OSS Candidate ISS#2710739): `this` can be deleted before the RunLoop executes the block as revealed by ASAN test runs.
71+
runAsync([sharedThis, func=std::make_shared<std::function<void()>>(std::move(func))] {
72+
if (sharedThis->m_shutdown == false) {
73+
sharedThis->tryFunc(*func);
7374
}
7475
});
7576
}
@@ -78,9 +79,11 @@
7879
if (m_shutdown) {
7980
return;
8081
}
81-
runSync([this, func=std::move(func)] {
82-
if (!m_shutdown) {
83-
tryFunc(func);
82+
83+
auto sharedThis = shared_from_this(); // TODO(OSS Candidate ISS#2710739): `this` can be deleted before the RunLoop executes the block as revealed by ASAN test runs.
84+
runSync([sharedThis, func=std::move(func)] {
85+
if (sharedThis->m_shutdown == false) {
86+
sharedThis->tryFunc(func);
8487
}
8588
});
8689
}

0 commit comments

Comments
 (0)