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

Side by Side Diff: mojo/edk/embedder/platform_channel_pair_unittest.cc

Issue 1651183003: Make PlatformChannelPair "dumb". (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 10 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
« no previous file with comments | « mojo/edk/embedder/platform_channel_pair.cc ('k') | mojo/edk/system/channel_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/edk/embedder/platform_channel_pair.h" 5 #include "mojo/edk/embedder/platform_channel_pair.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 #include <poll.h> 8 #include <poll.h>
9 #include <signal.h> 9 #include <signal.h>
10 #include <stdio.h> 10 #include <stdio.h>
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 } 60 }
61 61
62 private: 62 private:
63 struct sigaction old_action_; 63 struct sigaction old_action_;
64 64
65 MOJO_DISALLOW_COPY_AND_ASSIGN(PlatformChannelPairTest); 65 MOJO_DISALLOW_COPY_AND_ASSIGN(PlatformChannelPairTest);
66 }; 66 };
67 67
68 TEST_F(PlatformChannelPairTest, NoSigPipe) { 68 TEST_F(PlatformChannelPairTest, NoSigPipe) {
69 PlatformChannelPair channel_pair; 69 PlatformChannelPair channel_pair;
70 ScopedPlatformHandle server_handle = channel_pair.PassServerHandle(); 70 ScopedPlatformHandle server_handle = channel_pair.handle0.Pass();
71 ScopedPlatformHandle client_handle = channel_pair.PassClientHandle(); 71 ScopedPlatformHandle client_handle = channel_pair.handle1.Pass();
72 72
73 // Write to the client. 73 // Write to the client.
74 static const char kHello[] = "hello"; 74 static const char kHello[] = "hello";
75 EXPECT_EQ(static_cast<ssize_t>(sizeof(kHello)), 75 EXPECT_EQ(static_cast<ssize_t>(sizeof(kHello)),
76 write(client_handle.get().fd, kHello, sizeof(kHello))); 76 write(client_handle.get().fd, kHello, sizeof(kHello)));
77 77
78 // Close the client. 78 // Close the client.
79 client_handle.reset(); 79 client_handle.reset();
80 80
81 // Read from the server; this should be okay. 81 // Read from the server; this should be okay.
(...skipping 19 matching lines...) Expand all
101 struct iovec iov[2] = {{const_cast<char*>(kHello), sizeof(kHello)}, 101 struct iovec iov[2] = {{const_cast<char*>(kHello), sizeof(kHello)},
102 {const_cast<char*>(kHello), sizeof(kHello)}}; 102 {const_cast<char*>(kHello), sizeof(kHello)}};
103 result = PlatformChannelWritev(server_handle.get(), iov, 2); 103 result = PlatformChannelWritev(server_handle.get(), iov, 2);
104 EXPECT_EQ(-1, result); 104 EXPECT_EQ(-1, result);
105 if (errno != EPIPE) 105 if (errno != EPIPE)
106 PLOG(WARNING) << "write (expected EPIPE)"; 106 PLOG(WARNING) << "write (expected EPIPE)";
107 } 107 }
108 108
109 TEST_F(PlatformChannelPairTest, SendReceiveData) { 109 TEST_F(PlatformChannelPairTest, SendReceiveData) {
110 PlatformChannelPair channel_pair; 110 PlatformChannelPair channel_pair;
111 ScopedPlatformHandle server_handle = channel_pair.PassServerHandle(); 111 ScopedPlatformHandle server_handle = channel_pair.handle0.Pass();
112 ScopedPlatformHandle client_handle = channel_pair.PassClientHandle(); 112 ScopedPlatformHandle client_handle = channel_pair.handle1.Pass();
113 113
114 for (size_t i = 0; i < 10; i++) { 114 for (size_t i = 0; i < 10; i++) {
115 std::string send_string(1 << i, 'A' + i); 115 std::string send_string(1 << i, 'A' + i);
116 116
117 EXPECT_EQ(static_cast<ssize_t>(send_string.size()), 117 EXPECT_EQ(static_cast<ssize_t>(send_string.size()),
118 PlatformChannelWrite(server_handle.get(), send_string.data(), 118 PlatformChannelWrite(server_handle.get(), send_string.data(),
119 send_string.size())); 119 send_string.size()));
120 120
121 WaitReadable(client_handle.get()); 121 WaitReadable(client_handle.get());
122 122
123 char buf[10000] = {}; 123 char buf[10000] = {};
124 std::deque<ScopedPlatformHandle> received_handles; 124 std::deque<ScopedPlatformHandle> received_handles;
125 ssize_t result = PlatformChannelRecvmsg(client_handle.get(), buf, 125 ssize_t result = PlatformChannelRecvmsg(client_handle.get(), buf,
126 sizeof(buf), &received_handles); 126 sizeof(buf), &received_handles);
127 EXPECT_EQ(static_cast<ssize_t>(send_string.size()), result); 127 EXPECT_EQ(static_cast<ssize_t>(send_string.size()), result);
128 EXPECT_EQ(send_string, std::string(buf, static_cast<size_t>(result))); 128 EXPECT_EQ(send_string, std::string(buf, static_cast<size_t>(result)));
129 EXPECT_TRUE(received_handles.empty()); 129 EXPECT_TRUE(received_handles.empty());
130 } 130 }
131 } 131 }
132 132
133 TEST_F(PlatformChannelPairTest, SendReceiveFDs) { 133 TEST_F(PlatformChannelPairTest, SendReceiveFDs) {
134 mojo::system::test::ScopedTestDir test_dir; 134 mojo::system::test::ScopedTestDir test_dir;
135 135
136 static const char kHello[] = "hello"; 136 static const char kHello[] = "hello";
137 137
138 PlatformChannelPair channel_pair; 138 PlatformChannelPair channel_pair;
139 ScopedPlatformHandle server_handle = channel_pair.PassServerHandle(); 139 ScopedPlatformHandle server_handle = channel_pair.handle0.Pass();
140 ScopedPlatformHandle client_handle = channel_pair.PassClientHandle(); 140 ScopedPlatformHandle client_handle = channel_pair.handle1.Pass();
141 141
142 // Reduce the number of FDs opened on OS X to avoid test flake. 142 // Reduce the number of FDs opened on OS X to avoid test flake.
143 #if defined(OS_MACOSX) 143 #if defined(OS_MACOSX)
144 const size_t kNumHandlesToSend = kPlatformChannelMaxNumHandles / 2; 144 const size_t kNumHandlesToSend = kPlatformChannelMaxNumHandles / 2;
145 #else 145 #else
146 const size_t kNumHandlesToSend = kPlatformChannelMaxNumHandles; 146 const size_t kNumHandlesToSend = kPlatformChannelMaxNumHandles;
147 #endif 147 #endif
148 148
149 for (size_t i = 1; i < kNumHandlesToSend; i++) { 149 for (size_t i = 1; i < kNumHandlesToSend; i++) {
150 // Make |i| files, with the j-th file consisting of j copies of the digit 150 // Make |i| files, with the j-th file consisting of j copies of the digit
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 } 192 }
193 } 193 }
194 } 194 }
195 195
196 TEST_F(PlatformChannelPairTest, AppendReceivedFDs) { 196 TEST_F(PlatformChannelPairTest, AppendReceivedFDs) {
197 mojo::system::test::ScopedTestDir test_dir; 197 mojo::system::test::ScopedTestDir test_dir;
198 198
199 static const char kHello[] = "hello"; 199 static const char kHello[] = "hello";
200 200
201 PlatformChannelPair channel_pair; 201 PlatformChannelPair channel_pair;
202 ScopedPlatformHandle server_handle = channel_pair.PassServerHandle(); 202 ScopedPlatformHandle server_handle = channel_pair.handle0.Pass();
203 ScopedPlatformHandle client_handle = channel_pair.PassClientHandle(); 203 ScopedPlatformHandle client_handle = channel_pair.handle1.Pass();
204 204
205 const std::string file_contents("hello world"); 205 const std::string file_contents("hello world");
206 206
207 { 207 {
208 util::ScopedFILE fp(test_dir.CreateFile()); 208 util::ScopedFILE fp(test_dir.CreateFile());
209 ASSERT_TRUE(fp); 209 ASSERT_TRUE(fp);
210 ASSERT_EQ(file_contents.size(), 210 ASSERT_EQ(file_contents.size(),
211 fwrite(file_contents.data(), 1, file_contents.size(), fp.get())); 211 fwrite(file_contents.data(), 1, file_contents.size(), fp.get()));
212 std::vector<ScopedPlatformHandle> platform_handles; 212 std::vector<ScopedPlatformHandle> platform_handles;
213 platform_handles.push_back(test::PlatformHandleFromFILE(std::move(fp))); 213 platform_handles.push_back(test::PlatformHandleFromFILE(std::move(fp)));
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 char read_buf[100]; 247 char read_buf[100];
248 size_t bytes_read = fread(read_buf, 1, sizeof(read_buf), fp.get()); 248 size_t bytes_read = fread(read_buf, 1, sizeof(read_buf), fp.get());
249 EXPECT_EQ(file_contents.size(), bytes_read); 249 EXPECT_EQ(file_contents.size(), bytes_read);
250 EXPECT_EQ(file_contents, std::string(read_buf, bytes_read)); 250 EXPECT_EQ(file_contents, std::string(read_buf, bytes_read));
251 } 251 }
252 } 252 }
253 253
254 } // namespace 254 } // namespace
255 } // namespace embedder 255 } // namespace embedder
256 } // namespace mojo 256 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/embedder/platform_channel_pair.cc ('k') | mojo/edk/system/channel_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698