Commit 6cdab85d authored by Yegor's avatar Yegor Committed by GitHub

Sync test code with Cocoon (#6129)

* fix flutter watch benchmark

Syncs https://github.com/flutter/cocoon/commit/d2d7950ecd2c72421d75d9b5d54805cc554e92a8

* Split Android/iOS impl behind a unified interface

Syncs https://github.com/flutter/cocoon/commit/db87e10fa54317115479d0b85280c7e5eed08ff7

* Switch from pub get to flutter packages get

Syncs https://github.com/flutter/cocoon/commit/b378005cbbc5330058d5240a2970ca477c2c9722

* "silent" option in test runner; fix analysis errors;
parent 8a823328
...@@ -51,9 +51,11 @@ Future<Null> main(List<String> rawArgs) async { ...@@ -51,9 +51,11 @@ Future<Null> main(List<String> rawArgs) async {
return null; return null;
} }
bool silent = args['silent'];
for (String taskName in taskNames) { for (String taskName in taskNames) {
section('Running task "$taskName"'); section('Running task "$taskName"');
Map<String, dynamic> result = await runTask(taskName); Map<String, dynamic> result = await runTask(taskName, silent: silent);
if (!result['success']) if (!result['success'])
exitCode = 1; exitCode = 1;
...@@ -98,4 +100,9 @@ final ArgParser _argParser = new ArgParser() ...@@ -98,4 +100,9 @@ final ArgParser _argParser = new ArgParser()
); );
} }
}, },
)
..addFlag(
'silent',
negatable: true,
defaultsTo: false,
); );
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter_devicelab/tasks/perf_tests.dart'; import 'package:flutter_devicelab/tasks/perf_tests.dart';
import 'package:flutter_devicelab/framework/adb.dart';
import 'package:flutter_devicelab/framework/framework.dart'; import 'package:flutter_devicelab/framework/framework.dart';
Future<Null> main() async { Future<Null> main() async {
await task(createComplexLayoutStartupTest(ios: false)); await task(createComplexLayoutStartupTest(os: DeviceOperatingSystem.android));
} }
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter_devicelab/tasks/perf_tests.dart'; import 'package:flutter_devicelab/tasks/perf_tests.dart';
import 'package:flutter_devicelab/framework/adb.dart';
import 'package:flutter_devicelab/framework/framework.dart'; import 'package:flutter_devicelab/framework/framework.dart';
Future<Null> main() async { Future<Null> main() async {
await task(createComplexLayoutStartupTest(ios: true)); await task(createComplexLayoutStartupTest(os: DeviceOperatingSystem.ios));
} }
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter_devicelab/tasks/perf_tests.dart'; import 'package:flutter_devicelab/tasks/perf_tests.dart';
import 'package:flutter_devicelab/framework/adb.dart';
import 'package:flutter_devicelab/framework/framework.dart'; import 'package:flutter_devicelab/framework/framework.dart';
Future<Null> main() async { Future<Null> main() async {
await task(createComplexLayoutScrollPerfTest(ios: false)); await task(createComplexLayoutScrollPerfTest(os: DeviceOperatingSystem.android));
} }
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter_devicelab/tasks/perf_tests.dart'; import 'package:flutter_devicelab/tasks/perf_tests.dart';
import 'package:flutter_devicelab/framework/adb.dart';
import 'package:flutter_devicelab/framework/framework.dart'; import 'package:flutter_devicelab/framework/framework.dart';
Future<Null> main() async { Future<Null> main() async {
await task(createComplexLayoutScrollPerfTest(ios: true)); await task(createComplexLayoutScrollPerfTest(os: DeviceOperatingSystem.ios));
} }
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter_devicelab/tasks/perf_tests.dart'; import 'package:flutter_devicelab/tasks/perf_tests.dart';
import 'package:flutter_devicelab/framework/adb.dart';
import 'package:flutter_devicelab/framework/framework.dart'; import 'package:flutter_devicelab/framework/framework.dart';
Future<Null> main() async { Future<Null> main() async {
await task(createFlutterGalleryStartupTest(ios: false)); await task(createFlutterGalleryStartupTest(os: DeviceOperatingSystem.android));
} }
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter_devicelab/tasks/gallery.dart'; import 'package:flutter_devicelab/tasks/gallery.dart';
import 'package:flutter_devicelab/framework/adb.dart';
import 'package:flutter_devicelab/framework/framework.dart'; import 'package:flutter_devicelab/framework/framework.dart';
Future<Null> main() async { Future<Null> main() async {
await task(createGalleryTransitionTest(ios: false)); await task(createGalleryTransitionTest(os: DeviceOperatingSystem.android));
} }
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter_devicelab/tasks/perf_tests.dart'; import 'package:flutter_devicelab/tasks/perf_tests.dart';
import 'package:flutter_devicelab/framework/adb.dart';
import 'package:flutter_devicelab/framework/framework.dart'; import 'package:flutter_devicelab/framework/framework.dart';
Future<Null> main() async { Future<Null> main() async {
await task(createFlutterGalleryStartupTest(ios: true)); await task(createFlutterGalleryStartupTest(os: DeviceOperatingSystem.ios));
} }
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter_devicelab/tasks/gallery.dart'; import 'package:flutter_devicelab/tasks/gallery.dart';
import 'package:flutter_devicelab/framework/adb.dart';
import 'package:flutter_devicelab/framework/framework.dart'; import 'package:flutter_devicelab/framework/framework.dart';
Future<Null> main() async { Future<Null> main() async {
await task(createGalleryTransitionTest(ios: true)); await task(createGalleryTransitionTest(os: DeviceOperatingSystem.ios));
} }
...@@ -12,7 +12,7 @@ import 'package:flutter_devicelab/framework/utils.dart'; ...@@ -12,7 +12,7 @@ import 'package:flutter_devicelab/framework/utils.dart';
void main() { void main() {
task(() async { task(() async {
Adb device = await adb(); Device device = await devices.workingDevice;
await device.unlock(); await device.unlock();
Directory appDir = Directory appDir =
dir(path.join(flutterDirectory.path, 'examples/flutter_gallery')); dir(path.join(flutterDirectory.path, 'examples/flutter_gallery'));
......
This diff is collapsed.
...@@ -19,7 +19,10 @@ const Duration taskTimeoutWithGracePeriod = const Duration(minutes: 11); ...@@ -19,7 +19,10 @@ const Duration taskTimeoutWithGracePeriod = const Duration(minutes: 11);
/// ///
/// [taskName] is the name of the task. The corresponding task executable is /// [taskName] is the name of the task. The corresponding task executable is
/// expected to be found under `bin/tasks`. /// expected to be found under `bin/tasks`.
Future<Map<String, dynamic>> runTask(String taskName) async { ///
/// Running the task in [silent] mode will suppress standard output from task
/// processes and only print standard errors.
Future<Map<String, dynamic>> runTask(String taskName, { bool silent: false }) async {
String taskExecutable = 'bin/tasks/$taskName.dart'; String taskExecutable = 'bin/tasks/$taskName.dart';
if (!file(taskExecutable).existsSync()) if (!file(taskExecutable).existsSync())
...@@ -42,7 +45,9 @@ Future<Map<String, dynamic>> runTask(String taskName) async { ...@@ -42,7 +45,9 @@ Future<Map<String, dynamic>> runTask(String taskName) async {
.transform(new Utf8Decoder()) .transform(new Utf8Decoder())
.transform(new LineSplitter()) .transform(new LineSplitter())
.listen((String line) { .listen((String line) {
if (!silent) {
stdout.writeln('[$taskName] [STDOUT] $line'); stdout.writeln('[$taskName] [STDOUT] $line');
}
}); });
StreamSubscription<String> stderrSub = runner.stderr StreamSubscription<String> stderrSub = runner.stderr
......
...@@ -242,12 +242,6 @@ String get dartBin => ...@@ -242,12 +242,6 @@ String get dartBin =>
Future<int> dart(List<String> args) => exec(dartBin, args); Future<int> dart(List<String> args) => exec(dartBin, args);
Future<int> pub(String command) {
return exec(
path.join(flutterDirectory.path, 'bin', 'cache', 'dart-sdk', 'bin', 'pub'),
<String>[command]);
}
Future<dynamic> inDirectory(dynamic directory, Future<dynamic> action()) async { Future<dynamic> inDirectory(dynamic directory, Future<dynamic> action()) async {
String previousCwd = cwd; String previousCwd = cwd;
try { try {
......
...@@ -105,8 +105,7 @@ class FlutterAnalyzeAppBenchmark extends Benchmark { ...@@ -105,8 +105,7 @@ class FlutterAnalyzeAppBenchmark extends Benchmark {
Future<num> run() async { Future<num> run() async {
rm(benchmarkFile); rm(benchmarkFile);
await inDirectory(megaDir, () async { await inDirectory(megaDir, () async {
await flutter('analyze', options: <String>[ await flutter('watch', options: <String>[
'--watch',
'--benchmark', '--benchmark',
]); ]);
}); });
......
...@@ -12,23 +12,25 @@ import '../framework/adb.dart'; ...@@ -12,23 +12,25 @@ import '../framework/adb.dart';
import '../framework/framework.dart'; import '../framework/framework.dart';
import '../framework/utils.dart'; import '../framework/utils.dart';
TaskFunction createGalleryTransitionTest({ @required bool ios: false }) { TaskFunction createGalleryTransitionTest({ @required DeviceOperatingSystem os }) {
return new GalleryTransitionTest(ios: ios); return new GalleryTransitionTest(os: os);
} }
class GalleryTransitionTest { class GalleryTransitionTest {
GalleryTransitionTest({ this.ios }); GalleryTransitionTest({ this.os }) {
deviceOperatingSystem = os;
}
final bool ios; final DeviceOperatingSystem os;
Future<TaskResult> call() async { Future<TaskResult> call() async {
String deviceId = await getUnlockedDeviceId(ios: ios); String deviceId = (await devices.workingDevice).deviceId;
Directory galleryDirectory = Directory galleryDirectory =
dir('${flutterDirectory.path}/examples/flutter_gallery'); dir('${flutterDirectory.path}/examples/flutter_gallery');
await inDirectory(galleryDirectory, () async { await inDirectory(galleryDirectory, () async {
await pub('get'); await flutter('packages', options: <String>['get']);
if (ios) { if (os == DeviceOperatingSystem.ios) {
// This causes an Xcode project to be created. // This causes an Xcode project to be created.
await flutter('build', options: <String>['ios', '--profile']); await flutter('build', options: <String>['ios', '--profile']);
} }
......
...@@ -11,26 +11,26 @@ import '../framework/adb.dart'; ...@@ -11,26 +11,26 @@ import '../framework/adb.dart';
import '../framework/framework.dart'; import '../framework/framework.dart';
import '../framework/utils.dart'; import '../framework/utils.dart';
TaskFunction createComplexLayoutScrollPerfTest({ @required bool ios: false }) { TaskFunction createComplexLayoutScrollPerfTest({ @required DeviceOperatingSystem os }) {
return new PerfTest( return new PerfTest(
'${flutterDirectory.path}/dev/benchmarks/complex_layout', '${flutterDirectory.path}/dev/benchmarks/complex_layout',
'test_driver/scroll_perf.dart', 'test_driver/scroll_perf.dart',
'complex_layout_scroll_perf', 'complex_layout_scroll_perf',
ios: ios os: os,
); );
} }
TaskFunction createFlutterGalleryStartupTest({ bool ios: false }) { TaskFunction createFlutterGalleryStartupTest({ @required DeviceOperatingSystem os }) {
return new StartupTest( return new StartupTest(
'${flutterDirectory.path}/examples/flutter_gallery', '${flutterDirectory.path}/examples/flutter_gallery',
ios: ios os: os,
); );
} }
TaskFunction createComplexLayoutStartupTest({ bool ios: false }) { TaskFunction createComplexLayoutStartupTest({ @required DeviceOperatingSystem os }) {
return new StartupTest( return new StartupTest(
'${flutterDirectory.path}/dev/benchmarks/complex_layout', '${flutterDirectory.path}/dev/benchmarks/complex_layout',
ios: ios os: os,
); );
} }
...@@ -46,17 +46,19 @@ TaskFunction createComplexLayoutBuildTest() { ...@@ -46,17 +46,19 @@ TaskFunction createComplexLayoutBuildTest() {
class StartupTest { class StartupTest {
static const Duration _startupTimeout = const Duration(minutes: 2); static const Duration _startupTimeout = const Duration(minutes: 2);
StartupTest(this.testDirectory, { this.ios }); StartupTest(this.testDirectory, { this.os }) {
deviceOperatingSystem = os;
}
final String testDirectory; final String testDirectory;
final bool ios; final DeviceOperatingSystem os;
Future<TaskResult> call() async { Future<TaskResult> call() async {
return await inDirectory(testDirectory, () async { return await inDirectory(testDirectory, () async {
String deviceId = await getUnlockedDeviceId(ios: ios); String deviceId = (await devices.workingDevice).deviceId;
await pub('get'); await flutter('packages', options: <String>['get']);
if (ios) { if (os == DeviceOperatingSystem.ios) {
// This causes an Xcode project to be created. // This causes an Xcode project to be created.
await flutter('build', options: <String>['ios', '--profile']); await flutter('build', options: <String>['ios', '--profile']);
} }
...@@ -80,19 +82,19 @@ class StartupTest { ...@@ -80,19 +82,19 @@ class StartupTest {
/// performance. /// performance.
class PerfTest { class PerfTest {
PerfTest(this.testDirectory, this.testTarget, this.timelineFileName, { this.ios }); PerfTest(this.testDirectory, this.testTarget, this.timelineFileName, { this.os });
final String testDirectory; final String testDirectory;
final String testTarget; final String testTarget;
final String timelineFileName; final String timelineFileName;
final bool ios; final DeviceOperatingSystem os;
Future<TaskResult> call() { Future<TaskResult> call() {
return inDirectory(testDirectory, () async { return inDirectory(testDirectory, () async {
String deviceId = await getUnlockedDeviceId(ios: ios); String deviceId = (await devices.workingDevice).deviceId;
await pub('get'); await flutter('packages', options: <String>['get']);
if (ios) { if (os == DeviceOperatingSystem.ios) {
// This causes an Xcode project to be created. // This causes an Xcode project to be created.
await flutter('build', options: <String>['ios', '--profile']); await flutter('build', options: <String>['ios', '--profile']);
} }
...@@ -124,9 +126,9 @@ class BuildTest { ...@@ -124,9 +126,9 @@ class BuildTest {
Future<TaskResult> call() async { Future<TaskResult> call() async {
return await inDirectory(testDirectory, () async { return await inDirectory(testDirectory, () async {
Adb device = await adb(); Device device = await devices.workingDevice;
await device.unlock(); await device.unlock();
await pub('get'); await flutter('packages', options: <String>['get']);
Stopwatch watch = new Stopwatch()..start(); Stopwatch watch = new Stopwatch()..start();
await flutter('build', options: <String>[ await flutter('build', options: <String>[
......
...@@ -25,7 +25,7 @@ class EditRefreshTask { ...@@ -25,7 +25,7 @@ class EditRefreshTask {
final DateTime timestamp; final DateTime timestamp;
Future<TaskResult> call() async { Future<TaskResult> call() async {
Adb device = await adb(); Device device = await devices.workingDevice;
await device.unlock(); await device.unlock();
Benchmark benchmark = new EditRefreshBenchmark(commit, timestamp); Benchmark benchmark = new EditRefreshBenchmark(commit, timestamp);
section(benchmark.name); section(benchmark.name);
...@@ -57,7 +57,7 @@ class EditRefreshBenchmark extends Benchmark { ...@@ -57,7 +57,7 @@ class EditRefreshBenchmark extends Benchmark {
@override @override
Future<num> run() async { Future<num> run() async {
Adb device = await adb(); Device device = await devices.workingDevice;
rm(benchmarkFile); rm(benchmarkFile);
int exitCode = await inDirectory(megaDir, () async { int exitCode = await inDirectory(megaDir, () async {
return await flutter('run', return await flutter('run',
......
...@@ -24,7 +24,7 @@ TaskFunction createBasicMaterialAppSizeTest() { ...@@ -24,7 +24,7 @@ TaskFunction createBasicMaterialAppSizeTest() {
throw 'Failed to create sample Flutter app in ${sampleDir.path}'; throw 'Failed to create sample Flutter app in ${sampleDir.path}';
await inDirectory(sampleDir, () async { await inDirectory(sampleDir, () async {
await pub('get'); await flutter('packages', options: <String>['get']);
await flutter('build', options: <String>['clean']); await flutter('build', options: <String>['clean']);
await flutter('build', options: <String>['apk', '--release']); await flutter('build', options: <String>['apk', '--release']);
apkSizeInBytes = await file('${sampleDir.path}/build/app.apk').length(); apkSizeInBytes = await file('${sampleDir.path}/build/app.apk').length();
......
...@@ -10,28 +10,27 @@ import 'package:collection/collection.dart'; ...@@ -10,28 +10,27 @@ import 'package:collection/collection.dart';
import 'package:flutter_devicelab/framework/adb.dart'; import 'package:flutter_devicelab/framework/adb.dart';
void main() { void main() {
group('adb', () { group('device', () {
Adb device; Device device;
setUp(() { setUp(() {
FakeAdb.resetLog(); FakeDevice.resetLog();
adb = null; device = null;
device = new FakeAdb(); device = new FakeDevice();
}); });
tearDown(() { tearDown(() {
adb = realAdbGetter;
}); });
group('isAwake/isAsleep', () { group('isAwake/isAsleep', () {
test('reads Awake', () async { test('reads Awake', () async {
FakeAdb.pretendAwake(); FakeDevice.pretendAwake();
expect(await device.isAwake(), isTrue); expect(await device.isAwake(), isTrue);
expect(await device.isAsleep(), isFalse); expect(await device.isAsleep(), isFalse);
}); });
test('reads Asleep', () async { test('reads Asleep', () async {
FakeAdb.pretendAsleep(); FakeDevice.pretendAsleep();
expect(await device.isAwake(), isFalse); expect(await device.isAwake(), isFalse);
expect(await device.isAsleep(), isTrue); expect(await device.isAsleep(), isTrue);
}); });
...@@ -48,7 +47,7 @@ void main() { ...@@ -48,7 +47,7 @@ void main() {
group('wakeUp', () { group('wakeUp', () {
test('when awake', () async { test('when awake', () async {
FakeAdb.pretendAwake(); FakeDevice.pretendAwake();
await device.wakeUp(); await device.wakeUp();
expectLog(<CommandArgs>[ expectLog(<CommandArgs>[
cmd(command: 'dumpsys', arguments: <String>['power']), cmd(command: 'dumpsys', arguments: <String>['power']),
...@@ -56,7 +55,7 @@ void main() { ...@@ -56,7 +55,7 @@ void main() {
}); });
test('when asleep', () async { test('when asleep', () async {
FakeAdb.pretendAsleep(); FakeDevice.pretendAsleep();
await device.wakeUp(); await device.wakeUp();
expectLog(<CommandArgs>[ expectLog(<CommandArgs>[
cmd(command: 'dumpsys', arguments: <String>['power']), cmd(command: 'dumpsys', arguments: <String>['power']),
...@@ -67,7 +66,7 @@ void main() { ...@@ -67,7 +66,7 @@ void main() {
group('sendToSleep', () { group('sendToSleep', () {
test('when asleep', () async { test('when asleep', () async {
FakeAdb.pretendAsleep(); FakeDevice.pretendAsleep();
await device.sendToSleep(); await device.sendToSleep();
expectLog(<CommandArgs>[ expectLog(<CommandArgs>[
cmd(command: 'dumpsys', arguments: <String>['power']), cmd(command: 'dumpsys', arguments: <String>['power']),
...@@ -75,7 +74,7 @@ void main() { ...@@ -75,7 +74,7 @@ void main() {
}); });
test('when awake', () async { test('when awake', () async {
FakeAdb.pretendAwake(); FakeDevice.pretendAwake();
await device.sendToSleep(); await device.sendToSleep();
expectLog(<CommandArgs>[ expectLog(<CommandArgs>[
cmd(command: 'dumpsys', arguments: <String>['power']), cmd(command: 'dumpsys', arguments: <String>['power']),
...@@ -86,7 +85,7 @@ void main() { ...@@ -86,7 +85,7 @@ void main() {
group('unlock', () { group('unlock', () {
test('sends unlock event', () async { test('sends unlock event', () async {
FakeAdb.pretendAwake(); FakeDevice.pretendAwake();
await device.unlock(); await device.unlock();
expectLog(<CommandArgs>[ expectLog(<CommandArgs>[
cmd(command: 'dumpsys', arguments: <String>['power']), cmd(command: 'dumpsys', arguments: <String>['power']),
...@@ -98,10 +97,10 @@ void main() { ...@@ -98,10 +97,10 @@ void main() {
} }
void expectLog(List<CommandArgs> log) { void expectLog(List<CommandArgs> log) {
expect(FakeAdb.commandLog, log); expect(FakeDevice.commandLog, log);
} }
CommandArgs cmd({ String command, List<String> arguments, Map<String, String> env }) => new CommandArgs( CommandArgs cmd({String command, List<String> arguments, Map<String, String> env}) => new CommandArgs(
command: command, command: command,
arguments: arguments, arguments: arguments,
env: env env: env
...@@ -110,7 +109,7 @@ CommandArgs cmd({ String command, List<String> arguments, Map<String, String> en ...@@ -110,7 +109,7 @@ CommandArgs cmd({ String command, List<String> arguments, Map<String, String> en
typedef dynamic ExitErrorFactory(); typedef dynamic ExitErrorFactory();
class CommandArgs { class CommandArgs {
CommandArgs({ this.command, this.arguments, this.env }); CommandArgs({this.command, this.arguments, this.env});
final String command; final String command;
final List<String> arguments; final List<String> arguments;
...@@ -142,8 +141,8 @@ class CommandArgs { ...@@ -142,8 +141,8 @@ class CommandArgs {
: null.hashCode; : null.hashCode;
} }
class FakeAdb extends Adb { class FakeDevice extends AndroidDevice {
FakeAdb({ String deviceId: null }) : super(deviceId: deviceId); FakeDevice({String deviceId: null}) : super(deviceId: deviceId);
static String output = ''; static String output = '';
static ExitErrorFactory exitErrorFactory = () => null; static ExitErrorFactory exitErrorFactory = () => null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment