All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wake Liu <wakel@google.com>
To: Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Shuah Khan <shuah@kernel.org>,
	 linux-kselftest@vger.kernel.org
Cc: "Peter Zijlstra" <peterz@infradead.org>,
	"Darren Hart" <dvhart@infradead.org>,
	"Davidlohr Bueso" <dave@stgolabs.net>,
	"André Almeida" <andrealmeid@igalia.com>,
	"Carlos Llamas" <cmllamas@google.com>,
	"Edward Liaw" <edliaw@google.com>,
	linux-kernel@vger.kernel.org, wakel@google.com
Subject: [PATCH 2/2] selftests/futex: Correct validation logic in waitv
Date: Mon, 25 May 2026 07:57:48 +0000	[thread overview]
Message-ID: <20260525075748.3720995-3-wakel@google.com> (raw)
In-Reply-To: <20260525075748.3720995-1-wakel@google.com>

In futex_waitv negative tests (invalid_flag, unaligned_address, etc.),
test results were previously evaluated as:
    if (res == EINVAL)

Since sys_futex_waitv returns -1 on error and sets errno, direct positive
comparisons against res are always false, causing tests to silently pass
regardless of real errors.

Correct these validations to assert EXPECT_EQ(res, -1) and compare errno
directly against expected constants.

Signed-off-by: Wake Liu <wakel@google.com>
---
 .../selftests/futex/functional/futex_waitv.c  | 45 +++++++++----------
 1 file changed, 20 insertions(+), 25 deletions(-)

diff --git a/tools/testing/selftests/futex/functional/futex_waitv.c b/tools/testing/selftests/futex/functional/futex_waitv.c
index 7bed76a1caed..9dc0f9c1f22a 100644
--- a/tools/testing/selftests/futex/functional/futex_waitv.c
+++ b/tools/testing/selftests/futex/functional/futex_waitv.c
@@ -139,11 +139,10 @@ TEST(invalid_flag)
 	to.tv_sec++;
 
 	res = futex_waitv(waitv, NR_FUTEXES, 0, &to, CLOCK_MONOTONIC);
-	if (res == EINVAL) {
-		EXPECT_TRUE(0) TH_LOG("futex_waitv private returned: %d %s",
-				      res ? errno : res,
-				      res ? strerror(errno) : "");
-	}
+	EXPECT_EQ(res, -1) TH_LOG("futex_waitv returned unexpected result: %d", res);
+	if (res == -1)
+		EXPECT_EQ(errno, EINVAL)
+			TH_LOG("futex_waitv returned unexpected errno: %d", errno);
 }
 
 TEST(unaligned_address)
@@ -163,11 +162,10 @@ TEST(unaligned_address)
 	to.tv_sec++;
 
 	res = futex_waitv(waitv, NR_FUTEXES, 0, &to, CLOCK_MONOTONIC);
-	if (res == EINVAL) {
-		EXPECT_TRUE(0) TH_LOG("futex_wake private returned: %d %s",
-				      res ? errno : res,
-				      res ? strerror(errno) : "");
-	}
+	EXPECT_EQ(res, -1) TH_LOG("futex_waitv returned unexpected result: %d", res);
+	if (res == -1)
+		EXPECT_EQ(errno, EINVAL)
+			TH_LOG("futex_waitv returned unexpected errno: %d", errno);
 }
 
 TEST(null_address)
@@ -186,11 +184,10 @@ TEST(null_address)
 	to.tv_sec++;
 
 	res = futex_waitv(waitv, NR_FUTEXES, 0, &to, CLOCK_MONOTONIC);
-	if (res == EINVAL) {
-		EXPECT_TRUE(0) TH_LOG("futex_waitv private returned: %d %s",
-				      res ? errno : res,
-				      res ? strerror(errno) : "");
-	}
+	EXPECT_EQ(res, -1) TH_LOG("futex_waitv returned unexpected result: %d", res);
+	if (res == -1)
+		EXPECT_EQ(errno, EINVAL)
+			TH_LOG("futex_waitv returned unexpected errno: %d", errno);
 
 	/* Testing a NULL address for *waiters */
 	ASSERT_EQ(clock_gettime(CLOCK_MONOTONIC, &to), 0) TH_LOG("gettime64 failed");
@@ -198,11 +195,10 @@ TEST(null_address)
 	to.tv_sec++;
 
 	res = futex_waitv(NULL, NR_FUTEXES, 0, &to, CLOCK_MONOTONIC);
-	if (res == EINVAL) {
-		EXPECT_TRUE(0) TH_LOG("futex_waitv private returned: %d %s",
-				      res ? errno : res,
-				      res ? strerror(errno) : "");
-	}
+	EXPECT_EQ(res, -1) TH_LOG("futex_waitv returned unexpected result: %d", res);
+	if (res == -1)
+		EXPECT_EQ(errno, EINVAL)
+			TH_LOG("futex_waitv returned unexpected errno: %d", errno);
 }
 
 TEST(invalid_clockid)
@@ -219,11 +215,10 @@ TEST(invalid_clockid)
 	to.tv_sec++;
 
 	res = futex_waitv(NULL, NR_FUTEXES, 0, &to, CLOCK_TAI);
-	if (res == EINVAL) {
-		EXPECT_TRUE(0) TH_LOG("futex_waitv private returned: %d %s",
-				      res ? errno : res,
-				      res ? strerror(errno) : "");
-	}
+	EXPECT_EQ(res, -1) TH_LOG("futex_waitv returned unexpected result: %d", res);
+	if (res == -1)
+		EXPECT_EQ(errno, EINVAL)
+			TH_LOG("futex_waitv returned unexpected errno: %d", errno);
 }
 
 TEST_HARNESS_MAIN
-- 
2.54.0.746.g67dd491aae-goog


  parent reply	other threads:[~2026-05-25  7:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-25  7:57 [PATCH 0/2] selftests/futex: Migrate functional tests to harness and fix validations Wake Liu
2026-05-25  7:57 ` [PATCH 1/2] selftests/futex: Migrate functional tests to harness Wake Liu
2026-05-25 18:37   ` André Almeida
2026-05-25  7:57 ` Wake Liu [this message]
2026-05-26  1:06 ` [PATCH v2 0/2] selftests/futex: Migrate functional tests to harness and fix validations Wake Liu
2026-05-26  1:06   ` [PATCH v2 1/2] selftests/futex: Migrate functional tests to harness Wake Liu
2026-05-26  1:06   ` [PATCH v2 2/2] selftests/futex: Correct validation logic in waitv Wake Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260525075748.3720995-3-wakel@google.com \
    --to=wakel@google.com \
    --cc=andrealmeid@igalia.com \
    --cc=cmllamas@google.com \
    --cc=dave@stgolabs.net \
    --cc=dvhart@infradead.org \
    --cc=edliaw@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=shuah@kernel.org \
    --cc=tglx@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.