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