]> www.infradead.org Git - users/hch/misc.git/commitdiff
selftests/futex: Refactor futex_wait_private_mapped_file with kselftest_harness.h
authorAndré Almeida <andrealmeid@igalia.com>
Wed, 17 Sep 2025 21:21:47 +0000 (18:21 -0300)
committerThomas Gleixner <tglx@linutronix.de>
Sat, 20 Sep 2025 16:11:54 +0000 (18:11 +0200)
To reduce the boilerplate code, refactor futex_wait_private_mapped_file
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>
tools/testing/selftests/futex/functional/futex_wait_private_mapped_file.c
tools/testing/selftests/futex/functional/run.sh

index fb4148f23fa3722cb9c464e188b2747516534dbb..8952ebda14ab8a54d67be4cf36dd2913dbf3c403 100644 (file)
 #include <libgen.h>
 #include <signal.h>
 
-#include "logging.h"
 #include "futextest.h"
+#include "../../kselftest_harness.h"
 
-#define TEST_NAME "futex-wait-private-mapped-file"
 #define PAGE_SZ 4096
 
 char pad[PAGE_SZ] = {1};
@@ -40,86 +39,44 @@ char pad2[PAGE_SZ] = {1};
 #define WAKE_WAIT_US 3000000
 struct timespec wait_timeout = { .tv_sec = 5, .tv_nsec = 0};
 
-void usage(char *prog)
-{
-       printf("Usage: %s\n", prog);
-       printf("  -c    Use color\n");
-       printf("  -h    Display this help message\n");
-       printf("  -v L  Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n",
-              VQUIET, VCRITICAL, VINFO);
-}
-
 void *thr_futex_wait(void *arg)
 {
        int ret;
 
-       info("futex wait\n");
+       ksft_print_dbg_msg("futex wait\n");
        ret = futex_wait(&val, 1, &wait_timeout, 0);
-       if (ret && errno != EWOULDBLOCK && errno != ETIMEDOUT) {
-               error("futex error.\n", errno);
-               print_result(TEST_NAME, RET_ERROR);
-               exit(RET_ERROR);
-       }
+       if (ret && errno != EWOULDBLOCK && errno != ETIMEDOUT)
+               ksft_exit_fail_msg("futex error.\n");
 
        if (ret && errno == ETIMEDOUT)
-               fail("waiter timedout\n");
+               ksft_exit_fail_msg("waiter timedout\n");
 
-       info("futex_wait: ret = %d, errno = %d\n", ret, errno);
+       ksft_print_dbg_msg("futex_wait: ret = %d, errno = %d\n", ret, errno);
 
        return NULL;
 }
 
-int main(int argc, char **argv)
+TEST(wait_private_mapped_file)
 {
        pthread_t thr;
-       int ret = RET_PASS;
        int res;
-       int c;
-
-       while ((c = getopt(argc, argv, "chv:")) != -1) {
-               switch (c) {
-               case 'c':
-                       log_color(1);
-                       break;
-               case 'h':
-                       usage(basename(argv[0]));
-                       exit(0);
-               case 'v':
-                       log_verbosity(atoi(optarg));
-                       break;
-               default:
-                       usage(basename(argv[0]));
-                       exit(1);
-               }
-       }
-
-       ksft_print_header();
-       ksft_set_plan(1);
-       ksft_print_msg(
-               "%s: Test the futex value of private file mappings in FUTEX_WAIT\n",
-               basename(argv[0]));
-
-       ret = pthread_create(&thr, NULL, thr_futex_wait, NULL);
-       if (ret < 0) {
-               fprintf(stderr, "pthread_create error\n");
-               ret = RET_ERROR;
-               goto out;
-       }
-
-       info("wait a while\n");
+
+       res = pthread_create(&thr, NULL, thr_futex_wait, NULL);
+       if (res < 0)
+               ksft_exit_fail_msg("pthread_create error\n");
+
+       ksft_print_dbg_msg("wait a while\n");
        usleep(WAKE_WAIT_US);
        val = 2;
        res = futex_wake(&val, 1, 0);
-       info("futex_wake %d\n", res);
-       if (res != 1) {
-               fail("FUTEX_WAKE didn't find the waiting thread.\n");
-               ret = RET_FAIL;
-       }
+       ksft_print_dbg_msg("futex_wake %d\n", res);
+       if (res != 1)
+               ksft_exit_fail_msg("FUTEX_WAKE didn't find the waiting thread.\n");
 
-       info("join\n");
+       ksft_print_dbg_msg("join\n");
        pthread_join(thr, NULL);
 
- out:
-       print_result(TEST_NAME, ret);
-       return ret;
+       ksft_test_result_pass("wait_private_mapped_file");
 }
+
+TEST_HARNESS_MAIN
index 6cb07a4e760d2afc1f4c6b64e570c580ab332ea4..87666f21fa3bf99e7db03da0aea14a5af3e49e0d 100755 (executable)
@@ -48,7 +48,7 @@ echo
 
 echo
 ./futex_wait_uninitialized_heap
-./futex_wait_private_mapped_file $COLOR
+./futex_wait_private_mapped_file
 
 echo
 ./futex_wait $COLOR