diff --git a/.ci.yaml b/.ci.yaml index 846bbe8bbdc1..c90f684eab0e 100644 --- a/.ci.yaml +++ b/.ci.yaml @@ -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 diff --git a/dev/devicelab/bin/run.dart b/dev/devicelab/bin/run.dart index ce53f3139b56..25da577dde9c 100644 --- a/dev/devicelab/bin/run.dart +++ b/dev/devicelab/bin/run.dart @@ -62,6 +62,9 @@ Future main(List 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]}'); @@ -107,6 +110,7 @@ Future main(List rawArgs) async { gitBranch: gitBranch, luciBuilder: luciBuilder, resultsPath: resultsPath, + useEmulator: useEmulator, ); } } @@ -319,6 +323,11 @@ ArgParser createArgParser(List 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, diff --git a/dev/devicelab/lib/command/test.dart b/dev/devicelab/lib/command/test.dart index 437b80d94c48..a98d2b3ecebe 100644 --- a/dev/devicelab/lib/command/test.dart +++ b/dev/devicelab/lib/command/test.dart @@ -51,6 +51,10 @@ class TestCommand extends Command { '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 @@ -74,6 +78,7 @@ class TestCommand extends Command { 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, ); } diff --git a/dev/devicelab/lib/framework/runner.dart b/dev/devicelab/lib/framework/runner.dart index 1c40144adc07..3a76a7328560 100644 --- a/dev/devicelab/lib/framework/runner.dart +++ b/dev/devicelab/lib/framework/runner.dart @@ -39,6 +39,7 @@ Future runTasks( String? luciBuilder, String? resultsPath, List? taskArgs, + bool useEmulator = false, @visibleForTesting Map? isolateParams, @visibleForTesting Function(String) print = print, @visibleForTesting List? logs, @@ -59,6 +60,7 @@ Future runTasks( gitBranch: gitBranch, luciBuilder: luciBuilder, isolateParams: isolateParams, + useEmulator: useEmulator, ); if (!result.succeeded) { @@ -104,6 +106,7 @@ Future rerunTask( String? resultsPath, String? gitBranch, String? luciBuilder, + bool useEmulator = false, @visibleForTesting Map? isolateParams, }) async { section('Running task "$taskName"'); @@ -116,6 +119,7 @@ Future rerunTask( silent: silent, taskArgs: taskArgs, isolateParams: isolateParams, + useEmulator: useEmulator, ); print('Task result:'); @@ -152,6 +156,7 @@ Future runTask( String? localEngineSrcPath, String? deviceId, List? taskArgs, + bool useEmulator = false, @visibleForTesting Map? isolateParams, }) async { final String taskExecutable = 'bin/tasks/$taskName.dart'; @@ -160,6 +165,13 @@ Future runTask( throw 'Executable Dart file not found: $taskExecutable'; } + if (useEmulator) { + taskArgs ??= []; + taskArgs + ..add('--android-emulator') + ..add('--browser-name=android-chrome'); + } + final Process runner = await startProcess( dartBin, [ diff --git a/dev/devicelab/lib/framework/utils.dart b/dev/devicelab/lib/framework/utils.dart index 73d46125740b..868e4105b608 100644 --- a/dev/devicelab/lib/framework/utils.dart +++ b/dev/devicelab/lib/framework/utils.dart @@ -283,6 +283,7 @@ Future 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( [executable, ...?arguments], environment: newEnvironment,