summaryrefslogtreecommitdiffstats
path: root/sandbox/tests
diff options
context:
space:
mode:
authorjschuh@chromium.org <jschuh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-29 15:29:56 +0000
committerjschuh@chromium.org <jschuh@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-29 15:29:56 +0000
commitf6e06204466d7ce6d33a3f5a9cf3ae2128561df7 (patch)
tree13b24c2df28443793ee04ae4cf340bbf370bf8ed /sandbox/tests
parentb54b3fae08eee524456da5fdc598485e251cc8a0 (diff)
downloadchromium_src-f6e06204466d7ce6d33a3f5a9cf3ae2128561df7.zip
chromium_src-f6e06204466d7ce6d33a3f5a9cf3ae2128561df7.tar.gz
chromium_src-f6e06204466d7ce6d33a3f5a9cf3ae2128561df7.tar.bz2
Add a sandbox API for broker handle duplication
BUG=119250 Review URL: https://chromiumcodereview.appspot.com/9838083 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@129627 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sandbox/tests')
-rw-r--r--sandbox/tests/common/controller.cc36
-rw-r--r--sandbox/tests/common/controller.h15
2 files changed, 47 insertions, 4 deletions
diff --git a/sandbox/tests/common/controller.cc b/sandbox/tests/common/controller.cc
index a221ee1..3de3221 100644
--- a/sandbox/tests/common/controller.cc
+++ b/sandbox/tests/common/controller.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -51,6 +51,13 @@ std::wstring MakePathToSysWow64(const wchar_t* name, bool is_obj_man_path) {
return full_path;
}
+bool IsProcessRunning(HANDLE process) {
+ DWORD exit_code = 0;
+ if (::GetExitCodeProcess(process, &exit_code))
+ return exit_code == STILL_ACTIVE;
+ return false;
+}
+
} // namespace
namespace sandbox {
@@ -81,11 +88,13 @@ BrokerServices* GetBroker() {
}
TestRunner::TestRunner(JobLevel job_level, TokenLevel startup_token,
- TokenLevel main_token) : is_init_(false) {
+ TokenLevel main_token)
+ : is_init_(false), is_async_(false), target_process_id_(0) {
Init(job_level, startup_token, main_token);
}
-TestRunner::TestRunner() : is_init_(false) {
+TestRunner::TestRunner()
+ : is_init_(false), is_async_(false), target_process_id_(0) {
Init(JOB_LOCKDOWN, USER_RESTRICTED_SAME_ACCESS, USER_LOCKDOWN);
}
@@ -95,6 +104,8 @@ void TestRunner::Init(JobLevel job_level, TokenLevel startup_token,
policy_ = NULL;
timeout_ = kDefaultTimeout;
state_ = AFTER_REVERT;
+ is_async_= false;
+ target_process_id_ = 0;
broker_ = GetBroker();
if (!broker_)
@@ -115,6 +126,9 @@ TargetPolicy* TestRunner::GetPolicy() {
}
TestRunner::~TestRunner() {
+ if (target_process_)
+ ::TerminateProcess(target_process_, 0);
+
if (policy_)
policy_->Release();
}
@@ -177,6 +191,14 @@ int TestRunner::InternalRunTest(const wchar_t* command) {
if (!is_init_)
return SBOX_TEST_FAILED_TO_RUN_TEST;
+ // For simplicity TestRunner supports only one process per instance.
+ if (target_process_) {
+ if (IsProcessRunning(target_process_))
+ return SBOX_TEST_FAILED_TO_RUN_TEST;
+ target_process_.Close();
+ target_process_id_ = 0;
+ }
+
// Get the path to the sandboxed process.
wchar_t prog_name[MAX_PATH];
GetModuleFileNameW(NULL, prog_name, MAX_PATH);
@@ -198,6 +220,14 @@ int TestRunner::InternalRunTest(const wchar_t* command) {
::ResumeThread(target.hThread);
+ // For an asynchronous run we don't bother waiting.
+ if (is_async_) {
+ target_process_.Set(target.hProcess);
+ target_process_id_ = target.dwProcessId;
+ ::CloseHandle(target.hThread);
+ return SBOX_TEST_SUCCEEDED;
+ }
+
if (::IsDebuggerPresent()) {
// Don't kill the target process on a time-out while we are debugging.
timeout_ = INFINITE;
diff --git a/sandbox/tests/common/controller.h b/sandbox/tests/common/controller.h
index 3f1d0c2..0a78a0e 100644
--- a/sandbox/tests/common/controller.h
+++ b/sandbox/tests/common/controller.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,6 +8,7 @@
#include <windows.h>
#include <string>
+#include "base/win/scoped_handle.h"
#include "sandbox/src/sandbox.h"
namespace sandbox {
@@ -91,6 +92,9 @@ class TestRunner {
// Sets the timeout value for the child to run the command and return.
void SetTimeout(DWORD timeout_ms);
+ // Sets TestRunner to return without waiting for the process to exit.
+ void SetAsynchronous(bool is_async) { is_async_ = is_async; }
+
// Sets the desired state for the test to run.
void SetTestState(SboxTestsState desired_state);
@@ -98,6 +102,12 @@ class TestRunner {
// the policy manually.
TargetPolicy* GetPolicy();
+ // Return the process handle for an asynchronous test.
+ HANDLE process() { return target_process_; }
+
+ // Return the process ID for an asynchronous test.
+ DWORD process_id() { return target_process_id_; }
+
private:
// Initializes the data in the object. Sets is_init_ to tree if the
// function succeeds. This is meant to be called from the constructor.
@@ -112,6 +122,9 @@ class TestRunner {
DWORD timeout_;
SboxTestsState state_;
bool is_init_;
+ bool is_async_;
+ base::win::ScopedHandle target_process_;
+ DWORD target_process_id_;
};
// Returns the broker services.