diff --git a/Bluepill-cli/Bluepill-cli/Simulator/SimulatorMonitor.m b/Bluepill-cli/Bluepill-cli/Simulator/SimulatorMonitor.m index 2cb778b0..b71fb8ab 100644 --- a/Bluepill-cli/Bluepill-cli/Simulator/SimulatorMonitor.m +++ b/Bluepill-cli/Bluepill-cli/Simulator/SimulatorMonitor.m @@ -211,8 +211,12 @@ - (void)stopTestsWithErrorMessage:(NSString *)message forTestName:(NSString *)te if (![[self.device stateString] isEqualToString:@"Shutdown"]) { // self.appPID can be zero when running the parsing tests // since we're not actually creating a simulator and running an app. + [BPUtils printInfo:ERROR withString:@"Will kill the process with appPID: %d", self.appPID]; if (self.appPID && (kill(self.appPID, 0) == 0) && (kill(self.appPID, SIGTERM) < 0)) { + [BPUtils printInfo:ERROR withString:@"Failed to kill the process with appPID: %d", self.appPID]; perror("kill"); + } else { + [BPUtils printInfo:ERROR withString:@"Success killing the process with appPID: %d", self.appPID]; } } diff --git a/Bluepill-cli/Bluepill-cli/Simulator/SimulatorRunner.m b/Bluepill-cli/Bluepill-cli/Simulator/SimulatorRunner.m index b60ffbb1..38bcb27b 100644 --- a/Bluepill-cli/Bluepill-cli/Simulator/SimulatorRunner.m +++ b/Bluepill-cli/Bluepill-cli/Simulator/SimulatorRunner.m @@ -276,17 +276,21 @@ - (void)launchApplicationAndExecuteTestsWithParser:(BPTreeParser *)parser andCom self.monitor.hostBundleId = hostBundleId; parser.delegate = self.monitor; + // Keep the simulator runner around through processing of the block + __block typeof(self) blockSelf = self; + [self.device launchApplicationAsyncWithID:hostBundleId options:options completionHandler:^(NSError *error, pid_t pid) { + // Save the process ID to the monitor + blockSelf.monitor.appPID = pid; + if (error == nil) { dispatch_source_t source = dispatch_source_create(DISPATCH_SOURCE_TYPE_PROC, pid, DISPATCH_PROC_EXIT, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)); dispatch_source_set_event_handler(source, ^{ dispatch_source_cancel(source); }); - __block __weak SimulatorRunner *weakSelf = self; - weakSelf.monitor.appPID = pid; dispatch_source_set_cancel_handler(source, ^{ // Post a APPCLOSED signal to the fifo - [weakSelf.stdOutHandle writeData:[@"\nBP_APP_PROC_ENDED\n" dataUsingEncoding:NSUTF8StringEncoding]]; + [blockSelf.stdOutHandle writeData:[@"\nBP_APP_PROC_ENDED\n" dataUsingEncoding:NSUTF8StringEncoding]]; }); dispatch_resume(source); self.stdOutHandle.readabilityHandler = ^(NSFileHandle *handle) {