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

selftests/futex: Refactor futex_wait_unitialized_heap with kselftest_harness.h

To reduce the boilerplate code, refactor futex_wait_unitialized_heap
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
af3c79f8 f5a16834

+19 -59
+18 -58
tools/testing/selftests/futex/functional/futex_wait_uninitialized_heap.c
··· 29 29 #include <linux/futex.h> 30 30 #include <libgen.h> 31 31 32 - #include "logging.h" 33 32 #include "futextest.h" 33 + #include "../../kselftest_harness.h" 34 34 35 - #define TEST_NAME "futex-wait-uninitialized-heap" 36 35 #define WAIT_US 5000000 37 36 38 37 static int child_blocked = 1; 39 - static int child_ret; 38 + static bool child_ret; 40 39 void *buf; 41 - 42 - void usage(char *prog) 43 - { 44 - printf("Usage: %s\n", prog); 45 - printf(" -c Use color\n"); 46 - printf(" -h Display this help message\n"); 47 - printf(" -v L Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n", 48 - VQUIET, VCRITICAL, VINFO); 49 - } 50 40 51 41 void *wait_thread(void *arg) 52 42 { 53 43 int res; 54 44 55 - child_ret = RET_PASS; 45 + child_ret = true; 56 46 res = futex_wait(buf, 1, NULL, 0); 57 47 child_blocked = 0; 58 48 59 49 if (res != 0 && errno != EWOULDBLOCK) { 60 - error("futex failure\n", errno); 61 - child_ret = RET_ERROR; 50 + ksft_exit_fail_msg("futex failure\n"); 51 + child_ret = false; 62 52 } 63 53 pthread_exit(NULL); 64 54 } 65 55 66 - int main(int argc, char **argv) 56 + TEST(futex_wait_uninitialized_heap) 67 57 { 68 - int c, ret = RET_PASS; 69 58 long page_size; 70 59 pthread_t thr; 71 - 72 - while ((c = getopt(argc, argv, "chv:")) != -1) { 73 - switch (c) { 74 - case 'c': 75 - log_color(1); 76 - break; 77 - case 'h': 78 - usage(basename(argv[0])); 79 - exit(0); 80 - case 'v': 81 - log_verbosity(atoi(optarg)); 82 - break; 83 - default: 84 - usage(basename(argv[0])); 85 - exit(1); 86 - } 87 - } 60 + int ret; 88 61 89 62 page_size = sysconf(_SC_PAGESIZE); 90 63 91 64 buf = mmap(NULL, page_size, PROT_READ|PROT_WRITE, 92 65 MAP_PRIVATE|MAP_ANONYMOUS, 0, 0); 93 - if (buf == (void *)-1) { 94 - error("mmap\n", errno); 95 - exit(1); 96 - } 97 - 98 - ksft_print_header(); 99 - ksft_set_plan(1); 100 - ksft_print_msg("%s: Test the uninitialized futex value in FUTEX_WAIT\n", 101 - basename(argv[0])); 102 - 66 + if (buf == (void *)-1) 67 + ksft_exit_fail_msg("mmap\n"); 103 68 104 69 ret = pthread_create(&thr, NULL, wait_thread, NULL); 105 - if (ret) { 106 - error("pthread_create\n", errno); 107 - ret = RET_ERROR; 108 - goto out; 109 - } 70 + if (ret) 71 + ksft_exit_fail_msg("pthread_create\n"); 110 72 111 - info("waiting %dus for child to return\n", WAIT_US); 73 + ksft_print_dbg_msg("waiting %dus for child to return\n", WAIT_US); 112 74 usleep(WAIT_US); 113 75 114 - ret = child_ret; 115 - if (child_blocked) { 116 - fail("child blocked in kernel\n"); 117 - ret = RET_FAIL; 118 - } 76 + if (child_blocked) 77 + ksft_test_result_fail("child blocked in kernel\n"); 119 78 120 - out: 121 - print_result(TEST_NAME, ret); 122 - return ret; 79 + if (!child_ret) 80 + ksft_test_result_fail("child error\n"); 123 81 } 82 + 83 + TEST_HARNESS_MAIN
+1 -1
tools/testing/selftests/futex/functional/run.sh
··· 47 47 ./futex_wait_wouldblock 48 48 49 49 echo 50 - ./futex_wait_uninitialized_heap $COLOR 50 + ./futex_wait_uninitialized_heap 51 51 ./futex_wait_private_mapped_file $COLOR 52 52 53 53 echo