From 5bb64ce1b8c42fcd96e44a5be05e17f34a83f840 Mon Sep 17 00:00:00 2001 From: Nayana Bidari Date: Thu, 12 Nov 2020 22:55:09 -0800 Subject: Refactor SOL_SOCKET options Store all the socket level options in a struct and call {Get/Set}SockOpt on this struct. This will avoid implementing socket level options on all endpoints. This CL contains implementing one socket level option for tcp and udp endpoints. PiperOrigin-RevId: 342203981 --- test/syscalls/linux/socket_generic.cc | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test/syscalls/linux/socket_generic.cc') diff --git a/test/syscalls/linux/socket_generic.cc b/test/syscalls/linux/socket_generic.cc index 5d39e6fbd..796546224 100644 --- a/test/syscalls/linux/socket_generic.cc +++ b/test/syscalls/linux/socket_generic.cc @@ -818,5 +818,33 @@ TEST_P(AllSocketPairTest, GetSockoptProtocol) { } } +TEST_P(AllSocketPairTest, GetSockoptBroadcast) { + auto sockets = ASSERT_NO_ERRNO_AND_VALUE(NewSocketPair()); + int opt = -1; + socklen_t optlen = sizeof(opt); + EXPECT_THAT( + getsockopt(sockets->first_fd(), SOL_SOCKET, SO_BROADCAST, &opt, &optlen), + SyscallSucceeds()); + ASSERT_EQ(optlen, sizeof(opt)); + EXPECT_EQ(opt, 0); +} + +TEST_P(AllSocketPairTest, SetAndGetSocketBroadcastOption) { + auto sockets = ASSERT_NO_ERRNO_AND_VALUE(NewSocketPair()); + int kSockOptOn = 1; + ASSERT_THAT(setsockopt(sockets->first_fd(), SOL_SOCKET, SO_BROADCAST, + &kSockOptOn, sizeof(kSockOptOn)), + SyscallSucceedsWithValue(0)); + + int got = -1; + socklen_t length = sizeof(got); + ASSERT_THAT( + getsockopt(sockets->first_fd(), SOL_SOCKET, SO_BROADCAST, &got, &length), + SyscallSucceedsWithValue(0)); + + ASSERT_EQ(length, sizeof(got)); + EXPECT_EQ(got, kSockOptOn); +} + } // namespace testing } // namespace gvisor -- cgit v1.2.3