From 41a5e5d8f68617d19fa17a759ebb536ea4c3f11b Mon Sep 17 00:00:00 2001 From: Vyacheslav Egorov Date: Thu, 30 Nov 2017 21:15:27 +0100 Subject: [PATCH] Change few devicelab tests to support testing against local engine (#13268) * Change some of the dev/devicelab tests to support testing against local engine. We can already configure flutter tools to use local engine by setting FLUTTER_ENGINE environment variable. However when this variable is set this also requires setting --local-engine to specify which flavor of engine to use. This change changes tests in dev/devicelab to pass a sensible default for --local-engine, e.g. when testing hot reload on Android we pass android_debug and when testing release AOT build for IOS we pass ios_release. * Fix analysis issues * Update utils.dart --- dev/devicelab/lib/framework/utils.dart | 35 ++++++++++++++++++++ dev/devicelab/lib/tasks/hot_mode_tests.dart | 1 + dev/devicelab/lib/tasks/microbenchmarks.dart | 1 + dev/devicelab/lib/tasks/perf_tests.dart | 3 ++ 4 files changed, 40 insertions(+) diff --git a/dev/devicelab/lib/framework/utils.dart b/dev/devicelab/lib/framework/utils.dart index 3f87268ea9..d1fa4b8136 100644 --- a/dev/devicelab/lib/framework/utils.dart +++ b/dev/devicelab/lib/framework/utils.dart @@ -13,6 +13,8 @@ import 'package:path/path.dart' as path; import 'package:process/process.dart'; import 'package:stack_trace/stack_trace.dart'; +import 'adb.dart'; + /// Virtual current working directory, which affect functions, such as [exec]. String cwd = Directory.current.path; @@ -498,3 +500,36 @@ int parseServicePort(String line) { final Match match = _kObservatoryRegExp.firstMatch(line); return match == null ? null : int.parse(match.group(2)); } + +/// If FLUTTER_ENGINE environment variable is set then we need to pass +/// correct --local-engine setting too. +void setLocalEngineOptionIfNecessary(List options, [String flavor]) { + if (Platform.environment['FLUTTER_ENGINE'] != null) { + if (flavor == null) { + // If engine flavor was not specified explicitly then scan options looking + // for flags that specify the engine flavor (--release, --profile or + // --debug). Default flavor to debug if no flags were found. + const Map optionToFlavor = const { + '--release': 'release', + '--debug': 'debug', + '--profile': 'profile', + }; + + for (String option in options) { + flavor = optionToFlavor[option]; + if (flavor != null) { + break; + } + } + + flavor ??= 'debug'; + } + + const Map osNames = const { + DeviceOperatingSystem.ios: 'ios', + DeviceOperatingSystem.android: 'android', + }; + + options.add('--local-engine=${osNames[deviceOperatingSystem]}_$flavor'); + } +} diff --git a/dev/devicelab/lib/tasks/hot_mode_tests.dart b/dev/devicelab/lib/tasks/hot_mode_tests.dart index 03b5ffee82..b675453c71 100644 --- a/dev/devicelab/lib/tasks/hot_mode_tests.dart +++ b/dev/devicelab/lib/tasks/hot_mode_tests.dart @@ -26,6 +26,7 @@ TaskFunction createHotModeTest({ bool isPreviewDart2: false }) { ]; if (isPreviewDart2) options.add('--preview-dart-2'); + setLocalEngineOptionIfNecessary(options); int hotReloadCount = 0; await inDirectory(flutterDirectory, () async { rmTree(_editedFlutterGalleryDir); diff --git a/dev/devicelab/lib/tasks/microbenchmarks.dart b/dev/devicelab/lib/tasks/microbenchmarks.dart index e632b406b7..41f0c553a6 100644 --- a/dev/devicelab/lib/tasks/microbenchmarks.dart +++ b/dev/devicelab/lib/tasks/microbenchmarks.dart @@ -40,6 +40,7 @@ TaskFunction createMicrobenchmarkTask() { ]; if (previewDart2) options.add('--preview-dart-2'); + setLocalEngineOptionIfNecessary(options); options.add(benchmarkPath); return await _startFlutter( options: options, diff --git a/dev/devicelab/lib/tasks/perf_tests.dart b/dev/devicelab/lib/tasks/perf_tests.dart index 4986de7e60..1348fbc758 100644 --- a/dev/devicelab/lib/tasks/perf_tests.dart +++ b/dev/devicelab/lib/tasks/perf_tests.dart @@ -235,6 +235,7 @@ class CompileTest { } if (previewDart2) options.add('--preview-dart-2'); + setLocalEngineOptionIfNecessary(options); final String compileLog = await evalFlutter('build', options: options); watch.stop(); @@ -256,6 +257,7 @@ class CompileTest { final List options = ['--release']; if (previewDart2) options.add('--preview-dart-2'); + setLocalEngineOptionIfNecessary(options); switch (deviceOperatingSystem) { case DeviceOperatingSystem.ios: options.insert(0, 'ios'); @@ -288,6 +290,7 @@ class CompileTest { final List options = ['--debug']; if (previewDart2) options.add('--preview-dart-2'); + setLocalEngineOptionIfNecessary(options); switch (deviceOperatingSystem) { case DeviceOperatingSystem.ios: options.insert(0, 'ios');