Skip to content

[lldb] Revive TestSimulatorPlatform.py #142244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 49 additions & 5 deletions lldb/packages/Python/lldbsuite/test/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import sys
import tempfile
import subprocess
import json

# Third-party modules
import unittest
Expand Down Expand Up @@ -451,24 +452,67 @@ def apple_simulator_test(platform):
"""
Decorate the test as a test requiring a simulator for a specific platform.

Consider that a simulator is available if you have the corresponding SDK installed.
The SDK identifiers for simulators are iphonesimulator, appletvsimulator, watchsimulator
Consider that a simulator is available if you have the corresponding SDK
and runtime installed.

The SDK identifiers for simulators are iphonesimulator, appletvsimulator,
watchsimulator
"""

def should_skip_simulator_test():
if lldbplatformutil.getHostPlatform() not in ["darwin", "macosx"]:
return "simulator tests are run only on darwin hosts."

# Make sure we recognize the platform.
mapping = {
"iphone": "ios",
"appletv": "tvos",
"watch": "watchos",
}
if platform not in mapping:
return "unknown simulator platform: {}".format(platform)

# Make sure we have an SDK.
try:
output = subprocess.check_output(
["xcodebuild", "-showsdks"], stderr=subprocess.DEVNULL
).decode("utf-8")
if re.search("%ssimulator" % platform, output):
return None
else:
if not re.search("%ssimulator" % platform, output):
return "%s simulator is not supported on this system." % platform
except subprocess.CalledProcessError:
return "Simulators are unsupported on this system (xcodebuild failed)"

# Make sure we a simulator runtime.
try:
sim_devices_str = subprocess.check_output(
["xcrun", "simctl", "list", "-j", "devices"]
).decode("utf-8")

sim_devices = json.loads(sim_devices_str)["devices"]
for simulator in sim_devices:
if isinstance(simulator, dict):
runtime = simulator["name"]
devices = simulator["devices"]
else:
runtime = simulator
devices = sim_devices[simulator]

if not mapping[platform] in runtime.lower():
continue

for device in devices:
if (
"availability" in device
and device["availability"] == "(available)"
):
return None
if "isAvailable" in device and device["isAvailable"]:
return None

return "{} simulator is not supported on this system.".format(platform)
except (subprocess.CalledProcessError, json.decoder.JSONDecodeError):
return "Simulators are unsupported on this system (simctl failed)"

return skipTestIfFn(should_skip_simulator_test)


Expand Down
12 changes: 8 additions & 4 deletions lldb/test/API/macosx/simulator/TestSimulatorPlatform.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ def check_debugserver(self, log, expected_platform, expected_version):
if expected_version:
self.assertEqual(aout_info["min_version_os_sdk"], expected_version)

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

version_min = ""
if not vers:
vers = lldbutil.get_xcode_sdk_version(sdk)

version_min = ""
if env == "simulator":
version_min = "-m{}-simulator-version-min={}".format(os, vers)
elif os == "macosx":
Expand All @@ -56,11 +56,14 @@ def run_with(self, arch, os, vers, env, expected_load_command):
sdk_root = lldbutil.get_xcode_sdk_root(sdk)
clang = lldbutil.get_xcode_clang(sdk)

print(triple)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print(triple)
if self.TraceOn():
print(triple)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can go altogether, this was a leftover debug statement and not particularly helpful in general.


self.build(
dictionary={
"ARCH": arch,
"ARCH_CFLAGS": "-target {} {}".format(triple, version_min),
"SDKROOT": sdk_root,
"USE_SYSTEM_STDLIB": 1,
},
compiler=clang,
)
Expand Down Expand Up @@ -146,6 +149,7 @@ def test_watchos_armv7k(self):

@skipUnlessDarwin
@skipIfDarwinEmbedded
@skipIf(archs=["arm64", "arm64e"])
def test_lc_version_min_macosx(self):
"""Test running a back-deploying non-simulator MacOS X binary"""
self.run_with(
Expand Down Expand Up @@ -198,7 +202,7 @@ def test_ios_backdeploy_apple_silicon(self):
self.run_with(
arch=self.getArchitecture(),
os="ios",
vers="11.0",
vers="14.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version 11 here is (I believe) significant. Prior to 12 there was no x86_64-apple-ios-simulator triple, instead simulator binaries used load commands that produced a x86_64-apple-ios triple, which was assumed to mean simulator, due to the combination of x86 and iOS.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apple silicon and/or macCatalyst made the dedicated -simulator environment (and matching load commands) necessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I kept 11.0 for the non-Apple Silicon test. On AS it's not possible to test this as the linker automatically upgrades to the first supported AS version (14.0)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, but that's the arm64 test, so this is fine!

env="simulator",
expected_load_command="LC_BUILD_VERSION",
)
Expand Down Expand Up @@ -229,7 +233,7 @@ def test_tvos_backdeploy_apple_silicon(self):
self.run_with(
arch=self.getArchitecture(),
os="tvos",
vers="11.0",
vers="14.0",
env="simulator",
expected_load_command="LC_BUILD_VERSION",
)
Expand Down
Loading