]>
Commit | Line | Data |
---|---|---|
61eb22d3 UD |
1 | #! /bin/sh |
2 | ||
3 | common_objpfx=$1; shift | |
dfd2257a UD |
4 | elf_objpfx=$1; shift |
5 | rtld_installed_name=$1; shift | |
61eb22d3 | 6 | |
c277d2e5 UD |
7 | # We have to make the paths `common_objpfx' absolute. |
8 | case "$common_objpfx" in | |
9 | .*) | |
10 | common_objpfx="`pwd`/$common_objpfx" | |
11 | ;; | |
12 | *) | |
13 | ;; | |
14 | esac | |
15 | ||
c9243dac | 16 | # We have to find the libc and the NSS modules. |
c277d2e5 | 17 | library_path=${common_objpfx}:${common_objpfx}nss:${common_objpfx}nis:${common_objpfx}db2:${common_objpfx}hesiod |
c9243dac | 18 | |
7ce241a0 | 19 | # Since we use `sort' we must make sure to use the same locale everywhere. |
3f62b69a UD |
20 | LC_ALL=C |
21 | export LC_ALL | |
22 | LANG=C | |
23 | export LANG | |
24 | ||
61eb22d3 UD |
25 | # Create the arena |
26 | : ${TMPDIR=/tmp} | |
27 | testdir=$TMPDIR/globtest-dir | |
28 | testout=$TMPDIR/globtest-out | |
29 | ||
460adbb8 | 30 | trap 'chmod 777 $testdir/noread; rm -fr $testdir $testout' 1 2 3 15 |
61eb22d3 | 31 | |
460adbb8 | 32 | rm -fr $testdir 2>/dev/null |
61eb22d3 UD |
33 | mkdir $testdir |
34 | echo 1 > $testdir/file1 | |
35 | echo 2 > $testdir/file2 | |
3f62b69a UD |
36 | echo 3 > $testdir/-file3 |
37 | echo 4 > $testdir/~file4 | |
38 | echo 5 > $testdir/.file5 | |
39 | echo 6 > $testdir/'*file6' | |
61eb22d3 UD |
40 | mkdir $testdir/dir1 |
41 | mkdir $testdir/dir2 | |
460adbb8 UD |
42 | test -d $testdir/noread || mkdir $testdir/noread |
43 | chmod a-r $testdir/noread | |
61eb22d3 UD |
44 | echo 1_1 > $testdir/dir1/file1_1 |
45 | echo 1_2 > $testdir/dir1/file1_2 | |
46 | ||
47 | # Run some tests. | |
48 | result=0 | |
61eb22d3 | 49 | |
3f62b69a | 50 | # Normal test |
c9243dac | 51 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ |
14e9dd67 | 52 | ${common_objpfx}posix/globtest "$testdir" "*" | |
61eb22d3 UD |
53 | sort > $testout |
54 | cat <<"EOF" | cmp - $testout || result=1 | |
3f62b69a UD |
55 | `*file6' |
56 | `-file3' | |
57 | `dir1' | |
58 | `dir2' | |
59 | `file1' | |
60 | `file2' | |
460adbb8 | 61 | `noread' |
3f62b69a UD |
62 | `~file4' |
63 | EOF | |
64 | ||
65 | # Don't let glob sort it | |
c9243dac | 66 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ |
3f62b69a UD |
67 | ${common_objpfx}posix/globtest -s "$testdir" "*" | |
68 | sort > $testout | |
69 | cat <<"EOF" | cmp - $testout || result=1 | |
70 | `*file6' | |
71 | `-file3' | |
72 | `dir1' | |
73 | `dir2' | |
74 | `file1' | |
75 | `file2' | |
460adbb8 | 76 | `noread' |
3f62b69a UD |
77 | `~file4' |
78 | EOF | |
79 | ||
80 | # Mark directories | |
c9243dac | 81 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ |
3f62b69a UD |
82 | ${common_objpfx}posix/globtest -m "$testdir" "*" | |
83 | sort > $testout | |
84 | cat <<"EOF" | cmp - $testout || result=1 | |
85 | `*file6' | |
86 | `-file3' | |
87 | `dir1/' | |
88 | `dir2/' | |
89 | `file1' | |
90 | `file2' | |
460adbb8 | 91 | `noread/' |
3f62b69a UD |
92 | `~file4' |
93 | EOF | |
94 | ||
95 | # Find files starting with . | |
c9243dac | 96 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ |
3f62b69a UD |
97 | ${common_objpfx}posix/globtest -p "$testdir" "*" | |
98 | sort > $testout | |
99 | cat <<"EOF" | cmp - $testout || result=1 | |
100 | `*file6' | |
101 | `-file3' | |
102 | `.' | |
103 | `..' | |
104 | `.file5' | |
61eb22d3 UD |
105 | `dir1' |
106 | `dir2' | |
107 | `file1' | |
108 | `file2' | |
460adbb8 | 109 | `noread' |
3f62b69a UD |
110 | `~file4' |
111 | EOF | |
112 | ||
113 | # Test braces | |
c9243dac | 114 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ |
3f62b69a UD |
115 | ${common_objpfx}posix/globtest -b "$testdir" "file{1,2}" | |
116 | sort > $testout | |
117 | cat <<"EOF" | cmp - $testout || result=1 | |
118 | `file1' | |
119 | `file2' | |
120 | EOF | |
121 | ||
122 | # Test NOCHECK | |
c9243dac | 123 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ |
3f62b69a UD |
124 | ${common_objpfx}posix/globtest -c "$testdir" "abc" | |
125 | sort > $testout | |
126 | cat <<"EOF" | cmp - $testout || result=1 | |
127 | `abc' | |
61eb22d3 UD |
128 | EOF |
129 | ||
3f62b69a | 130 | # Test NOMAGIC without magic characters |
c9243dac | 131 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ |
3f62b69a UD |
132 | ${common_objpfx}posix/globtest -g "$testdir" "abc" | |
133 | sort > $testout | |
134 | cat <<"EOF" | cmp - $testout || result=1 | |
135 | `abc' | |
136 | EOF | |
137 | ||
138 | # Test NOMAGIC with magic characters | |
c9243dac | 139 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ |
3f62b69a UD |
140 | ${common_objpfx}posix/globtest -g "$testdir" "abc*" | |
141 | sort > $testout | |
142 | cat <<"EOF" | cmp - $testout || result=1 | |
143 | GLOB_NOMATCH | |
144 | EOF | |
145 | ||
146 | # Test subdirs correctly | |
c9243dac | 147 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ |
14e9dd67 | 148 | ${common_objpfx}posix/globtest "$testdir" "*/*" | |
61eb22d3 UD |
149 | sort > $testout |
150 | cat <<"EOF" | cmp - $testout || result=1 | |
151 | `dir1/file1_1' | |
152 | `dir1/file1_2' | |
61eb22d3 UD |
153 | EOF |
154 | ||
3f62b69a | 155 | # Test subdirs for invalid names |
c9243dac | 156 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ |
14e9dd67 | 157 | ${common_objpfx}posix/globtest "$testdir" "*/1" | |
61eb22d3 UD |
158 | sort > $testout |
159 | cat <<"EOF" | cmp - $testout || result=1 | |
160 | GLOB_NOMATCH | |
61eb22d3 UD |
161 | EOF |
162 | ||
3f62b69a | 163 | # Test subdirs with wildcard |
c9243dac | 164 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ |
14e9dd67 | 165 | ${common_objpfx}posix/globtest "$testdir" "*/*1_1" | |
61eb22d3 UD |
166 | sort > $testout |
167 | cat <<"EOF" | cmp - $testout || result=1 | |
168 | `dir1/file1_1' | |
3f62b69a UD |
169 | EOF |
170 | ||
171 | # Test subdirs with ? | |
c9243dac | 172 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ |
3f62b69a UD |
173 | ${common_objpfx}posix/globtest "$testdir" "*/*?_?" | |
174 | sort > $testout | |
175 | cat <<"EOF" | cmp - $testout || result=1 | |
176 | `dir1/file1_1' | |
177 | `dir1/file1_2' | |
61eb22d3 UD |
178 | EOF |
179 | ||
c9243dac | 180 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ |
14e9dd67 | 181 | ${common_objpfx}posix/globtest "$testdir" "*/file1_1" | |
61eb22d3 UD |
182 | sort > $testout |
183 | cat <<"EOF" | cmp - $testout || result=1 | |
184 | `dir1/file1_1' | |
61eb22d3 UD |
185 | EOF |
186 | ||
c9243dac | 187 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ |
14e9dd67 | 188 | ${common_objpfx}posix/globtest "$testdir" "*-/*" | |
61eb22d3 UD |
189 | sort > $testout |
190 | cat <<"EOF" | cmp - $testout || result=1 | |
191 | GLOB_NOMATCH | |
61eb22d3 UD |
192 | EOF |
193 | ||
c9243dac | 194 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ |
14e9dd67 | 195 | ${common_objpfx}posix/globtest "$testdir" "*-" | |
61eb22d3 UD |
196 | sort > $testout |
197 | cat <<"EOF" | cmp - $testout || result=1 | |
198 | GLOB_NOMATCH | |
3f62b69a UD |
199 | EOF |
200 | ||
201 | # Test subdirs with ? | |
c9243dac | 202 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ |
3f62b69a UD |
203 | ${common_objpfx}posix/globtest "$testdir" "*/*?_?" | |
204 | sort > $testout | |
205 | cat <<"EOF" | cmp - $testout || result=1 | |
206 | `dir1/file1_1' | |
207 | `dir1/file1_2' | |
208 | EOF | |
209 | ||
460adbb8 UD |
210 | # Test subdirs with [ .. ] |
211 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ | |
212 | ${common_objpfx}posix/globtest "$testdir" "*/file1_[12]" | | |
213 | sort > $testout | |
214 | cat <<"EOF" | cmp - $testout || result=1 | |
215 | `dir1/file1_1' | |
216 | `dir1/file1_2' | |
217 | EOF | |
218 | ||
219 | # Test ']' inside bracket expression | |
220 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ | |
221 | ${common_objpfx}posix/globtest "$testdir" "dir1/file1_[]12]" | | |
222 | sort > $testout | |
223 | cat <<"EOF" | cmp - $testout || result=1 | |
224 | `dir1/file1_1' | |
225 | `dir1/file1_2' | |
226 | EOF | |
227 | ||
3f62b69a | 228 | # Test tilde expansion |
c9243dac UD |
229 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ |
230 | ${common_objpfx}posix/globtest -q -t "$testdir" "~" | | |
231 | sort >$testout | |
7ce241a0 | 232 | echo ~ | cmp - $testout || result=1 |
3f62b69a UD |
233 | |
234 | # Test tilde expansion with trailing slash | |
c9243dac UD |
235 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ |
236 | ${common_objpfx}posix/globtest -q -t "$testdir" "~/" | | |
237 | sort > $testout | |
7ce241a0 | 238 | echo ~/ | cmp - $testout || result=1 |
3f62b69a UD |
239 | |
240 | # Test tilde expansion with username | |
c9243dac UD |
241 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ |
242 | ${common_objpfx}posix/globtest -q -t "$testdir" "~"$USER | | |
243 | sort > $testout | |
7ce241a0 | 244 | eval echo ~$USER | cmp - $testout || result=1 |
3f62b69a UD |
245 | |
246 | # Tilde expansion shouldn't match a file | |
1bc21e7a UD |
247 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ |
248 | ${common_objpfx}posix/globtest -T "$testdir" "~file4" | | |
249 | sort > $testout | |
250 | cat <<"EOF" | cmp - $testout || result=1 | |
251 | GLOB_NOMATCH | |
252 | EOF | |
3f62b69a UD |
253 | |
254 | # Matching \** should only find *file6 | |
c9243dac | 255 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ |
3f62b69a UD |
256 | ${common_objpfx}posix/globtest "$testdir" "\**" | |
257 | sort > $testout | |
258 | cat <<"EOF" | cmp - $testout || result=1 | |
259 | `*file6' | |
260 | EOF | |
261 | ||
262 | # ... unless NOESCAPE is used, in which case it shouldn't match anything. | |
c9243dac | 263 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ |
3f62b69a UD |
264 | ${common_objpfx}posix/globtest -e "$testdir" "\**" | |
265 | sort > $testout | |
266 | cat <<"EOF" | cmp - $testout || result=1 | |
267 | GLOB_NOMATCH | |
268 | EOF | |
269 | ||
460adbb8 UD |
270 | # Matching \*file6 should find *file6 |
271 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ | |
272 | ${common_objpfx}posix/globtest "$testdir" "\*file6" | | |
273 | sort > $testout | |
274 | cat <<"EOF" | cmp - $testout || result=1 | |
275 | `*file6' | |
276 | EOF | |
277 | ||
3f62b69a | 278 | # Try a recursive failed search |
c9243dac | 279 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ |
3f62b69a UD |
280 | ${common_objpfx}posix/globtest -e "$testdir" "a*/*" | |
281 | sort > $testout | |
282 | cat <<"EOF" | cmp - $testout || result=1 | |
283 | GLOB_NOMATCH | |
284 | EOF | |
285 | ||
460adbb8 UD |
286 | # ... with GLOB_ERR |
287 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ | |
288 | ${common_objpfx}posix/globtest -E "$testdir" "a*/*" | | |
289 | sort > $testout | |
290 | cat <<"EOF" | cmp - $testout || result=1 | |
291 | GLOB_NOMATCH | |
292 | EOF | |
293 | ||
294 | # Try a recursive search in unreadable directory | |
295 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ | |
296 | ${common_objpfx}posix/globtest "$testdir" "noread/*" | | |
297 | sort > $testout | |
298 | cat <<"EOF" | cmp - $testout || result=1 | |
299 | GLOB_NOMATCH | |
300 | EOF | |
301 | ||
302 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ | |
303 | ${common_objpfx}posix/globtest "$testdir" "noread*/*" | | |
304 | sort > $testout | |
305 | cat <<"EOF" | cmp - $testout || result=1 | |
306 | GLOB_NOMATCH | |
307 | EOF | |
308 | ||
3b690639 UD |
309 | # The following tests will fail if run as root. |
310 | user=`id -un 2> /dev/null` | |
311 | if test -z "$user"; then | |
312 | uid="$USER" | |
313 | fi | |
314 | if test "$user" != root; then | |
315 | # ... with GLOB_ERR | |
316 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ | |
317 | ${common_objpfx}posix/globtest -E "$testdir" "noread/*" | | |
318 | sort > $testout | |
319 | cat <<"EOF" | cmp - $testout || result=1 | |
460adbb8 UD |
320 | GLOB_ABORTED |
321 | EOF | |
3b690639 | 322 | fi # not run as root |
460adbb8 UD |
323 | |
324 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ | |
325 | ${common_objpfx}posix/globtest -E "$testdir" "noread*/*" | | |
326 | sort > $testout | |
327 | cat <<"EOF" | cmp - $testout || result=1 | |
328 | GLOB_ABORTED | |
329 | EOF | |
330 | ||
3f62b69a | 331 | # Try multiple patterns (GLOB_APPEND) |
c9243dac | 332 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ |
3f62b69a UD |
333 | ${common_objpfx}posix/globtest "$testdir" "file1" "*/*" | |
334 | sort > $testout | |
335 | cat <<"EOF" | cmp - $testout || result=1 | |
336 | `dir1/file1_1' | |
337 | `dir1/file1_2' | |
338 | `file1' | |
339 | EOF | |
340 | ||
341 | # Try multiple patterns (GLOB_APPEND) with offset (GLOB_DOOFFS) | |
c9243dac | 342 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ |
3f62b69a UD |
343 | ${common_objpfx}posix/globtest -o "$testdir" "file1" "*/*" | |
344 | sort > $testout | |
345 | cat <<"EOF" | cmp - $testout || result=1 | |
346 | `abc' | |
347 | `dir1/file1_1' | |
348 | `dir1/file1_2' | |
349 | `file1' | |
61eb22d3 UD |
350 | EOF |
351 | ||
e852e889 UD |
352 | # Test NOCHECK with non-existing file in subdir. |
353 | ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \ | |
354 | ${common_objpfx}posix/globtest -c "$testdir" "*/blahblah" | | |
355 | sort > $testout | |
356 | cat <<"EOF" | cmp - $testout || result=1 | |
357 | `dir1/blahblah' | |
358 | `dir2/blahblah' | |
460adbb8 | 359 | `noread/blahblah' |
e852e889 UD |
360 | EOF |
361 | ||
61eb22d3 | 362 | if test $result -eq 0; then |
460adbb8 | 363 | chmod 777 $testdir/noread |
3f62b69a | 364 | rm -fr $testdir $testout |
61eb22d3 UD |
365 | fi |
366 | ||
367 | exit $result | |
368 | ||
369 | # Preserve executable bits for this shell script. | |
370 | Local Variables: | |
371 | eval:(defun frobme () (set-file-modes buffer-file-name file-mode)) | |
372 | eval:(make-local-variable 'file-mode) | |
373 | eval:(setq file-mode (file-modes (buffer-file-name))) | |
374 | eval:(make-local-variable 'after-save-hook) | |
375 | eval:(add-hook 'after-save-hook 'frobme) | |
376 | End: |