From: Wake Liu <[email protected]>

In futex_waitv negative tests (invalid_flag, unaligned_address, etc.), test
results are 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.

[ tglx: Fixup coding style ]

Signed-off-by: Wake Liu <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Link: https://patch.msgid.link/[email protected]
(cherry picked from commit a894f6f403320c65b26816be00d9b694e606cae1)

Rebase note: mainline moved futex_waitv.c to kselftest_harness in
commit a91e8e372e4f ("selftests/futex: Refactor futex_waitv with
kselftest_harness.h"), which this tree lacks, so the checks keep the
ksft_test_result_*() form: a result other than -1 or an errno other
than the expected one fails the subtest. The NULL waitv.uaddr check
expects EFAULT: here it runs on an otherwise valid waitv[], and a NULL
futex address is answered with EFAULT; in mainline it gets EINVAL
only from the zeroed flags of the other entries.

https://virtuozzo.atlassian.net/browse/VSTOR-152660
Feature: fix selftests

Signed-off-by: Eva Kurchatova <[email protected]>
---
 .../selftests/futex/functional/futex_waitv.c  | 55 ++++++++++++-------
 1 file changed, 35 insertions(+), 20 deletions(-)

diff --git a/tools/testing/selftests/futex/functional/futex_waitv.c 
b/tools/testing/selftests/futex/functional/futex_waitv.c
index 98edb25690d9..f58f3fa8f0e0 100644
--- a/tools/testing/selftests/futex/functional/futex_waitv.c
+++ b/tools/testing/selftests/futex/functional/futex_waitv.c
@@ -184,10 +184,13 @@ int main(int argc, char *argv[])
        to.tv_sec++;
 
        res = futex_waitv(waitv, NR_FUTEXES, 0, &to, CLOCK_MONOTONIC);
-       if (res == EINVAL) {
-               ksft_test_result_fail("futex_waitv private returned: %d %s\n",
-                                     res ? errno : res,
-                                     res ? strerror(errno) : "");
+       if (res != -1) {
+               ksft_test_result_fail("futex_waitv without FUTEX_32: unexpected 
result: %d\n",
+                                     res);
+               ret = RET_FAIL;
+       } else if (errno != EINVAL) {
+               ksft_test_result_fail("futex_waitv without FUTEX_32: unexpected 
errno: %d\n",
+                                     errno);
                ret = RET_FAIL;
        } else {
                ksft_test_result_pass("futex_waitv without FUTEX_32\n");
@@ -203,10 +206,13 @@ int main(int argc, char *argv[])
        to.tv_sec++;
 
        res = futex_waitv(waitv, NR_FUTEXES, 0, &to, CLOCK_MONOTONIC);
-       if (res == EINVAL) {
-               ksft_test_result_fail("futex_wake private returned: %d %s\n",
-                                     res ? errno : res,
-                                     res ? strerror(errno) : "");
+       if (res != -1) {
+               ksft_test_result_fail("futex_waitv with an unaligned address: 
unexpected result: %d\n",
+                                     res);
+               ret = RET_FAIL;
+       } else if (errno != EINVAL) {
+               ksft_test_result_fail("futex_waitv with an unaligned address: 
unexpected errno: %d\n",
+                                     errno);
                ret = RET_FAIL;
        } else {
                ksft_test_result_pass("futex_waitv with an unaligned 
address\n");
@@ -221,10 +227,13 @@ int main(int argc, char *argv[])
        to.tv_sec++;
 
        res = futex_waitv(waitv, NR_FUTEXES, 0, &to, CLOCK_MONOTONIC);
-       if (res == EINVAL) {
-               ksft_test_result_fail("futex_waitv private returned: %d %s\n",
-                                     res ? errno : res,
-                                     res ? strerror(errno) : "");
+       if (res != -1) {
+               ksft_test_result_fail("futex_waitv NULL address in waitv.uaddr: 
unexpected result: %d\n",
+                                     res);
+               ret = RET_FAIL;
+       } else if (errno != EFAULT) {
+               ksft_test_result_fail("futex_waitv NULL address in waitv.uaddr: 
unexpected errno: %d\n",
+                                     errno);
                ret = RET_FAIL;
        } else {
                ksft_test_result_pass("futex_waitv NULL address in 
waitv.uaddr\n");
@@ -237,10 +246,13 @@ int main(int argc, char *argv[])
        to.tv_sec++;
 
        res = futex_waitv(NULL, NR_FUTEXES, 0, &to, CLOCK_MONOTONIC);
-       if (res == EINVAL) {
-               ksft_test_result_fail("futex_waitv private returned: %d %s\n",
-                                     res ? errno : res,
-                                     res ? strerror(errno) : "");
+       if (res != -1) {
+               ksft_test_result_fail("futex_waitv NULL address in *waiters: 
unexpected result: %d\n",
+                                     res);
+               ret = RET_FAIL;
+       } else if (errno != EINVAL) {
+               ksft_test_result_fail("futex_waitv NULL address in *waiters: 
unexpected errno: %d\n",
+                                     errno);
                ret = RET_FAIL;
        } else {
                ksft_test_result_pass("futex_waitv NULL address in *waiters\n");
@@ -255,10 +267,13 @@ int main(int argc, char *argv[])
        to.tv_sec++;
 
        res = futex_waitv(waitv, NR_FUTEXES, 0, &to, CLOCK_TAI);
-       if (res == EINVAL) {
-               ksft_test_result_fail("futex_waitv private returned: %d %s\n",
-                                     res ? errno : res,
-                                     res ? strerror(errno) : "");
+       if (res != -1) {
+               ksft_test_result_fail("futex_waitv invalid clockid: unexpected 
result: %d\n",
+                                     res);
+               ret = RET_FAIL;
+       } else if (errno != EINVAL) {
+               ksft_test_result_fail("futex_waitv invalid clockid: unexpected 
errno: %d\n",
+                                     errno);
                ret = RET_FAIL;
        } else {
                ksft_test_result_pass("futex_waitv invalid clockid\n");
-- 
2.56.0

_______________________________________________
Devel mailing list
[email protected]
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to