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