Unverified Commit f989d551 authored by Ricardo Amador's avatar Ricardo Amador Committed by GitHub

Devicelab android emulator (#113472)

* Testing whether emulator is possible.

* Adding changes to see if emulator can be used from recipe.

* adding emulator support.

* Add the emulator flag for testing.

* Using string for boolean since it cannot be parsed in properties

* Checking to see if these changes are being used.

* Updated bool back to string

* Remove trailing whitespace from file.
parent 0449030a
...@@ -1385,6 +1385,7 @@ targets: ...@@ -1385,6 +1385,7 @@ targets:
tags: > tags: >
["devicelab" ,"android", "linux"] ["devicelab" ,"android", "linux"]
task_name: android_defines_test task_name: android_defines_test
use_emulator: "true"
- name: Linux_android android_obfuscate_test - name: Linux_android android_obfuscate_test
recipe: devicelab/devicelab_drone recipe: devicelab/devicelab_drone
......
...@@ -62,6 +62,9 @@ Future<void> main(List<String> rawArgs) async { ...@@ -62,6 +62,9 @@ Future<void> main(List<String> rawArgs) async {
/// Path to write test results to. /// Path to write test results to.
final String? resultsPath = args['results-file'] as String?; final String? resultsPath = args['results-file'] as String?;
/// Use an emulator for this test if it is an android test.
final bool useEmulator = (args['use-emulator'] as bool?) ?? false;
if (args.wasParsed('list')) { if (args.wasParsed('list')) {
for (int i = 0; i < taskNames.length; i++) { for (int i = 0; i < taskNames.length; i++) {
print('${(i + 1).toString().padLeft(3)} - ${taskNames[i]}'); print('${(i + 1).toString().padLeft(3)} - ${taskNames[i]}');
...@@ -107,6 +110,7 @@ Future<void> main(List<String> rawArgs) async { ...@@ -107,6 +110,7 @@ Future<void> main(List<String> rawArgs) async {
gitBranch: gitBranch, gitBranch: gitBranch,
luciBuilder: luciBuilder, luciBuilder: luciBuilder,
resultsPath: resultsPath, resultsPath: resultsPath,
useEmulator: useEmulator,
); );
} }
} }
...@@ -319,6 +323,11 @@ ArgParser createArgParser(List<String> taskNames) { ...@@ -319,6 +323,11 @@ ArgParser createArgParser(List<String> taskNames) {
'running when a task is completed. If any Dart processes are terminated ' 'running when a task is completed. If any Dart processes are terminated '
'in this way, the test is considered to have failed.', 'in this way, the test is considered to have failed.',
) )
..addFlag(
'use-emulator',
help: 'If this is an android test, use an emulator to run the test instead of '
'a physical device.'
)
..addMultiOption( ..addMultiOption(
'test', 'test',
hide: true, hide: true,
......
...@@ -51,6 +51,10 @@ class TestCommand extends Command<void> { ...@@ -51,6 +51,10 @@ class TestCommand extends Command<void> {
'silent', 'silent',
help: 'Suppresses standard output and only print standard error output.', help: 'Suppresses standard output and only print standard error output.',
); );
argParser.addFlag(
'use-emulator',
help: 'Use an emulator instead of a device to run tests.'
);
} }
@override @override
...@@ -74,6 +78,7 @@ class TestCommand extends Command<void> { ...@@ -74,6 +78,7 @@ class TestCommand extends Command<void> {
luciBuilder: argResults!['luci-builder'] as String?, luciBuilder: argResults!['luci-builder'] as String?,
resultsPath: argResults!['results-file'] as String?, resultsPath: argResults!['results-file'] as String?,
silent: (argResults!['silent'] as bool?) ?? false, silent: (argResults!['silent'] as bool?) ?? false,
useEmulator: (argResults!['use-emulator'] as bool?) ?? false,
taskArgs: taskArgs, taskArgs: taskArgs,
); );
} }
......
...@@ -39,6 +39,7 @@ Future<void> runTasks( ...@@ -39,6 +39,7 @@ Future<void> runTasks(
String? luciBuilder, String? luciBuilder,
String? resultsPath, String? resultsPath,
List<String>? taskArgs, List<String>? taskArgs,
bool useEmulator = false,
@visibleForTesting Map<String, String>? isolateParams, @visibleForTesting Map<String, String>? isolateParams,
@visibleForTesting Function(String) print = print, @visibleForTesting Function(String) print = print,
@visibleForTesting List<String>? logs, @visibleForTesting List<String>? logs,
...@@ -59,6 +60,7 @@ Future<void> runTasks( ...@@ -59,6 +60,7 @@ Future<void> runTasks(
gitBranch: gitBranch, gitBranch: gitBranch,
luciBuilder: luciBuilder, luciBuilder: luciBuilder,
isolateParams: isolateParams, isolateParams: isolateParams,
useEmulator: useEmulator,
); );
if (!result.succeeded) { if (!result.succeeded) {
...@@ -104,6 +106,7 @@ Future<TaskResult> rerunTask( ...@@ -104,6 +106,7 @@ Future<TaskResult> rerunTask(
String? resultsPath, String? resultsPath,
String? gitBranch, String? gitBranch,
String? luciBuilder, String? luciBuilder,
bool useEmulator = false,
@visibleForTesting Map<String, String>? isolateParams, @visibleForTesting Map<String, String>? isolateParams,
}) async { }) async {
section('Running task "$taskName"'); section('Running task "$taskName"');
...@@ -116,6 +119,7 @@ Future<TaskResult> rerunTask( ...@@ -116,6 +119,7 @@ Future<TaskResult> rerunTask(
silent: silent, silent: silent,
taskArgs: taskArgs, taskArgs: taskArgs,
isolateParams: isolateParams, isolateParams: isolateParams,
useEmulator: useEmulator,
); );
print('Task result:'); print('Task result:');
...@@ -152,6 +156,7 @@ Future<TaskResult> runTask( ...@@ -152,6 +156,7 @@ Future<TaskResult> runTask(
String? localEngineSrcPath, String? localEngineSrcPath,
String? deviceId, String? deviceId,
List<String>? taskArgs, List<String>? taskArgs,
bool useEmulator = false,
@visibleForTesting Map<String, String>? isolateParams, @visibleForTesting Map<String, String>? isolateParams,
}) async { }) async {
final String taskExecutable = 'bin/tasks/$taskName.dart'; final String taskExecutable = 'bin/tasks/$taskName.dart';
...@@ -160,6 +165,13 @@ Future<TaskResult> runTask( ...@@ -160,6 +165,13 @@ Future<TaskResult> runTask(
throw 'Executable Dart file not found: $taskExecutable'; throw 'Executable Dart file not found: $taskExecutable';
} }
if (useEmulator) {
taskArgs ??= <String>[];
taskArgs
..add('--android-emulator')
..add('--browser-name=android-chrome');
}
final Process runner = await startProcess( final Process runner = await startProcess(
dartBin, dartBin,
<String>[ <String>[
......
...@@ -283,6 +283,7 @@ Future<Process> startProcess( ...@@ -283,6 +283,7 @@ Future<Process> startProcess(
newEnvironment['BOT'] = isBot ? 'true' : 'false'; newEnvironment['BOT'] = isBot ? 'true' : 'false';
newEnvironment['LANG'] = 'en_US.UTF-8'; newEnvironment['LANG'] = 'en_US.UTF-8';
print('Executing "$command" in "$finalWorkingDirectory" with environment $newEnvironment'); print('Executing "$command" in "$finalWorkingDirectory" with environment $newEnvironment');
final Process process = await _processManager.start( final Process process = await _processManager.start(
<String>[executable, ...?arguments], <String>[executable, ...?arguments],
environment: newEnvironment, environment: newEnvironment,
......
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