Skip to content

Commit af3c79f

Browse files
andrealmeidKAGA-KOKO
authored andcommitted
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>
1 parent f5a1683 commit af3c79f

2 files changed

Lines changed: 19 additions & 59 deletions

File tree

tools/testing/selftests/futex/functional/futex_wait_uninitialized_heap.c

Lines changed: 18 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -29,95 +29,55 @@
2929
#include <linux/futex.h>
3030
#include <libgen.h>
3131

32-
#include "logging.h"
3332
#include "futextest.h"
33+
#include "../../kselftest_harness.h"
3434

35-
#define TEST_NAME "futex-wait-uninitialized-heap"
3635
#define WAIT_US 5000000
3736

3837
static int child_blocked = 1;
39-
static int child_ret;
38+
static bool child_ret;
4039
void *buf;
4140

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-
5141
void *wait_thread(void *arg)
5242
{
5343
int res;
5444

55-
child_ret = RET_PASS;
45+
child_ret = true;
5646
res = futex_wait(buf, 1, NULL, 0);
5747
child_blocked = 0;
5848

5949
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;
6252
}
6353
pthread_exit(NULL);
6454
}
6555

66-
int main(int argc, char **argv)
56+
TEST(futex_wait_uninitialized_heap)
6757
{
68-
int c, ret = RET_PASS;
6958
long page_size;
7059
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;
8861

8962
page_size = sysconf(_SC_PAGESIZE);
9063

9164
buf = mmap(NULL, page_size, PROT_READ|PROT_WRITE,
9265
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");
10368

10469
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");
11072

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);
11274
usleep(WAIT_US);
11375

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");
11978

120-
out:
121-
print_result(TEST_NAME, ret);
122-
return ret;
79+
if (!child_ret)
80+
ksft_test_result_fail("child error\n");
12381
}
82+
83+
TEST_HARNESS_MAIN

tools/testing/selftests/futex/functional/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ echo
4747
./futex_wait_wouldblock
4848

4949
echo
50-
./futex_wait_uninitialized_heap $COLOR
50+
./futex_wait_uninitialized_heap
5151
./futex_wait_private_mapped_file $COLOR
5252

5353
echo

0 commit comments

Comments
 (0)