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: get_robust_list01
22 *
23 * Test Description:
24 * Verify that get_robust_list() returns the proper errno for various failure
25 * cases
26 *
27 * Usage: <for command-line>
28 * get_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 <[email protected]>
38 * -Created
39 *
40 * Restrictions:
41 * None.
42 *
43 */
44
45 #include <sys/types.h>
46 #include <sys/syscall.h>
47
48 #include <errno.h>
49 #include <stdint.h>
50 #include <stdio.h>
51 #include <stdlib.h>
52
53 #include "test.h"
54 #include "safe_macros.h"
55 #include "lapi/syscalls.h"
56
57 char *TCID = "get_robust_list01";
58 int TST_TOTAL = 5;
59
60 struct robust_list {
61 struct robust_list *next;
62 };
63
64 struct robust_list_head {
65 struct robust_list list;
66 long futex_offset;
67 struct robust_list *list_op_pending;
68 };
69 static pid_t unused_pid;
70
71 void setup(void);
72 void cleanup(void);
73
main(int argc,char ** argv)74 int main(int argc, char **argv)
75 {
76 int lc;
77 struct robust_list_head head;
78 size_t len_ptr; /* size of structure struct robust_list_head */
79
80 tst_parse_opts(argc, argv, NULL, NULL);
81
82 setup();
83
84 len_ptr = sizeof(struct robust_list_head);
85
86 for (lc = 0; TEST_LOOPING(lc); ++lc) {
87 tst_count = 0;
88
89 /*
90 * The get_robust_list function fails with EFAULT if the size of the
91 * struct robust_list_head can't be stored in the memory address space
92 * specified by len_ptr argument, or the head of the robust list can't
93 * be stored in the memory address space specified by the head_ptr
94 * argument.
95 */
96
97 TEST(tst_syscall(__NR_get_robust_list, 0,
98 (struct robust_list_head *)&head,
99 NULL));
100
101 if (TEST_RETURN == -1) {
102 if (TEST_ERRNO == EFAULT)
103 tst_resm(TPASS,
104 "get_robust_list failed as expected with "
105 "EFAULT");
106 else
107 tst_resm(TFAIL | TTERRNO,
108 "get_robust_list failed unexpectedly");
109 } else
110 tst_resm(TFAIL,
111 "get_robust_list succeeded unexpectedly");
112
113 TEST(tst_syscall(__NR_get_robust_list, 0,
114 NULL,
115 &len_ptr));
116
117 if (TEST_RETURN) {
118 if (TEST_ERRNO == EFAULT)
119 tst_resm(TPASS,
120 "get_robust_list failed as expected with "
121 "EFAULT");
122 else
123 tst_resm(TFAIL | TTERRNO,
124 "get_robust_list failed unexpectedly");
125 } else
126 tst_resm(TFAIL,
127 "get_robust_list succeeded unexpectedly");
128
129 /*
130 * The get_robust_list function fails with ESRCH if it can't
131 * find the task specified by the pid argument.
132 */
133
134 TEST(tst_syscall(__NR_get_robust_list, unused_pid,
135 (struct robust_list_head *)&head,
136 &len_ptr));
137
138 if (TEST_RETURN == -1) {
139 if (TEST_ERRNO == ESRCH)
140 tst_resm(TPASS,
141 "get_robust_list failed as expected with "
142 "ESRCH");
143 else
144 tst_resm(TFAIL | TTERRNO,
145 "get_robust_list failed unexpectedly");
146 } else
147 tst_resm(TFAIL,
148 "get_robust_list succeeded unexpectedly");
149
150 TEST(tst_syscall(__NR_get_robust_list, 0,
151 (struct robust_list_head **)&head,
152 &len_ptr));
153
154 if (TEST_RETURN == 0)
155 tst_resm(TPASS, "get_robust_list succeeded");
156 else
157 tst_resm(TFAIL | TTERRNO,
158 "get_robust_list failed unexpectedly");
159
160 SAFE_SETUID(cleanup, 1);
161
162 TEST(tst_syscall(__NR_get_robust_list, 1,
163 (struct robust_list_head *)&head,
164 &len_ptr));
165
166 if (TEST_RETURN == -1) {
167 if (TEST_ERRNO == EPERM)
168 tst_resm(TPASS,
169 "get_robust_list failed as expected with "
170 "EPERM");
171 else
172 tst_resm(TFAIL | TERRNO,
173 "get_robust_list failed unexpectedly");
174 } else
175 tst_resm(TFAIL,
176 "get_robust_list succeeded unexpectedly");
177 }
178
179 cleanup();
180
181 tst_exit();
182 }
183
setup(void)184 void setup(void)
185 {
186 tst_require_root();
187
188 unused_pid = tst_get_unused_pid(cleanup);
189
190 TEST_PAUSE;
191 }
192
cleanup(void)193 void cleanup(void)
194 {
195 }
196