Skip to content

Commit 4ba629e

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

2 files changed

Lines changed: 8 additions & 42 deletions

File tree

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

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <linux/prctl.h>
1515
#include <sys/prctl.h>
1616

17-
#include "logging.h"
17+
#include "../../kselftest_harness.h"
1818

1919
#define MAX_THREADS 64
2020

@@ -128,45 +128,14 @@ static void futex_dummy_op(void)
128128
ksft_exit_fail_msg("pthread_mutex_timedlock() did not timeout: %d.\n", ret);
129129
}
130130

131-
static void usage(char *prog)
132-
{
133-
printf("Usage: %s\n", prog);
134-
printf(" -c Use color\n");
135-
printf(" -h Display this help message\n");
136-
printf(" -v L Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n",
137-
VQUIET, VCRITICAL, VINFO);
138-
}
139-
140131
static const char *test_msg_auto_create = "Automatic hash bucket init on thread creation.\n";
141132
static const char *test_msg_auto_inc = "Automatic increase with more than 16 CPUs\n";
142133

143-
int main(int argc, char *argv[])
134+
TEST(priv_hash)
144135
{
145136
int futex_slots1, futex_slotsn, online_cpus;
146137
pthread_mutexattr_t mutex_attr_pi;
147138
int ret, retry = 20;
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(21);
170139

171140
ret = pthread_mutexattr_init(&mutex_attr_pi);
172141
ret |= pthread_mutexattr_setprotocol(&mutex_attr_pi, PTHREAD_PRIO_INHERIT);
@@ -279,7 +248,7 @@ int main(int argc, char *argv[])
279248
ret = futex_hash_slots_set(0);
280249
ksft_test_result(ret == 0, "Global hash request\n");
281250
if (ret != 0)
282-
goto out;
251+
return;
283252

284253
futex_hash_slots_set_must_fail(4);
285254
futex_hash_slots_set_must_fail(8);
@@ -288,17 +257,14 @@ int main(int argc, char *argv[])
288257
futex_hash_slots_set_must_fail(6);
289258

290259
ret = pthread_barrier_init(&barrier_main, NULL, MAX_THREADS);
291-
if (ret != 0) {
260+
if (ret != 0)
292261
ksft_exit_fail_msg("pthread_barrier_init failed: %m\n");
293-
return 1;
294-
}
262+
295263
create_max_threads(thread_lock_fn);
296264
join_max_threads();
297265

298266
ret = futex_hash_slots_get();
299267
ksft_test_result(ret == 0, "Continue to use global hash\n");
300-
301-
out:
302-
ksft_finished();
303-
return 0;
304268
}
269+
270+
TEST_HARNESS_MAIN

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ echo
6060
./futex_waitv
6161

6262
echo
63-
./futex_priv_hash $COLOR
63+
./futex_priv_hash
6464

6565
echo
6666
./futex_numa_mpol $COLOR

0 commit comments

Comments
 (0)