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 <andrealm...@igalia.com>
---
 .../functional/futex_wait_uninitialized_heap.c     | 76 +++++-----------------
 tools/testing/selftests/futex/functional/run.sh    |  2 +-
 2 files changed, 19 insertions(+), 59 deletions(-)

diff --git 
a/tools/testing/selftests/futex/functional/futex_wait_uninitialized_heap.c 
b/tools/testing/selftests/futex/functional/futex_wait_uninitialized_heap.c
index 
ed9cd07e31c1a980bb505bb97617282411b6085a..ce2301500d839ca7b2d527ab4e072b9f00d1146a
 100644
--- a/tools/testing/selftests/futex/functional/futex_wait_uninitialized_heap.c
+++ b/tools/testing/selftests/futex/functional/futex_wait_uninitialized_heap.c
@@ -29,95 +29,55 @@
 #include <linux/futex.h>
 #include <libgen.h>
 
-#include "logging.h"
 #include "futextest.h"
+#include "../../kselftest_harness.h"
 
-#define TEST_NAME "futex-wait-uninitialized-heap"
 #define WAIT_US 5000000
 
 static int child_blocked = 1;
-static int child_ret;
+static bool child_ret;
 void *buf;
 
-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 *wait_thread(void *arg)
 {
        int res;
 
-       child_ret = RET_PASS;
+       child_ret = true;
        res = futex_wait(buf, 1, NULL, 0);
        child_blocked = 0;
 
        if (res != 0 && errno != EWOULDBLOCK) {
-               error("futex failure\n", errno);
-               child_ret = RET_ERROR;
+               ksft_exit_fail_msg("futex failure\n");
+               child_ret = false;
        }
        pthread_exit(NULL);
 }
 
-int main(int argc, char **argv)
+TEST(futex_wait_uninitialized_heap)
 {
-       int c, ret = RET_PASS;
        long page_size;
        pthread_t thr;
-
-       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);
-               }
-       }
+       int ret;
 
        page_size = sysconf(_SC_PAGESIZE);
 
        buf = mmap(NULL, page_size, PROT_READ|PROT_WRITE,
                   MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
-       if (buf == (void *)-1) {
-               error("mmap\n", errno);
-               exit(1);
-       }
-
-       ksft_print_header();
-       ksft_set_plan(1);
-       ksft_print_msg("%s: Test the uninitialized futex value in FUTEX_WAIT\n",
-              basename(argv[0]));
-
+       if (buf == (void *)-1)
+               ksft_exit_fail_msg("mmap\n");
 
        ret = pthread_create(&thr, NULL, wait_thread, NULL);
-       if (ret) {
-               error("pthread_create\n", errno);
-               ret = RET_ERROR;
-               goto out;
-       }
+       if (ret)
+               ksft_exit_fail_msg("pthread_create\n");
 
-       info("waiting %dus for child to return\n", WAIT_US);
+       ksft_print_dbg_msg("waiting %dus for child to return\n", WAIT_US);
        usleep(WAIT_US);
 
-       ret = child_ret;
-       if (child_blocked) {
-               fail("child blocked in kernel\n");
-               ret = RET_FAIL;
-       }
+       if (child_blocked)
+               ksft_test_result_fail("child blocked in kernel\n");
 
- out:
-       print_result(TEST_NAME, ret);
-       return ret;
+       if (!child_ret)
+               ksft_test_result_fail("child error\n");
 }
+
+TEST_HARNESS_MAIN
diff --git a/tools/testing/selftests/futex/functional/run.sh 
b/tools/testing/selftests/futex/functional/run.sh
index 
4a4fe9891f1ef8d69bb968a3a2be6c7dccd3575f..a93eb2a21d4aa23f874bf11ccc852838a4c3866f
 100755
--- a/tools/testing/selftests/futex/functional/run.sh
+++ b/tools/testing/selftests/futex/functional/run.sh
@@ -47,7 +47,7 @@ echo
 ./futex_wait_wouldblock
 
 echo
-./futex_wait_uninitialized_heap $COLOR
+./futex_wait_uninitialized_heap
 ./futex_wait_private_mapped_file $COLOR
 
 echo

-- 
2.49.0


Reply via email to