1 /*
2 *
3 * Copyright (c) International Business Machines Corp., 2001
4 *
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 /*
21 * Test Name: set_robust_list01
22 *
23 * Test Description:
24 * Verify that set_robust_list() returns the proper errno for various failure
25 * cases
26 *
27 * Usage: <for command-line>
28 * set_robust_list01 [-c n] [-e][-i n] [-I x] [-p x] [-t]
29 * where, -c n : Run n copies concurrently.
30 * -e : Turn on errno logging.
31 * -i n : Execute test n times.
32 * -I x : Execute test for x seconds.
33 * -P x : Pause for x seconds between iterations.
34 * -t : Turn on syscall timing.
35 *
36 * History
37 * 07/2008 Ramon de Carvalho Valle <rcvalle@br.ibm.com>
38 * -Created
39 *
40 * Restrictions:
41 * None.
42 *
43 */
44
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <errno.h>
48
49 #include <sys/syscall.h>
50 #include <sys/types.h>
51
52 #ifdef __NR_set_robust_list
53 #ifndef __user
54 #define __user
55 #endif
56
57 struct robust_list {
58 struct robust_list __user *next;
59 };
60
61 struct robust_list_head {
62 struct robust_list list;
63 long futex_offset;
64 struct robust_list __user *list_op_pending;
65 };
66 #endif
67
68 #include "test.h"
69
70 char *TCID = "set_robust_list01";
71 int TST_TOTAL = 2;
72
73 void setup(void);
74 void cleanup(void);
75
main(int argc,char ** argv)76 int main(int argc, char **argv)
77 {
78 #ifdef __NR_set_robust_list
79 int lc;
80 #endif
81 #ifdef __NR_set_robust_list
82 struct robust_list_head head;
83 size_t len; /* size of structure struct robust_list_head */
84 int retval;
85 #endif
86
87 tst_parse_opts(argc, argv, NULL, NULL);
88
89 setup();
90
91 #ifdef __NR_set_robust_list
92
93 len = sizeof(struct robust_list_head);
94
95 for (lc = 0; TEST_LOOPING(lc); ++lc) {
96 tst_count = 0;
97
98 /*
99 * The set_robust_list function fails with EINVAL if the len argument
100 * doesn't match the size of structure struct robust_list_head.
101 */
102
103 TEST(retval = syscall(__NR_set_robust_list, &head, -1));
104
105 if (TEST_RETURN) {
106 if (TEST_ERRNO == EINVAL)
107 tst_resm(TPASS,
108 "set_robust_list: retval = %ld (expected %d), "
109 "errno = %d (expected %d)",
110 TEST_RETURN, -1, TEST_ERRNO, EINVAL);
111 else
112 tst_resm(TFAIL,
113 "set_robust_list: retval = %ld (expected %d), "
114 "errno = %d (expected %d)",
115 TEST_RETURN, -1, TEST_ERRNO, EINVAL);
116 } else {
117 tst_resm(TFAIL,
118 "set_robust_list: retval = %ld (expected %d), "
119 "errno = %d (expected %d)", TEST_RETURN, -1,
120 TEST_ERRNO, EINVAL);
121 }
122
123 /*
124 * This call to set_robust_list function should be sucessful.
125 */
126
127 TEST(retval = syscall(__NR_set_robust_list, &head, len));
128
129 if (TEST_RETURN == 0) {
130 tst_resm(TPASS,
131 "set_robust_list: retval = %ld (expected %d), "
132 "errno = %d (expected %d)", TEST_RETURN, 0,
133 TEST_ERRNO, 0);
134 } else {
135 tst_resm(TFAIL,
136 "set_robust_list: retval = %ld (expected %d), "
137 "errno = %d (expected %d)", TEST_RETURN, 0,
138 TEST_ERRNO, 0);
139 }
140
141 }
142
143 #else
144
145 tst_resm(TCONF, "set_robust_list: system call not available.");
146
147 #endif
148
149 cleanup();
150
151 exit(EXIT_SUCCESS);
152 }
153
setup(void)154 void setup(void)
155 {
156 TEST_PAUSE;
157 }
158
cleanup(void)159 void cleanup(void)
160 {
161 }
162