Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 5882da8

Browse files
authored
Redirect run_ios_tests.sh to run_ios_tests.dart. (#53717)
Part of flutter/flutter#143953. If this merges cleanly, and is not reverted, we can delete `run_ios_tests.sh` and be done.
1 parent 84c9d09 commit 5882da8

File tree

2 files changed

+64
-106
lines changed

2 files changed

+64
-106
lines changed

testing/scenario_app/bin/run_ios_tests.dart

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ void main(List<String> args) async {
4545
} else {
4646
iosEngineVariant = 'ios_debug_sim_unopt';
4747
}
48-
final String dumpXcresultOnFailurePath;
48+
49+
// Null if the tests should create and dispose their own temporary directory.
50+
String? dumpXcresultOnFailurePath;
4951
if (results.option('dump-xcresult-on-failure') case final String path) {
5052
dumpXcresultOnFailurePath = path;
51-
} else {
52-
dumpXcresultOnFailurePath = io.Directory.systemTemp.createTempSync().path;
5353
}
5454

5555
// Run the actual script.
@@ -88,6 +88,12 @@ void main(List<String> args) async {
8888
}
8989
}
9090

91+
void _deleteIfPresent(io.FileSystemEntity entity) {
92+
if (entity.existsSync()) {
93+
entity.deleteSync(recursive: true);
94+
}
95+
}
96+
9197
/// Runs the script.
9298
///
9399
/// The [cleanup] set contains cleanup tasks to run when the script is either
@@ -105,7 +111,7 @@ Future<void> _run(
105111
required String osVersion,
106112
required bool withImpeller,
107113
required bool withSkia,
108-
required String dumpXcresultOnFailure,
114+
required String? dumpXcresultOnFailure,
109115
}) async {
110116
// Terminate early on SIGINT.
111117
late final StreamSubscription<void> sigint;
@@ -127,7 +133,7 @@ Future<void> _run(
127133
iosEngineVariant: iosEngineVariant,
128134
);
129135

130-
cleanup.add(() => resultBundle.deleteSync(recursive: true));
136+
cleanup.add(() => _deleteIfPresent(resultBundle));
131137

132138
if (withSkia) {
133139
io.stderr.writeln('Running simulator tests with Skia');
@@ -141,22 +147,31 @@ Future<void> _run(
141147
xcodeBuildExtraArgs: [
142148
// Plist with `FTEEnableImpeller=NO`; all projects in the workspace require this file.
143149
// For example, `FlutterAppExtensionTestHost` has a dummy file under the below directory.
144-
r'INFOPLIST_FILE="$(TARGET_NAME)/Info_Skia.plist"',
150+
r'INFOPLIST_FILE=$(TARGET_NAME)/Info_Skia.plist',
145151
],
146152
);
147153
cleanup.add(process.kill);
148154

155+
// Create a temporary directory, if needed.
156+
var storePath = dumpXcresultOnFailure;
157+
if (storePath == null) {
158+
final dumpDir = io.Directory.systemTemp.createTempSync();
159+
storePath = dumpDir.path;
160+
cleanup.add(() => dumpDir.delete(recursive: true));
161+
}
162+
149163
if (await process.exitCode != 0) {
150164
final String outputPath = _zipAndStoreFailedTestResults(
151165
iosEngineVariant: iosEngineVariant,
152-
resultBundlePath: resultBundle.path,
153-
storePath: dumpXcresultOnFailure,
166+
resultBundle: resultBundle,
167+
storePath: storePath,
154168
);
155169
io.stderr.writeln('Failed test results are stored at $outputPath');
156170
throw _ToolFailure('test failed.');
157171
} else {
158172
io.stderr.writeln('test succcess.');
159173
}
174+
_deleteIfPresent(resultBundle);
160175
}
161176

162177
if (withImpeller) {
@@ -169,17 +184,26 @@ Future<void> _run(
169184
);
170185
cleanup.add(process.kill);
171186

187+
// Create a temporary directory, if needed.
188+
var storePath = dumpXcresultOnFailure;
189+
if (storePath == null) {
190+
final dumpDir = io.Directory.systemTemp.createTempSync();
191+
storePath = dumpDir.path;
192+
cleanup.add(() => dumpDir.delete(recursive: true));
193+
}
194+
172195
if (await process.exitCode != 0) {
173196
final String outputPath = _zipAndStoreFailedTestResults(
174197
iosEngineVariant: iosEngineVariant,
175-
resultBundlePath: resultBundle.path,
176-
storePath: dumpXcresultOnFailure,
198+
resultBundle: resultBundle,
199+
storePath: storePath,
177200
);
178201
io.stderr.writeln('Failed test results are stored at $outputPath');
179202
throw _ToolFailure('test failed.');
180203
} else {
181204
io.stderr.writeln('test succcess.');
182205
}
206+
_deleteIfPresent(resultBundle);
183207
}
184208
}
185209

@@ -261,8 +285,9 @@ void _ensureSimulatorsRotateAutomaticallyForPlatformViewRotationTest() {
261285
}
262286

263287
void _deleteAnyExistingDevices({required String deviceName}) {
264-
io.stderr
265-
.writeln('Deleting any existing simulator devices named $deviceName...');
288+
io.stderr.writeln(
289+
'Deleting any existing simulator devices named $deviceName...',
290+
);
266291

267292
bool deleteSimulator() {
268293
final result = io.Process.runSync(
@@ -314,8 +339,9 @@ void _createDevice({
314339
));
315340

316341
// Create a temporary directory to store the test results.
317-
final result =
318-
io.Directory(scenarioPath).createTempSync('ios_scenario_xcresult');
342+
final result = io.Directory(scenarioPath).createTempSync(
343+
'ios_scenario_xcresult',
344+
);
319345
return (scenarioPath, result);
320346
}
321347

@@ -353,7 +379,7 @@ Future<io.Process> _runTests({
353379
@useResult
354380
String _zipAndStoreFailedTestResults({
355381
required String iosEngineVariant,
356-
required String resultBundlePath,
382+
required io.Directory resultBundle,
357383
required String storePath,
358384
}) {
359385
final outputPath = path.join(storePath, '$iosEngineVariant.zip');
@@ -363,11 +389,15 @@ String _zipAndStoreFailedTestResults({
363389
'-q',
364390
'-r',
365391
outputPath,
366-
resultBundlePath,
392+
resultBundle.path,
367393
],
368394
);
369395
if (result.exitCode != 0) {
370-
throw Exception('Failed to zip the test results: ${result.stderr}');
396+
throw Exception(
397+
'Failed to zip the test results (exit code = ${result.exitCode}).\n\n'
398+
'Stderr: ${result.stderr}\n\n'
399+
'Stdout: ${result.stdout}',
400+
);
371401
}
372402
return outputPath;
373403
}

testing/scenario_app/run_ios_tests.sh

Lines changed: 17 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/bin/bash
22

3-
set -e
3+
# TODO(matanlurey): Remove all references are gone and using run_ios_tests.dart.
4+
# See https://github.com/flutter/flutter/issues/143953 for tracking.
45

6+
set -e
57

68
# Needed because if it is set, cd may print the path it changed to.
79
unset CDPATH
@@ -24,94 +26,20 @@ function follow_links() (
2426
echo "$file"
2527
)
2628

27-
SCRIPT_DIR=$(follow_links "$(dirname -- "${BASH_SOURCE[0]}")")
28-
SRC_DIR="$(cd "$SCRIPT_DIR/../../.."; pwd -P)"
29-
30-
if uname -m | grep "arm64"; then
31-
FLUTTER_ENGINE="ios_debug_sim_unopt_arm64"
32-
else
33-
FLUTTER_ENGINE="ios_debug_sim_unopt"
34-
fi
35-
36-
if [[ $# -eq 1 ]]; then
37-
FLUTTER_ENGINE="$1"
38-
fi
39-
40-
# Make sure simulators rotate automatically for "PlatformViewRotation" test.
41-
# Can also be set via Simulator app Device > Rotate Device Automatically
42-
defaults write com.apple.iphonesimulator RotateWindowWhenSignaledByGuest -int 1
43-
44-
SCENARIO_PATH=$SRC_DIR/out/$FLUTTER_ENGINE/scenario_app/Scenarios
45-
pushd .
46-
cd $SCENARIO_PATH
47-
48-
RESULT_BUNDLE_FOLDER=$(mktemp -d ios_scenario_xcresult_XXX)
49-
RESULT_BUNDLE_PATH="${SCENARIO_PATH}/${RESULT_BUNDLE_FOLDER}"
50-
51-
# Zip and upload xcresult to luci.
52-
# First parameter ($1) is the zip output name.
53-
zip_and_upload_xcresult_to_luci () {
54-
# We don't want the zip to contain the abusolute path,
55-
# so use relative path (./$RESULT_BUNDLE_FOLDER) instead.
56-
zip -q -r $1 "./$RESULT_BUNDLE_FOLDER"
57-
mv -f $1 $FLUTTER_TEST_OUTPUTS_DIR
58-
exit 1
29+
function dart_bin() {
30+
dart_path="$1/flutter/third_party/dart/tools/sdks/dart-sdk/bin"
31+
if [[ ! -e "$dart_path" ]]; then
32+
dart_path="$1/third_party/dart/tools/sdks/dart-sdk/bin"
33+
fi
34+
echo "$dart_path"
5935
}
6036

61-
readonly DEVICE_NAME="iPhone SE (3rd generation)"
62-
readonly DEVICE=com.apple.CoreSimulator.SimDeviceType.iPhone-SE-3rd-generation
63-
readonly OS_RUNTIME=com.apple.CoreSimulator.SimRuntime.iOS-17-0
64-
readonly OS="17.0"
65-
66-
# Delete any existing devices named "iPhone SE (3rd generation)". Having more
67-
# than one may cause issues when builds target the device.
68-
echo "Deleting any existing devices names $DEVICE_NAME..."
69-
RESULT=0
70-
while [[ $RESULT == 0 ]]; do
71-
xcrun simctl delete "$DEVICE_NAME" || RESULT=1
72-
if [ $RESULT == 0 ]; then
73-
echo "Deleted $DEVICE_NAME"
74-
fi
75-
done
76-
echo ""
77-
78-
echo "Creating $DEVICE_NAME $DEVICE $OS_RUNTIME ..."
79-
xcrun simctl create "$DEVICE_NAME" "$DEVICE" "$OS_RUNTIME"
80-
echo ""
81-
82-
echo "Running simulator tests with Impeller"
83-
echo ""
84-
85-
if set -o pipefail && xcodebuild -sdk iphonesimulator \
86-
-scheme Scenarios \
87-
-resultBundlePath "$RESULT_BUNDLE_PATH/ios_scenario.xcresult" \
88-
-destination "platform=iOS Simulator,OS=$OS,name=$DEVICE_NAME" \
89-
clean test \
90-
FLUTTER_ENGINE="$FLUTTER_ENGINE"; then
91-
echo "test success."
92-
else
93-
echo "test failed."
94-
zip_and_upload_xcresult_to_luci "ios_scenario_xcresult.zip"
95-
fi
96-
rm -rf $RESULT_BUNDLE_PATH
97-
98-
echo "Running simulator tests with Skia"
99-
echo ""
100-
101-
# Override Info.plist with FLTEnableImpeller=NO, all projects in the workspace requires a Info_Skia.plist.
102-
# For example, FlutterAppExtensionTestHost has a Info_Skia.plist dummy file in its directory.
103-
if set -o pipefail && xcodebuild -sdk iphonesimulator \
104-
-scheme Scenarios \
105-
-resultBundlePath "$RESULT_BUNDLE_PATH/ios_scenario.xcresult" \
106-
-destination "platform=iOS Simulator,OS=$OS,name=$DEVICE_NAME" \
107-
clean test \
108-
FLUTTER_ENGINE="$FLUTTER_ENGINE" \
109-
INFOPLIST_FILE="\$(TARGET_NAME)/Info_Skia.plist"; then
110-
echo "test success."
111-
else
112-
echo "test failed."
113-
zip_and_upload_xcresult_to_luci "ios_scenario_impeller_xcresult.zip"
114-
fi
115-
rm -rf $RESULT_BUNDLE_PATH
37+
SCRIPT_DIR=$(follow_links "$(dirname -- "${BASH_SOURCE[0]}")")
38+
SRC_DIR="$(cd "$SCRIPT_DIR/../../.."; pwd -P)"
39+
DART_BIN=$(dart_bin "$SRC_DIR")
40+
DART="${DART_BIN}/dart"
11641

117-
popd
42+
"$DART" \
43+
--disable-dart-dev \
44+
testing/scenario_app/bin/run_ios_tests.dart \
45+
"$@"

0 commit comments

Comments
 (0)