1 /* 2 * Copyright (C) 2015 Cyril Hrubis <chrubis (at) suse.cz> 3 * 4 * Based on futextest (futext_wait_timeout.c and futex_wait_ewouldblock.c) 5 * written by Darren Hart <dvhltc (at) us.ibm.com> 6 * Gowrishankar <gowrishankar.m (at) in.ibm.com> 7 * 8 * Licensed under the GNU GPLv2 or later. 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 2 of the License, or 12 * (at your option) any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 17 * the GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 22 */ 23 /* 24 * 1. Block on a futex and wait for timeout. 25 * 2. Test if FUTEX_WAIT op returns -EWOULDBLOCK if the futex value differs 26 * from the expected one. 27 */ 28 29 #include <errno.h> 30 31 #include "test.h" 32 #include "futextest.h" 33 34 const char *TCID="futex_wait01"; 35 36 struct testcase { 37 futex_t *f_addr; 38 futex_t f_val; 39 int opflags; 40 int exp_errno; 41 }; 42 43 static futex_t futex = FUTEX_INITIALIZER; 44 static struct timespec to = {.tv_sec = 0, .tv_nsec = 10000}; 45 46 static struct testcase testcases[] = { 47 {&futex, FUTEX_INITIALIZER, 0, ETIMEDOUT}, 48 {&futex, FUTEX_INITIALIZER+1, 0, EWOULDBLOCK}, 49 {&futex, FUTEX_INITIALIZER, FUTEX_PRIVATE_FLAG, ETIMEDOUT}, 50 {&futex, FUTEX_INITIALIZER+1, FUTEX_PRIVATE_FLAG, EWOULDBLOCK}, 51 }; 52 53 const int TST_TOTAL=ARRAY_SIZE(testcases); 54 55 static void verify_futex_wait(struct testcase *tc) 56 { 57 int res; 58 59 res = futex_wait(tc->f_addr, tc->f_val, &to, tc->opflags); 60 61 if (res != -1) { 62 tst_resm(TFAIL, "futex_wait() returned %i, expected -1", res); 63 return; 64 } 65 66 if (errno != tc->exp_errno) { 67 tst_resm(TFAIL | TERRNO, "expected errno=%s", 68 tst_strerrno(tc->exp_errno)); 69 return; 70 } 71 72 tst_resm(TPASS | TERRNO, "futex_wait()"); 73 } 74 75 int main(int argc, char *argv[]) 76 { 77 int lc, i; 78 79 tst_parse_opts(argc, argv, NULL, NULL); 80 81 for (lc = 0; TEST_LOOPING(lc); lc++) { 82 for (i = 0; i < TST_TOTAL; i++) 83 verify_futex_wait(testcases + i); 84 } 85 86 tst_exit(); 87 } 88