Skip to content

Commit

Permalink
Run tests on either macOS 12 or macOS 13 (#5089)
Browse files Browse the repository at this point in the history
In preparation for migrating our fleet to macOS 13, we're updating tests to run on either macOS 12 or macOS 13.
  • Loading branch information
vashworth committed Oct 10, 2023
1 parent 158ec1f commit 4b483f2
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ platform_properties:
[
{"dependency": "gems", "version": "v3.3.14"}
]
os: Mac-12
os: "Mac-12|Mac-13"
device_type: none
cpu: arm64
$flutter/osx_sdk : >-
Expand All @@ -77,7 +77,7 @@ platform_properties:
[
{"dependency": "gems", "version": "v3.3.14"}
]
os: Mac-12
os: "Mac-12|Mac-13"
device_type: none
cpu: x86
$flutter/osx_sdk : >-
Expand Down
14 changes: 14 additions & 0 deletions .ci/scripts/boot_simulator.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash
# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
set -e

# The name here must match create_simulator.sh
readonly DEVICE_NAME=Flutter-iPhone

# Allow boot to fail; cases like "Unable to boot device in current state: Booted"
# exit with failure.
xcrun simctl boot "$DEVICE_NAME" || :
echo -e ""
xcrun simctl list
15 changes: 14 additions & 1 deletion .ci/scripts/create_simulator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,18 @@ readonly DEVICE_NAME=Flutter-iPhone
readonly DEVICE=com.apple.CoreSimulator.SimDeviceType.iPhone-14
readonly OS=com.apple.CoreSimulator.SimRuntime.iOS-16-4

xcrun simctl list
# Delete any existing devices named Flutter-iPhone. Having more than one may
# cause issues when builds target the device.
echo -e "Deleting any existing devices names $DEVICE_NAME..."
RESULT=0
while [[ $RESULT == 0 ]]; do
xcrun simctl delete "$DEVICE_NAME" || RESULT=1
if [ $RESULT == 0 ]; then
echo -e "Deleted $DEVICE_NAME"
fi
done
echo -e ""

echo -e "\nCreating $DEVICE_NAME $DEVICE $OS ...\n"
xcrun simctl create "$DEVICE_NAME" "$DEVICE" "$OS" | xargs xcrun simctl boot
xcrun simctl list
7 changes: 6 additions & 1 deletion .ci/targets/ios_platform_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ tasks:
args: ["xcode-analyze", "--ios", "--ios-min-version=13.0"]
- name: native test
script: script/tool_runner.sh
args: ["native-test", "--ios", "--ios-destination", "platform=iOS Simulator,name=iPhone 14,OS=latest"]
# Simulator name must match name in create_simulator.sh
args: ["native-test", "--ios", "--ios-destination", "platform=iOS Simulator,name=Flutter-iPhone,OS=16.4"]
- name: boot simulator
# Ensure simulator is still booted
script: .ci/scripts/boot_simulator.sh
infra_step: true # Note infra steps failing prevents "always" from running.
- name: drive examples
# `drive-examples` contains integration tests, which changes the UI of the application.
# This UI change sometimes affects `xctest`.
Expand Down
45 changes: 44 additions & 1 deletion packages/pigeon/tool/shared/test_suites.dart
Original file line number Diff line number Diff line change
Expand Up @@ -294,11 +294,54 @@ Future<int> _runIOSPluginUnitTests(String testPluginPath) async {
return compileCode;
}

const String deviceName = 'Pigeon-Test-iPhone';
const String deviceType = 'com.apple.CoreSimulator.SimDeviceType.iPhone-14';
const String deviceRuntime = 'com.apple.CoreSimulator.SimRuntime.iOS-16-4';
const String deviceOS = '16.4';
await _createSimulator(deviceName, deviceType, deviceRuntime);
return runXcodeBuild(
'$examplePath/ios',
sdk: 'iphonesimulator',
destination: 'platform=iOS Simulator,name=iPhone 14',
destination: 'platform=iOS Simulator,name=$deviceName,OS=$deviceOS',
extraArguments: <String>['test'],
).whenComplete(() => _deleteSimulator(deviceName));
}

Future<int> _createSimulator(
String deviceName,
String deviceType,
String deviceRuntime,
) async {
// Delete any existing simulators with the same name until it fails. It will
// fail once there are no simulators with the name. Having more than one may
// cause issues when builds target the device.
int deleteResult = 0;
while (deleteResult == 0) {
deleteResult = await _deleteSimulator(deviceName);
}
return runProcess(
'xcrun',
<String>[
'simctl',
'create',
deviceName,
deviceType,
deviceRuntime,
],
streamOutput: false,
logFailure: true,
);
}

Future<int> _deleteSimulator(String deviceName) async {
return runProcess(
'xcrun',
<String>[
'simctl',
'delete',
deviceName,
],
streamOutput: false,
);
}

Expand Down

0 comments on commit 4b483f2

Please sign in to comment.