Skip to content

Commit

Permalink
Devicelab android emulator (#113472)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
ricardoamador committed Jan 17, 2023
1 parent 0449030 commit f989d55
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions .ci.yaml
Expand Up @@ -1385,6 +1385,7 @@ targets:
tags: >
["devicelab" ,"android", "linux"]
task_name: android_defines_test
use_emulator: "true"

- name: Linux_android android_obfuscate_test
recipe: devicelab/devicelab_drone
Expand Down
9 changes: 9 additions & 0 deletions dev/devicelab/bin/run.dart
Expand Up @@ -62,6 +62,9 @@ Future<void> main(List<String> rawArgs) async {
/// Path to write test results to.
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')) {
for (int i = 0; i < taskNames.length; i++) {
print('${(i + 1).toString().padLeft(3)} - ${taskNames[i]}');
Expand Down Expand Up @@ -107,6 +110,7 @@ Future<void> main(List<String> rawArgs) async {
gitBranch: gitBranch,
luciBuilder: luciBuilder,
resultsPath: resultsPath,
useEmulator: useEmulator,
);
}
}
Expand Down Expand Up @@ -319,6 +323,11 @@ ArgParser createArgParser(List<String> taskNames) {
'running when a task is completed. If any Dart processes are terminated '
'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(
'test',
hide: true,
Expand Down
5 changes: 5 additions & 0 deletions dev/devicelab/lib/command/test.dart
Expand Up @@ -51,6 +51,10 @@ class TestCommand extends Command<void> {
'silent',
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
Expand All @@ -74,6 +78,7 @@ class TestCommand extends Command<void> {
luciBuilder: argResults!['luci-builder'] as String?,
resultsPath: argResults!['results-file'] as String?,
silent: (argResults!['silent'] as bool?) ?? false,
useEmulator: (argResults!['use-emulator'] as bool?) ?? false,
taskArgs: taskArgs,
);
}
Expand Down
12 changes: 12 additions & 0 deletions dev/devicelab/lib/framework/runner.dart
Expand Up @@ -39,6 +39,7 @@ Future<void> runTasks(
String? luciBuilder,
String? resultsPath,
List<String>? taskArgs,
bool useEmulator = false,
@visibleForTesting Map<String, String>? isolateParams,
@visibleForTesting Function(String) print = print,
@visibleForTesting List<String>? logs,
Expand All @@ -59,6 +60,7 @@ Future<void> runTasks(
gitBranch: gitBranch,
luciBuilder: luciBuilder,
isolateParams: isolateParams,
useEmulator: useEmulator,
);

if (!result.succeeded) {
Expand Down Expand Up @@ -104,6 +106,7 @@ Future<TaskResult> rerunTask(
String? resultsPath,
String? gitBranch,
String? luciBuilder,
bool useEmulator = false,
@visibleForTesting Map<String, String>? isolateParams,
}) async {
section('Running task "$taskName"');
Expand All @@ -116,6 +119,7 @@ Future<TaskResult> rerunTask(
silent: silent,
taskArgs: taskArgs,
isolateParams: isolateParams,
useEmulator: useEmulator,
);

print('Task result:');
Expand Down Expand Up @@ -152,6 +156,7 @@ Future<TaskResult> runTask(
String? localEngineSrcPath,
String? deviceId,
List<String>? taskArgs,
bool useEmulator = false,
@visibleForTesting Map<String, String>? isolateParams,
}) async {
final String taskExecutable = 'bin/tasks/$taskName.dart';
Expand All @@ -160,6 +165,13 @@ Future<TaskResult> runTask(
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(
dartBin,
<String>[
Expand Down
1 change: 1 addition & 0 deletions dev/devicelab/lib/framework/utils.dart
Expand Up @@ -283,6 +283,7 @@ Future<Process> startProcess(
newEnvironment['BOT'] = isBot ? 'true' : 'false';
newEnvironment['LANG'] = 'en_US.UTF-8';
print('Executing "$command" in "$finalWorkingDirectory" with environment $newEnvironment');

final Process process = await _processManager.start(
<String>[executable, ...?arguments],
environment: newEnvironment,
Expand Down

0 comments on commit f989d55

Please sign in to comment.