1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2015 Cyril Hrubis <[email protected]>
4 *
5 * futex_wake() returns 0 (0 woken up processes) when no processes wait on the mutex.
6 */
7
8 #include <limits.h>
9
10 #include "futextest.h"
11
12 struct testcase {
13 futex_t *f_addr;
14 int nr_wake;
15 int opflags;
16 };
17
18 static futex_t futex = FUTEX_INITIALIZER;
19
20 static struct testcase testcases[] = {
21 /* nr_wake = 0 is noop */
22 {&futex, 0, 0},
23 {&futex, 0, FUTEX_PRIVATE_FLAG},
24 {&futex, 1, 0},
25 {&futex, 1, FUTEX_PRIVATE_FLAG},
26 {&futex, INT_MAX, 0},
27 {&futex, INT_MAX, FUTEX_PRIVATE_FLAG},
28 };
29
30 static struct futex_test_variants variants[] = {
31 #if (__NR_futex != __LTP__NR_INVALID_SYSCALL)
32 { .fntype = FUTEX_FN_FUTEX, .desc = "syscall with old kernel spec"},
33 #endif
34
35 #if (__NR_futex_time64 != __LTP__NR_INVALID_SYSCALL)
36 { .fntype = FUTEX_FN_FUTEX64, .desc = "syscall time64 with kernel spec"},
37 #endif
38 };
39
run(unsigned int n)40 static void run(unsigned int n)
41 {
42 struct futex_test_variants *tv = &variants[tst_variant];
43 struct testcase *tc = &testcases[n];
44 int res;
45
46 res = futex_wake(tv->fntype, tc->f_addr, tc->nr_wake, tc->opflags);
47 if (res != 0) {
48 tst_res(TFAIL | TERRNO, "futex_wake() failed");
49 return;
50 }
51
52 tst_res(TPASS, "futex_wake() passed");
53 }
54
setup(void)55 static void setup(void)
56 {
57 struct futex_test_variants *tv = &variants[tst_variant];
58
59 tst_res(TINFO, "Testing variant: %s", tv->desc);
60 futex_supported_by_kernel(tv->fntype);
61 }
62
63 static struct tst_test test = {
64 .setup = setup,
65 .test = run,
66 .tcnt = ARRAY_SIZE(testcases),
67 .test_variants = ARRAY_SIZE(variants),
68 };
69