gh-133131: Discover an appropriate iOS simulator rather than hard-coding iPhone SE 3rd gen (#133132)

Determines a candidate simulator at runtime rather than hardcoding iPhone SE.
This commit is contained in:
Russell Keith-Magee 2025-04-30 05:35:36 +08:00 committed by GitHub
parent c46635aa5a
commit 42b0b0667e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 41 additions and 3 deletions

View file

@ -0,0 +1,2 @@
The iOS testbed will now select the most recently released "SE-class" device
for testing if a device isn't explicitly specified.

View file

@ -123,6 +123,36 @@ async def async_check_output(*args, **kwargs):
)
# Select a simulator device to use.
async def select_simulator_device():
# List the testing simulators, in JSON format
raw_json = await async_check_output(
"xcrun", "simctl", "--set", "testing", "list", "-j"
)
json_data = json.loads(raw_json)
# Any device will do; we'll look for "SE" devices - but the name isn't
# consistent over time. Older Xcode versions will use "iPhone SE (Nth
# generation)"; As of 2025, they've started using "iPhone 16e".
#
# When Xcode is updated after a new release, new devices will be available
# and old ones will be dropped from the set available on the latest iOS
# version. Select the one with the highest minimum runtime version - this
# is an indicator of the "newest" released device, which should always be
# supported on the "most recent" iOS version.
se_simulators = sorted(
(devicetype["minRuntimeVersion"], devicetype["name"])
for devicetype in json_data["devicetypes"]
if devicetype["productFamily"] == "iPhone"
and (
("iPhone " in devicetype["name"] and devicetype["name"].endswith("e"))
or "iPhone SE " in devicetype["name"]
)
)
return se_simulators[-1][1]
# Return a list of UDIDs associated with booted simulators
async def list_devices():
try:
@ -371,12 +401,16 @@ def update_plist(testbed_path, args):
plistlib.dump(info, f)
async def run_testbed(simulator: str, args: list[str], verbose: bool=False):
async def run_testbed(simulator: str | None, args: list[str], verbose: bool=False):
location = Path(__file__).parent
print("Updating plist...", end="", flush=True)
update_plist(location, args)
print(" done.", flush=True)
if simulator is None:
simulator = await select_simulator_device()
print(f"Running test on {simulator}", flush=True)
# We need to get an exclusive lock on simulator creation, to avoid issues
# with multiple simulators starting and being unable to tell which
# simulator is due to which testbed instance. See
@ -453,8 +487,10 @@ def main():
)
run.add_argument(
"--simulator",
default="iPhone SE (3rd Generation)",
help="The name of the simulator to use (default: 'iPhone SE (3rd Generation)')",
help=(
"The name of the simulator to use (eg: 'iPhone 16e'). Defaults to ",
"the most recently released 'entry level' iPhone device."
)
)
run.add_argument(
"-v", "--verbose",