Skip to content

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

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 1 commit into from
Apr 29, 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
Original file line number Diff line number Diff line change
@@ -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.
42 changes: 39 additions & 3 deletions iOS/testbed/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
Loading