[PATCH RFC v5 08/10] selftest: tun: Test vnet ioctls without device
From: Akihiko Odaki
Date: Tue Oct 08 2024 - 03:58:46 EST
Ensure that vnet ioctls result in EBADFD when the underlying device is
deleted.
Signed-off-by: Akihiko Odaki <akihiko.odaki@xxxxxxxxxx>
---
tools/testing/selftests/net/tun.c | 74 +++++++++++++++++++++++++++++++++++++++
1 file changed, 74 insertions(+)
diff --git a/tools/testing/selftests/net/tun.c b/tools/testing/selftests/net/tun.c
index fa83918b62d1..463dd98f2b80 100644
--- a/tools/testing/selftests/net/tun.c
+++ b/tools/testing/selftests/net/tun.c
@@ -159,4 +159,78 @@ TEST_F(tun, reattach_close_delete) {
EXPECT_EQ(tun_delete(self->ifname), 0);
}
+FIXTURE(tun_deleted)
+{
+ char ifname[IFNAMSIZ];
+ int fd;
+};
+
+FIXTURE_SETUP(tun_deleted)
+{
+ self->ifname[0] = 0;
+ self->fd = tun_alloc(self->ifname);
+ ASSERT_LE(0, self->fd);
+
+ ASSERT_EQ(0, tun_delete(self->ifname))
+ EXPECT_EQ(0, close(self->fd));
+}
+
+FIXTURE_TEARDOWN(tun_deleted)
+{
+ EXPECT_EQ(0, close(self->fd));
+}
+
+TEST_F(tun_deleted, getvnethdrsz)
+{
+ ASSERT_EQ(-1, ioctl(self->fd, TUNGETVNETHDRSZ));
+ EXPECT_EQ(EBADFD, errno);
+}
+
+TEST_F(tun_deleted, setvnethdrsz)
+{
+ ASSERT_EQ(-1, ioctl(self->fd, TUNSETVNETHDRSZ));
+ EXPECT_EQ(EBADFD, errno);
+}
+
+TEST_F(tun_deleted, getvnetle)
+{
+ ASSERT_EQ(-1, ioctl(self->fd, TUNGETVNETLE));
+ EXPECT_EQ(EBADFD, errno);
+}
+
+TEST_F(tun_deleted, setvnetle)
+{
+ ASSERT_EQ(-1, ioctl(self->fd, TUNSETVNETLE));
+ EXPECT_EQ(EBADFD, errno);
+}
+
+TEST_F(tun_deleted, getvnetbe)
+{
+ ASSERT_EQ(-1, ioctl(self->fd, TUNGETVNETBE));
+ EXPECT_EQ(EBADFD, errno);
+}
+
+TEST_F(tun_deleted, setvnetbe)
+{
+ ASSERT_EQ(-1, ioctl(self->fd, TUNSETVNETBE));
+ EXPECT_EQ(EBADFD, errno);
+}
+
+TEST_F(tun_deleted, getvnethashcap)
+{
+ struct tun_vnet_hash cap;
+ int i = ioctl(self->fd, TUNGETVNETHASHCAP, &cap);
+
+ if (i == -1 && errno == EBADFD)
+ SKIP(return, "TUNGETVNETHASHCAP not supported");
+
+ EXPECT_EQ(0, i);
+}
+
+TEST_F(tun_deleted, setvnethash)
+{
+ ASSERT_EQ(-1, ioctl(self->fd, TUNSETVNETHASH));
+ EXPECT_EQ(EBADFD, errno);
+}
+
TEST_HARNESS_MAIN
--
2.46.2