| OLD | NEW |
| 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> |
| 11 #include <sys/socket.h> | 11 #include <sys/socket.h> |
| 12 #include <sys/types.h> | 12 #include <sys/types.h> |
| 13 #include <sys/uio.h> | 13 #include <sys/uio.h> |
| 14 #include <unistd.h> | 14 #include <unistd.h> |
| 15 | 15 |
| 16 #include <deque> | 16 #include <deque> |
| 17 | 17 |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 20 #include "mojo/edk/embedder/platform_channel_utils.h" | 20 #include "mojo/edk/embedder/platform_channel_utils.h" |
| 21 #include "mojo/edk/embedder/platform_handle.h" | 21 #include "mojo/edk/embedder/platform_handle.h" |
| 22 #include "mojo/edk/embedder/platform_handle_vector.h" | 22 #include "mojo/edk/embedder/platform_handle_vector.h" |
| 23 #include "mojo/edk/embedder/scoped_platform_handle.h" | 23 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 24 #include "mojo/edk/test/scoped_test_dir.h" | 24 #include "mojo/edk/system/test/scoped_test_dir.h" |
| 25 #include "mojo/edk/test/test_utils.h" | 25 #include "mojo/edk/test/test_utils.h" |
| 26 #include "mojo/edk/util/scoped_file.h" | 26 #include "mojo/edk/util/scoped_file.h" |
| 27 #include "mojo/public/cpp/system/macros.h" | 27 #include "mojo/public/cpp/system/macros.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 29 |
| 30 namespace mojo { | 30 namespace mojo { |
| 31 namespace embedder { | 31 namespace embedder { |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 void WaitReadable(PlatformHandle h) { | 34 void WaitReadable(PlatformHandle h) { |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 std::deque<PlatformHandle> received_handles; | 120 std::deque<PlatformHandle> received_handles; |
| 121 ssize_t result = PlatformChannelRecvmsg(client_handle.get(), buf, | 121 ssize_t result = PlatformChannelRecvmsg(client_handle.get(), buf, |
| 122 sizeof(buf), &received_handles); | 122 sizeof(buf), &received_handles); |
| 123 EXPECT_EQ(static_cast<ssize_t>(send_string.size()), result); | 123 EXPECT_EQ(static_cast<ssize_t>(send_string.size()), result); |
| 124 EXPECT_EQ(send_string, std::string(buf, static_cast<size_t>(result))); | 124 EXPECT_EQ(send_string, std::string(buf, static_cast<size_t>(result))); |
| 125 EXPECT_TRUE(received_handles.empty()); | 125 EXPECT_TRUE(received_handles.empty()); |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 | 128 |
| 129 TEST_F(PlatformChannelPairTest, SendReceiveFDs) { | 129 TEST_F(PlatformChannelPairTest, SendReceiveFDs) { |
| 130 mojo::test::ScopedTestDir test_dir; | 130 mojo::system::test::ScopedTestDir test_dir; |
| 131 | 131 |
| 132 static const char kHello[] = "hello"; | 132 static const char kHello[] = "hello"; |
| 133 | 133 |
| 134 PlatformChannelPair channel_pair; | 134 PlatformChannelPair channel_pair; |
| 135 ScopedPlatformHandle server_handle = channel_pair.PassServerHandle().Pass(); | 135 ScopedPlatformHandle server_handle = channel_pair.PassServerHandle().Pass(); |
| 136 ScopedPlatformHandle client_handle = channel_pair.PassClientHandle().Pass(); | 136 ScopedPlatformHandle client_handle = channel_pair.PassClientHandle().Pass(); |
| 137 | 137 |
| 138 // Reduce the number of FDs opened on OS X to avoid test flake. | 138 // Reduce the number of FDs opened on OS X to avoid test flake. |
| 139 #if defined(OS_MACOSX) | 139 #if defined(OS_MACOSX) |
| 140 const size_t kNumHandlesToSend = kPlatformChannelMaxNumHandles / 2; | 140 const size_t kNumHandlesToSend = kPlatformChannelMaxNumHandles / 2; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 rewind(fp.get()); | 183 rewind(fp.get()); |
| 184 char read_buf[kNumHandlesToSend]; | 184 char read_buf[kNumHandlesToSend]; |
| 185 size_t bytes_read = fread(read_buf, 1, sizeof(read_buf), fp.get()); | 185 size_t bytes_read = fread(read_buf, 1, sizeof(read_buf), fp.get()); |
| 186 EXPECT_EQ(j + 1, bytes_read); | 186 EXPECT_EQ(j + 1, bytes_read); |
| 187 EXPECT_EQ(std::string(j + 1, c), std::string(read_buf, bytes_read)); | 187 EXPECT_EQ(std::string(j + 1, c), std::string(read_buf, bytes_read)); |
| 188 } | 188 } |
| 189 } | 189 } |
| 190 } | 190 } |
| 191 | 191 |
| 192 TEST_F(PlatformChannelPairTest, AppendReceivedFDs) { | 192 TEST_F(PlatformChannelPairTest, AppendReceivedFDs) { |
| 193 mojo::test::ScopedTestDir test_dir; | 193 mojo::system::test::ScopedTestDir test_dir; |
| 194 | 194 |
| 195 static const char kHello[] = "hello"; | 195 static const char kHello[] = "hello"; |
| 196 | 196 |
| 197 PlatformChannelPair channel_pair; | 197 PlatformChannelPair channel_pair; |
| 198 ScopedPlatformHandle server_handle = channel_pair.PassServerHandle().Pass(); | 198 ScopedPlatformHandle server_handle = channel_pair.PassServerHandle().Pass(); |
| 199 ScopedPlatformHandle client_handle = channel_pair.PassClientHandle().Pass(); | 199 ScopedPlatformHandle client_handle = channel_pair.PassClientHandle().Pass(); |
| 200 | 200 |
| 201 const std::string file_contents("hello world"); | 201 const std::string file_contents("hello world"); |
| 202 | 202 |
| 203 { | 203 { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 char read_buf[100]; | 244 char read_buf[100]; |
| 245 size_t bytes_read = fread(read_buf, 1, sizeof(read_buf), fp.get()); | 245 size_t bytes_read = fread(read_buf, 1, sizeof(read_buf), fp.get()); |
| 246 EXPECT_EQ(file_contents.size(), bytes_read); | 246 EXPECT_EQ(file_contents.size(), bytes_read); |
| 247 EXPECT_EQ(file_contents, std::string(read_buf, bytes_read)); | 247 EXPECT_EQ(file_contents, std::string(read_buf, bytes_read)); |
| 248 } | 248 } |
| 249 } | 249 } |
| 250 | 250 |
| 251 } // namespace | 251 } // namespace |
| 252 } // namespace embedder | 252 } // namespace embedder |
| 253 } // namespace mojo | 253 } // namespace mojo |
| OLD | NEW |