Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: futex: Test sys_futex_waitv() wouldblock

Test if futex_waitv() returns -EWOULDBLOCK correctly when the expected
value is different from the actual value for a waiter.

Signed-off-by: André Almeida <andrealmeid@collabora.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20210923171111.300673-22-andrealmeid@collabora.com

authored by

André Almeida and committed by
Peter Zijlstra
9d57f7c7 02e56ccb

+37 -4
+37 -4
tools/testing/selftests/futex/functional/futex_wait_wouldblock.c
··· 22 22 #include <string.h> 23 23 #include <time.h> 24 24 #include "futextest.h" 25 + #include "futex2test.h" 25 26 #include "logging.h" 26 27 27 28 #define TEST_NAME "futex-wait-wouldblock" ··· 43 42 futex_t f1 = FUTEX_INITIALIZER; 44 43 int res, ret = RET_PASS; 45 44 int c; 45 + struct futex_waitv waitv = { 46 + .uaddr = (uintptr_t)&f1, 47 + .val = f1+1, 48 + .flags = FUTEX_32, 49 + .__reserved = 0 50 + }; 46 51 47 52 while ((c = getopt(argc, argv, "cht:v:")) != -1) { 48 53 switch (c) { ··· 68 61 } 69 62 70 63 ksft_print_header(); 71 - ksft_set_plan(1); 64 + ksft_set_plan(2); 72 65 ksft_print_msg("%s: Test the unexpected futex value in FUTEX_WAIT\n", 73 66 basename(argv[0])); 74 67 75 68 info("Calling futex_wait on f1: %u @ %p with val=%u\n", f1, &f1, f1+1); 76 69 res = futex_wait(&f1, f1+1, &to, FUTEX_PRIVATE_FLAG); 77 70 if (!res || errno != EWOULDBLOCK) { 78 - fail("futex_wait returned: %d %s\n", 79 - res ? errno : res, res ? strerror(errno) : ""); 71 + ksft_test_result_fail("futex_wait returned: %d %s\n", 72 + res ? errno : res, 73 + res ? strerror(errno) : ""); 80 74 ret = RET_FAIL; 75 + } else { 76 + ksft_test_result_pass("futex_wait\n"); 81 77 } 82 78 83 - print_result(TEST_NAME, ret); 79 + if (clock_gettime(CLOCK_MONOTONIC, &to)) { 80 + error("clock_gettime failed\n", errno); 81 + return errno; 82 + } 83 + 84 + to.tv_nsec += timeout_ns; 85 + 86 + if (to.tv_nsec >= 1000000000) { 87 + to.tv_sec++; 88 + to.tv_nsec -= 1000000000; 89 + } 90 + 91 + info("Calling futex_waitv on f1: %u @ %p with val=%u\n", f1, &f1, f1+1); 92 + res = futex_waitv(&waitv, 1, 0, &to, CLOCK_MONOTONIC); 93 + if (!res || errno != EWOULDBLOCK) { 94 + ksft_test_result_pass("futex_waitv returned: %d %s\n", 95 + res ? errno : res, 96 + res ? strerror(errno) : ""); 97 + ret = RET_FAIL; 98 + } else { 99 + ksft_test_result_pass("futex_waitv\n"); 100 + } 101 + 102 + ksft_print_cnts(); 84 103 return ret; 85 104 }