Port tests in udp_socket.cc to Fuchsia

Separate out a test in udp_socket.cc that depends on <linux/errqueue.h> so the
rest of the tests can run on Fuchsia.

PiperOrigin-RevId: 283322633
This commit is contained in:
Jay Zhuang 2019-12-02 05:37:09 -08:00 committed by gVisor bot
parent 10bbcf97d2
commit aa70523da2
5 changed files with 1427 additions and 1324 deletions

View File

@ -3351,11 +3351,15 @@ cc_binary(
],
)
cc_binary(
name = "udp_socket_test",
cc_library(
name = "udp_socket_test_cases",
testonly = 1,
srcs = ["udp_socket.cc"],
linkstatic = 1,
srcs = [
"udp_socket_test_cases.cc",
] + select_for_linux([
"udp_socket_errqueue_test_case.cc",
]),
hdrs = ["udp_socket_test_cases.h"],
deps = [
":socket_test_util",
":unix_domain_socket_test_util",
@ -3366,6 +3370,17 @@ cc_binary(
"@com_google_absl//absl/time",
"@com_google_googletest//:gtest",
],
alwayslink = 1,
)
cc_binary(
name = "udp_socket_test",
testonly = 1,
srcs = ["udp_socket.cc"],
linkstatic = 1,
deps = [
":udp_socket_test_cases",
],
)
cc_binary(

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,54 @@
// Copyright 2018 The gVisor Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "test/syscalls/linux/udp_socket_test_cases.h"
#include <arpa/inet.h>
#include <fcntl.h>
#include <linux/errqueue.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include "gtest/gtest.h"
#include "absl/base/macros.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "test/syscalls/linux/socket_test_util.h"
#include "test/syscalls/linux/unix_domain_socket_test_util.h"
#include "test/util/test_util.h"
#include "test/util/thread_util.h"
namespace gvisor {
namespace testing {
TEST_P(UdpSocketTest, ErrorQueue) {
char cmsgbuf[CMSG_SPACE(sizeof(sock_extended_err))];
msghdr msg;
memset(&msg, 0, sizeof(msg));
iovec iov;
memset(&iov, 0, sizeof(iov));
msg.msg_iov = &iov;
msg.msg_iovlen = 1;
msg.msg_control = cmsgbuf;
msg.msg_controllen = sizeof(cmsgbuf);
// recv*(MSG_ERRQUEUE) never blocks, even without MSG_DONTWAIT.
EXPECT_THAT(RetryEINTR(recvmsg)(s_, &msg, MSG_ERRQUEUE),
SyscallFailsWithErrno(EAGAIN));
}
} // namespace testing
} // namespace gvisor

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,74 @@
// Copyright 2019 The gVisor Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef THIRD_PARTY_GOLANG_GVISOR_TEST_SYSCALLS_LINUX_SOCKET_IPV4_UDP_UNBOUND_H_
#define THIRD_PARTY_GOLANG_GVISOR_TEST_SYSCALLS_LINUX_SOCKET_IPV4_UDP_UNBOUND_H_
#include "gtest/gtest.h"
#include "test/syscalls/linux/socket_test_util.h"
namespace gvisor {
namespace testing {
// The initial port to be be used on gvisor.
constexpr int TestPort = 40000;
// Fixture for tests parameterized by the address family to use (AF_INET and
// AF_INET6) when creating sockets.
class UdpSocketTest
: public ::testing::TestWithParam<gvisor::testing::AddressFamily> {
protected:
// Creates two sockets that will be used by test cases.
void SetUp() override;
// Closes the sockets created by SetUp().
void TearDown() override {
EXPECT_THAT(close(s_), SyscallSucceeds());
EXPECT_THAT(close(t_), SyscallSucceeds());
for (size_t i = 0; i < ABSL_ARRAYSIZE(ports_); ++i) {
ASSERT_NO_ERRNO(FreeAvailablePort(ports_[i]));
}
}
// First UDP socket.
int s_;
// Second UDP socket.
int t_;
// The length of the socket address.
socklen_t addrlen_;
// Initialized address pointing to loopback and port TestPort+i.
struct sockaddr* addr_[3];
// Initialize "any" address.
struct sockaddr* anyaddr_;
// Used ports.
int ports_[3];
private:
// Storage for the loopback addresses.
struct sockaddr_storage addr_storage_[3];
// Storage for the "any" address.
struct sockaddr_storage anyaddr_storage_;
};
} // namespace testing
} // namespace gvisor
#endif // THIRD_PARTY_GOLANG_GVISOR_TEST_SYSCALLS_LINUX_SOCKET_IPV4_UDP_UNBOUND_H_