summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-08 22:13:43 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-09-08 22:13:43 +0000
commit59fbd7d15372d3117599cbd19b5b9cfc663b3de8 (patch)
treeac29a73b8edc7f7db21b975f784c05b09ddc24aa /chrome
parent46c83b6653ccb747209014de85a980c31d8d1835 (diff)
downloadchromium_src-59fbd7d15372d3117599cbd19b5b9cfc663b3de8.zip
chromium_src-59fbd7d15372d3117599cbd19b5b9cfc663b3de8.tar.gz
chromium_src-59fbd7d15372d3117599cbd19b5b9cfc663b3de8.tar.bz2
GTTF: Use job objects more for things launched by tests.
BUG=none Review URL: http://codereview.chromium.org/7841046 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100272 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/test/base/layout_test_http_server.cc30
-rw-r--r--chrome/test/base/layout_test_http_server.h9
-rw-r--r--chrome/test/ui/ui_test_suite.cc18
-rw-r--r--chrome/test/ui/ui_test_suite.h7
4 files changed, 63 insertions, 1 deletions
diff --git a/chrome/test/base/layout_test_http_server.cc b/chrome/test/base/layout_test_http_server.cc
index 7ac0012..7ae0891 100644
--- a/chrome/test/base/layout_test_http_server.cc
+++ b/chrome/test/base/layout_test_http_server.cc
@@ -74,12 +74,27 @@ bool LayoutTestHttpServer::Start() {
cmd_line.AppendArgNative(FILE_PATH_LITERAL("--layout_tests_dir=") +
layout_tests_dir.value());
+#if defined(OS_WIN)
// For Windows 7, if we start the lighttpd server on the foreground mode,
// it will mess up with the command window and cause conhost.exe to crash. To
// work around this, we start the http server on the background mode.
-#if defined(OS_WIN)
if (base::win::GetVersion() >= base::win::VERSION_WIN7)
cmd_line.AppendArg("--run_background");
+
+ job_handle_.Set(CreateJobObject(NULL, NULL));
+ if (!job_handle_.IsValid()) {
+ LOG(ERROR) << "Could not create JobObject.";
+ return false;
+ }
+
+ JOBOBJECT_EXTENDED_LIMIT_INFORMATION limit_info = {0};
+ limit_info.BasicLimitInformation.LimitFlags =
+ JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
+ if (0 == SetInformationJobObject(job_handle_.Get(),
+ JobObjectExtendedLimitInformation, &limit_info, sizeof(limit_info))) {
+ LOG(ERROR) << "Could not SetInformationJobObject.";
+ return false;
+ }
#endif
// The Python script waits for the server to start responding to requests,
@@ -87,6 +102,9 @@ bool LayoutTestHttpServer::Start() {
// continuing.
base::LaunchOptions options;
options.wait = true;
+#if defined(OS_WIN)
+ options.job_handle = job_handle_.Get();
+#endif
running_ = base::LaunchProcess(cmd_line, options, NULL);
return running_;
}
@@ -104,8 +122,18 @@ bool LayoutTestHttpServer::Stop() {
base::LaunchOptions options;
options.wait = true;
+#if defined(OS_WIN)
+ options.job_handle = job_handle_.Get();
+#endif
bool stopped = base::LaunchProcess(cmd_line, options, NULL);
running_ = !stopped;
+
+#if defined(OS_WIN)
+ // Close the job object handle now. This should clean up
+ // any orphaned processes.
+ job_handle_.Close();
+#endif
+
return stopped;
}
diff --git a/chrome/test/base/layout_test_http_server.h b/chrome/test/base/layout_test_http_server.h
index 9e8de92..e3893b70 100644
--- a/chrome/test/base/layout_test_http_server.h
+++ b/chrome/test/base/layout_test_http_server.h
@@ -9,6 +9,10 @@
#include "base/compiler_specific.h"
#include "base/file_path.h"
+#if defined(OS_WIN)
+#include "base/win/scoped_handle.h"
+#endif
+
// This object bounds the lifetime of an external HTTP server
// used for layout tests.
//
@@ -37,6 +41,11 @@ class LayoutTestHttpServer {
bool running_; // True if the server is currently running.
+#if defined(OS_WIN)
+ // JobObject used to clean up orphaned child processes.
+ base::win::ScopedHandle job_handle_;
+#endif
+
DISALLOW_COPY_AND_ASSIGN(LayoutTestHttpServer);
};
diff --git a/chrome/test/ui/ui_test_suite.cc b/chrome/test/ui/ui_test_suite.cc
index e0967c4..5a5e07f 100644
--- a/chrome/test/ui/ui_test_suite.cc
+++ b/chrome/test/ui/ui_test_suite.cc
@@ -32,6 +32,7 @@ void UITestSuite::Shutdown() {
#if defined(OS_WIN)
if (crash_service_)
base::KillProcess(crash_service_, 0, false);
+ job_handle_.Close();
#endif
ChromeTestSuite::Shutdown();
}
@@ -45,6 +46,21 @@ void UITestSuite::LoadCrashService() {
if (base::GetProcessCount(L"crash_service.exe", NULL))
return;
+ job_handle_.Set(CreateJobObject(NULL, NULL));
+ if (!job_handle_.IsValid()) {
+ LOG(ERROR) << "Could not create JobObject.";
+ return;
+ }
+
+ JOBOBJECT_EXTENDED_LIMIT_INFORMATION limit_info = {0};
+ limit_info.BasicLimitInformation.LimitFlags =
+ JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
+ if (0 == SetInformationJobObject(job_handle_.Get(),
+ JobObjectExtendedLimitInformation, &limit_info, sizeof(limit_info))) {
+ LOG(ERROR) << "Could not SetInformationJobObject.";
+ return;
+ }
+
FilePath exe_dir;
if (!PathService::Get(base::DIR_EXE, &exe_dir)) {
LOG(ERROR) << "Failed to get path to DIR_EXE, "
@@ -52,6 +68,8 @@ void UITestSuite::LoadCrashService() {
return;
}
+ base::LaunchOptions launch_options;
+ launch_options.job_handle = job_handle_.Get();
FilePath crash_service = exe_dir.Append(L"crash_service.exe");
if (!base::LaunchProcess(crash_service.value(), base::LaunchOptions(),
&crash_service_)) {
diff --git a/chrome/test/ui/ui_test_suite.h b/chrome/test/ui/ui_test_suite.h
index 5995174..8d43a13 100644
--- a/chrome/test/ui/ui_test_suite.h
+++ b/chrome/test/ui/ui_test_suite.h
@@ -9,6 +9,10 @@
#include "base/process.h"
#include "chrome/test/base/chrome_test_suite.h"
+#if defined(OS_WIN)
+#include "base/win/scoped_handle.h"
+#endif
+
class UITestSuite : public ChromeTestSuite {
public:
UITestSuite(int argc, char** argv);
@@ -22,6 +26,9 @@ class UITestSuite : public ChromeTestSuite {
void LoadCrashService();
base::ProcessHandle crash_service_;
+
+ // JobObject used to clean up orphaned child processes.
+ base::win::ScopedHandle job_handle_;
#endif
};