Commit 64c79760 authored by Greg Thompson's avatar Greg Thompson Committed by Commit Bot

Add ProcessLifetimeObserver::OnTimedOut.

This allows consumers of TestLauncher and content::LaunchTests to take
action on child process timeout before the process is terminated.

BUG=764415
R=phajdan.jr@chromium.org,sky@chromium.org

Change-Id: Iccb359273c464f1e660a079af92edfc7feed817f
Reviewed-on: https://chromium-review.googlesource.com/746701
Commit-Queue: Greg Thompson <grt@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#513091}
parent 7fc711d9
...@@ -350,6 +350,9 @@ int LaunchChildTestProcessWithOptions(const CommandLine& command_line, ...@@ -350,6 +350,9 @@ int LaunchChildTestProcessWithOptions(const CommandLine& command_line,
int exit_code = 0; int exit_code = 0;
if (!process.WaitForExitWithTimeout(timeout, &exit_code)) { if (!process.WaitForExitWithTimeout(timeout, &exit_code)) {
if (observer)
observer->OnTimedOut(command_line);
*was_timeout = true; *was_timeout = true;
exit_code = -1; // Set a non-zero exit code to signal a failure. exit_code = -1; // Set a non-zero exit code to signal a failure.
......
...@@ -86,6 +86,11 @@ class ProcessLifetimeObserver { ...@@ -86,6 +86,11 @@ class ProcessLifetimeObserver {
// caller owns the ProcessHandle. // caller owns the ProcessHandle.
virtual void OnLaunched(ProcessHandle handle, ProcessId id) {} virtual void OnLaunched(ProcessHandle handle, ProcessId id) {}
// Invoked when a test process exceeds its runtime, immediately before it is
// terminated. |command_line| is the command line used to launch the process.
// NOTE: this method is invoked on the thread the process is launched on.
virtual void OnTimedOut(const CommandLine& command_line) {}
// Invoked after a child process finishes, reporting the process |exit_code|, // Invoked after a child process finishes, reporting the process |exit_code|,
// child process |elapsed_time|, whether or not the process was terminated as // child process |elapsed_time|, whether or not the process was terminated as
// a result of a timeout, and the output of the child (stdout and stderr // a result of a timeout, and the output of the child (stdout and stderr
......
...@@ -168,6 +168,10 @@ class WrapperTestLauncherDelegate : public base::TestLauncherDelegate { ...@@ -168,6 +168,10 @@ class WrapperTestLauncherDelegate : public base::TestLauncherDelegate {
test_state_->ChildProcessLaunched(handle, id); test_state_->ChildProcessLaunched(handle, id);
} }
void OnTimedOut(const base::CommandLine& command_line) override {
test_launcher_delegate_->OnTestTimedOut(command_line);
}
void OnCompleted(int exit_code, void OnCompleted(int exit_code,
base::TimeDelta elapsed_time, base::TimeDelta elapsed_time,
bool was_timeout, bool was_timeout,
...@@ -198,6 +202,10 @@ class WrapperTestLauncherDelegate : public base::TestLauncherDelegate { ...@@ -198,6 +202,10 @@ class WrapperTestLauncherDelegate : public base::TestLauncherDelegate {
const std::string test_name, const std::string test_name,
const base::TestResult& pre_test_result); const base::TestResult& pre_test_result);
// Relays timeout notification from the TestLauncher (by way of a
// ProcessLifetimeObserver) to the caller's content::TestLauncherDelegate.
void OnTestTimedOut(const base::CommandLine& command_line);
// Callback to receive result of a test. // Callback to receive result of a test.
// |output_file| is a path to xml file written by test-launcher // |output_file| is a path to xml file written by test-launcher
// child process. It contains information about test and failed // child process. It contains information about test and failed
...@@ -473,6 +481,11 @@ void WrapperTestLauncherDelegate::RunDependentTest( ...@@ -473,6 +481,11 @@ void WrapperTestLauncherDelegate::RunDependentTest(
} }
} }
void WrapperTestLauncherDelegate::OnTestTimedOut(
const base::CommandLine& command_line) {
launcher_delegate_->OnTestTimedOut(command_line);
}
void WrapperTestLauncherDelegate::GTestCallback( void WrapperTestLauncherDelegate::GTestCallback(
base::TestLauncher* test_launcher, base::TestLauncher* test_launcher,
const std::vector<std::string>& test_names, const std::vector<std::string>& test_names,
......
...@@ -62,6 +62,10 @@ class TestLauncherDelegate { ...@@ -62,6 +62,10 @@ class TestLauncherDelegate {
// jobs. // jobs.
virtual void PreSharding() {} virtual void PreSharding() {}
// Invoked when a child process times out immediately before it is terminated.
// |command_line| is the command line of the child process.
virtual void OnTestTimedOut(const base::CommandLine& command_line) {}
// Called prior to returning from LaunchTests(). Gives the delegate a chance // Called prior to returning from LaunchTests(). Gives the delegate a chance
// to do cleanup before state created by TestLauncher has been destroyed (such // to do cleanup before state created by TestLauncher has been destroyed (such
// as the AtExitManager). // as the AtExitManager).
......
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