Skip to content

Commit d35ca2f

Browse files
andrealmeidKAGA-KOKO
authored andcommitted
selftests/futex: Refactor futex_numa_mpol with kselftest_harness.h
To reduce the boilerplate code, refactor futex_numa_mpol 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 4ba629e commit d35ca2f

2 files changed

Lines changed: 9 additions & 47 deletions

File tree

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

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
#include <linux/futex.h>
1717
#include <sys/mman.h>
1818

19-
#include "logging.h"
2019
#include "futextest.h"
2120
#include "futex2test.h"
21+
#include "../../kselftest_harness.h"
2222

2323
#define MAX_THREADS 64
2424

@@ -131,42 +131,16 @@ static void test_futex(void *futex_ptr, int err_value)
131131
__test_futex(futex_ptr, err_value, FUTEX2_SIZE_U32 | FUTEX_PRIVATE_FLAG | FUTEX2_NUMA);
132132
}
133133

134-
static void usage(char *prog)
134+
static void test_futex_mpol(void *futex_ptr, int err_value)
135135
{
136-
printf("Usage: %s\n", prog);
137-
printf(" -c Use color\n");
138-
printf(" -h Display this help message\n");
139-
printf(" -v L Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n",
140-
VQUIET, VCRITICAL, VINFO);
136+
__test_futex(futex_ptr, err_value, FUTEX2_SIZE_U32 | FUTEX_PRIVATE_FLAG | FUTEX2_NUMA | FUTEX2_MPOL);
141137
}
142138

143-
int main(int argc, char *argv[])
139+
TEST(futex_numa_mpol)
144140
{
145141
struct futex32_numa *futex_numa;
146-
int mem_size;
147142
void *futex_ptr;
148-
int c;
149-
150-
while ((c = getopt(argc, argv, "chv:")) != -1) {
151-
switch (c) {
152-
case 'c':
153-
log_color(1);
154-
break;
155-
case 'h':
156-
usage(basename(argv[0]));
157-
exit(0);
158-
break;
159-
case 'v':
160-
log_verbosity(atoi(optarg));
161-
break;
162-
default:
163-
usage(basename(argv[0]));
164-
exit(1);
165-
}
166-
}
167-
168-
ksft_print_header();
169-
ksft_set_plan(2);
143+
int mem_size;
170144

171145
mem_size = sysconf(_SC_PAGE_SIZE);
172146
futex_ptr = mmap(NULL, mem_size * 2, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
@@ -239,6 +213,7 @@ int main(int argc, char *argv[])
239213
#else
240214
ksft_test_result_skip("futex2 MPOL hints test requires libnuma 2.0.16+\n");
241215
#endif
242-
ksft_finished();
243-
return 0;
216+
munmap(futex_ptr, mem_size * 2);
244217
}
218+
219+
TEST_HARNESS_MAIN

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

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,6 @@
1818
#
1919
###############################################################################
2020

21-
# Test for a color capable console
22-
if [ -z "$USE_COLOR" ]; then
23-
tput setf 7 || tput setaf 7
24-
if [ $? -eq 0 ]; then
25-
USE_COLOR=1
26-
tput sgr0
27-
fi
28-
fi
29-
if [ "$USE_COLOR" -eq 1 ]; then
30-
COLOR="-c"
31-
fi
32-
33-
3421
echo
3522
./futex_requeue_pi
3623

@@ -63,4 +50,4 @@ echo
6350
./futex_priv_hash
6451

6552
echo
66-
./futex_numa_mpol $COLOR
53+
./futex_numa_mpol

0 commit comments

Comments
 (0)