diff options
author | Kevin Krakauer <krakauer@google.com> | 2019-09-26 15:07:59 -0700 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2019-09-26 15:09:20 -0700 |
commit | 543492650dd528c1d837d788dcd3b5138e8dc1c0 (patch) | |
tree | 16d362aea43c130ea59d802923752caedf8dbb8a /test/syscalls/linux/raw_socket_ipv4.cc | |
parent | 3221e8372cbd41bbe74d0bef82519de6e2852e13 (diff) |
Make raw socket tests pass in environments with or without CAP_NET_RAW.
PiperOrigin-RevId: 271442321
Diffstat (limited to 'test/syscalls/linux/raw_socket_ipv4.cc')
-rw-r--r-- | test/syscalls/linux/raw_socket_ipv4.cc | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/test/syscalls/linux/raw_socket_ipv4.cc b/test/syscalls/linux/raw_socket_ipv4.cc index 352037c88..cde2f07c9 100644 --- a/test/syscalls/linux/raw_socket_ipv4.cc +++ b/test/syscalls/linux/raw_socket_ipv4.cc @@ -67,7 +67,11 @@ class RawSocketTest : public ::testing::TestWithParam<int> { }; void RawSocketTest::SetUp() { - SKIP_IF(!ASSERT_NO_ERRNO_AND_VALUE(HaveCapability(CAP_NET_RAW))); + if (!ASSERT_NO_ERRNO_AND_VALUE(HaveCapability(CAP_NET_RAW))) { + ASSERT_THAT(socket(AF_INET, SOCK_RAW, Protocol()), + SyscallFailsWithErrno(EPERM)); + GTEST_SKIP(); + } ASSERT_THAT(s_ = socket(AF_INET, SOCK_RAW, Protocol()), SyscallSucceeds()); @@ -79,9 +83,10 @@ void RawSocketTest::SetUp() { } void RawSocketTest::TearDown() { - SKIP_IF(!ASSERT_NO_ERRNO_AND_VALUE(HaveCapability(CAP_NET_RAW))); - - EXPECT_THAT(close(s_), SyscallSucceeds()); + // TearDown will be run even if we skip the test. + if (ASSERT_NO_ERRNO_AND_VALUE(HaveCapability(CAP_NET_RAW))) { + EXPECT_THAT(close(s_), SyscallSucceeds()); + } } // We should be able to create multiple raw sockets for the same protocol. |