Commit d131a8df authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Fix --keep-app-running default and make devicelab verboser (#10957)

parent 845c1b7f
...@@ -152,7 +152,7 @@ class AndroidDeviceDiscovery implements DeviceDiscovery { ...@@ -152,7 +152,7 @@ class AndroidDeviceDiscovery implements DeviceDiscovery {
results.add(deviceID); results.add(deviceID);
} }
} else { } else {
throw 'Failed to parse device from adb output: $line'; throw 'Failed to parse device from adb output: "$line"';
} }
} }
...@@ -259,6 +259,7 @@ class AndroidDevice implements Device { ...@@ -259,6 +259,7 @@ class AndroidDevice implements Device {
Future<Map<String, dynamic>> getMemoryStats(String packageName) async { Future<Map<String, dynamic>> getMemoryStats(String packageName) async {
final String meminfo = await shellEval('dumpsys', <String>['meminfo', packageName]); final String meminfo = await shellEval('dumpsys', <String>['meminfo', packageName]);
final Match match = new RegExp(r'TOTAL\s+(\d+)').firstMatch(meminfo); final Match match = new RegExp(r'TOTAL\s+(\d+)').firstMatch(meminfo);
assert(match != null, 'could not parse dumpsys meminfo output');
return <String, dynamic>{ return <String, dynamic>{
'total_kb': int.parse(match.group(1)), 'total_kb': int.parse(match.group(1)),
}; };
......
...@@ -173,7 +173,7 @@ Future<Process> startProcess( ...@@ -173,7 +173,7 @@ Future<Process> startProcess(
String workingDirectory, String workingDirectory,
}) async { }) async {
final String command = '$executable ${arguments?.join(" ") ?? ""}'; final String command = '$executable ${arguments?.join(" ") ?? ""}';
print('Executing: $command'); print('\nExecuting: $command');
environment ??= <String, String>{}; environment ??= <String, String>{};
environment['BOT'] = 'true'; environment['BOT'] = 'true';
final Process process = await _processManager.start( final Process process = await _processManager.start(
...@@ -184,8 +184,8 @@ Future<Process> startProcess( ...@@ -184,8 +184,8 @@ Future<Process> startProcess(
final ProcessInfo processInfo = new ProcessInfo(command, process); final ProcessInfo processInfo = new ProcessInfo(command, process);
_runningProcesses.add(processInfo); _runningProcesses.add(processInfo);
process.exitCode.whenComplete(() { process.exitCode.then((int exitCode) {
print('\n'); // separate the output of this script from subsequent output to make logs easier to read print('exitcode: $exitCode');
_runningProcesses.remove(processInfo); _runningProcesses.remove(processInfo);
}); });
...@@ -218,15 +218,22 @@ Future<int> exec( ...@@ -218,15 +218,22 @@ Future<int> exec(
}) async { }) async {
final Process process = await startProcess(executable, arguments, environment: environment); final Process process = await startProcess(executable, arguments, environment: environment);
final Completer<Null> stdoutDone = new Completer<Null>();
final Completer<Null> stderrDone = new Completer<Null>();
process.stdout process.stdout
.transform(UTF8.decoder) .transform(UTF8.decoder)
.transform(const LineSplitter()) .transform(const LineSplitter())
.listen(print); .listen((String line) {
print('stdout: $line');
}, onDone: () { stdoutDone.complete(); });
process.stderr process.stderr
.transform(UTF8.decoder) .transform(UTF8.decoder)
.transform(const LineSplitter()) .transform(const LineSplitter())
.listen(stderr.writeln); .listen((String line) {
print('stderr: $line');
}, onDone: () { stderrDone.complete(); });
await Future.wait<Null>(<Future<Null>>[stdoutDone.future, stderrDone.future]);
final int exitCode = await process.exitCode; final int exitCode = await process.exitCode;
if (exitCode != 0 && !canFail) if (exitCode != 0 && !canFail)
...@@ -237,7 +244,7 @@ Future<int> exec( ...@@ -237,7 +244,7 @@ Future<int> exec(
/// Executes a command and returns its standard output as a String. /// Executes a command and returns its standard output as a String.
/// ///
/// Standard error is redirected to the current process' standard error stream. /// For logging purposes, the command's output is also printed out.
Future<String> eval( Future<String> eval(
String executable, String executable,
List<String> arguments, { List<String> arguments, {
...@@ -245,16 +252,31 @@ Future<String> eval( ...@@ -245,16 +252,31 @@ Future<String> eval(
bool canFail: false, bool canFail: false,
}) async { }) async {
final Process process = await startProcess(executable, arguments, environment: environment); final Process process = await startProcess(executable, arguments, environment: environment);
process.stderr.listen((List<int> data) {
stderr.add(data); final StringBuffer output = new StringBuffer();
}); final Completer<Null> stdoutDone = new Completer<Null>();
final String output = await UTF8.decodeStream(process.stdout); final Completer<Null> stderrDone = new Completer<Null>();
process.stdout
.transform(UTF8.decoder)
.transform(const LineSplitter())
.listen((String line) {
print('stdout: $line');
output.writeln(line);
}, onDone: () { stdoutDone.complete(); });
process.stderr
.transform(UTF8.decoder)
.transform(const LineSplitter())
.listen((String line) {
print('stderr: $line');
}, onDone: () { stderrDone.complete(); });
await Future.wait<Null>(<Future<Null>>[stdoutDone.future, stderrDone.future]);
final int exitCode = await process.exitCode; final int exitCode = await process.exitCode;
if (exitCode != 0 && !canFail) if (exitCode != 0 && !canFail)
fail('Executable failed with exit code $exitCode.'); fail('Executable failed with exit code $exitCode.');
return output.trimRight(); return output.toString().trimRight();
} }
Future<int> flutter(String command, { Future<int> flutter(String command, {
......
...@@ -41,6 +41,7 @@ class DriveCommand extends RunCommandBase { ...@@ -41,6 +41,7 @@ class DriveCommand extends RunCommandBase {
DriveCommand() { DriveCommand() {
argParser.addFlag( argParser.addFlag(
'keep-app-running', 'keep-app-running',
defaultsTo: null,
negatable: true, negatable: true,
help: help:
'Will keep the Flutter application running when done testing.\n' 'Will keep the Flutter application running when done testing.\n'
......
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