Avoid random stacktraces being printed from tools/test.py during test runs

Previously the testing script was just printing interleaved stack traces with
all the other output. Which means it's not associatable with a single test and
is highly confusing!

This CL associates the stack trace information of tests which time out to the
particular test which timed out.

R=whesse@google.com

Review URL: https://codereview.chromium.org/2524733004 .
This commit is contained in:
Martin Kustermann 2016-11-23 08:39:27 +01:00
parent 171da0489f
commit b1c04f0538

View file

@ -1854,6 +1854,7 @@ class RunningProcess {
int pid;
OutputLog stdout = new OutputLog();
OutputLog stderr = new OutputLog();
List<String> diagnostics = <String>[];
bool compilationSkipped = false;
Completer<CommandOutput> completer;
@ -1917,46 +1918,35 @@ class RunningProcess {
// Close stdin so that tests that try to block on input will fail.
process.stdin.close();
void timeoutHandler() {
timeoutHandler() async {
timedOut = true;
if (process != null) {
var executable, arguments;
if (io.Platform.isLinux) {
// Try to print stack traces of the timed out process.
io.Process.run('eu-stack', ['-p ${process.pid}'])
.then((result) {
io.stdout.write(result.stdout);
io.stderr.write(result.stderr);
})
.catchError(
(error) => print("Error when printing stack trace: $error"))
.whenComplete(() {
if (!process.kill()) {
DebugLogger.error("Unable to kill ${process.pid}");
}
});
executable = 'eu-stack';
arguments = ['-p ${process.pid}'];
} else if (io.Platform.isMacOS) {
// Try to print stack traces of the timed out process.
// `sample` is a sampling profiler but we ask it sample for 1
// second with a 4 second delay between samples so that we only
// sample the threads once.
io.Process.run('/usr/bin/sample',
['${process.pid}', '1', '4000', '-mayDie'])
.then((result) {
io.stdout.write(result.stdout);
io.stderr.write(result.stderr);
})
.catchError(
(error) => print("Error when printing stack trace: $error"))
.whenComplete(() {
if (!process.kill()) {
DebugLogger.error("Unable to kill ${process.pid}");
}
});
} else {
if (!process.kill()) {
DebugLogger.error("Unable to kill ${process.pid}");
executable = '/usr/bin/sample';
arguments = ['${process.pid}', '1', '4000', '-mayDie'];
}
if (executable != null) {
try {
var result = await io.Process.run(executable, arguments);
diagnostics.addAll(result.stdout.split('\n'));
diagnostics.addAll(result.stderr.split('\n'));
} catch (error) {
diagnostics.add("Unable to capture stack traces: $error");
}
}
if (!process.kill()) {
diagnostics.add("Unable to kill ${process.pid}");
}
}
}
@ -2014,6 +2004,7 @@ class RunningProcess {
new DateTime.now().difference(startTime),
compilationSkipped,
pid);
commandOutput.diagnostics.addAll(diagnostics);
return commandOutput;
}