OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "mojo/common/test/multiprocess_test_base.h" | 5 #include "mojo/common/test/multiprocess_test_base.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/process/kill.h" | 9 #include "base/process/kill.h" |
10 #include "base/process/process_handle.h" | 10 #include "base/process/process_handle.h" |
| 11 // TODO(vtl): Remove build_config.h include when fully implemented on Windows. |
11 #include "build/build_config.h" | 12 #include "build/build_config.h" |
12 | 13 |
13 namespace mojo { | 14 namespace mojo { |
14 namespace test { | 15 namespace test { |
15 | 16 |
16 MultiprocessTestBase::MultiprocessTestBase() | 17 MultiprocessTestBase::MultiprocessTestBase() |
17 : test_child_handle_(base::kNullProcessHandle) { | 18 : test_child_handle_(base::kNullProcessHandle) { |
18 } | 19 } |
19 | 20 |
20 MultiprocessTestBase::~MultiprocessTestBase() { | 21 MultiprocessTestBase::~MultiprocessTestBase() { |
21 CHECK_EQ(test_child_handle_, base::kNullProcessHandle); | 22 CHECK_EQ(test_child_handle_, base::kNullProcessHandle); |
22 } | 23 } |
23 | 24 |
24 void MultiprocessTestBase::SetUp() { | 25 void MultiprocessTestBase::SetUp() { |
25 CHECK_EQ(test_child_handle_, base::kNullProcessHandle); | 26 CHECK_EQ(test_child_handle_, base::kNullProcessHandle); |
26 | 27 |
27 MultiProcessTest::SetUp(); | 28 MultiProcessTest::SetUp(); |
28 | 29 |
29 // TODO(vtl): Not implemented on Windows yet. | 30 // TODO(vtl): Not implemented on Windows yet. |
30 #if defined(OS_POSIX) | 31 #if defined(OS_POSIX) |
31 platform_server_channel_ = | 32 platform_server_channel = |
32 system::PlatformServerChannel::Create("TestChannel"); | 33 system::PlatformServerChannel::Create("TestChannel"); |
33 #endif | 34 #endif |
34 } | 35 } |
35 | 36 |
36 void MultiprocessTestBase::TearDown() { | 37 void MultiprocessTestBase::TearDown() { |
37 CHECK_EQ(test_child_handle_, base::kNullProcessHandle); | 38 CHECK_EQ(test_child_handle_, base::kNullProcessHandle); |
38 | 39 |
39 platform_server_channel_.reset(); | 40 platform_server_channel.reset(); |
40 | 41 |
41 MultiProcessTest::TearDown(); | 42 MultiProcessTest::TearDown(); |
42 } | 43 } |
43 | 44 |
44 void MultiprocessTestBase::StartChild(const std::string& test_child_name) { | 45 void MultiprocessTestBase::StartChild(const std::string& test_child_name) { |
45 CHECK(platform_server_channel_.get()); | 46 CHECK(platform_server_channel.get()); |
46 CHECK(!test_child_name.empty()); | 47 CHECK(!test_child_name.empty()); |
47 CHECK_EQ(test_child_handle_, base::kNullProcessHandle); | 48 CHECK_EQ(test_child_handle_, base::kNullProcessHandle); |
48 | 49 |
49 std::string test_child_main = test_child_name + "TestChildMain"; | 50 std::string test_child_main = test_child_name + "TestChildMain"; |
50 | 51 |
51 #if defined(OS_POSIX) | 52 #if defined(OS_POSIX) |
52 CommandLine unused(CommandLine::NO_PROGRAM); | 53 CommandLine unused(CommandLine::NO_PROGRAM); |
53 base::FileHandleMappingVector fds_to_map; | 54 base::FileHandleMappingVector fds_to_map; |
54 platform_server_channel_->GetDataNeededToPassClientChannelToChildProcess( | 55 platform_server_channel->GetDataNeededToPassClientChannelToChildProcess( |
55 &unused, &fds_to_map); | 56 &unused, &fds_to_map); |
56 test_child_handle_ = SpawnChild(test_child_main, fds_to_map, false); | 57 test_child_handle_ = SpawnChild(test_child_main, fds_to_map, false); |
57 #elif defined(OS_WIN) | 58 #elif defined(OS_WIN) |
58 test_child_handle_ = SpawnChild(test_child_main, false); | 59 test_child_handle_ = SpawnChild(test_child_main, false); |
59 #else | 60 #else |
60 #error "Not supported yet." | 61 #error "Not supported yet." |
61 #endif | 62 #endif |
62 // TODO(vtl): Not implemented on Windows yet. | 63 // TODO(vtl): Not implemented on Windows yet. |
63 #if defined(OS_POSIX) | 64 #if defined(OS_POSIX) |
64 platform_server_channel_->ChildProcessLaunched(); | 65 platform_server_channel->ChildProcessLaunched(); |
65 #endif | 66 #endif |
66 | 67 |
67 CHECK_NE(test_child_handle_, base::kNullProcessHandle); | 68 CHECK_NE(test_child_handle_, base::kNullProcessHandle); |
68 } | 69 } |
69 | 70 |
70 int MultiprocessTestBase::WaitForChildShutdown() { | 71 int MultiprocessTestBase::WaitForChildShutdown() { |
71 CHECK_NE(test_child_handle_, base::kNullProcessHandle); | 72 CHECK_NE(test_child_handle_, base::kNullProcessHandle); |
72 | 73 |
73 static const int kTimeoutSeconds = 5; | 74 static const int kTimeoutSeconds = 5; |
74 int rv = -1; | 75 int rv = -1; |
75 CHECK(base::WaitForExitCodeWithTimeout( | 76 CHECK(base::WaitForExitCodeWithTimeout( |
76 test_child_handle_, &rv, base::TimeDelta::FromSeconds(kTimeoutSeconds))); | 77 test_child_handle_, &rv, base::TimeDelta::FromSeconds(kTimeoutSeconds))); |
77 base::CloseProcessHandle(test_child_handle_); | 78 base::CloseProcessHandle(test_child_handle_); |
78 test_child_handle_ = base::kNullProcessHandle; | 79 test_child_handle_ = base::kNullProcessHandle; |
79 return rv; | 80 return rv; |
80 } | 81 } |
81 | 82 |
82 CommandLine MultiprocessTestBase::MakeCmdLine(const std::string& procname, | 83 CommandLine MultiprocessTestBase::MakeCmdLine(const std::string& procname, |
83 bool debug_on_start) { | 84 bool debug_on_start) { |
84 CHECK(platform_server_channel_.get()); | 85 CHECK(platform_server_channel.get()); |
85 | 86 |
86 CommandLine command_line = | 87 CommandLine command_line = |
87 base::MultiProcessTest::MakeCmdLine(procname, debug_on_start); | 88 base::MultiProcessTest::MakeCmdLine(procname, debug_on_start); |
88 // TODO(vtl): Not implemented on Windows yet. | 89 // TODO(vtl): Not implemented on Windows yet. |
89 #if defined(OS_POSIX) | 90 #if defined(OS_POSIX) |
90 base::FileHandleMappingVector unused; | 91 base::FileHandleMappingVector unused; |
91 platform_server_channel_->GetDataNeededToPassClientChannelToChildProcess( | 92 platform_server_channel->GetDataNeededToPassClientChannelToChildProcess( |
92 &command_line, &unused); | 93 &command_line, &unused); |
93 #endif | 94 #endif |
94 return command_line; | 95 return command_line; |
95 } | 96 } |
96 | 97 |
97 // static | 98 // static |
98 void MultiprocessTestBase::ChildSetup() { | 99 void MultiprocessTestBase::ChildSetup() { |
99 // TODO(vtl) | 100 CHECK(CommandLine::InitializedForCurrentProcess()); |
100 NOTIMPLEMENTED(); | 101 // TODO(vtl): Not implemented on Windows yet. |
| 102 #if defined(OS_POSIX) |
| 103 platform_client_channel = |
| 104 system::PlatformClientChannel::CreateFromParentProcess( |
| 105 *CommandLine::ForCurrentProcess()); |
| 106 CHECK(platform_client_channel.get()); |
| 107 #endif |
101 } | 108 } |
102 | 109 |
| 110 // static |
| 111 scoped_ptr<system::PlatformClientChannel> |
| 112 MultiprocessTestBase::platform_client_channel; |
| 113 |
103 } // namespace test | 114 } // namespace test |
104 } // namespace mojo | 115 } // namespace mojo |
OLD | NEW |