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

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

Issue 134373005: Mojo: Refactor PlatformChannel stuff. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months 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
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"
(...skipping 11 matching lines...) Expand all
22 CHECK_EQ(test_child_handle_, base::kNullProcessHandle); 22 CHECK_EQ(test_child_handle_, base::kNullProcessHandle);
23 } 23 }
24 24
25 void MultiprocessTestBase::SetUp() { 25 void MultiprocessTestBase::SetUp() {
26 CHECK_EQ(test_child_handle_, base::kNullProcessHandle); 26 CHECK_EQ(test_child_handle_, base::kNullProcessHandle);
27 27
28 MultiProcessTest::SetUp(); 28 MultiProcessTest::SetUp();
29 29
30 // TODO(vtl): Not implemented on Windows yet. 30 // TODO(vtl): Not implemented on Windows yet.
31 #if defined(OS_POSIX) 31 #if defined(OS_POSIX)
32 platform_server_channel = 32 platform_channel_pair_.reset(new system::PlatformChannelPair());
33 system::PlatformServerChannel::Create("TestChannel"); 33 server_platform_channel = platform_channel_pair_->CreateServerChannel();
34 #endif 34 #endif
35 } 35 }
36 36
37 void MultiprocessTestBase::TearDown() { 37 void MultiprocessTestBase::TearDown() {
38 CHECK_EQ(test_child_handle_, base::kNullProcessHandle); 38 CHECK_EQ(test_child_handle_, base::kNullProcessHandle);
39 39
40 platform_server_channel.reset(); 40 server_platform_channel.reset();
41 platform_channel_pair_.reset();
41 42
42 MultiProcessTest::TearDown(); 43 MultiProcessTest::TearDown();
43 } 44 }
44 45
45 void MultiprocessTestBase::StartChild(const std::string& test_child_name) { 46 void MultiprocessTestBase::StartChild(const std::string& test_child_name) {
46 CHECK(platform_server_channel.get()); 47 CHECK(platform_channel_pair_.get());
47 CHECK(!test_child_name.empty()); 48 CHECK(!test_child_name.empty());
48 CHECK_EQ(test_child_handle_, base::kNullProcessHandle); 49 CHECK_EQ(test_child_handle_, base::kNullProcessHandle);
49 50
50 std::string test_child_main = test_child_name + "TestChildMain"; 51 std::string test_child_main = test_child_name + "TestChildMain";
51 52
52 #if defined(OS_POSIX) 53 #if defined(OS_POSIX)
53 CommandLine unused(CommandLine::NO_PROGRAM); 54 CommandLine unused(CommandLine::NO_PROGRAM);
54 base::FileHandleMappingVector fds_to_map; 55 base::FileHandleMappingVector fds_to_map;
55 platform_server_channel->GetDataNeededToPassClientChannelToChildProcess( 56 platform_channel_pair_->PrepareToPassClientChannelToChildProcess(&unused,
56 &unused, &fds_to_map); 57 &fds_to_map);
57 test_child_handle_ = SpawnChild(test_child_main, fds_to_map, false); 58 test_child_handle_ = SpawnChild(test_child_main, fds_to_map, false);
58 #elif defined(OS_WIN) 59 #elif defined(OS_WIN)
59 test_child_handle_ = SpawnChild(test_child_main, false); 60 test_child_handle_ = SpawnChild(test_child_main, false);
60 #else 61 #else
61 #error "Not supported yet." 62 #error "Not supported yet."
62 #endif 63 #endif
63 // TODO(vtl): Not implemented on Windows yet. 64 // TODO(vtl): Not implemented on Windows yet.
64 #if defined(OS_POSIX) 65 #if defined(OS_POSIX)
65 platform_server_channel->ChildProcessLaunched(); 66 platform_channel_pair_->ChildProcessLaunched();
66 #endif 67 #endif
67 68
68 CHECK_NE(test_child_handle_, base::kNullProcessHandle); 69 CHECK_NE(test_child_handle_, base::kNullProcessHandle);
69 } 70 }
70 71
71 int MultiprocessTestBase::WaitForChildShutdown() { 72 int MultiprocessTestBase::WaitForChildShutdown() {
72 CHECK_NE(test_child_handle_, base::kNullProcessHandle); 73 CHECK_NE(test_child_handle_, base::kNullProcessHandle);
73 74
74 static const int kTimeoutSeconds = 5; 75 static const int kTimeoutSeconds = 5;
75 int rv = -1; 76 int rv = -1;
76 CHECK(base::WaitForExitCodeWithTimeout( 77 CHECK(base::WaitForExitCodeWithTimeout(
77 test_child_handle_, &rv, base::TimeDelta::FromSeconds(kTimeoutSeconds))); 78 test_child_handle_, &rv, base::TimeDelta::FromSeconds(kTimeoutSeconds)));
78 base::CloseProcessHandle(test_child_handle_); 79 base::CloseProcessHandle(test_child_handle_);
79 test_child_handle_ = base::kNullProcessHandle; 80 test_child_handle_ = base::kNullProcessHandle;
80 return rv; 81 return rv;
81 } 82 }
82 83
83 CommandLine MultiprocessTestBase::MakeCmdLine(const std::string& procname, 84 CommandLine MultiprocessTestBase::MakeCmdLine(const std::string& procname,
84 bool debug_on_start) { 85 bool debug_on_start) {
85 CHECK(platform_server_channel.get()); 86 CHECK(platform_channel_pair_.get());
86 87
87 CommandLine command_line = 88 CommandLine command_line =
88 base::MultiProcessTest::MakeCmdLine(procname, debug_on_start); 89 base::MultiProcessTest::MakeCmdLine(procname, debug_on_start);
89 // TODO(vtl): Not implemented on Windows yet. 90 // TODO(vtl): Not implemented on Windows yet.
90 #if defined(OS_POSIX) 91 #if defined(OS_POSIX)
91 base::FileHandleMappingVector unused; 92 base::FileHandleMappingVector unused;
92 platform_server_channel->GetDataNeededToPassClientChannelToChildProcess( 93 platform_channel_pair_->PrepareToPassClientChannelToChildProcess(
93 &command_line, &unused); 94 &command_line, &unused);
94 #endif 95 #endif
95 return command_line; 96 return command_line;
96 } 97 }
97 98
98 // static 99 // static
99 void MultiprocessTestBase::ChildSetup() { 100 void MultiprocessTestBase::ChildSetup() {
100 CHECK(CommandLine::InitializedForCurrentProcess()); 101 CHECK(CommandLine::InitializedForCurrentProcess());
101 // TODO(vtl): Not implemented on Windows yet. 102 // TODO(vtl): Not implemented on Windows yet.
102 #if defined(OS_POSIX) 103 #if defined(OS_POSIX)
103 platform_client_channel = 104 client_platform_channel =
104 system::PlatformClientChannel::CreateFromParentProcess( 105 system::PlatformChannelPair::CreateClientChannelFromParentProcess(
105 *CommandLine::ForCurrentProcess()); 106 *CommandLine::ForCurrentProcess());
106 CHECK(platform_client_channel.get()); 107 CHECK(client_platform_channel.get());
107 #endif 108 #endif
108 } 109 }
109 110
110 // static 111 // static
111 scoped_ptr<system::PlatformClientChannel> 112 scoped_ptr<system::PlatformChannel>
112 MultiprocessTestBase::platform_client_channel; 113 MultiprocessTestBase::client_platform_channel;
113 114
114 } // namespace test 115 } // namespace test
115 } // namespace mojo 116 } // 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