Skip to content

Commit a7f495f

Browse files
authored
[lldb] Revive TestSimulatorPlatform.py (#142244)
This test was incorrectly disabled and bitrotted since then. This PR fixes up the test and re-enables it. - Build against the system libc++ (which can target the simulator) - Bump the deployment target for iOS and tvOS on Apple Silicon - Skip backdeploying to pre-Apple Silicon OS on Apple Silicon.
1 parent 94877ce commit a7f495f

File tree

2 files changed

+57
-9
lines changed

2 files changed

+57
-9
lines changed

lldb/packages/Python/lldbsuite/test/decorators.py

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import sys
1010
import tempfile
1111
import subprocess
12+
import json
1213

1314
# Third-party modules
1415
import unittest
@@ -451,24 +452,67 @@ def apple_simulator_test(platform):
451452
"""
452453
Decorate the test as a test requiring a simulator for a specific platform.
453454
454-
Consider that a simulator is available if you have the corresponding SDK installed.
455-
The SDK identifiers for simulators are iphonesimulator, appletvsimulator, watchsimulator
455+
Consider that a simulator is available if you have the corresponding SDK
456+
and runtime installed.
457+
458+
The SDK identifiers for simulators are iphonesimulator, appletvsimulator,
459+
watchsimulator
456460
"""
457461

458462
def should_skip_simulator_test():
459463
if lldbplatformutil.getHostPlatform() not in ["darwin", "macosx"]:
460464
return "simulator tests are run only on darwin hosts."
465+
466+
# Make sure we recognize the platform.
467+
mapping = {
468+
"iphone": "ios",
469+
"appletv": "tvos",
470+
"watch": "watchos",
471+
}
472+
if platform not in mapping:
473+
return "unknown simulator platform: {}".format(platform)
474+
475+
# Make sure we have an SDK.
461476
try:
462477
output = subprocess.check_output(
463478
["xcodebuild", "-showsdks"], stderr=subprocess.DEVNULL
464479
).decode("utf-8")
465-
if re.search("%ssimulator" % platform, output):
466-
return None
467-
else:
480+
if not re.search("%ssimulator" % platform, output):
468481
return "%s simulator is not supported on this system." % platform
469482
except subprocess.CalledProcessError:
470483
return "Simulators are unsupported on this system (xcodebuild failed)"
471484

485+
# Make sure we a simulator runtime.
486+
try:
487+
sim_devices_str = subprocess.check_output(
488+
["xcrun", "simctl", "list", "-j", "devices"]
489+
).decode("utf-8")
490+
491+
sim_devices = json.loads(sim_devices_str)["devices"]
492+
for simulator in sim_devices:
493+
if isinstance(simulator, dict):
494+
runtime = simulator["name"]
495+
devices = simulator["devices"]
496+
else:
497+
runtime = simulator
498+
devices = sim_devices[simulator]
499+
500+
if not mapping[platform] in runtime.lower():
501+
continue
502+
503+
for device in devices:
504+
if (
505+
"availability" in device
506+
and device["availability"] == "(available)"
507+
):
508+
return None
509+
if "isAvailable" in device and device["isAvailable"]:
510+
return None
511+
512+
return "{} simulator is not supported on this system.".format(platform)
513+
except (subprocess.CalledProcessError, json.decoder.JSONDecodeError):
514+
return "Simulators are unsupported on this system (simctl failed)"
515+
472516
return skipTestIfFn(should_skip_simulator_test)
473517

474518

lldb/test/API/macosx/simulator/TestSimulatorPlatform.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ def check_debugserver(self, log, expected_platform, expected_version):
3939
if expected_version:
4040
self.assertEqual(aout_info["min_version_os_sdk"], expected_version)
4141

42-
@skipIf(bugnumber="rdar://76995109")
4342
def run_with(self, arch, os, vers, env, expected_load_command):
4443
env_list = [env] if env else []
4544
triple = "-".join([arch, "apple", os + vers] + env_list)
4645
sdk = lldbutil.get_xcode_sdk(os, env)
4746

48-
version_min = ""
4947
if not vers:
5048
vers = lldbutil.get_xcode_sdk_version(sdk)
49+
50+
version_min = ""
5151
if env == "simulator":
5252
version_min = "-m{}-simulator-version-min={}".format(os, vers)
5353
elif os == "macosx":
@@ -56,11 +56,14 @@ def run_with(self, arch, os, vers, env, expected_load_command):
5656
sdk_root = lldbutil.get_xcode_sdk_root(sdk)
5757
clang = lldbutil.get_xcode_clang(sdk)
5858

59+
print(triple)
60+
5961
self.build(
6062
dictionary={
6163
"ARCH": arch,
6264
"ARCH_CFLAGS": "-target {} {}".format(triple, version_min),
6365
"SDKROOT": sdk_root,
66+
"USE_SYSTEM_STDLIB": 1,
6467
},
6568
compiler=clang,
6669
)
@@ -146,6 +149,7 @@ def test_watchos_armv7k(self):
146149

147150
@skipUnlessDarwin
148151
@skipIfDarwinEmbedded
152+
@skipIf(archs=["arm64", "arm64e"])
149153
def test_lc_version_min_macosx(self):
150154
"""Test running a back-deploying non-simulator MacOS X binary"""
151155
self.run_with(
@@ -198,7 +202,7 @@ def test_ios_backdeploy_apple_silicon(self):
198202
self.run_with(
199203
arch=self.getArchitecture(),
200204
os="ios",
201-
vers="11.0",
205+
vers="14.0",
202206
env="simulator",
203207
expected_load_command="LC_BUILD_VERSION",
204208
)
@@ -229,7 +233,7 @@ def test_tvos_backdeploy_apple_silicon(self):
229233
self.run_with(
230234
arch=self.getArchitecture(),
231235
os="tvos",
232-
vers="11.0",
236+
vers="14.0",
233237
env="simulator",
234238
expected_load_command="LC_BUILD_VERSION",
235239
)

0 commit comments

Comments
 (0)