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