From 04b37c822022c27cb144e4af5ef21043a74127f3 Mon Sep 17 00:00:00 2001 From: Mithun Iyer Date: Thu, 7 Jan 2021 15:06:18 -0800 Subject: Fix tuntap_test to cleanup after CreateInterfaceNoCap PiperOrigin-RevId: 350646249 --- test/syscalls/linux/tuntap.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'test/syscalls') diff --git a/test/syscalls/linux/tuntap.cc b/test/syscalls/linux/tuntap.cc index 5ac337d1a..538652183 100644 --- a/test/syscalls/linux/tuntap.cc +++ b/test/syscalls/linux/tuntap.cc @@ -162,12 +162,19 @@ TEST(TuntapStaticTest, NetTunExists) { class TuntapTest : public ::testing::Test { protected: + void SetUp() override { + have_net_admin_cap_ = + ASSERT_NO_ERRNO_AND_VALUE(HaveCapability(CAP_NET_ADMIN)); + } + void TearDown() override { - if (ASSERT_NO_ERRNO_AND_VALUE(HaveCapability(CAP_NET_ADMIN))) { + if (have_net_admin_cap_) { // Bring back capability if we had dropped it in test case. ASSERT_NO_ERRNO(SetCapability(CAP_NET_ADMIN, true)); } } + + bool have_net_admin_cap_; }; TEST_F(TuntapTest, CreateInterfaceNoCap) { -- cgit v1.2.3