mirror of
https://github.com/flutter/flutter
synced 2024-08-25 11:07:06 +00:00
Funnel devicelab tests through utils process methods (#122161)
Funnel devicelab tests through utils process methods
This commit is contained in:
parent
244372b303
commit
a16e620ec2
|
@ -58,10 +58,9 @@ Future<TaskResult> _doTest() async {
|
|||
final String gradlew = Platform.isWindows ? 'gradlew.bat' : 'gradlew';
|
||||
final String gradlewExecutable =
|
||||
Platform.isWindows ? '.\\$gradlew' : './$gradlew';
|
||||
final String flutterPath = path.join(flutterDirectory, 'bin', 'flutter');
|
||||
await utils.eval(flutterPath, <String>['precache', '--android'],
|
||||
await utils.flutter('precache', options: <String>['--android'],
|
||||
workingDirectory: modulePath);
|
||||
await utils.eval(flutterPath, <String>['pub', 'get'],
|
||||
await utils.flutter('pub', options: <String>['get'],
|
||||
workingDirectory: modulePath);
|
||||
_copyGradleFromModule(modulePath, androidPath);
|
||||
|
||||
|
|
|
@ -53,9 +53,9 @@ class NewGalleryChromeRunTest {
|
|||
]);
|
||||
|
||||
final List<String> options = <String>['-d', 'chrome', '--verbose', '--resident'];
|
||||
final Process process = await startProcess(
|
||||
path.join(flutterDirectory.path, 'bin', 'flutter'),
|
||||
flutterCommandArgs('run', options),
|
||||
final Process process = await startFlutter(
|
||||
'run',
|
||||
options: options,
|
||||
);
|
||||
|
||||
final Completer<void> stdoutDone = Completer<void>();
|
||||
|
|
|
@ -38,14 +38,13 @@ enum TestStep {
|
|||
|
||||
Future<int> runTest({bool coverage = false, bool noPub = false}) async {
|
||||
final Stopwatch clock = Stopwatch()..start();
|
||||
final List<String> arguments = flutterCommandArgs('test', <String>[
|
||||
if (coverage) '--coverage',
|
||||
if (noPub) '--no-pub',
|
||||
path.join('flutter_test', 'trivial_widget_test.dart'),
|
||||
]);
|
||||
final Process analysis = await startProcess(
|
||||
path.join(flutterDirectory.path, 'bin', 'flutter'),
|
||||
arguments,
|
||||
final Process analysis = await startFlutter(
|
||||
'test',
|
||||
options: <String>[
|
||||
if (coverage) '--coverage',
|
||||
if (noPub) '--no-pub',
|
||||
path.join('flutter_test', 'trivial_widget_test.dart'),
|
||||
],
|
||||
workingDirectory: path.join(flutterDirectory.path, 'dev', 'automated_tests'),
|
||||
);
|
||||
int badLines = 0;
|
||||
|
|
|
@ -38,10 +38,10 @@ void main() {
|
|||
final Completer<void> ready = Completer<void>();
|
||||
late bool ok;
|
||||
print('run: starting...');
|
||||
final Process run = await startProcess(
|
||||
path.join(flutterDirectory.path, 'bin', 'flutter'),
|
||||
final Process run = await startFlutter(
|
||||
'run',
|
||||
// --fast-start does not support routes.
|
||||
<String>['run', '--verbose', '--disable-service-auth-codes', '--no-fast-start', '--no-publish-port', '-d', device.deviceId, '--route', '/smuggle-it', 'lib/route.dart'],
|
||||
options: <String>['--verbose', '--disable-service-auth-codes', '--no-fast-start', '--no-publish-port', '-d', device.deviceId, '--route', '/smuggle-it', 'lib/route.dart'],
|
||||
);
|
||||
run.stdout
|
||||
.transform<String>(utf8.decoder)
|
||||
|
@ -70,9 +70,9 @@ void main() {
|
|||
throw 'Failed to run test app.';
|
||||
}
|
||||
print('drive: starting...');
|
||||
final Process drive = await startProcess(
|
||||
path.join(flutterDirectory.path, 'bin', 'flutter'),
|
||||
<String>['drive', '--use-existing-app', 'http://127.0.0.1:$vmServicePort/', '--no-keep-app-running', 'lib/route.dart'],
|
||||
final Process drive = await startFlutter(
|
||||
'drive',
|
||||
options: <String>['--use-existing-app', 'http://127.0.0.1:$vmServicePort/', '--no-keep-app-running', 'lib/route.dart'],
|
||||
);
|
||||
drive.stdout
|
||||
.transform<String>(utf8.decoder)
|
||||
|
|
|
@ -25,9 +25,9 @@ void main() {
|
|||
final Completer<void> ready = Completer<void>();
|
||||
late bool ok;
|
||||
print('run: starting...');
|
||||
final Process run = await startProcess(
|
||||
path.join(flutterDirectory.path, 'bin', 'flutter'),
|
||||
<String>['run', '--verbose', '--no-fast-start', '--no-publish-port', '--disable-service-auth-codes', '-d', device.deviceId, 'lib/main.dart'],
|
||||
final Process run = await startFlutter(
|
||||
'run',
|
||||
options: <String>['--verbose', '--no-fast-start', '--no-publish-port', '--disable-service-auth-codes', '-d', device.deviceId, 'lib/main.dart'],
|
||||
);
|
||||
run.stdout
|
||||
.transform<String>(utf8.decoder)
|
||||
|
|
|
@ -433,7 +433,7 @@ Future<String> eval(
|
|||
return output.toString().trimRight();
|
||||
}
|
||||
|
||||
List<String> flutterCommandArgs(String command, List<String> options) {
|
||||
List<String> _flutterCommandArgs(String command, List<String> options) {
|
||||
// Commands support the --device-timeout flag.
|
||||
final Set<String> supportedDeviceTimeoutCommands = <String>{
|
||||
'attach',
|
||||
|
@ -470,10 +470,11 @@ Future<int> flutter(String command, {
|
|||
List<String> options = const <String>[],
|
||||
bool canFail = false, // as in, whether failures are ok. False means that they are fatal.
|
||||
Map<String, String>? environment,
|
||||
String? workingDirectory,
|
||||
}) {
|
||||
final List<String> args = flutterCommandArgs(command, options);
|
||||
final List<String> args = _flutterCommandArgs(command, options);
|
||||
return exec(path.join(flutterDirectory.path, 'bin', 'flutter'), args,
|
||||
canFail: canFail, environment: environment);
|
||||
canFail: canFail, environment: environment, workingDirectory: workingDirectory);
|
||||
}
|
||||
|
||||
/// Starts a Flutter subprocess.
|
||||
|
@ -502,13 +503,15 @@ Future<Process> startFlutter(String command, {
|
|||
List<String> options = const <String>[],
|
||||
Map<String, String> environment = const <String, String>{},
|
||||
bool isBot = true, // set to false to pretend not to be on a bot (e.g. to test user-facing outputs)
|
||||
}) {
|
||||
final List<String> args = flutterCommandArgs(command, options);
|
||||
String? workingDirectory,
|
||||
}) async {
|
||||
final List<String> args = _flutterCommandArgs(command, options);
|
||||
return startProcess(
|
||||
path.join(flutterDirectory.path, 'bin', 'flutter'),
|
||||
args,
|
||||
environment: environment,
|
||||
isBot: isBot,
|
||||
workingDirectory: workingDirectory,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -518,16 +521,17 @@ Future<String> evalFlutter(String command, {
|
|||
bool canFail = false, // as in, whether failures are ok. False means that they are fatal.
|
||||
Map<String, String>? environment,
|
||||
StringBuffer? stderr, // if not null, the stderr will be written here.
|
||||
String? workingDirectory,
|
||||
}) {
|
||||
final List<String> args = flutterCommandArgs(command, options);
|
||||
final List<String> args = _flutterCommandArgs(command, options);
|
||||
return eval(path.join(flutterDirectory.path, 'bin', 'flutter'), args,
|
||||
canFail: canFail, environment: environment, stderr: stderr);
|
||||
canFail: canFail, environment: environment, stderr: stderr, workingDirectory: workingDirectory);
|
||||
}
|
||||
|
||||
Future<ProcessResult> executeFlutter(String command, {
|
||||
List<String> options = const <String>[],
|
||||
}) async {
|
||||
final List<String> args = flutterCommandArgs(command, options);
|
||||
final List<String> args = _flutterCommandArgs(command, options);
|
||||
return _processManager.run(
|
||||
<String>[path.join(flutterDirectory.path, 'bin', 'flutter'), ...args],
|
||||
workingDirectory: cwd,
|
||||
|
|
|
@ -88,9 +88,9 @@ Future<void> main() async {
|
|||
section('Flutter run (mode: $mode)');
|
||||
late Process run;
|
||||
await inDirectory(path.join(tempDir.path, 'app'), () async {
|
||||
run = await startProcess(
|
||||
path.join(flutterDirectory.path, 'bin', 'flutter'),
|
||||
flutterCommandArgs('run', <String>['--$mode', '--verbose']),
|
||||
run = await startFlutter(
|
||||
'run',
|
||||
options: <String>['--$mode', '--verbose'],
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -77,9 +77,9 @@ void main() {
|
|||
|
||||
late Process run;
|
||||
await inDirectory(path.join(tempDir.path, 'app'), () async {
|
||||
run = await startProcess(
|
||||
path.join(flutterDirectory.path, 'bin', 'flutter'),
|
||||
flutterCommandArgs('run', <String>['--$mode']),
|
||||
run = await startFlutter(
|
||||
'run',
|
||||
options: <String>['--$mode'],
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -143,9 +143,9 @@ class ApluginPlatformInterfaceMacOS {
|
|||
|
||||
late Process run;
|
||||
await inDirectory(path.join(tempDir.path, 'app'), () async {
|
||||
run = await startProcess(
|
||||
path.join(flutterDirectory.path, 'bin', 'flutter'),
|
||||
flutterCommandArgs('run', <String>['-d', 'macos', '-v']),
|
||||
run = await startFlutter(
|
||||
'run',
|
||||
options: <String>['-d', 'macos', '-v'],
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -22,7 +22,6 @@ const String kReplacementLine = 'fontSize: (orientation == Orientation.portrait)
|
|||
|
||||
TaskFunction createHotModeTest({
|
||||
String? deviceIdOverride,
|
||||
Map<String, String>? environment,
|
||||
bool checkAppRunningOnLocalDevice = false,
|
||||
}) {
|
||||
// This file is modified during the test and needs to be restored at the end.
|
||||
|
@ -63,71 +62,83 @@ TaskFunction createHotModeTest({
|
|||
|
||||
try {
|
||||
await inDirectory<void>(_editedFlutterGalleryDir, () async {
|
||||
smallReloadData = await captureReloadData(options, environment, benchmarkFile, (String line, Process process) {
|
||||
if (!line.contains('Reloaded ')) {
|
||||
return;
|
||||
}
|
||||
if (hotReloadCount == 0) {
|
||||
// Update a file for 2 library invalidation.
|
||||
final File appDartSource = file(path.join(
|
||||
_editedFlutterGalleryDir.path, 'lib/gallery/app.dart',
|
||||
));
|
||||
appDartSource.writeAsStringSync(
|
||||
appDartSource.readAsStringSync().replaceFirst(
|
||||
"'Flutter Gallery'", "'Updated Flutter Gallery'",
|
||||
));
|
||||
process.stdin.writeln('r');
|
||||
hotReloadCount += 1;
|
||||
} else {
|
||||
process.stdin.writeln('q');
|
||||
}
|
||||
});
|
||||
|
||||
mediumReloadData = await captureReloadData(options, environment, benchmarkFile, (String line, Process process) {
|
||||
if (!line.contains('Reloaded ')) {
|
||||
return;
|
||||
}
|
||||
if (hotReloadCount == 1) {
|
||||
// Update a file for ~50 library invalidation.
|
||||
final File appDartSource = file(path.join(
|
||||
_editedFlutterGalleryDir.path, 'lib/demo/calculator/home.dart',
|
||||
));
|
||||
appDartSource.writeAsStringSync(
|
||||
appDartSource.readAsStringSync().replaceFirst(kSourceLine, kReplacementLine)
|
||||
);
|
||||
process.stdin.writeln('r');
|
||||
hotReloadCount += 1;
|
||||
} else {
|
||||
process.stdin.writeln('q');
|
||||
}
|
||||
});
|
||||
|
||||
largeReloadData = await captureReloadData(options, environment, benchmarkFile, (String line, Process process) async {
|
||||
if (!line.contains('Reloaded ')) {
|
||||
return;
|
||||
}
|
||||
if (hotReloadCount == 2) {
|
||||
// Trigger a framework invalidation (370 libraries) without modifying the source
|
||||
flutterFrameworkSource.writeAsStringSync(
|
||||
'${flutterFrameworkSource.readAsStringSync()}\n'
|
||||
);
|
||||
process.stdin.writeln('r');
|
||||
hotReloadCount += 1;
|
||||
} else {
|
||||
if (checkAppRunningOnLocalDevice) {
|
||||
await _checkAppRunning(true);
|
||||
smallReloadData = await captureReloadData(
|
||||
options: options,
|
||||
benchmarkFile: benchmarkFile,
|
||||
onLine: (String line, Process process) {
|
||||
if (!line.contains('Reloaded ')) {
|
||||
return;
|
||||
}
|
||||
process.stdin.writeln('q');
|
||||
}
|
||||
});
|
||||
if (hotReloadCount == 0) {
|
||||
// Update a file for 2 library invalidation.
|
||||
final File appDartSource = file(path.join(
|
||||
_editedFlutterGalleryDir.path,
|
||||
'lib/gallery/app.dart',
|
||||
));
|
||||
appDartSource.writeAsStringSync(appDartSource.readAsStringSync().replaceFirst(
|
||||
"'Flutter Gallery'",
|
||||
"'Updated Flutter Gallery'",
|
||||
));
|
||||
process.stdin.writeln('r');
|
||||
hotReloadCount += 1;
|
||||
} else {
|
||||
process.stdin.writeln('q');
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
mediumReloadData = await captureReloadData(
|
||||
options: options,
|
||||
benchmarkFile: benchmarkFile,
|
||||
onLine: (String line, Process process) {
|
||||
if (!line.contains('Reloaded ')) {
|
||||
return;
|
||||
}
|
||||
if (hotReloadCount == 1) {
|
||||
// Update a file for ~50 library invalidation.
|
||||
final File appDartSource = file(path.join(
|
||||
_editedFlutterGalleryDir.path, 'lib/demo/calculator/home.dart',
|
||||
));
|
||||
appDartSource.writeAsStringSync(
|
||||
appDartSource.readAsStringSync().replaceFirst(kSourceLine, kReplacementLine)
|
||||
);
|
||||
process.stdin.writeln('r');
|
||||
hotReloadCount += 1;
|
||||
} else {
|
||||
process.stdin.writeln('q');
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
largeReloadData = await captureReloadData(
|
||||
options: options,
|
||||
benchmarkFile: benchmarkFile,
|
||||
onLine: (String line, Process process) async {
|
||||
if (!line.contains('Reloaded ')) {
|
||||
return;
|
||||
}
|
||||
if (hotReloadCount == 2) {
|
||||
// Trigger a framework invalidation (370 libraries) without modifying the source
|
||||
flutterFrameworkSource.writeAsStringSync(
|
||||
'${flutterFrameworkSource.readAsStringSync()}\n'
|
||||
);
|
||||
process.stdin.writeln('r');
|
||||
hotReloadCount += 1;
|
||||
} else {
|
||||
if (checkAppRunningOnLocalDevice) {
|
||||
await _checkAppRunning(true);
|
||||
}
|
||||
process.stdin.writeln('q');
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// Start `flutter run` again to make sure it loads from the previous
|
||||
// state. Frontend loads up from previously generated kernel files.
|
||||
{
|
||||
final Process process = await startProcess(
|
||||
path.join(flutterDirectory.path, 'bin', 'flutter'),
|
||||
flutterCommandArgs('run', options),
|
||||
environment: environment,
|
||||
final Process process = await startFlutter(
|
||||
'run',
|
||||
options: options,
|
||||
);
|
||||
final Completer<void> stdoutDone = Completer<void>();
|
||||
final Completer<void> stderrDone = Completer<void>();
|
||||
|
@ -233,16 +244,14 @@ TaskFunction createHotModeTest({
|
|||
};
|
||||
}
|
||||
|
||||
Future<Map<String, dynamic>> captureReloadData(
|
||||
List<String> options,
|
||||
Map<String, String>? environment,
|
||||
File benchmarkFile,
|
||||
void Function(String, Process) onLine,
|
||||
) async {
|
||||
final Process process = await startProcess(
|
||||
path.join(flutterDirectory.path, 'bin', 'flutter'),
|
||||
flutterCommandArgs('run', options),
|
||||
environment: environment,
|
||||
Future<Map<String, dynamic>> captureReloadData({
|
||||
required List<String> options,
|
||||
required File benchmarkFile,
|
||||
required void Function(String, Process) onLine,
|
||||
}) async {
|
||||
final Process process = await startFlutter(
|
||||
'run',
|
||||
options: options,
|
||||
);
|
||||
|
||||
final Completer<void> stdoutDone = Completer<void>();
|
||||
|
|
|
@ -867,17 +867,19 @@ class DevtoolsStartupTest {
|
|||
break;
|
||||
}
|
||||
|
||||
final Process process = await startProcess(path.join(flutterDirectory.path, 'bin', 'flutter'), <String>[
|
||||
final Process process = await startFlutter(
|
||||
'run',
|
||||
'--no-android-gradle-daemon',
|
||||
'--no-publish-port',
|
||||
'--verbose',
|
||||
'--profile',
|
||||
'-d',
|
||||
device.deviceId,
|
||||
if (applicationBinaryPath != null)
|
||||
'--use-application-binary=$applicationBinaryPath',
|
||||
]);
|
||||
options: <String>[
|
||||
'--no-android-gradle-daemon',
|
||||
'--no-publish-port',
|
||||
'--verbose',
|
||||
'--profile',
|
||||
'-d',
|
||||
device.deviceId,
|
||||
if (applicationBinaryPath != null)
|
||||
'--use-application-binary=$applicationBinaryPath',
|
||||
],
|
||||
);
|
||||
final Completer<void> completer = Completer<void>();
|
||||
bool sawLine = false;
|
||||
process.stdout
|
||||
|
|
|
@ -21,18 +21,15 @@ TaskFunction runTask(adb.DeviceOperatingSystem operatingSystem) {
|
|||
final Directory appDir = utils.dir(path.join(utils.flutterDirectory.path,
|
||||
'dev/benchmarks/platform_channels_benchmarks'));
|
||||
final Process flutterProcess = await utils.inDirectory(appDir, () async {
|
||||
final String flutterExe =
|
||||
path.join(utils.flutterDirectory.path, 'bin', 'flutter');
|
||||
final List<String> createArgs = <String>[
|
||||
'create',
|
||||
'--platforms',
|
||||
'ios,android',
|
||||
'--no-overwrite',
|
||||
'-v',
|
||||
'.',
|
||||
];
|
||||
print('\nExecuting: $flutterExe $createArgs $appDir');
|
||||
await utils.eval(flutterExe, createArgs);
|
||||
print('\nExecuting: flutter create $createArgs $appDir');
|
||||
await utils.flutter('create', options: createArgs);
|
||||
|
||||
final List<String> options = <String>[
|
||||
'-v',
|
||||
|
|
|
@ -42,13 +42,13 @@ TaskFunction createWebDevModeTest(String webDevice, bool enableIncrementalCompil
|
|||
recursiveCopy(flutterGalleryDir, _editedFlutterGalleryDir);
|
||||
await inDirectory<void>(_editedFlutterGalleryDir, () async {
|
||||
{
|
||||
await exec(
|
||||
path.join(flutterDirectory.path, 'bin', 'flutter'),
|
||||
<String>['packages', 'get'],
|
||||
await flutter(
|
||||
'packages',
|
||||
options: <String>['get'],
|
||||
);
|
||||
final Process process = await startProcess(
|
||||
path.join(flutterDirectory.path, 'bin', 'flutter'),
|
||||
flutterCommandArgs('run', options),
|
||||
final Process process = await startFlutter(
|
||||
'run',
|
||||
options: options,
|
||||
);
|
||||
|
||||
final Completer<void> stdoutDone = Completer<void>();
|
||||
|
@ -127,9 +127,9 @@ TaskFunction createWebDevModeTest(String webDevice, bool enableIncrementalCompil
|
|||
{
|
||||
|
||||
final Stopwatch sw = Stopwatch()..start();
|
||||
final Process process = await startProcess(
|
||||
path.join(flutterDirectory.path, 'bin', 'flutter'),
|
||||
flutterCommandArgs('run', options),
|
||||
final Process process = await startFlutter(
|
||||
'run',
|
||||
options: options,
|
||||
);
|
||||
final Completer<void> stdoutDone = Completer<void>();
|
||||
final Completer<void> stderrDone = Completer<void>();
|
||||
|
|
Loading…
Reference in a new issue