Author: Jonas Devlieghere Date: 2020-08-11T11:07:04-07:00 New Revision: 7adf5bd18147b8acdab6e2720b4073e8c35bdf9a
URL: https://github.com/llvm/llvm-project/commit/7adf5bd18147b8acdab6e2720b4073e8c35bdf9a DIFF: https://github.com/llvm/llvm-project/commit/7adf5bd18147b8acdab6e2720b4073e8c35bdf9a.diff LOG: [lldb] Look beyond the first line to find the PID in TestAppleSimulatorOSType The current code fails when the first stderr line doesn't match the given regex to parse the PID. This patch changes the code to read the first 10 lines before giving up. It also adds tracing for the simctl commands. Added: Modified: lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py Removed: ################################################################################ diff --git a/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py b/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py index a259ef66832b..9bba50313c04 100644 --- a/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py +++ b/lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py @@ -12,9 +12,13 @@ class TestAppleSimulatorOSType(gdbremote_testcase.GdbRemoteTestCaseBase): mydir = TestBase.compute_mydir(__file__) + # Number of stderr lines to read from the simctl output. + READ_LINES = 10 + def check_simulator_ostype(self, sdk, platform, arch='x86_64'): - sim_devices_str = subprocess.check_output(['xcrun', 'simctl', 'list', - '-j', 'devices']).decode("utf-8") + cmd = ['xcrun', 'simctl', 'list', '-j', 'devices'] + self.trace(' '.join(cmd)) + sim_devices_str = subprocess.check_output(cmd).decode("utf-8") sim_devices = json.loads(sim_devices_str)['devices'] # Find an available simulator for the requested platform deviceUDID = None @@ -48,19 +52,27 @@ def check_simulator_ostype(self, sdk, platform, arch='x86_64'): self.build(dictionary={ 'EXE': exe_name, 'SDKROOT': sdkroot.strip(), 'ARCH': arch }) exe_path = self.getBuildArtifact(exe_name) - sim_launcher = subprocess.Popen(['xcrun', 'simctl', 'spawn', '-s', - deviceUDID, exe_path, - 'print-pid', 'sleep:10'], - stderr=subprocess.PIPE) + cmd = [ + 'xcrun', 'simctl', 'spawn', '-s', deviceUDID, exe_path, + 'print-pid', 'sleep:10' + ] + self.trace(' '.join(cmd)) + sim_launcher = subprocess.Popen(cmd, stderr=subprocess.PIPE) # Get the PID from the process output pid = None - while not pid: + + # Read the first READ_LINES to try to find the PID. + for _ in range(0, self.READ_LINES): stderr = sim_launcher.stderr.readline().decode("utf-8") - if stderr == '': + if not stderr: continue - m = re.match(r"PID: (.*)", stderr) - self.assertIsNotNone(m) - pid = int(m.group(1)) + match = re.match(r"PID: (.*)", stderr) + if match: + pid = int(match.group(1)) + break + + # Make sure we found the PID. + self.assertIsNotNone(pid) # Launch debug monitor attaching to the simulated process self.init_debugserver_test() _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits