Skip to content

Commit 852cecb

Browse files
jmagmanclocksmith
authored andcommitted
Run flutter tester with arch -x86_64 on arm64 Mac (flutter#92508)
1 parent 52c01db commit 852cecb

File tree

2 files changed

+88
-2
lines changed

2 files changed

+88
-2
lines changed

packages/flutter_tools/lib/src/test/flutter_tester_device.dart

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import '../base/common.dart';
1616
import '../base/file_system.dart';
1717
import '../base/io.dart';
1818
import '../base/logger.dart';
19+
import '../base/os.dart';
1920
import '../base/platform.dart';
2021
import '../convert.dart';
2122
import '../device.dart';
@@ -46,7 +47,13 @@ class FlutterTesterTestDevice extends TestDevice {
4647
}) : assert(shellPath != null), // Please provide the path to the shell in the SKY_SHELL environment variable.
4748
assert(!debuggingOptions.startPaused || enableObservatory),
4849
_gotProcessObservatoryUri = enableObservatory
49-
? Completer<Uri>() : (Completer<Uri>()..complete(null));
50+
? Completer<Uri>() : (Completer<Uri>()..complete(null)),
51+
_operatingSystemUtils = OperatingSystemUtils(
52+
fileSystem: fileSystem,
53+
logger: logger,
54+
platform: platform,
55+
processManager: processManager,
56+
);
5057

5158
/// Used for logging to identify the test that is currently being executed.
5259
final int id;
@@ -70,6 +77,7 @@ class FlutterTesterTestDevice extends TestDevice {
7077

7178
Process _process;
7279
HttpServer _server;
80+
final OperatingSystemUtils _operatingSystemUtils;
7381

7482
/// Starts the device.
7583
///
@@ -87,6 +95,13 @@ class FlutterTesterTestDevice extends TestDevice {
8795
logger.printTrace('test $id: test harness socket server is running at port:${_server.port}');
8896

8997
final List<String> command = <String>[
98+
// Until an arm64 flutter tester binary is available, force to run in Rosetta
99+
// to avoid "unexpectedly got a signal in sigtramp" crash.
100+
// https://github.com/flutter/flutter/issues/88106
101+
if (_operatingSystemUtils.hostPlatform == HostPlatform.darwin_arm) ...<String>[
102+
'/usr/bin/arch',
103+
'-x86_64',
104+
],
90105
shellPath,
91106
if (enableObservatory) ...<String>[
92107
// Some systems drive the _FlutterPlatform class in an unusual way, where

packages/flutter_tools/test/general.shard/flutter_tester_device_test.dart

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,66 @@ void main() {
5151
dartEntrypointArgs: dartEntrypointArgs,
5252
);
5353

54+
testUsingContext('runs in Rosetta on arm64 Mac', () async {
55+
final FakeProcessManager processManager = FakeProcessManager.empty();
56+
final FlutterTesterTestDevice device = TestFlutterTesterDevice(
57+
platform: FakePlatform(operatingSystem: 'macos'),
58+
fileSystem: fileSystem,
59+
processManager: processManager,
60+
enableObservatory: false,
61+
dartEntrypointArgs: const <String>[],
62+
);
63+
processManager.addCommands(<FakeCommand>[
64+
const FakeCommand(
65+
command: <String>[
66+
'which',
67+
'sysctl',
68+
],
69+
),
70+
const FakeCommand(
71+
command: <String>[
72+
'sysctl',
73+
'hw.optional.arm64',
74+
],
75+
stdout: 'hw.optional.arm64: 1',
76+
),
77+
FakeCommand(command: const <String>[
78+
'/usr/bin/arch',
79+
'-x86_64',
80+
'/',
81+
'--disable-observatory',
82+
'--ipv6',
83+
'--enable-checked-mode',
84+
'--verify-entry-points',
85+
'--enable-software-rendering',
86+
'--skia-deterministic-rendering',
87+
'--enable-dart-profiling',
88+
'--non-interactive',
89+
'--use-test-fonts',
90+
'--packages=.dart_tool/package_config.json',
91+
'example.dill',
92+
], environment: <String, String>{
93+
'FLUTTER_TEST': 'true',
94+
'FONTCONFIG_FILE': device.fontConfigManager.fontConfigFile.path,
95+
'SERVER_PORT': '0',
96+
'APP_NAME': '',
97+
}),
98+
]);
99+
await device.start('example.dill');
100+
expect(processManager.hasRemainingExpectations, isFalse);
101+
});
102+
54103
group('The FLUTTER_TEST environment variable is passed to the test process', () {
55104
setUp(() {
56-
processManager = FakeProcessManager.empty();
105+
processManager = FakeProcessManager.list(<FakeCommand>[
106+
const FakeCommand(
107+
command: <String>[
108+
'uname',
109+
'-m',
110+
],
111+
stdout: 'x86_64',
112+
),
113+
]);
57114
device = createDevice();
58115

59116
fileSystem
@@ -127,6 +184,13 @@ void main() {
127184
group('Dart Entrypoint Args', () {
128185
setUp(() {
129186
processManager = FakeProcessManager.list(<FakeCommand>[
187+
const FakeCommand(
188+
command: <String>[
189+
'uname',
190+
'-m',
191+
],
192+
stdout: 'x86_64',
193+
),
130194
const FakeCommand(
131195
command: <String>[
132196
'/',
@@ -161,6 +225,13 @@ void main() {
161225
group('DDS', () {
162226
setUp(() {
163227
processManager = FakeProcessManager.list(<FakeCommand>[
228+
const FakeCommand(
229+
command: <String>[
230+
'uname',
231+
'-m',
232+
],
233+
stdout: 'x86_64',
234+
),
164235
const FakeCommand(
165236
command: <String>[
166237
'/',

0 commit comments

Comments
 (0)