• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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   * Block on a futex and wait for wakeup.
21   *
22   * This tests uses shared memory page to store the mutex variable.
23   */
24 
25 #include <sys/mman.h>
26 #include <sys/wait.h>
27 #include <errno.h>
28 
29 #include "test.h"
30 #include "safe_macros.h"
31 #include "futextest.h"
32 #include "futex_common.h"
33 
34 const char *TCID="futex_wait02";
35 const int TST_TOTAL=1;
36 
do_child(void)37 static void do_child(void)
38 {
39 	int ret;
40 
41 	tst_process_state_wait2(getppid(), 'S');
42 
43 	ret = futex_wake(futex, 1, 0);
44 
45 	if (ret != 1)
46 		tst_brkm(TFAIL, NULL, "futex_wake() returned %i", ret);
47 
48 	exit(TPASS);
49 }
50 
verify_futex_wait(void)51 static void verify_futex_wait(void)
52 {
53 	int res;
54 	int pid;
55 
56 	pid = tst_fork();
57 
58 	switch (pid) {
59 	case 0:
60 		do_child();
61 	break;
62 	case -1:
63 		tst_brkm(TBROK | TERRNO, NULL, "fork() failed");
64 	break;
65 	default:
66 	break;
67 	}
68 
69 	res = futex_wait(futex, *futex, NULL, 0);
70 
71 	if (res) {
72 		tst_resm(TFAIL, "futex_wait() returned %i, errno %s",
73 		         res, tst_strerrno(errno));
74 	}
75 
76 	SAFE_WAIT(NULL, &res);
77 
78 	if (WIFEXITED(res) && WEXITSTATUS(res) == TPASS)
79 		tst_resm(TPASS, "futex_wait() woken up");
80 	else
81 		tst_resm(TFAIL, "child failed");
82 }
83 
main(int argc,char * argv[])84 int main(int argc, char *argv[])
85 {
86 	int lc;
87 
88 	tst_parse_opts(argc, argv, NULL, NULL);
89 
90 	setup();
91 
92 	for (lc = 0; TEST_LOOPING(lc); lc++)
93 		verify_futex_wait();
94 
95 	tst_exit();
96 }
97