git: b18799757947 - main - fusefs: More accurately test the unique tokens in the test suite

From: Alan Somers <asomers_at_FreeBSD.org>
Date: Wed, 18 Dec 2024 16:21:46 UTC
The branch main has been updated by asomers:

URL: https://cgit.FreeBSD.org/src/commit/?id=b1879975794772ee51f0b4865753364c7d7626c3

commit b1879975794772ee51f0b4865753364c7d7626c3
Author:     Alan Somers <asomers@FreeBSD.org>
AuthorDate: 2024-12-18 01:38:05 +0000
Commit:     Alan Somers <asomers@FreeBSD.org>
CommitDate: 2024-12-18 16:21:35 +0000

    fusefs: More accurately test the unique tokens in the test suite
    
    Every fuse ticket has a "unique" token.  As the name implies, they're
    supposed to be unique.  Previously the fusefs test suite verified their
    uniqueness by relying on the fact that they are also sequential.  But
    they aren't guaranteed to be sequential.  Enhance the tests by removing
    that convenient assumption.
    
    MFC after:      2 weeks
    Sponsored by:   Axcient
---
 tests/sys/fs/fusefs/mockfs.cc | 15 ++++++---------
 tests/sys/fs/fusefs/mockfs.hh |  6 ++++--
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/tests/sys/fs/fusefs/mockfs.cc b/tests/sys/fs/fusefs/mockfs.cc
index bd7bd1b663f9..023cecd0276f 100644
--- a/tests/sys/fs/fusefs/mockfs.cc
+++ b/tests/sys/fs/fusefs/mockfs.cc
@@ -421,6 +421,7 @@ MockFS::MockFS(int max_readahead, bool allow_other, bool default_permissions,
 	uint32_t kernel_minor_version, uint32_t max_write, bool async,
 	bool noclusterr, unsigned time_gran, bool nointr, bool noatime,
 	const char *fsname, const char *subtype)
+	: m_uniques(new std::unordered_set<uint64_t>)
 {
 	struct sigaction sa;
 	struct iovec *iov = NULL;
@@ -436,7 +437,7 @@ MockFS::MockFS(int max_readahead, bool allow_other, bool default_permissions,
 	m_pm = pm;
 	m_time_gran = time_gran;
 	m_quit = false;
-	m_last_unique = 0;
+
 	if (m_pm == KQ)
 		m_kq = kqueue();
 	else
@@ -738,14 +739,10 @@ void MockFS::audit_request(const mockfs_buf_in &in, ssize_t buflen) {
 	default:
 		FAIL() << "Unknown opcode " << in.header.opcode;
 	}
-	/*
-	 * Check that the ticket's unique value is sequential.  Technically it
-	 * doesn't need to be sequential, merely unique.  But the current
-	 * fusefs driver _does_ make it sequential, and that's easy to check
-	 * for.
-	 */
-	if (in.header.unique != ++m_last_unique)
-		FAIL() << "Non-sequential unique value";
+	/* Verify that the ticket's unique value is actually unique. */
+	if (m_uniques->find(in.header.unique) != m_uniques->end())
+		FAIL() << "Non-unique \"unique\" value";
+	m_uniques->insert(in.header.unique);
 }
 
 void MockFS::init(uint32_t flags) {
diff --git a/tests/sys/fs/fusefs/mockfs.hh b/tests/sys/fs/fusefs/mockfs.hh
index 958964f769d4..38efcd049a61 100644
--- a/tests/sys/fs/fusefs/mockfs.hh
+++ b/tests/sys/fs/fusefs/mockfs.hh
@@ -36,6 +36,8 @@ extern "C" {
 #include "fuse_kernel.h"
 }
 
+#include <unordered_set>
+
 #include <gmock/gmock.h>
 
 #define TIME_T_MAX (std::numeric_limits<time_t>::max())
@@ -298,8 +300,8 @@ class MockFS {
 	/* pid of the test process */
 	pid_t m_pid;
 
-	/* The unique value of the header of the last received operation */
-	uint64_t m_last_unique;
+	/* Every "unique" value of a fuse ticket seen so far */
+	std::unique_ptr<std::unordered_set<uint64_t>> m_uniques;
 
 	/* Method the daemon should use for I/O to and from /dev/fuse */
 	enum poll_method m_pm;