git: e9b411d27333 - main - tests/fusefs: fix all tests that depend on kern.maxphys

From: Gleb Smirnoff <glebius_at_FreeBSD.org>
Date: Mon, 06 May 2024 19:03:54 UTC
The branch main has been updated by glebius:

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

commit e9b411d273336647e61704213964b995952a44fd
Author:     Gleb Smirnoff <glebius@FreeBSD.org>
AuthorDate: 2024-05-06 19:03:20 +0000
Commit:     Gleb Smirnoff <glebius@FreeBSD.org>
CommitDate: 2024-05-06 19:03:20 +0000

    tests/fusefs: fix all tests that depend on kern.maxphys
    
    The tests try to read kern.maxphys sysctl into int value, while
    unsigned long is required.  Not sure when this was broken, seems like
    since cd8537910406e.
    
    Reviewed by:            asomers
    Differential Revision:  https://reviews.freebsd.org/D45053
---
 tests/sys/fs/fusefs/bmap.cc  | 12 ++++++------
 tests/sys/fs/fusefs/read.cc  |  2 +-
 tests/sys/fs/fusefs/utils.cc | 13 ++++++-------
 tests/sys/fs/fusefs/utils.hh |  2 +-
 tests/sys/fs/fusefs/write.cc |  5 +++--
 5 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/tests/sys/fs/fusefs/bmap.cc b/tests/sys/fs/fusefs/bmap.cc
index 4c9edac9360a..48c9c7d038ed 100644
--- a/tests/sys/fs/fusefs/bmap.cc
+++ b/tests/sys/fs/fusefs/bmap.cc
@@ -105,8 +105,8 @@ TEST_F(Bmap, bmap)
 	arg.runb = -1;
 	ASSERT_EQ(0, ioctl(fd, FIOBMAP2, &arg)) << strerror(errno);
 	EXPECT_EQ(arg.bn, pbn);
-	EXPECT_EQ(arg.runp, m_maxphys / m_maxbcachebuf - 1);
-	EXPECT_EQ(arg.runb, m_maxphys / m_maxbcachebuf - 1);
+	EXPECT_EQ((unsigned long)arg.runp, m_maxphys / m_maxbcachebuf - 1);
+	EXPECT_EQ((unsigned long)arg.runb, m_maxphys / m_maxbcachebuf - 1);
 
 	leak(fd);
 }
@@ -142,7 +142,7 @@ TEST_F(Bmap, default_)
 	arg.runb = -1;
 	ASSERT_EQ(0, ioctl(fd, FIOBMAP2, &arg)) << strerror(errno);
 	EXPECT_EQ(arg.bn, 0);
-	EXPECT_EQ(arg.runp, m_maxphys / m_maxbcachebuf - 1);
+	EXPECT_EQ((unsigned long )arg.runp, m_maxphys / m_maxbcachebuf - 1);
 	EXPECT_EQ(arg.runb, 0);
 
 	/* In the middle */
@@ -152,8 +152,8 @@ TEST_F(Bmap, default_)
 	arg.runb = -1;
 	ASSERT_EQ(0, ioctl(fd, FIOBMAP2, &arg)) << strerror(errno);
 	EXPECT_EQ(arg.bn, lbn * m_maxbcachebuf / DEV_BSIZE);
-	EXPECT_EQ(arg.runp, m_maxphys / m_maxbcachebuf - 1);
-	EXPECT_EQ(arg.runb, m_maxphys / m_maxbcachebuf - 1);
+	EXPECT_EQ((unsigned long )arg.runp, m_maxphys / m_maxbcachebuf - 1);
+	EXPECT_EQ((unsigned long )arg.runb, m_maxphys / m_maxbcachebuf - 1);
 
 	/* Last block */
 	lbn = filesize / m_maxbcachebuf - 1;
@@ -163,7 +163,7 @@ TEST_F(Bmap, default_)
 	ASSERT_EQ(0, ioctl(fd, FIOBMAP2, &arg)) << strerror(errno);
 	EXPECT_EQ(arg.bn, lbn * m_maxbcachebuf / DEV_BSIZE);
 	EXPECT_EQ(arg.runp, 0);
-	EXPECT_EQ(arg.runb, m_maxphys / m_maxbcachebuf - 1);
+	EXPECT_EQ((unsigned long )arg.runb, m_maxphys / m_maxbcachebuf - 1);
 
 	leak(fd);
 }
diff --git a/tests/sys/fs/fusefs/read.cc b/tests/sys/fs/fusefs/read.cc
index 373f742d4fd3..9693428914e6 100644
--- a/tests/sys/fs/fusefs/read.cc
+++ b/tests/sys/fs/fusefs/read.cc
@@ -1339,7 +1339,7 @@ TEST_P(ReadAhead, readahead) {
 	expect_open(ino, 0, 1);
 	maxcontig = m_noclusterr ? m_maxbcachebuf :
 		m_maxbcachebuf + m_maxreadahead;
-	clustersize = MIN(maxcontig, m_maxphys);
+	clustersize = MIN((unsigned long )maxcontig, m_maxphys);
 	for (offs = 0; offs < bufsize; offs += clustersize) {
 		len = std::min((size_t)clustersize, (size_t)(filesize - offs));
 		expect_read(ino, offs, len, len, contents + offs);
diff --git a/tests/sys/fs/fusefs/utils.cc b/tests/sys/fs/fusefs/utils.cc
index 55a552e28eeb..831ded0c0815 100644
--- a/tests/sys/fs/fusefs/utils.cc
+++ b/tests/sys/fs/fusefs/utils.cc
@@ -130,8 +130,7 @@ class FuseEnv: public Environment {
 void FuseTest::SetUp() {
 	const char *maxbcachebuf_node = "vfs.maxbcachebuf";
 	const char *maxphys_node = "kern.maxphys";
-	int val = 0;
-	size_t size = sizeof(val);
+	size_t size;
 
 	/*
 	 * XXX check_environment should be called from FuseEnv::SetUp, but
@@ -141,12 +140,12 @@ void FuseTest::SetUp() {
 	if (IsSkipped())
 		return;
 
-	ASSERT_EQ(0, sysctlbyname(maxbcachebuf_node, &val, &size, NULL, 0))
-		<< strerror(errno);
-	m_maxbcachebuf = val;
-	ASSERT_EQ(0, sysctlbyname(maxphys_node, &val, &size, NULL, 0))
+	size = sizeof(m_maxbcachebuf);
+	ASSERT_EQ(0, sysctlbyname(maxbcachebuf_node, &m_maxbcachebuf, &size,
+		NULL, 0)) << strerror(errno);
+	size = sizeof(m_maxphys);
+	ASSERT_EQ(0, sysctlbyname(maxphys_node, &m_maxphys, &size, NULL, 0))
 		<< strerror(errno);
-	m_maxphys = val;
 	/*
 	 * Set the default max_write to a distinct value from MAXPHYS to catch
 	 * bugs that confuse the two.
diff --git a/tests/sys/fs/fusefs/utils.hh b/tests/sys/fs/fusefs/utils.hh
index 383f01ea4bfe..506e8a985212 100644
--- a/tests/sys/fs/fusefs/utils.hh
+++ b/tests/sys/fs/fusefs/utils.hh
@@ -77,7 +77,7 @@ class FuseTest : public ::testing::Test {
 
 	public:
 	int m_maxbcachebuf;
-	int m_maxphys;
+	unsigned long m_maxphys;
 
 	FuseTest():
 		m_maxreadahead(0),
diff --git a/tests/sys/fs/fusefs/write.cc b/tests/sys/fs/fusefs/write.cc
index f931f350a7c3..336ec79c8fec 100644
--- a/tests/sys/fs/fusefs/write.cc
+++ b/tests/sys/fs/fusefs/write.cc
@@ -184,7 +184,7 @@ virtual void SetUp() {
 	if (m_maxphys < 2 * DFLTPHYS)
 		GTEST_SKIP() << "MAXPHYS must be at least twice DFLTPHYS"
 			<< " for this test";
-	if (m_maxphys < 2 * m_maxbcachebuf)
+	if (m_maxphys < 2 * (unsigned long )m_maxbcachebuf)
 		GTEST_SKIP() << "MAXPHYS must be at least twice maxbcachebuf"
 			<< " for this test";
 }
@@ -860,7 +860,8 @@ TEST_F(WriteMaxWrite, write)
 	ssize_t halfbufsize, bufsize;
 
 	halfbufsize = m_mock->m_maxwrite;
-	if (halfbufsize >= m_maxbcachebuf || halfbufsize >= m_maxphys)
+	if (halfbufsize >= m_maxbcachebuf ||
+	    (unsigned long )halfbufsize >= m_maxphys)
 		GTEST_SKIP() << "Must lower m_maxwrite for this test";
 	bufsize = halfbufsize * 2;
 	contents = new int[bufsize / sizeof(int)];