1 /*
2 * Copyright (C) 2015 Cyril Hrubis <chrubis@suse.cz>
3 *
4 * Licensed under the GNU GPLv2 or later.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #define TRESHOLD_US 100000
21
verify_futex_wait_bitset(long long wait_us,clock_t clk_id)22 static void verify_futex_wait_bitset(long long wait_us, clock_t clk_id)
23 {
24 struct timespec start, to, end;
25 futex_t futex = FUTEX_INITIALIZER;
26 u_int32_t bitset = 0xffffffff;
27 int flags = clk_id == CLOCK_REALTIME ? FUTEX_CLOCK_REALTIME : 0;
28
29 tst_resm(TINFO, "testing futex_wait_bitset() timeout with %s",
30 clk_id == CLOCK_REALTIME ? "CLOCK_REALTIME" : "CLOCK_MONOTONIC");
31
32 clock_gettime(clk_id, &start);
33 to = tst_timespec_add_us(start, wait_us);
34
35 TEST(futex_wait_bitset(&futex, futex, &to, bitset, flags));
36
37 clock_gettime(clk_id, &end);
38
39 if (TEST_RETURN != -1) {
40 tst_resm(TFAIL, "futex_wait_bitset() returned %li, expected -1",
41 TEST_RETURN);
42 return;
43 }
44
45 if (TEST_ERRNO == ENOSYS) {
46 tst_resm(TCONF, "In this kernel, futex() does not support "
47 "FUTEX_WAIT_BITSET operation");
48 return;
49 }
50
51 if (TEST_ERRNO != ETIMEDOUT) {
52 tst_resm(TFAIL | TTERRNO, "expected %s",
53 tst_strerrno(ETIMEDOUT));
54 return;
55 }
56
57 if (tst_timespec_lt(end, to)) {
58 tst_resm(TFAIL,
59 "futex_wait_bitset() woken up prematurely %llius, expected %llius",
60 tst_timespec_diff_us(end, start), wait_us);
61 return;
62 }
63
64 if (tst_timespec_diff_us(end, to) > TRESHOLD_US) {
65 tst_resm(TFAIL,
66 "futex_wait_bitset() waited too long %llius, expected %llius",
67 tst_timespec_diff_us(end, start), wait_us);
68 return;
69 }
70
71 tst_resm(TPASS, "futex_wait_bitset() waited %llius, expected %llius",
72 tst_timespec_diff_us(end, start), wait_us);
73 }
74