From 86b664eeb64f7bb32135b94d3f0d5c651189f10a Mon Sep 17 00:00:00 2001 From: Xiaobo Zhang Date: Fri, 22 Sep 2017 14:54:54 -0700 Subject: [PATCH] Merge a few crash tickets fix and static linking fix (#198) * Add debug print out for crash at calling "logEntry.log = [logEntry.log stringByAppendingString:@"\n"];" and "return [BPTreeAssembler sharedInstance].currentTest;". Suspect these two crash are caused by nil pointers * update with coding style changes for previous commit * remove extra debug print out:TOOLS-154094, so far no more report for the two crash points * TOOLS-155868: iOS simulator crash Potential fix for two crash points, suspect both are caused by null pointers Crash point: 10 bluepill 0x000000010a667769 -[BPRunner runWithBPXCTestFiles:] + 1932 (BPRunner.m:228) 11 bluepill 0x000000010a66186a main + 994 (main.m:101) 10 bp 0x000000010b187c01 +[BPUtils runShell:] + 269 (BPUtils.m:182) 11 bp 0x000000010b1a54e1 main + 1234 (main.m:36) * add -s option to xargs for static linking * Removed debug log --- .../Bluepill/Reporters/BPTreeParser.m | 3 +++ Bluepill-runner/Bluepill-runner/BPRunner.m | 2 +- .../BluepillRunnerTests/BPIntegrationTests.m | 1 - Source/Shared/BPUtils.m | 17 +++++++++++++---- Source/Shared/BPXCTestFile.m | 2 +- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Bluepill-cli/Bluepill-cli/Bluepill/Reporters/BPTreeParser.m b/Bluepill-cli/Bluepill-cli/Bluepill/Reporters/BPTreeParser.m index 9970408c..41d8c7be 100644 --- a/Bluepill-cli/Bluepill-cli/Bluepill/Reporters/BPTreeParser.m +++ b/Bluepill-cli/Bluepill-cli/Bluepill/Reporters/BPTreeParser.m @@ -461,6 +461,9 @@ - (void)parseLine:(nullable NSString *)line { } logEntry = self.current; } + if (logEntry.log == nil) { + logEntry.log = @""; + } logEntry.log = [logEntry.log stringByAppendingString:line]; logEntry.log = [logEntry.log stringByAppendingString:@"\n"]; } diff --git a/Bluepill-runner/Bluepill-runner/BPRunner.m b/Bluepill-runner/Bluepill-runner/BPRunner.m index 0be7908e..3c832ae9 100644 --- a/Bluepill-runner/Bluepill-runner/BPRunner.m +++ b/Bluepill-runner/Bluepill-runner/BPRunner.m @@ -253,7 +253,7 @@ - (int)runWithBPXCTestFiles:(NSArray *)xcTestFiles { rc = (rc || [task terminationStatus]); }]; if (!task) { - NSLog(@"Failed to launch: %@ %@", [task launchPath], [task arguments]); + [BPUtils printInfo:ERROR withString:@"task is nil!"]; exit(1); } [task launch]; diff --git a/Bluepill-runner/BluepillRunnerTests/BPIntegrationTests.m b/Bluepill-runner/BluepillRunnerTests/BPIntegrationTests.m index d3726d99..99dd87ee 100644 --- a/Bluepill-runner/BluepillRunnerTests/BPIntegrationTests.m +++ b/Bluepill-runner/BluepillRunnerTests/BPIntegrationTests.m @@ -121,7 +121,6 @@ - (void)testTwoBPInstancesWithXCTestRunFile { int rc = [runner runWithBPXCTestFiles:app.testBundles]; XCTAssert(app.testBundles[1].skipTestIdentifiers.count == 7); XCTAssert(rc != 0); // this runs tests that fail - } - (void)testTwoBPInstancesTestCaseFail { diff --git a/Source/Shared/BPUtils.m b/Source/Shared/BPUtils.m index 9fd01dfc..1f59b3a6 100644 --- a/Source/Shared/BPUtils.m +++ b/Source/Shared/BPUtils.m @@ -171,15 +171,24 @@ + (BOOL)isStdOut:(NSString *)fileName { + (NSString *)runShell:(NSString *)command { NSAssert(command, @"Command should not be nil"); - NSTask *task = [NSTask new]; + NSTask *task = [[NSTask alloc] init]; + NSData *data; task.launchPath = @"/bin/sh"; task.arguments = @[@"-c", command]; - NSPipe *pipe = [NSPipe new]; + NSPipe *pipe = [[NSPipe alloc] init]; task.standardError = pipe; task.standardOutput = pipe; NSFileHandle *fh = pipe.fileHandleForReading; - [task launch]; - NSData *data = [fh readDataToEndOfFile]; + if (task) { + [task launch]; + } else { + NSAssert(task, @"task should not be nil"); + } + if (fh) { + data = [fh readDataToEndOfFile]; + } else { + NSAssert(task, @"fh should not be nil"); + } [task waitUntilExit]; return [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] stringByTrimmingCharactersInSet:[NSCharacterSet newlineCharacterSet]]; } diff --git a/Source/Shared/BPXCTestFile.m b/Source/Shared/BPXCTestFile.m index 30f22262..218a25d2 100644 --- a/Source/Shared/BPXCTestFile.m +++ b/Source/Shared/BPXCTestFile.m @@ -14,7 +14,7 @@ @implementation BPXCTestFile -NSString *swiftNmCmdline = @"nm -gU '%@' | cut -d' ' -f3 | xargs xcrun swift-demangle | cut -d' ' -f3 | grep -e '[\\.|_]'test"; +NSString *swiftNmCmdline = @"nm -gU '%@' | cut -d' ' -f3 | xargs -s 131072 xcrun swift-demangle | cut -d' ' -f3 | grep -e '[\\.|_]'test"; NSString *objcNmCmdline = @"nm -U '%@' | grep ' t ' | cut -d' ' -f3,4 | cut -d'-' -f2 | cut -d'[' -f2 | cut -d']' -f1 | grep ' test'"; + (instancetype)BPXCTestFileFromXCTestBundle:(NSString *)testBundlePath