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 * Block on a futex and wait for wakeup. 21 * 22 * This tests uses private mutexes with threads. 23 */ 24 25 #include <errno.h> 26 #include <pthread.h> 27 28 #include "test.h" 29 #include "futextest.h" 30 31 const char *TCID="futex_wait03"; 32 const int TST_TOTAL=1; 33 34 static futex_t futex = FUTEX_INITIALIZER; 35 36 static void *threaded(void *arg LTP_ATTRIBUTE_UNUSED) 37 { 38 long ret; 39 40 tst_process_state_wait2(getpid(), 'S'); 41 42 ret = futex_wake(&futex, 1, FUTEX_PRIVATE_FLAG); 43 44 return (void*)ret; 45 } 46 47 static void verify_futex_wait(void) 48 { 49 long ret; 50 int res; 51 pthread_t t; 52 53 res = pthread_create(&t, NULL, threaded, NULL); 54 if (res) { 55 tst_brkm(TBROK, NULL, "pthread_create(): %s", 56 tst_strerrno(res)); 57 } 58 59 res = futex_wait(&futex, futex, NULL, FUTEX_PRIVATE_FLAG); 60 if (res) { 61 tst_resm(TFAIL, "futex_wait() returned %i, errno %s", 62 res, tst_strerrno(errno)); 63 pthread_join(t, NULL); 64 return; 65 } 66 67 res = pthread_join(t, (void*)&ret); 68 if (res) 69 tst_brkm(TBROK, NULL, "pthread_join(): %s", tst_strerrno(res)); 70 71 if (ret != 1) 72 tst_resm(TFAIL, "futex_wake() returned %li", ret); 73 else 74 tst_resm(TPASS, "futex_wait() woken up"); 75 } 76 77 int main(int argc, char *argv[]) 78 { 79 int lc; 80 81 tst_parse_opts(argc, argv, NULL, NULL); 82 83 for (lc = 0; TEST_LOOPING(lc); lc++) 84 verify_futex_wait(); 85 86 tst_exit(); 87 } 88