JDevlieghere created this revision.
JDevlieghere added a reviewer: aprantl.
JDevlieghere requested review of this revision.
The current code fails when the the first attempt to read the PID from stderr
doesn't match the given regex. This patch changes the code to make up to 10
attempts.
Repository:
rLLDB LLDB
https://reviews.llvm.org/D85758
Files:
lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py
Index: lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py
===================================================================
--- lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py
+++ lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py
@@ -12,9 +12,13 @@
mydir = TestBase.compute_mydir(__file__)
+ # Number of attempts to read the PID from the simctl output.
+ PID_RETRIES = 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 @@
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:
+
+ # Make PID_RETRIES attempt to get the PID.
+ for _ in range(0, self.PID_RETRIES):
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()
Index: lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py
===================================================================
--- lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py
+++ lldb/test/API/tools/lldb-server/TestAppleSimulatorOSType.py
@@ -12,9 +12,13 @@
mydir = TestBase.compute_mydir(__file__)
+ # Number of attempts to read the PID from the simctl output.
+ PID_RETRIES = 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 @@
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:
+
+ # Make PID_RETRIES attempt to get the PID.
+ for _ in range(0, self.PID_RETRIES):
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
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits