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_icmp.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_icmp.cc')
-rw-r--r-- | test/syscalls/linux/raw_socket_icmp.cc | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/test/syscalls/linux/raw_socket_icmp.cc b/test/syscalls/linux/raw_socket_icmp.cc index 971592d7d..8bcaba6f1 100644 --- a/test/syscalls/linux/raw_socket_icmp.cc +++ b/test/syscalls/linux/raw_socket_icmp.cc @@ -77,7 +77,11 @@ class RawSocketICMPTest : public ::testing::Test { }; void RawSocketICMPTest::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, IPPROTO_ICMP), + SyscallFailsWithErrno(EPERM)); + GTEST_SKIP(); + } ASSERT_THAT(s_ = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP), SyscallSucceeds()); @@ -90,9 +94,10 @@ void RawSocketICMPTest::SetUp() { } void RawSocketICMPTest::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'll only read an echo in this case, as the kernel won't respond to the |