Skip to content

Commit f5a1683

Browse files
andrealmeidKAGA-KOKO
authored andcommitted
selftests/futex: Refactor futex_wait_wouldblock with kselftest_harness.h
To reduce the boilerplate code, refactor futex_wait_wouldblock 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 0c02abf commit f5a1683

2 files changed

Lines changed: 24 additions & 54 deletions

File tree

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

Lines changed: 23 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -21,72 +21,44 @@
2121
#include <stdlib.h>
2222
#include <string.h>
2323
#include <time.h>
24+
2425
#include "futextest.h"
2526
#include "futex2test.h"
26-
#include "logging.h"
27+
#include "../../kselftest_harness.h"
2728

28-
#define TEST_NAME "futex-wait-wouldblock"
2929
#define timeout_ns 100000
3030

31-
void usage(char *prog)
32-
{
33-
printf("Usage: %s\n", prog);
34-
printf(" -c Use color\n");
35-
printf(" -h Display this help message\n");
36-
printf(" -v L Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n",
37-
VQUIET, VCRITICAL, VINFO);
38-
}
39-
40-
int main(int argc, char *argv[])
31+
TEST(futex_wait_wouldblock)
4132
{
4233
struct timespec to = {.tv_sec = 0, .tv_nsec = timeout_ns};
4334
futex_t f1 = FUTEX_INITIALIZER;
44-
int res, ret = RET_PASS;
45-
int c;
46-
struct futex_waitv waitv = {
47-
.uaddr = (uintptr_t)&f1,
48-
.val = f1+1,
49-
.flags = FUTEX_32,
50-
.__reserved = 0
51-
};
35+
int res;
5236

53-
while ((c = getopt(argc, argv, "cht:v:")) != -1) {
54-
switch (c) {
55-
case 'c':
56-
log_color(1);
57-
break;
58-
case 'h':
59-
usage(basename(argv[0]));
60-
exit(0);
61-
case 'v':
62-
log_verbosity(atoi(optarg));
63-
break;
64-
default:
65-
usage(basename(argv[0]));
66-
exit(1);
67-
}
68-
}
69-
70-
ksft_print_header();
71-
ksft_set_plan(2);
72-
ksft_print_msg("%s: Test the unexpected futex value in FUTEX_WAIT\n",
73-
basename(argv[0]));
74-
75-
info("Calling futex_wait on f1: %u @ %p with val=%u\n", f1, &f1, f1+1);
37+
ksft_print_dbg_msg("Calling futex_wait on f1: %u @ %p with val=%u\n", f1, &f1, f1+1);
7638
res = futex_wait(&f1, f1+1, &to, FUTEX_PRIVATE_FLAG);
7739
if (!res || errno != EWOULDBLOCK) {
7840
ksft_test_result_fail("futex_wait returned: %d %s\n",
7941
res ? errno : res,
8042
res ? strerror(errno) : "");
81-
ret = RET_FAIL;
8243
} else {
8344
ksft_test_result_pass("futex_wait\n");
8445
}
46+
}
8547

86-
if (clock_gettime(CLOCK_MONOTONIC, &to)) {
87-
error("clock_gettime failed\n", errno);
88-
return errno;
89-
}
48+
TEST(futex_waitv_wouldblock)
49+
{
50+
struct timespec to = {.tv_sec = 0, .tv_nsec = timeout_ns};
51+
futex_t f1 = FUTEX_INITIALIZER;
52+
struct futex_waitv waitv = {
53+
.uaddr = (uintptr_t)&f1,
54+
.val = f1 + 1,
55+
.flags = FUTEX_32,
56+
.__reserved = 0,
57+
};
58+
int res;
59+
60+
if (clock_gettime(CLOCK_MONOTONIC, &to))
61+
ksft_exit_fail_msg("clock_gettime failed %d\n", errno);
9062

9163
to.tv_nsec += timeout_ns;
9264

@@ -95,17 +67,15 @@ int main(int argc, char *argv[])
9567
to.tv_nsec -= 1000000000;
9668
}
9769

98-
info("Calling futex_waitv on f1: %u @ %p with val=%u\n", f1, &f1, f1+1);
70+
ksft_print_dbg_msg("Calling futex_waitv on f1: %u @ %p with val=%u\n", f1, &f1, f1+1);
9971
res = futex_waitv(&waitv, 1, 0, &to, CLOCK_MONOTONIC);
10072
if (!res || errno != EWOULDBLOCK) {
10173
ksft_test_result_fail("futex_waitv returned: %d %s\n",
10274
res ? errno : res,
10375
res ? strerror(errno) : "");
104-
ret = RET_FAIL;
10576
} else {
10677
ksft_test_result_pass("futex_waitv\n");
10778
}
108-
109-
ksft_print_cnts();
110-
return ret;
11179
}
80+
81+
TEST_HARNESS_MAIN

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ echo
4444
./futex_wait_timeout
4545

4646
echo
47-
./futex_wait_wouldblock $COLOR
47+
./futex_wait_wouldblock
4848

4949
echo
5050
./futex_wait_uninitialized_heap $COLOR

0 commit comments

Comments
 (0)