Skip to content

Commit f989d55

Browse files
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.
1 parent 0449030 commit f989d55

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

.ci.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,7 @@ targets:
13851385
tags: >
13861386
["devicelab" ,"android", "linux"]
13871387
task_name: android_defines_test
1388+
use_emulator: "true"
13881389

13891390
- name: Linux_android android_obfuscate_test
13901391
recipe: devicelab/devicelab_drone

dev/devicelab/bin/run.dart

+9
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ Future<void> main(List<String> rawArgs) async {
6262
/// Path to write test results to.
6363
final String? resultsPath = args['results-file'] as String?;
6464

65+
/// Use an emulator for this test if it is an android test.
66+
final bool useEmulator = (args['use-emulator'] as bool?) ?? false;
67+
6568
if (args.wasParsed('list')) {
6669
for (int i = 0; i < taskNames.length; i++) {
6770
print('${(i + 1).toString().padLeft(3)} - ${taskNames[i]}');
@@ -107,6 +110,7 @@ Future<void> main(List<String> rawArgs) async {
107110
gitBranch: gitBranch,
108111
luciBuilder: luciBuilder,
109112
resultsPath: resultsPath,
113+
useEmulator: useEmulator,
110114
);
111115
}
112116
}
@@ -319,6 +323,11 @@ ArgParser createArgParser(List<String> taskNames) {
319323
'running when a task is completed. If any Dart processes are terminated '
320324
'in this way, the test is considered to have failed.',
321325
)
326+
..addFlag(
327+
'use-emulator',
328+
help: 'If this is an android test, use an emulator to run the test instead of '
329+
'a physical device.'
330+
)
322331
..addMultiOption(
323332
'test',
324333
hide: true,

dev/devicelab/lib/command/test.dart

+5
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ class TestCommand extends Command<void> {
5151
'silent',
5252
help: 'Suppresses standard output and only print standard error output.',
5353
);
54+
argParser.addFlag(
55+
'use-emulator',
56+
help: 'Use an emulator instead of a device to run tests.'
57+
);
5458
}
5559

5660
@override
@@ -74,6 +78,7 @@ class TestCommand extends Command<void> {
7478
luciBuilder: argResults!['luci-builder'] as String?,
7579
resultsPath: argResults!['results-file'] as String?,
7680
silent: (argResults!['silent'] as bool?) ?? false,
81+
useEmulator: (argResults!['use-emulator'] as bool?) ?? false,
7782
taskArgs: taskArgs,
7883
);
7984
}

dev/devicelab/lib/framework/runner.dart

+12
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Future<void> runTasks(
3939
String? luciBuilder,
4040
String? resultsPath,
4141
List<String>? taskArgs,
42+
bool useEmulator = false,
4243
@visibleForTesting Map<String, String>? isolateParams,
4344
@visibleForTesting Function(String) print = print,
4445
@visibleForTesting List<String>? logs,
@@ -59,6 +60,7 @@ Future<void> runTasks(
5960
gitBranch: gitBranch,
6061
luciBuilder: luciBuilder,
6162
isolateParams: isolateParams,
63+
useEmulator: useEmulator,
6264
);
6365

6466
if (!result.succeeded) {
@@ -104,6 +106,7 @@ Future<TaskResult> rerunTask(
104106
String? resultsPath,
105107
String? gitBranch,
106108
String? luciBuilder,
109+
bool useEmulator = false,
107110
@visibleForTesting Map<String, String>? isolateParams,
108111
}) async {
109112
section('Running task "$taskName"');
@@ -116,6 +119,7 @@ Future<TaskResult> rerunTask(
116119
silent: silent,
117120
taskArgs: taskArgs,
118121
isolateParams: isolateParams,
122+
useEmulator: useEmulator,
119123
);
120124

121125
print('Task result:');
@@ -152,6 +156,7 @@ Future<TaskResult> runTask(
152156
String? localEngineSrcPath,
153157
String? deviceId,
154158
List<String>? taskArgs,
159+
bool useEmulator = false,
155160
@visibleForTesting Map<String, String>? isolateParams,
156161
}) async {
157162
final String taskExecutable = 'bin/tasks/$taskName.dart';
@@ -160,6 +165,13 @@ Future<TaskResult> runTask(
160165
throw 'Executable Dart file not found: $taskExecutable';
161166
}
162167

168+
if (useEmulator) {
169+
taskArgs ??= <String>[];
170+
taskArgs
171+
..add('--android-emulator')
172+
..add('--browser-name=android-chrome');
173+
}
174+
163175
final Process runner = await startProcess(
164176
dartBin,
165177
<String>[

dev/devicelab/lib/framework/utils.dart

+1
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ Future<Process> startProcess(
283283
newEnvironment['BOT'] = isBot ? 'true' : 'false';
284284
newEnvironment['LANG'] = 'en_US.UTF-8';
285285
print('Executing "$command" in "$finalWorkingDirectory" with environment $newEnvironment');
286+
286287
final Process process = await _processManager.start(
287288
<String>[executable, ...?arguments],
288289
environment: newEnvironment,

0 commit comments

Comments
 (0)