Chromium Code Reviews| Index: base/posix/unix_domain_socket_linux_unittest.cc |
| diff --git a/base/posix/unix_domain_socket_linux_unittest.cc b/base/posix/unix_domain_socket_linux_unittest.cc |
| index bb7154fe5e971d568fbaacaf86a2bbee1bd0921a..4996e20913379056d66698467e600ed097028727 100644 |
| --- a/base/posix/unix_domain_socket_linux_unittest.cc |
| +++ b/base/posix/unix_domain_socket_linux_unittest.cc |
| @@ -77,6 +77,61 @@ TEST(UnixDomainSocketTest, SendRecvMsgAvoidsSIGPIPE) { |
| ASSERT_EQ(0, sigaction(SIGPIPE, &oldact, NULL)); |
| } |
| +// Simple sanity check within a single process that receiving PIDs works. |
| +// Additional tests are in sandbox/linux/tests/unix_domain_socket_unittest.cc. |
|
jln (very slow on Chromium)
2014/04/24 18:32:58
Remove this line, as base/ should not be tested by
mdempsky
2014/04/24 19:00:34
Done.
|
| +TEST(UnixDomainSocketTest, RecvPid) { |
| + int fds[2]; |
| + ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_SEQPACKET, 0, fds)); |
| + base::ScopedFD recv_sock(fds[0]); |
| + base::ScopedFD send_sock(fds[1]); |
| + |
| + ASSERT_TRUE(UnixDomainSocket::EnableReceiveProcessId(recv_sock.get())); |
| + |
| + static const char kHello[] = "hello"; |
| + ASSERT_TRUE(UnixDomainSocket::SendMsg( |
| + send_sock.get(), kHello, sizeof(kHello), std::vector<int>())); |
| + |
| + char buf[sizeof(kHello) + 1]; |
|
jln (very slow on Chromium)
2014/04/24 18:32:58
Did you add the + 1 to be able to test that you on
mdempsky
2014/04/24 19:00:34
Correct.
|
| + base::ProcessId sender_pid; |
| + std::vector<int> fd_vec; |
| + const ssize_t nread = UnixDomainSocket::RecvMsgWithPid( |
| + recv_sock.get(), buf, sizeof(buf), &fd_vec, &sender_pid); |
| + ASSERT_EQ(sizeof(kHello), static_cast<size_t>(nread)); |
| + ASSERT_EQ(0, memcmp(buf, kHello, sizeof(kHello))); |
| + ASSERT_EQ(0U, fd_vec.size()); |
| + |
| + ASSERT_EQ(getpid(), sender_pid); |
| +} |
| + |
| +// Same as above, but send the max number of file descriptors too. |
| +TEST(UnixDomainSocketTest, RecvPidWithMaxDescriptors) { |
| + int fds[2]; |
| + ASSERT_EQ(0, socketpair(AF_UNIX, SOCK_SEQPACKET, 0, fds)); |
| + base::ScopedFD recv_sock(fds[0]); |
| + base::ScopedFD send_sock(fds[1]); |
| + |
| + ASSERT_TRUE(UnixDomainSocket::EnableReceiveProcessId(recv_sock.get())); |
| + |
| + static const char kHello[] = "hello"; |
| + std::vector<int> fd_vec(UnixDomainSocket::kMaxFileDescriptors, |
| + send_sock.get()); |
| + ASSERT_TRUE(UnixDomainSocket::SendMsg( |
| + send_sock.get(), kHello, sizeof(kHello), fd_vec)); |
| + |
| + char buf[sizeof(kHello) + 1]; |
| + base::ProcessId sender_pid; |
| + const ssize_t nread = UnixDomainSocket::RecvMsgWithPid( |
| + recv_sock.get(), buf, sizeof(buf), &fd_vec, &sender_pid); |
| + ASSERT_EQ(sizeof(kHello), static_cast<size_t>(nread)); |
| + ASSERT_EQ(0, memcmp(buf, kHello, sizeof(kHello))); |
| + ASSERT_EQ(UnixDomainSocket::kMaxFileDescriptors, fd_vec.size()); |
| + for (size_t i = 0; i < UnixDomainSocket::kMaxFileDescriptors; i++) { |
| + ASSERT_EQ(0, IGNORE_EINTR(close(fd_vec[i]))); |
| + } |
| + |
| + ASSERT_EQ(getpid(), sender_pid); |
| +} |
| + |
| } // namespace |
| } // namespace base |