Skip to content

Commit a16e620

Browse files
authored
Funnel devicelab tests through utils process methods (#122161)
Funnel devicelab tests through utils process methods
1 parent 244372b commit a16e620

13 files changed

+142
-132
lines changed

dev/devicelab/bin/tasks/flutter_engine_group_performance.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,9 @@ Future<TaskResult> _doTest() async {
5858
final String gradlew = Platform.isWindows ? 'gradlew.bat' : 'gradlew';
5959
final String gradlewExecutable =
6060
Platform.isWindows ? '.\\$gradlew' : './$gradlew';
61-
final String flutterPath = path.join(flutterDirectory, 'bin', 'flutter');
62-
await utils.eval(flutterPath, <String>['precache', '--android'],
61+
await utils.flutter('precache', options: <String>['--android'],
6362
workingDirectory: modulePath);
64-
await utils.eval(flutterPath, <String>['pub', 'get'],
63+
await utils.flutter('pub', options: <String>['get'],
6564
workingDirectory: modulePath);
6665
_copyGradleFromModule(modulePath, androidPath);
6766

dev/devicelab/bin/tasks/flutter_gallery_v2_chrome_run_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ class NewGalleryChromeRunTest {
5353
]);
5454

5555
final List<String> options = <String>['-d', 'chrome', '--verbose', '--resident'];
56-
final Process process = await startProcess(
57-
path.join(flutterDirectory.path, 'bin', 'flutter'),
58-
flutterCommandArgs('run', options),
56+
final Process process = await startFlutter(
57+
'run',
58+
options: options,
5959
);
6060

6161
final Completer<void> stdoutDone = Completer<void>();

dev/devicelab/bin/tasks/flutter_test_performance.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@ enum TestStep {
3838

3939
Future<int> runTest({bool coverage = false, bool noPub = false}) async {
4040
final Stopwatch clock = Stopwatch()..start();
41-
final List<String> arguments = flutterCommandArgs('test', <String>[
42-
if (coverage) '--coverage',
43-
if (noPub) '--no-pub',
44-
path.join('flutter_test', 'trivial_widget_test.dart'),
45-
]);
46-
final Process analysis = await startProcess(
47-
path.join(flutterDirectory.path, 'bin', 'flutter'),
48-
arguments,
41+
final Process analysis = await startFlutter(
42+
'test',
43+
options: <String>[
44+
if (coverage) '--coverage',
45+
if (noPub) '--no-pub',
46+
path.join('flutter_test', 'trivial_widget_test.dart'),
47+
],
4948
workingDirectory: path.join(flutterDirectory.path, 'dev', 'automated_tests'),
5049
);
5150
int badLines = 0;

dev/devicelab/bin/tasks/routing_test.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ void main() {
3838
final Completer<void> ready = Completer<void>();
3939
late bool ok;
4040
print('run: starting...');
41-
final Process run = await startProcess(
42-
path.join(flutterDirectory.path, 'bin', 'flutter'),
41+
final Process run = await startFlutter(
42+
'run',
4343
// --fast-start does not support routes.
44-
<String>['run', '--verbose', '--disable-service-auth-codes', '--no-fast-start', '--no-publish-port', '-d', device.deviceId, '--route', '/smuggle-it', 'lib/route.dart'],
44+
options: <String>['--verbose', '--disable-service-auth-codes', '--no-fast-start', '--no-publish-port', '-d', device.deviceId, '--route', '/smuggle-it', 'lib/route.dart'],
4545
);
4646
run.stdout
4747
.transform<String>(utf8.decoder)
@@ -70,9 +70,9 @@ void main() {
7070
throw 'Failed to run test app.';
7171
}
7272
print('drive: starting...');
73-
final Process drive = await startProcess(
74-
path.join(flutterDirectory.path, 'bin', 'flutter'),
75-
<String>['drive', '--use-existing-app', 'http://127.0.0.1:$vmServicePort/', '--no-keep-app-running', 'lib/route.dart'],
73+
final Process drive = await startFlutter(
74+
'drive',
75+
options: <String>['--use-existing-app', 'http://127.0.0.1:$vmServicePort/', '--no-keep-app-running', 'lib/route.dart'],
7676
);
7777
drive.stdout
7878
.transform<String>(utf8.decoder)

dev/devicelab/bin/tasks/service_extensions_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ void main() {
2525
final Completer<void> ready = Completer<void>();
2626
late bool ok;
2727
print('run: starting...');
28-
final Process run = await startProcess(
29-
path.join(flutterDirectory.path, 'bin', 'flutter'),
30-
<String>['run', '--verbose', '--no-fast-start', '--no-publish-port', '--disable-service-auth-codes', '-d', device.deviceId, 'lib/main.dart'],
28+
final Process run = await startFlutter(
29+
'run',
30+
options: <String>['--verbose', '--no-fast-start', '--no-publish-port', '--disable-service-auth-codes', '-d', device.deviceId, 'lib/main.dart'],
3131
);
3232
run.stdout
3333
.transform<String>(utf8.decoder)

dev/devicelab/lib/framework/utils.dart

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ Future<String> eval(
433433
return output.toString().trimRight();
434434
}
435435

436-
List<String> flutterCommandArgs(String command, List<String> options) {
436+
List<String> _flutterCommandArgs(String command, List<String> options) {
437437
// Commands support the --device-timeout flag.
438438
final Set<String> supportedDeviceTimeoutCommands = <String>{
439439
'attach',
@@ -470,10 +470,11 @@ Future<int> flutter(String command, {
470470
List<String> options = const <String>[],
471471
bool canFail = false, // as in, whether failures are ok. False means that they are fatal.
472472
Map<String, String>? environment,
473+
String? workingDirectory,
473474
}) {
474-
final List<String> args = flutterCommandArgs(command, options);
475+
final List<String> args = _flutterCommandArgs(command, options);
475476
return exec(path.join(flutterDirectory.path, 'bin', 'flutter'), args,
476-
canFail: canFail, environment: environment);
477+
canFail: canFail, environment: environment, workingDirectory: workingDirectory);
477478
}
478479

479480
/// Starts a Flutter subprocess.
@@ -502,13 +503,15 @@ Future<Process> startFlutter(String command, {
502503
List<String> options = const <String>[],
503504
Map<String, String> environment = const <String, String>{},
504505
bool isBot = true, // set to false to pretend not to be on a bot (e.g. to test user-facing outputs)
505-
}) {
506-
final List<String> args = flutterCommandArgs(command, options);
506+
String? workingDirectory,
507+
}) async {
508+
final List<String> args = _flutterCommandArgs(command, options);
507509
return startProcess(
508510
path.join(flutterDirectory.path, 'bin', 'flutter'),
509511
args,
510512
environment: environment,
511513
isBot: isBot,
514+
workingDirectory: workingDirectory,
512515
);
513516
}
514517

@@ -518,16 +521,17 @@ Future<String> evalFlutter(String command, {
518521
bool canFail = false, // as in, whether failures are ok. False means that they are fatal.
519522
Map<String, String>? environment,
520523
StringBuffer? stderr, // if not null, the stderr will be written here.
524+
String? workingDirectory,
521525
}) {
522-
final List<String> args = flutterCommandArgs(command, options);
526+
final List<String> args = _flutterCommandArgs(command, options);
523527
return eval(path.join(flutterDirectory.path, 'bin', 'flutter'), args,
524-
canFail: canFail, environment: environment, stderr: stderr);
528+
canFail: canFail, environment: environment, stderr: stderr, workingDirectory: workingDirectory);
525529
}
526530

527531
Future<ProcessResult> executeFlutter(String command, {
528532
List<String> options = const <String>[],
529533
}) async {
530-
final List<String> args = flutterCommandArgs(command, options);
534+
final List<String> args = _flutterCommandArgs(command, options);
531535
return _processManager.run(
532536
<String>[path.join(flutterDirectory.path, 'bin', 'flutter'), ...args],
533537
workingDirectory: cwd,

dev/devicelab/lib/tasks/android_choreographer_do_frame_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ Future<void> main() async {
8888
section('Flutter run (mode: $mode)');
8989
late Process run;
9090
await inDirectory(path.join(tempDir.path, 'app'), () async {
91-
run = await startProcess(
92-
path.join(flutterDirectory.path, 'bin', 'flutter'),
93-
flutterCommandArgs('run', <String>['--$mode', '--verbose']),
91+
run = await startFlutter(
92+
'run',
93+
options: <String>['--$mode', '--verbose'],
9494
);
9595
});
9696

dev/devicelab/lib/tasks/android_lifecycles_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ void main() {
7777

7878
late Process run;
7979
await inDirectory(path.join(tempDir.path, 'app'), () async {
80-
run = await startProcess(
81-
path.join(flutterDirectory.path, 'bin', 'flutter'),
82-
flutterCommandArgs('run', <String>['--$mode']),
80+
run = await startFlutter(
81+
'run',
82+
options: <String>['--$mode'],
8383
);
8484
});
8585

dev/devicelab/lib/tasks/dart_plugin_registry_tests.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ class ApluginPlatformInterfaceMacOS {
143143

144144
late Process run;
145145
await inDirectory(path.join(tempDir.path, 'app'), () async {
146-
run = await startProcess(
147-
path.join(flutterDirectory.path, 'bin', 'flutter'),
148-
flutterCommandArgs('run', <String>['-d', 'macos', '-v']),
146+
run = await startFlutter(
147+
'run',
148+
options: <String>['-d', 'macos', '-v'],
149149
);
150150
});
151151

dev/devicelab/lib/tasks/hot_mode_tests.dart

Lines changed: 77 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ const String kReplacementLine = 'fontSize: (orientation == Orientation.portrait)
2222

2323
TaskFunction createHotModeTest({
2424
String? deviceIdOverride,
25-
Map<String, String>? environment,
2625
bool checkAppRunningOnLocalDevice = false,
2726
}) {
2827
// This file is modified during the test and needs to be restored at the end.
@@ -63,71 +62,83 @@ TaskFunction createHotModeTest({
6362

6463
try {
6564
await inDirectory<void>(_editedFlutterGalleryDir, () async {
66-
smallReloadData = await captureReloadData(options, environment, benchmarkFile, (String line, Process process) {
67-
if (!line.contains('Reloaded ')) {
68-
return;
69-
}
70-
if (hotReloadCount == 0) {
71-
// Update a file for 2 library invalidation.
72-
final File appDartSource = file(path.join(
73-
_editedFlutterGalleryDir.path, 'lib/gallery/app.dart',
74-
));
75-
appDartSource.writeAsStringSync(
76-
appDartSource.readAsStringSync().replaceFirst(
77-
"'Flutter Gallery'", "'Updated Flutter Gallery'",
65+
smallReloadData = await captureReloadData(
66+
options: options,
67+
benchmarkFile: benchmarkFile,
68+
onLine: (String line, Process process) {
69+
if (!line.contains('Reloaded ')) {
70+
return;
71+
}
72+
if (hotReloadCount == 0) {
73+
// Update a file for 2 library invalidation.
74+
final File appDartSource = file(path.join(
75+
_editedFlutterGalleryDir.path,
76+
'lib/gallery/app.dart',
77+
));
78+
appDartSource.writeAsStringSync(appDartSource.readAsStringSync().replaceFirst(
79+
"'Flutter Gallery'",
80+
"'Updated Flutter Gallery'",
7881
));
79-
process.stdin.writeln('r');
80-
hotReloadCount += 1;
81-
} else {
82-
process.stdin.writeln('q');
83-
}
84-
});
82+
process.stdin.writeln('r');
83+
hotReloadCount += 1;
84+
} else {
85+
process.stdin.writeln('q');
86+
}
87+
},
88+
);
8589

86-
mediumReloadData = await captureReloadData(options, environment, benchmarkFile, (String line, Process process) {
87-
if (!line.contains('Reloaded ')) {
88-
return;
89-
}
90-
if (hotReloadCount == 1) {
91-
// Update a file for ~50 library invalidation.
92-
final File appDartSource = file(path.join(
93-
_editedFlutterGalleryDir.path, 'lib/demo/calculator/home.dart',
94-
));
95-
appDartSource.writeAsStringSync(
96-
appDartSource.readAsStringSync().replaceFirst(kSourceLine, kReplacementLine)
97-
);
98-
process.stdin.writeln('r');
99-
hotReloadCount += 1;
100-
} else {
101-
process.stdin.writeln('q');
102-
}
103-
});
90+
mediumReloadData = await captureReloadData(
91+
options: options,
92+
benchmarkFile: benchmarkFile,
93+
onLine: (String line, Process process) {
94+
if (!line.contains('Reloaded ')) {
95+
return;
96+
}
97+
if (hotReloadCount == 1) {
98+
// Update a file for ~50 library invalidation.
99+
final File appDartSource = file(path.join(
100+
_editedFlutterGalleryDir.path, 'lib/demo/calculator/home.dart',
101+
));
102+
appDartSource.writeAsStringSync(
103+
appDartSource.readAsStringSync().replaceFirst(kSourceLine, kReplacementLine)
104+
);
105+
process.stdin.writeln('r');
106+
hotReloadCount += 1;
107+
} else {
108+
process.stdin.writeln('q');
109+
}
110+
},
111+
);
104112

105-
largeReloadData = await captureReloadData(options, environment, benchmarkFile, (String line, Process process) async {
106-
if (!line.contains('Reloaded ')) {
107-
return;
108-
}
109-
if (hotReloadCount == 2) {
110-
// Trigger a framework invalidation (370 libraries) without modifying the source
111-
flutterFrameworkSource.writeAsStringSync(
112-
'${flutterFrameworkSource.readAsStringSync()}\n'
113-
);
114-
process.stdin.writeln('r');
115-
hotReloadCount += 1;
116-
} else {
117-
if (checkAppRunningOnLocalDevice) {
118-
await _checkAppRunning(true);
113+
largeReloadData = await captureReloadData(
114+
options: options,
115+
benchmarkFile: benchmarkFile,
116+
onLine: (String line, Process process) async {
117+
if (!line.contains('Reloaded ')) {
118+
return;
119+
}
120+
if (hotReloadCount == 2) {
121+
// Trigger a framework invalidation (370 libraries) without modifying the source
122+
flutterFrameworkSource.writeAsStringSync(
123+
'${flutterFrameworkSource.readAsStringSync()}\n'
124+
);
125+
process.stdin.writeln('r');
126+
hotReloadCount += 1;
127+
} else {
128+
if (checkAppRunningOnLocalDevice) {
129+
await _checkAppRunning(true);
130+
}
131+
process.stdin.writeln('q');
119132
}
120-
process.stdin.writeln('q');
121-
}
122-
});
133+
},
134+
);
123135

124136
// Start `flutter run` again to make sure it loads from the previous
125137
// state. Frontend loads up from previously generated kernel files.
126138
{
127-
final Process process = await startProcess(
128-
path.join(flutterDirectory.path, 'bin', 'flutter'),
129-
flutterCommandArgs('run', options),
130-
environment: environment,
139+
final Process process = await startFlutter(
140+
'run',
141+
options: options,
131142
);
132143
final Completer<void> stdoutDone = Completer<void>();
133144
final Completer<void> stderrDone = Completer<void>();
@@ -233,16 +244,14 @@ TaskFunction createHotModeTest({
233244
};
234245
}
235246

236-
Future<Map<String, dynamic>> captureReloadData(
237-
List<String> options,
238-
Map<String, String>? environment,
239-
File benchmarkFile,
240-
void Function(String, Process) onLine,
241-
) async {
242-
final Process process = await startProcess(
243-
path.join(flutterDirectory.path, 'bin', 'flutter'),
244-
flutterCommandArgs('run', options),
245-
environment: environment,
247+
Future<Map<String, dynamic>> captureReloadData({
248+
required List<String> options,
249+
required File benchmarkFile,
250+
required void Function(String, Process) onLine,
251+
}) async {
252+
final Process process = await startFlutter(
253+
'run',
254+
options: options,
246255
);
247256

248257
final Completer<void> stdoutDone = Completer<void>();

dev/devicelab/lib/tasks/perf_tests.dart

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -867,17 +867,19 @@ class DevtoolsStartupTest {
867867
break;
868868
}
869869

870-
final Process process = await startProcess(path.join(flutterDirectory.path, 'bin', 'flutter'), <String>[
870+
final Process process = await startFlutter(
871871
'run',
872-
'--no-android-gradle-daemon',
873-
'--no-publish-port',
874-
'--verbose',
875-
'--profile',
876-
'-d',
877-
device.deviceId,
878-
if (applicationBinaryPath != null)
879-
'--use-application-binary=$applicationBinaryPath',
880-
]);
872+
options: <String>[
873+
'--no-android-gradle-daemon',
874+
'--no-publish-port',
875+
'--verbose',
876+
'--profile',
877+
'-d',
878+
device.deviceId,
879+
if (applicationBinaryPath != null)
880+
'--use-application-binary=$applicationBinaryPath',
881+
],
882+
);
881883
final Completer<void> completer = Completer<void>();
882884
bool sawLine = false;
883885
process.stdout

0 commit comments

Comments
 (0)