Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(12)

Side by Side Diff: mojo/common/test/multiprocess_test_base.cc

Issue 99473007: Mojo: Add a Mojo-specific multiprocess test base class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "mojo/common/test/multiprocess_test_base.h"
6
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "base/process/kill.h"
10 #include "base/process/process_handle.h"
11 #include "build/build_config.h"
12
13 namespace mojo {
14 namespace test {
15
16 MultiprocessTestBase::MultiprocessTestBase()
17 : test_child_handle_(base::kNullProcessHandle) {
18 }
19
20 MultiprocessTestBase::~MultiprocessTestBase() {
21 CHECK_EQ(test_child_handle_, base::kNullProcessHandle);
22 }
23
24 void MultiprocessTestBase::SetUp() {
25 CHECK_EQ(test_child_handle_, base::kNullProcessHandle);
26
27 MultiProcessTest::SetUp();
28
29 platform_server_channel_ =
30 system::PlatformServerChannel::Create("TestChannel");
31 }
32
33 void MultiprocessTestBase::TearDown() {
34 CHECK_EQ(test_child_handle_, base::kNullProcessHandle);
35
36 platform_server_channel_.reset();
37
38 MultiProcessTest::TearDown();
39 }
40
41 void MultiprocessTestBase::StartChild(const std::string& test_child_name) {
42 CHECK(platform_server_channel_.get());
43 CHECK(!test_child_name.empty());
44 CHECK_EQ(test_child_handle_, base::kNullProcessHandle);
45
46 std::string test_child_main = test_child_name + "TestChildMain";
47
48 #if defined(OS_POSIX)
49 CommandLine unused(CommandLine::NO_PROGRAM);
50 base::FileHandleMappingVector fds_to_map;
51 platform_server_channel_->GetDataNeededToPassClientChannelToChildProcess(
52 &unused, &fds_to_map);
53 test_child_handle_ = SpawnChild(test_child_main, fds_to_map, false);
54 #elif defined(OS_WIN)
55 test_child_handle_ = SpawnChild(test_child_main, false);
56 #else
57 #error "Not supported yet."
58 #endif
59 platform_server_channel_->ChildProcessLaunched();
60
61 CHECK_NE(test_child_handle_, base::kNullProcessHandle);
62 }
63
64 int MultiprocessTestBase::WaitForChildShutdown() {
65 CHECK_NE(test_child_handle_, base::kNullProcessHandle);
66
67 static const int kTimeoutSeconds = 5;
68 int rv = -1;
69 CHECK(base::WaitForExitCodeWithTimeout(
70 test_child_handle_, &rv, base::TimeDelta::FromSeconds(kTimeoutSeconds)));
71 base::CloseProcessHandle(test_child_handle_);
72 test_child_handle_ = base::kNullProcessHandle;
73 return rv;
74 }
75
76 CommandLine MultiprocessTestBase::MakeCmdLine(const std::string& procname,
77 bool debug_on_start) {
78 CHECK(platform_server_channel_.get());
79
80 CommandLine command_line =
81 base::MultiProcessTest::MakeCmdLine(procname, debug_on_start);
82 base::FileHandleMappingVector unused;
83 platform_server_channel_->GetDataNeededToPassClientChannelToChildProcess(
84 &command_line, &unused);
85 return command_line;
86 }
87
88 // static
89 void MultiprocessTestBase::ChildSetup() {
90 // TODO(vtl)
91 NOTIMPLEMENTED();
92 }
93
94 } // namespace test
95 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698