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

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: comment + win fix 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 // TODO(vtl): Not implemented on Windows yet.
30 #if defined(OS_POSIX)
31 platform_server_channel_ =
32 system::PlatformServerChannel::Create("TestChannel");
33 #endif
34 }
35
36 void MultiprocessTestBase::TearDown() {
37 CHECK_EQ(test_child_handle_, base::kNullProcessHandle);
38
39 platform_server_channel_.reset();
40
41 MultiProcessTest::TearDown();
42 }
43
44 void MultiprocessTestBase::StartChild(const std::string& test_child_name) {
45 CHECK(platform_server_channel_.get());
46 CHECK(!test_child_name.empty());
47 CHECK_EQ(test_child_handle_, base::kNullProcessHandle);
48
49 std::string test_child_main = test_child_name + "TestChildMain";
50
51 #if defined(OS_POSIX)
52 CommandLine unused(CommandLine::NO_PROGRAM);
53 base::FileHandleMappingVector fds_to_map;
54 platform_server_channel_->GetDataNeededToPassClientChannelToChildProcess(
55 &unused, &fds_to_map);
56 test_child_handle_ = SpawnChild(test_child_main, fds_to_map, false);
57 #elif defined(OS_WIN)
58 test_child_handle_ = SpawnChild(test_child_main, false);
59 #else
60 #error "Not supported yet."
61 #endif
62 // TODO(vtl): Not implemented on Windows yet.
63 #if defined(OS_POSIX)
64 platform_server_channel_->ChildProcessLaunched();
65 #endif
66
67 CHECK_NE(test_child_handle_, base::kNullProcessHandle);
68 }
69
70 int MultiprocessTestBase::WaitForChildShutdown() {
71 CHECK_NE(test_child_handle_, base::kNullProcessHandle);
72
73 static const int kTimeoutSeconds = 5;
74 int rv = -1;
75 CHECK(base::WaitForExitCodeWithTimeout(
76 test_child_handle_, &rv, base::TimeDelta::FromSeconds(kTimeoutSeconds)));
77 base::CloseProcessHandle(test_child_handle_);
78 test_child_handle_ = base::kNullProcessHandle;
79 return rv;
80 }
81
82 CommandLine MultiprocessTestBase::MakeCmdLine(const std::string& procname,
83 bool debug_on_start) {
84 CHECK(platform_server_channel_.get());
85
86 CommandLine command_line =
87 base::MultiProcessTest::MakeCmdLine(procname, debug_on_start);
88 // TODO(vtl): Not implemented on Windows yet.
89 #if defined(OS_POSIX)
90 base::FileHandleMappingVector unused;
91 platform_server_channel_->GetDataNeededToPassClientChannelToChildProcess(
92 &command_line, &unused);
93 #endif
94 return command_line;
95 }
96
97 // static
98 void MultiprocessTestBase::ChildSetup() {
99 // TODO(vtl)
100 NOTIMPLEMENTED();
101 }
102
103 } // namespace test
104 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/common/test/multiprocess_test_base.h ('k') | mojo/common/test/multiprocess_test_base_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698