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

selftests/futex: Refactor futex_requeue with kselftest_harness.h

To reduce the boilerplate code, refactor futex_requeue 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
f341a20f e5c04d0f

+25 -55
+24 -54
tools/testing/selftests/futex/functional/futex_requeue.c
··· 7 7 8 8 #include <pthread.h> 9 9 #include <limits.h> 10 - #include "logging.h" 11 - #include "futextest.h" 12 10 13 - #define TEST_NAME "futex-requeue" 11 + #include "futextest.h" 12 + #include "../../kselftest_harness.h" 13 + 14 14 #define timeout_ns 30000000 15 15 #define WAKE_WAIT_US 10000 16 16 17 17 volatile futex_t *f1; 18 - 19 - void usage(char *prog) 20 - { 21 - printf("Usage: %s\n", prog); 22 - printf(" -c Use color\n"); 23 - printf(" -h Display this help message\n"); 24 - printf(" -v L Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n", 25 - VQUIET, VCRITICAL, VINFO); 26 - } 27 18 28 19 void *waiterfn(void *arg) 29 20 { ··· 29 38 return NULL; 30 39 } 31 40 32 - int main(int argc, char *argv[]) 41 + TEST(requeue_single) 33 42 { 34 - pthread_t waiter[10]; 35 - int res, ret = RET_PASS; 36 - int c, i; 37 43 volatile futex_t _f1 = 0; 38 44 volatile futex_t f2 = 0; 45 + pthread_t waiter[10]; 46 + int res; 39 47 40 48 f1 = &_f1; 41 - 42 - while ((c = getopt(argc, argv, "cht:v:")) != -1) { 43 - switch (c) { 44 - case 'c': 45 - log_color(1); 46 - break; 47 - case 'h': 48 - usage(basename(argv[0])); 49 - exit(0); 50 - case 'v': 51 - log_verbosity(atoi(optarg)); 52 - break; 53 - default: 54 - usage(basename(argv[0])); 55 - exit(1); 56 - } 57 - } 58 - 59 - ksft_print_header(); 60 - ksft_set_plan(2); 61 - ksft_print_msg("%s: Test futex_requeue\n", 62 - basename(argv[0])); 63 49 64 50 /* 65 51 * Requeue a waiter from f1 to f2, and wake f2. 66 52 */ 67 53 if (pthread_create(&waiter[0], NULL, waiterfn, NULL)) 68 - error("pthread_create failed\n", errno); 54 + ksft_exit_fail_msg("pthread_create failed\n"); 69 55 70 56 usleep(WAKE_WAIT_US); 71 57 72 - info("Requeuing 1 futex from f1 to f2\n"); 58 + ksft_print_dbg_msg("Requeuing 1 futex from f1 to f2\n"); 73 59 res = futex_cmp_requeue(f1, 0, &f2, 0, 1, 0); 74 - if (res != 1) { 60 + if (res != 1) 75 61 ksft_test_result_fail("futex_requeue simple returned: %d %s\n", 76 62 res ? errno : res, 77 63 res ? strerror(errno) : ""); 78 - ret = RET_FAIL; 79 - } 80 64 81 - 82 - info("Waking 1 futex at f2\n"); 65 + ksft_print_dbg_msg("Waking 1 futex at f2\n"); 83 66 res = futex_wake(&f2, 1, 0); 84 67 if (res != 1) { 85 68 ksft_test_result_fail("futex_requeue simple returned: %d %s\n", 86 69 res ? errno : res, 87 70 res ? strerror(errno) : ""); 88 - ret = RET_FAIL; 89 71 } else { 90 72 ksft_test_result_pass("futex_requeue simple succeeds\n"); 91 73 } 74 + } 92 75 76 + TEST(requeue_multiple) 77 + { 78 + volatile futex_t _f1 = 0; 79 + volatile futex_t f2 = 0; 80 + pthread_t waiter[10]; 81 + int res, i; 82 + 83 + f1 = &_f1; 93 84 94 85 /* 95 86 * Create 10 waiters at f1. At futex_requeue, wake 3 and requeue 7. ··· 79 106 */ 80 107 for (i = 0; i < 10; i++) { 81 108 if (pthread_create(&waiter[i], NULL, waiterfn, NULL)) 82 - error("pthread_create failed\n", errno); 109 + ksft_exit_fail_msg("pthread_create failed\n"); 83 110 } 84 111 85 112 usleep(WAKE_WAIT_US); 86 113 87 - info("Waking 3 futexes at f1 and requeuing 7 futexes from f1 to f2\n"); 114 + ksft_print_dbg_msg("Waking 3 futexes at f1 and requeuing 7 futexes from f1 to f2\n"); 88 115 res = futex_cmp_requeue(f1, 0, &f2, 3, 7, 0); 89 116 if (res != 10) { 90 117 ksft_test_result_fail("futex_requeue many returned: %d %s\n", 91 118 res ? errno : res, 92 119 res ? strerror(errno) : ""); 93 - ret = RET_FAIL; 94 120 } 95 121 96 - info("Waking INT_MAX futexes at f2\n"); 122 + ksft_print_dbg_msg("Waking INT_MAX futexes at f2\n"); 97 123 res = futex_wake(&f2, INT_MAX, 0); 98 124 if (res != 7) { 99 125 ksft_test_result_fail("futex_requeue many returned: %d %s\n", 100 126 res ? errno : res, 101 127 res ? strerror(errno) : ""); 102 - ret = RET_FAIL; 103 128 } else { 104 129 ksft_test_result_pass("futex_requeue many succeeds\n"); 105 130 } 106 - 107 - ksft_print_cnts(); 108 - return ret; 109 131 } 132 + 133 + TEST_HARNESS_MAIN
+1 -1
tools/testing/selftests/futex/functional/run.sh
··· 54 54 ./futex_wait 55 55 56 56 echo 57 - ./futex_requeue $COLOR 57 + ./futex_requeue 58 58 59 59 echo 60 60 ./futex_waitv $COLOR