[devicelab] Add results path flag to test runner (#72765)
This commit is contained in:
@@ -42,6 +42,9 @@ String luciBuilder;
|
||||
/// Whether to exit on first test failure.
|
||||
bool exitOnFirstTestFailure;
|
||||
|
||||
/// Path to write test results to.
|
||||
String resultsPath;
|
||||
|
||||
/// File containing a service account token.
|
||||
///
|
||||
/// If passed, the test run results will be uploaded to Flutter infrastructure.
|
||||
@@ -65,6 +68,16 @@ Future<void> main(List<String> rawArgs) async {
|
||||
return;
|
||||
}
|
||||
|
||||
deviceId = args['device-id'] as String;
|
||||
exitOnFirstTestFailure = args['exit'] as bool;
|
||||
gitBranch = args['git-branch'] as String;
|
||||
localEngine = args['local-engine'] as String;
|
||||
localEngineSrcPath = args['local-engine-src-path'] as String;
|
||||
luciBuilder = args['luci-builder'] as String;
|
||||
resultsPath = args['results-file'] as String;
|
||||
serviceAccountTokenFile = args['service-account-token-file'] as String;
|
||||
silent = args['silent'] as bool;
|
||||
|
||||
if (!args.wasParsed('task')) {
|
||||
if (args.wasParsed('stage') || args.wasParsed('all')) {
|
||||
addTasks(
|
||||
@@ -89,15 +102,6 @@ Future<void> main(List<String> rawArgs) async {
|
||||
return;
|
||||
}
|
||||
|
||||
deviceId = args['device-id'] as String;
|
||||
exitOnFirstTestFailure = args['exit'] as bool;
|
||||
gitBranch = args['git-branch'] as String;
|
||||
localEngine = args['local-engine'] as String;
|
||||
localEngineSrcPath = args['local-engine-src-path'] as String;
|
||||
luciBuilder = args['luci-builder'] as String;
|
||||
serviceAccountTokenFile = args['service-account-token-file'] as String;
|
||||
silent = args['silent'] as bool;
|
||||
|
||||
if (args.wasParsed('ab')) {
|
||||
await _runABTest();
|
||||
} else {
|
||||
@@ -120,8 +124,17 @@ Future<void> _runTasks() async {
|
||||
print(const JsonEncoder.withIndent(' ').convert(result));
|
||||
section('Finished task "$taskName"');
|
||||
|
||||
if (serviceAccountTokenFile != null) {
|
||||
if (resultsPath != null) {
|
||||
final Cocoon cocoon = Cocoon();
|
||||
await cocoon.writeTaskResultToFile(
|
||||
builderName: luciBuilder,
|
||||
gitBranch: gitBranch,
|
||||
result: result,
|
||||
resultsPath: resultsPath,
|
||||
);
|
||||
} else if (serviceAccountTokenFile != null) {
|
||||
final Cocoon cocoon = Cocoon(serviceAccountTokenPath: serviceAccountTokenFile);
|
||||
|
||||
/// Cocoon references LUCI tasks by the [luciBuilder] instead of [taskName].
|
||||
await cocoon.sendTaskResult(builderName: luciBuilder, result: result, gitBranch: gitBranch);
|
||||
}
|
||||
@@ -224,7 +237,7 @@ File _uniqueFile(String filenameTemplate) {
|
||||
File file = File(parts[0] + parts[1]);
|
||||
int i = 1;
|
||||
while (file.existsSync()) {
|
||||
file = File(parts[0]+i.toString()+parts[1]);
|
||||
file = File(parts[0] + i.toString() + parts[1]);
|
||||
i++;
|
||||
}
|
||||
return file;
|
||||
@@ -355,10 +368,7 @@ final ArgParser _argParser = ArgParser()
|
||||
'locally. Defaults to \$FLUTTER_ENGINE if set, or tries to guess at\n'
|
||||
'the location based on the value of the --flutter-root option.',
|
||||
)
|
||||
..addOption(
|
||||
'luci-builder',
|
||||
help: '[Flutter infrastructure] Name of the LUCI builder being run on.'
|
||||
)
|
||||
..addOption('luci-builder', help: '[Flutter infrastructure] Name of the LUCI builder being run on.')
|
||||
..addFlag(
|
||||
'match-host-platform',
|
||||
defaultsTo: true,
|
||||
@@ -367,6 +377,11 @@ final ArgParser _argParser = ArgParser()
|
||||
'on a windows host). Each test publishes its '
|
||||
'`required_agent_capabilities`\nin the `manifest.yaml` file.',
|
||||
)
|
||||
..addOption(
|
||||
'results-file',
|
||||
help: '[Flutter infrastructure] File path for test results. If passed with\n'
|
||||
'task, will write test results to the file.'
|
||||
)
|
||||
..addOption(
|
||||
'service-account-token-file',
|
||||
help: '[Flutter infrastructure] Authentication for uploading results.',
|
||||
|
||||
21
dev/devicelab/bin/test_runner.dart
Normal file
21
dev/devicelab/bin/test_runner.dart
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:args/command_runner.dart';
|
||||
import 'package:flutter_devicelab/command/upload_metrics.dart';
|
||||
|
||||
final CommandRunner<void> runner =
|
||||
CommandRunner<void>('devicelab_runner', 'DeviceLab test runner for recording performance metrics on applications')
|
||||
..addCommand(UploadMetricsCommand());
|
||||
|
||||
Future<void> main(List<String> rawArgs) async {
|
||||
runner.run(rawArgs).catchError((dynamic error) {
|
||||
stderr.writeln('$error\n');
|
||||
stderr.writeln('Usage:\n');
|
||||
stderr.writeln(runner.usage);
|
||||
exit(64); // Exit code 64 indicates a usage error.
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user