Skip to content

Commit 58245c3

Browse files
Hixiegspencergoog
authored andcommitted
Fix --keep-app-running default and make devicelab verboser (flutter#10957)
1 parent f1c7233 commit 58245c3

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

dev/devicelab/lib/framework/adb.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class AndroidDeviceDiscovery implements DeviceDiscovery {
152152
results.add(deviceID);
153153
}
154154
} else {
155-
throw 'Failed to parse device from adb output: $line';
155+
throw 'Failed to parse device from adb output: "$line"';
156156
}
157157
}
158158

@@ -259,6 +259,7 @@ class AndroidDevice implements Device {
259259
Future<Map<String, dynamic>> getMemoryStats(String packageName) async {
260260
final String meminfo = await shellEval('dumpsys', <String>['meminfo', packageName]);
261261
final Match match = new RegExp(r'TOTAL\s+(\d+)').firstMatch(meminfo);
262+
assert(match != null, 'could not parse dumpsys meminfo output');
262263
return <String, dynamic>{
263264
'total_kb': int.parse(match.group(1)),
264265
};

dev/devicelab/lib/framework/utils.dart

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ Future<Process> startProcess(
173173
String workingDirectory,
174174
}) async {
175175
final String command = '$executable ${arguments?.join(" ") ?? ""}';
176-
print('Executing: $command');
176+
print('\nExecuting: $command');
177177
environment ??= <String, String>{};
178178
environment['BOT'] = 'true';
179179
final Process process = await _processManager.start(
@@ -184,8 +184,8 @@ Future<Process> startProcess(
184184
final ProcessInfo processInfo = new ProcessInfo(command, process);
185185
_runningProcesses.add(processInfo);
186186

187-
process.exitCode.whenComplete(() {
188-
print('\n'); // separate the output of this script from subsequent output to make logs easier to read
187+
process.exitCode.then((int exitCode) {
188+
print('exitcode: $exitCode');
189189
_runningProcesses.remove(processInfo);
190190
});
191191

@@ -218,15 +218,22 @@ Future<int> exec(
218218
}) async {
219219
final Process process = await startProcess(executable, arguments, environment: environment);
220220

221+
final Completer<Null> stdoutDone = new Completer<Null>();
222+
final Completer<Null> stderrDone = new Completer<Null>();
221223
process.stdout
222224
.transform(UTF8.decoder)
223225
.transform(const LineSplitter())
224-
.listen(print);
226+
.listen((String line) {
227+
print('stdout: $line');
228+
}, onDone: () { stdoutDone.complete(); });
225229
process.stderr
226230
.transform(UTF8.decoder)
227231
.transform(const LineSplitter())
228-
.listen(stderr.writeln);
232+
.listen((String line) {
233+
print('stderr: $line');
234+
}, onDone: () { stderrDone.complete(); });
229235

236+
await Future.wait<Null>(<Future<Null>>[stdoutDone.future, stderrDone.future]);
230237
final int exitCode = await process.exitCode;
231238

232239
if (exitCode != 0 && !canFail)
@@ -237,24 +244,39 @@ Future<int> exec(
237244

238245
/// Executes a command and returns its standard output as a String.
239246
///
240-
/// Standard error is redirected to the current process' standard error stream.
247+
/// For logging purposes, the command's output is also printed out.
241248
Future<String> eval(
242249
String executable,
243250
List<String> arguments, {
244251
Map<String, String> environment,
245252
bool canFail: false,
246253
}) async {
247254
final Process process = await startProcess(executable, arguments, environment: environment);
248-
process.stderr.listen((List<int> data) {
249-
stderr.add(data);
250-
});
251-
final String output = await UTF8.decodeStream(process.stdout);
255+
256+
final StringBuffer output = new StringBuffer();
257+
final Completer<Null> stdoutDone = new Completer<Null>();
258+
final Completer<Null> stderrDone = new Completer<Null>();
259+
process.stdout
260+
.transform(UTF8.decoder)
261+
.transform(const LineSplitter())
262+
.listen((String line) {
263+
print('stdout: $line');
264+
output.writeln(line);
265+
}, onDone: () { stdoutDone.complete(); });
266+
process.stderr
267+
.transform(UTF8.decoder)
268+
.transform(const LineSplitter())
269+
.listen((String line) {
270+
print('stderr: $line');
271+
}, onDone: () { stderrDone.complete(); });
272+
273+
await Future.wait<Null>(<Future<Null>>[stdoutDone.future, stderrDone.future]);
252274
final int exitCode = await process.exitCode;
253275

254276
if (exitCode != 0 && !canFail)
255277
fail('Executable failed with exit code $exitCode.');
256278

257-
return output.trimRight();
279+
return output.toString().trimRight();
258280
}
259281

260282
Future<int> flutter(String command, {

packages/flutter_tools/lib/src/commands/drive.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class DriveCommand extends RunCommandBase {
4141
DriveCommand() {
4242
argParser.addFlag(
4343
'keep-app-running',
44+
defaultsTo: null,
4445
negatable: true,
4546
help:
4647
'Will keep the Flutter application running when done testing.\n'

0 commit comments

Comments
 (0)