drm/panel: panel-himax-hx83102: support for csot-pna957qt1-1 MIPI-DSI panel
[drm/drm-misc.git] / tools / testing / selftests / futex / functional / futex_requeue.c
blob51485be6eb2f1be6d0e30bc26c116515a0e5e7cc
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright Collabora Ltd., 2021
5 * futex cmp requeue test by André Almeida <andrealmeid@collabora.com>
6 */
8 #include <pthread.h>
9 #include <limits.h>
10 #include "logging.h"
11 #include "futextest.h"
13 #define TEST_NAME "futex-requeue"
14 #define timeout_ns 30000000
15 #define WAKE_WAIT_US 10000
17 volatile futex_t *f1;
19 void usage(char *prog)
21 printf("Usage: %s\n", prog);
22 printf(" -c Use color\n");
23 printf(" -h Display this help message\n");
24 printf(" -v L Verbosity level: %d=QUIET %d=CRITICAL %d=INFO\n",
25 VQUIET, VCRITICAL, VINFO);
28 void *waiterfn(void *arg)
30 struct timespec to;
32 to.tv_sec = 0;
33 to.tv_nsec = timeout_ns;
35 if (futex_wait(f1, *f1, &to, 0))
36 printf("waiter failed errno %d\n", errno);
38 return NULL;
41 int main(int argc, char *argv[])
43 pthread_t waiter[10];
44 int res, ret = RET_PASS;
45 int c, i;
46 volatile futex_t _f1 = 0;
47 volatile futex_t f2 = 0;
49 f1 = &_f1;
51 while ((c = getopt(argc, argv, "cht:v:")) != -1) {
52 switch (c) {
53 case 'c':
54 log_color(1);
55 break;
56 case 'h':
57 usage(basename(argv[0]));
58 exit(0);
59 case 'v':
60 log_verbosity(atoi(optarg));
61 break;
62 default:
63 usage(basename(argv[0]));
64 exit(1);
68 ksft_print_header();
69 ksft_set_plan(2);
70 ksft_print_msg("%s: Test futex_requeue\n",
71 basename(argv[0]));
74 * Requeue a waiter from f1 to f2, and wake f2.
76 if (pthread_create(&waiter[0], NULL, waiterfn, NULL))
77 error("pthread_create failed\n", errno);
79 usleep(WAKE_WAIT_US);
81 info("Requeuing 1 futex from f1 to f2\n");
82 res = futex_cmp_requeue(f1, 0, &f2, 0, 1, 0);
83 if (res != 1) {
84 ksft_test_result_fail("futex_requeue simple returned: %d %s\n",
85 res ? errno : res,
86 res ? strerror(errno) : "");
87 ret = RET_FAIL;
91 info("Waking 1 futex at f2\n");
92 res = futex_wake(&f2, 1, 0);
93 if (res != 1) {
94 ksft_test_result_fail("futex_requeue simple returned: %d %s\n",
95 res ? errno : res,
96 res ? strerror(errno) : "");
97 ret = RET_FAIL;
98 } else {
99 ksft_test_result_pass("futex_requeue simple succeeds\n");
104 * Create 10 waiters at f1. At futex_requeue, wake 3 and requeue 7.
105 * At futex_wake, wake INT_MAX (should be exactly 7).
107 for (i = 0; i < 10; i++) {
108 if (pthread_create(&waiter[i], NULL, waiterfn, NULL))
109 error("pthread_create failed\n", errno);
112 usleep(WAKE_WAIT_US);
114 info("Waking 3 futexes at f1 and requeuing 7 futexes from f1 to f2\n");
115 res = futex_cmp_requeue(f1, 0, &f2, 3, 7, 0);
116 if (res != 10) {
117 ksft_test_result_fail("futex_requeue many returned: %d %s\n",
118 res ? errno : res,
119 res ? strerror(errno) : "");
120 ret = RET_FAIL;
123 info("Waking INT_MAX futexes at f2\n");
124 res = futex_wake(&f2, INT_MAX, 0);
125 if (res != 7) {
126 ksft_test_result_fail("futex_requeue many returned: %d %s\n",
127 res ? errno : res,
128 res ? strerror(errno) : "");
129 ret = RET_FAIL;
130 } else {
131 ksft_test_result_pass("futex_requeue many succeeds\n");
134 ksft_print_cnts();
135 return ret;