xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/futex/futex_wait05.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (C) 2015-2017 Cyril Hrubis <[email protected]>
4  */
5 
6 /*
7  * 1. Block on a futex and wait for timeout.
8  * 2. Check that the futex waited for expected time.
9  */
10 
11 #include <errno.h>
12 
13 #include "tst_timer_test.h"
14 #include "futextest.h"
15 
sample_fn(int clk_id,long long usec)16 int sample_fn(int clk_id, long long usec)
17 {
18 	struct timespec to = tst_timespec_from_us(usec);
19 	futex_t futex = FUTEX_INITIALIZER;
20 
21 	tst_timer_start(clk_id);
22 	TEST(syscall(SYS_futex, &futex, FUTEX_WAIT, futex, &to, NULL, 0));
23 	tst_timer_stop();
24 	tst_timer_sample();
25 
26 	if (TST_RET != -1) {
27 		tst_res(TFAIL, "futex_wait() returned %li, expected -1",
28 			TST_RET);
29 		return 1;
30 	}
31 
32 	if (TST_ERR != ETIMEDOUT) {
33 		tst_res(TFAIL | TTERRNO, "expected errno=%s",
34 		        tst_strerrno(ETIMEDOUT));
35 		return 1;
36 	}
37 
38 	return 0;
39 }
40 
41 static struct tst_test test = {
42 	.scall = "futex_wait()",
43 	.sample = sample_fn,
44 };
45