1 /* 2 * Copyright (C) 2015 Cyril Hrubis <chrubis (at) 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 * futex_wake() returns 0 (0 woken up processes) when no processes wait on the mutex. 21 */ 22 23 #include <errno.h> 24 25 #include "test.h" 26 #include "futextest.h" 27 28 const char *TCID="futex_wake01"; 29 30 struct testcase { 31 futex_t *f_addr; 32 int nr_wake; 33 int opflags; 34 }; 35 36 static futex_t futex = FUTEX_INITIALIZER; 37 38 static struct testcase testcases[] = { 39 /* nr_wake = 0 is noop */ 40 {&futex, 0, 0}, 41 {&futex, 0, FUTEX_PRIVATE_FLAG}, 42 {&futex, 1, 0}, 43 {&futex, 1, FUTEX_PRIVATE_FLAG}, 44 {&futex, INT_MAX, 0}, 45 {&futex, INT_MAX, FUTEX_PRIVATE_FLAG}, 46 }; 47 48 const int TST_TOTAL=ARRAY_SIZE(testcases); 49 50 static void verify_futex_wake(struct testcase *tc) 51 { 52 int res; 53 54 res = futex_wake(tc->f_addr, tc->nr_wake, tc->opflags); 55 56 if (res != 0) { 57 tst_resm(TFAIL, "futex_wake() returned %i, expected 0", res); 58 return; 59 } 60 61 tst_resm(TPASS, "futex_wake() returned 0"); 62 } 63 64 int main(int argc, char *argv[]) 65 { 66 int lc, i; 67 68 tst_parse_opts(argc, argv, NULL, NULL); 69 70 for (lc = 0; TEST_LOOPING(lc); lc++) { 71 for (i = 0; i < TST_TOTAL; i++) 72 verify_futex_wake(testcases + i); 73 } 74 75 tst_exit(); 76 } 77