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

selftests/futex: Refactor futex_waitv with kselftest_harness.h

To reduce the boilerplate code, refactor futex_waitv test to use
kselftest_harness header instead of futex's logging header.

Signed-off-by: André Almeida <andrealmeid@igalia.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

authored by

André Almeida and committed by
Thomas Gleixner
a91e8e37 f341a20f

+45 -56
+44 -55
tools/testing/selftests/futex/functional/futex_waitv.c
··· 15 15 #include <pthread.h> 16 16 #include <stdint.h> 17 17 #include <sys/shm.h> 18 + 18 19 #include "futextest.h" 19 20 #include "futex2test.h" 20 - #include "logging.h" 21 + #include "../../kselftest_harness.h" 21 22 22 - #define TEST_NAME "futex-wait" 23 23 #define WAKE_WAIT_US 10000 24 24 #define NR_FUTEXES 30 25 25 static struct futex_waitv waitv[NR_FUTEXES]; 26 26 u_int32_t futexes[NR_FUTEXES] = {0}; 27 - 28 - void usage(char *prog) 29 - { 30 - printf("Usage: %s\n", prog); 31 - printf(" -c Use color\n"); 32 - printf(" -h Display this help message\n"); 33 - printf(" -v L Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n", 34 - VQUIET, VCRITICAL, VINFO); 35 - } 36 27 37 28 void *waiterfn(void *arg) 38 29 { ··· 32 41 33 42 /* setting absolute timeout for futex2 */ 34 43 if (clock_gettime(CLOCK_MONOTONIC, &to)) 35 - error("gettime64 failed\n", errno); 44 + ksft_exit_fail_msg("gettime64 failed\n"); 36 45 37 46 to.tv_sec++; 38 47 ··· 48 57 return NULL; 49 58 } 50 59 51 - int main(int argc, char *argv[]) 60 + TEST(private_waitv) 52 61 { 53 62 pthread_t waiter; 54 - int res, ret = RET_PASS; 55 - struct timespec to; 56 - int c, i; 57 - 58 - while ((c = getopt(argc, argv, "cht:v:")) != -1) { 59 - switch (c) { 60 - case 'c': 61 - log_color(1); 62 - break; 63 - case 'h': 64 - usage(basename(argv[0])); 65 - exit(0); 66 - case 'v': 67 - log_verbosity(atoi(optarg)); 68 - break; 69 - default: 70 - usage(basename(argv[0])); 71 - exit(1); 72 - } 73 - } 74 - 75 - ksft_print_header(); 76 - ksft_set_plan(7); 77 - ksft_print_msg("%s: Test FUTEX_WAITV\n", 78 - basename(argv[0])); 63 + int res, i; 79 64 80 65 for (i = 0; i < NR_FUTEXES; i++) { 81 66 waitv[i].uaddr = (uintptr_t)&futexes[i]; ··· 62 95 63 96 /* Private waitv */ 64 97 if (pthread_create(&waiter, NULL, waiterfn, NULL)) 65 - error("pthread_create failed\n", errno); 98 + ksft_exit_fail_msg("pthread_create failed\n"); 66 99 67 100 usleep(WAKE_WAIT_US); 68 101 ··· 71 104 ksft_test_result_fail("futex_wake private returned: %d %s\n", 72 105 res ? errno : res, 73 106 res ? strerror(errno) : ""); 74 - ret = RET_FAIL; 75 107 } else { 76 108 ksft_test_result_pass("futex_waitv private\n"); 77 109 } 110 + } 111 + 112 + TEST(shared_waitv) 113 + { 114 + pthread_t waiter; 115 + int res, i; 78 116 79 117 /* Shared waitv */ 80 118 for (i = 0; i < NR_FUTEXES; i++) { ··· 100 128 } 101 129 102 130 if (pthread_create(&waiter, NULL, waiterfn, NULL)) 103 - error("pthread_create failed\n", errno); 131 + ksft_exit_fail_msg("pthread_create failed\n"); 104 132 105 133 usleep(WAKE_WAIT_US); 106 134 ··· 109 137 ksft_test_result_fail("futex_wake shared returned: %d %s\n", 110 138 res ? errno : res, 111 139 res ? strerror(errno) : ""); 112 - ret = RET_FAIL; 113 140 } else { 114 141 ksft_test_result_pass("futex_waitv shared\n"); 115 142 } 116 143 117 144 for (i = 0; i < NR_FUTEXES; i++) 118 145 shmdt(u64_to_ptr(waitv[i].uaddr)); 146 + } 147 + 148 + TEST(invalid_flag) 149 + { 150 + struct timespec to; 151 + int res; 119 152 120 153 /* Testing a waiter without FUTEX_32 flag */ 121 154 waitv[0].flags = FUTEX_PRIVATE_FLAG; 122 155 123 156 if (clock_gettime(CLOCK_MONOTONIC, &to)) 124 - error("gettime64 failed\n", errno); 157 + ksft_exit_fail_msg("gettime64 failed\n"); 125 158 126 159 to.tv_sec++; 127 160 ··· 135 158 ksft_test_result_fail("futex_waitv private returned: %d %s\n", 136 159 res ? errno : res, 137 160 res ? strerror(errno) : ""); 138 - ret = RET_FAIL; 139 161 } else { 140 162 ksft_test_result_pass("futex_waitv without FUTEX_32\n"); 141 163 } 164 + } 165 + 166 + TEST(unaligned_address) 167 + { 168 + struct timespec to; 169 + int res; 142 170 143 171 /* Testing a waiter with an unaligned address */ 144 172 waitv[0].flags = FUTEX_PRIVATE_FLAG | FUTEX_32; 145 173 waitv[0].uaddr = 1; 146 174 147 175 if (clock_gettime(CLOCK_MONOTONIC, &to)) 148 - error("gettime64 failed\n", errno); 176 + ksft_exit_fail_msg("gettime64 failed\n"); 149 177 150 178 to.tv_sec++; 151 179 ··· 159 177 ksft_test_result_fail("futex_wake private returned: %d %s\n", 160 178 res ? errno : res, 161 179 res ? strerror(errno) : ""); 162 - ret = RET_FAIL; 163 180 } else { 164 181 ksft_test_result_pass("futex_waitv with an unaligned address\n"); 165 182 } 183 + } 184 + 185 + TEST(null_address) 186 + { 187 + struct timespec to; 188 + int res; 166 189 167 190 /* Testing a NULL address for waiters.uaddr */ 168 191 waitv[0].uaddr = 0x00000000; 169 192 170 193 if (clock_gettime(CLOCK_MONOTONIC, &to)) 171 - error("gettime64 failed\n", errno); 194 + ksft_exit_fail_msg("gettime64 failed\n"); 172 195 173 196 to.tv_sec++; 174 197 ··· 182 195 ksft_test_result_fail("futex_waitv private returned: %d %s\n", 183 196 res ? errno : res, 184 197 res ? strerror(errno) : ""); 185 - ret = RET_FAIL; 186 198 } else { 187 199 ksft_test_result_pass("futex_waitv NULL address in waitv.uaddr\n"); 188 200 } 189 201 190 202 /* Testing a NULL address for *waiters */ 191 203 if (clock_gettime(CLOCK_MONOTONIC, &to)) 192 - error("gettime64 failed\n", errno); 204 + ksft_exit_fail_msg("gettime64 failed\n"); 193 205 194 206 to.tv_sec++; 195 207 ··· 197 211 ksft_test_result_fail("futex_waitv private returned: %d %s\n", 198 212 res ? errno : res, 199 213 res ? strerror(errno) : ""); 200 - ret = RET_FAIL; 201 214 } else { 202 215 ksft_test_result_pass("futex_waitv NULL address in *waiters\n"); 203 216 } 217 + } 218 + 219 + TEST(invalid_clockid) 220 + { 221 + struct timespec to; 222 + int res; 204 223 205 224 /* Testing an invalid clockid */ 206 225 if (clock_gettime(CLOCK_MONOTONIC, &to)) 207 - error("gettime64 failed\n", errno); 226 + ksft_exit_fail_msg("gettime64 failed\n"); 208 227 209 228 to.tv_sec++; 210 229 ··· 218 227 ksft_test_result_fail("futex_waitv private returned: %d %s\n", 219 228 res ? errno : res, 220 229 res ? strerror(errno) : ""); 221 - ret = RET_FAIL; 222 230 } else { 223 231 ksft_test_result_pass("futex_waitv invalid clockid\n"); 224 232 } 225 - 226 - ksft_print_cnts(); 227 - return ret; 228 233 } 234 + 235 + TEST_HARNESS_MAIN
+1 -1
tools/testing/selftests/futex/functional/run.sh
··· 57 57 ./futex_requeue 58 58 59 59 echo 60 - ./futex_waitv $COLOR 60 + ./futex_waitv 61 61 62 62 echo 63 63 ./futex_priv_hash $COLOR