* sysdeps/m68k/setjmp.c: Also define setjmp and _setjmp if
[glibc.git] / posix / globtest.sh
blob678a6d9b1ac1492da267f8a1c315075c0b213d73
1 #! /bin/sh
3 common_objpfx=$1; shift
4 elf_objpfx=$1; shift
5 rtld_installed_name=$1; shift
6 logfile=$common_objpfx/posix/globtest.out
8 # We have to make the paths `common_objpfx' absolute.
9 case "$common_objpfx" in
10 .*)
11 common_objpfx="`pwd`/$common_objpfx"
15 esac
17 # We have to find the libc and the NSS modules.
18 library_path=${common_objpfx}:${common_objpfx}nss:${common_objpfx}nis:${common_objpfx}db2:${common_objpfx}hesiod
20 # Since we use `sort' we must make sure to use the same locale everywhere.
21 LC_ALL=C
22 export LC_ALL
23 LANG=C
24 export LANG
26 # Create the arena
27 : ${TMPDIR=/tmp}
28 testdir=$TMPDIR/globtest-dir
29 testout=$TMPDIR/globtest-out
31 trap 'chmod 777 $testdir/noread; rm -fr $testdir $testout' 1 2 3 15
33 rm -fr $testdir 2>/dev/null
34 mkdir $testdir
35 echo 1 > $testdir/file1
36 echo 2 > $testdir/file2
37 echo 3 > $testdir/-file3
38 echo 4 > $testdir/~file4
39 echo 5 > $testdir/.file5
40 echo 6 > $testdir/'*file6'
41 mkdir $testdir/dir1
42 mkdir $testdir/dir2
43 test -d $testdir/noread || mkdir $testdir/noread
44 chmod a-r $testdir/noread
45 echo 1_1 > $testdir/dir1/file1_1
46 echo 1_2 > $testdir/dir1/file1_2
48 # Run some tests.
49 result=0
50 rm -f $logfile
52 # Normal test
53 failed=0
54 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
55 ${common_objpfx}posix/globtest "$testdir" "*" |
56 sort > $testout
57 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
58 `*file6'
59 `-file3'
60 `dir1'
61 `dir2'
62 `file1'
63 `file2'
64 `noread'
65 `~file4'
66 EOF
67 if test $failed -ne 0; then
68 echo "Normal test failed" >> $logfile
69 result=1
72 # Don't let glob sort it
73 failed=0
74 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
75 ${common_objpfx}posix/globtest -s "$testdir" "*" |
76 sort > $testout
77 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
78 `*file6'
79 `-file3'
80 `dir1'
81 `dir2'
82 `file1'
83 `file2'
84 `noread'
85 `~file4'
86 EOF
87 if test $failed -ne 0; then
88 echo "No sort test failed" >> $logfile
89 result=1
92 # Mark directories
93 failed=0
94 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
95 ${common_objpfx}posix/globtest -m "$testdir" "*" |
96 sort > $testout
97 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
98 `*file6'
99 `-file3'
100 `dir1/'
101 `dir2/'
102 `file1'
103 `file2'
104 `noread/'
105 `~file4'
107 if test $failed -ne 0; then
108 echo "Mark directories test failed" >> $logfile
109 result=1
112 # Find files starting with .
113 failed=0
114 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
115 ${common_objpfx}posix/globtest -p "$testdir" "*" |
116 sort > $testout
117 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
118 `*file6'
119 `-file3'
121 `..'
122 `.file5'
123 `dir1'
124 `dir2'
125 `file1'
126 `file2'
127 `noread'
128 `~file4'
130 if test $failed -ne 0; then
131 echo "Leading period test failed" >> $logfile
132 result=1
135 # Test braces
136 failed=0
137 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
138 ${common_objpfx}posix/globtest -b "$testdir" "file{1,2}" |
139 sort > $testout
140 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
141 `file1'
142 `file2'
144 if test $failed -ne 0; then
145 echo "Braces test failed" >> $logfile
146 result=1
149 # Test NOCHECK
150 failed=0
151 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
152 ${common_objpfx}posix/globtest -c "$testdir" "abc" |
153 sort > $testout
154 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
155 `abc'
157 if test $failed -ne 0; then
158 echo "No check test failed" >> $logfile
159 result=1
162 # Test NOMAGIC without magic characters
163 failed=0
164 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
165 ${common_objpfx}posix/globtest -g "$testdir" "abc" |
166 sort > $testout
167 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
168 `abc'
170 if test $failed -ne 0; then
171 echo "No magic test failed" >> $logfile
172 result=1
175 # Test NOMAGIC with magic characters
176 failed=0
177 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
178 ${common_objpfx}posix/globtest -g "$testdir" "abc*" |
179 sort > $testout
180 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
181 GLOB_NOMATCH
183 if test $failed -ne 0; then
184 echo "No magic w/ magic chars test failed" >> $logfile
185 result=1
188 # Test subdirs correctly
189 failed=0
190 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
191 ${common_objpfx}posix/globtest "$testdir" "*/*" |
192 sort > $testout
193 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
194 `dir1/file1_1'
195 `dir1/file1_2'
197 if test $failed -ne 0; then
198 echo "Subdirs test failed" >> $logfile
199 result=1
202 # Test subdirs for invalid names
203 failed=0
204 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
205 ${common_objpfx}posix/globtest "$testdir" "*/1" |
206 sort > $testout
207 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
208 GLOB_NOMATCH
210 if test $failed -ne 0; then
211 echo "Invalid subdir test failed" >> $logfile
212 result=1
215 # Test subdirs with wildcard
216 failed=0
217 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
218 ${common_objpfx}posix/globtest "$testdir" "*/*1_1" |
219 sort > $testout
220 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
221 `dir1/file1_1'
223 if test $failed -ne 0; then
224 echo "Wildcard subdir test failed" >> $logfile
225 result=1
228 # Test subdirs with ?
229 failed=0
230 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
231 ${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
232 sort > $testout
233 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
234 `dir1/file1_1'
235 `dir1/file1_2'
237 if test $failed -ne 0; then
238 echo "Wildcard2 subdir test failed" >> $logfile
239 result=1
242 failed=0
243 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
244 ${common_objpfx}posix/globtest "$testdir" "*/file1_1" |
245 sort > $testout
246 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
247 `dir1/file1_1'
249 if test $failed -ne 0; then
250 echo "Wildcard3 subdir test failed" >> $logfile
251 result=1
254 failed=0
255 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
256 ${common_objpfx}posix/globtest "$testdir" "*-/*" |
257 sort > $testout
258 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
259 GLOB_NOMATCH
261 if test $failed -ne 0; then
262 echo "Wildcard4 subdir test failed" >> $logfile
263 result=1
266 failed=0
267 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
268 ${common_objpfx}posix/globtest "$testdir" "*-" |
269 sort > $testout
270 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
271 GLOB_NOMATCH
273 if test $failed -ne 0; then
274 echo "Wildcard5 subdir test failed" >> $logfile
275 result=1
278 # Test subdirs with ?
279 failed=0
280 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
281 ${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
282 sort > $testout
283 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
284 `dir1/file1_1'
285 `dir1/file1_2'
287 if test $failed -ne 0; then
288 echo "Wildcard6 subdir test failed" >> $logfile
289 result=1
292 # Test subdirs with [ .. ]
293 failed=0
294 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
295 ${common_objpfx}posix/globtest "$testdir" "*/file1_[12]" |
296 sort > $testout
297 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
298 `dir1/file1_1'
299 `dir1/file1_2'
301 if test $failed -ne 0; then
302 echo "Brackets test failed" >> $logfile
303 result=1
306 # Test ']' inside bracket expression
307 failed=0
308 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
309 ${common_objpfx}posix/globtest "$testdir" "dir1/file1_[]12]" |
310 sort > $testout
311 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
312 `dir1/file1_1'
313 `dir1/file1_2'
315 if test $failed -ne 0; then
316 echo "Brackets2 test failed" >> $logfile
317 result=1
320 # Test tilde expansion
321 failed=0
322 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
323 ${common_objpfx}posix/globtest -q -t "$testdir" "~" |
324 sort >$testout
325 echo ~ | cmp - $testout >> $logfile || failed=1
326 if test $failed -ne 0; then
327 if test -d ~; then
328 echo "Tilde test failed" >> $logfile
329 result=1
330 else
331 echo "Tilde test could not be run" >> $logfile
335 # Test tilde expansion with trailing slash
336 failed=0
337 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
338 ${common_objpfx}posix/globtest -q -t "$testdir" "~/" |
339 sort > $testout
340 # Some shell incorrectly(?) convert ~/ into // if ~ expands to /.
341 if test ~/ = //; then
342 echo / | cmp - $testout >> $logfile || failed=1
343 else
344 echo ~/ | cmp - $testout >> $logfile || failed=1
346 if test $failed -ne 0; then
347 if test -d ~/; then
348 echo "Tilde2 test failed" >> $logfile
349 result=1
350 else
351 echo "Tilde2 test could not be run" >> $logfile
355 # Test tilde expansion with username
356 failed=0
357 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
358 ${common_objpfx}posix/globtest -q -t "$testdir" "~"$USER |
359 sort > $testout
360 eval echo ~$USER | cmp - $testout >> $logfile || failed=1
361 if test $failed -ne 0; then
362 if eval test -d ~$USER; then
363 echo "Tilde3 test failed" >> $logfile
364 result=1
365 else
366 echo "Tilde3 test could not be run" >> $logfile
370 # Tilde expansion shouldn't match a file
371 failed=0
372 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
373 ${common_objpfx}posix/globtest -T "$testdir" "~file4" |
374 sort > $testout
375 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
376 GLOB_NOMATCH
378 if test $failed -ne 0; then
379 echo "Tilde4 test failed" >> $logfile
380 result=1
383 # Matching \** should only find *file6
384 failed=0
385 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
386 ${common_objpfx}posix/globtest "$testdir" "\**" |
387 sort > $testout
388 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
389 `*file6'
391 if test $failed -ne 0; then
392 echo "Star test failed" >> $logfile
393 result=1
396 # ... unless NOESCAPE is used, in which case it shouldn't match anything.
397 failed=0
398 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
399 ${common_objpfx}posix/globtest -e "$testdir" "\**" |
400 sort > $testout
401 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
402 GLOB_NOMATCH
404 if test $failed -ne 0; then
405 echo "Star2 test failed" >> $logfile
406 result=1
409 # Matching \*file6 should find *file6
410 failed=0
411 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
412 ${common_objpfx}posix/globtest "$testdir" "\*file6" |
413 sort > $testout
414 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
415 `*file6'
417 if test $failed -ne 0; then
418 echo "Star3 test failed" >> $logfile
419 result=1
422 # Try a recursive failed search
423 failed=0
424 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
425 ${common_objpfx}posix/globtest -e "$testdir" "a*/*" |
426 sort > $testout
427 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
428 GLOB_NOMATCH
430 if test $failed -ne 0; then
431 echo "Star4 test failed" >> $logfile
432 result=1
435 # ... with GLOB_ERR
436 failed=0
437 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
438 ${common_objpfx}posix/globtest -E "$testdir" "a*/*" |
439 sort > $testout
440 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
441 GLOB_NOMATCH
443 if test $failed -ne 0; then
444 echo "Star5 test failed" >> $logfile
445 result=1
448 # Try a recursive search in unreadable directory
449 failed=0
450 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
451 ${common_objpfx}posix/globtest "$testdir" "noread/*" |
452 sort > $testout
453 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
454 GLOB_NOMATCH
456 if test $failed -ne 0; then
457 echo "Star6 test failed" >> $logfile
458 result=1
461 failed=0
462 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
463 ${common_objpfx}posix/globtest "$testdir" "noread*/*" |
464 sort > $testout
465 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
466 GLOB_NOMATCH
468 if test $failed -ne 0; then
469 echo "Star6 test failed" >> $logfile
470 result=1
473 # The following tests will fail if run as root.
474 user=`id -un 2> /dev/null`
475 if test -z "$user"; then
476 uid="$USER"
478 if test "$user" != root; then
479 # ... with GLOB_ERR
480 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
481 ${common_objpfx}posix/globtest -E "$testdir" "noread/*" |
482 sort > $testout
483 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
484 GLOB_ABORTED
487 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
488 ${common_objpfx}posix/globtest -E "$testdir" "noread*/*" |
489 sort > $testout
490 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
491 GLOB_ABORTED
493 if test $failed -ne 0; then
494 echo "GLOB_ERR test failed" >> $logfile
495 result=1
497 fi # not run as root
499 # Try multiple patterns (GLOB_APPEND)
500 failed=0
501 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
502 ${common_objpfx}posix/globtest "$testdir" "file1" "*/*" |
503 sort > $testout
504 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
505 `dir1/file1_1'
506 `dir1/file1_2'
507 `file1'
509 if test $failed -ne 0; then
510 echo "GLOB_APPEND test failed" >> $logfile
511 result=1
514 # Try multiple patterns (GLOB_APPEND) with offset (GLOB_DOOFFS)
515 failed=0
516 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
517 ${common_objpfx}posix/globtest -o "$testdir" "file1" "*/*" |
518 sort > $testout
519 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
520 `abc'
521 `dir1/file1_1'
522 `dir1/file1_2'
523 `file1'
525 if test $failed -ne 0; then
526 echo "GLOB_APPEND2 test failed" >> $logfile
527 result=1
530 # Test NOCHECK with non-existing file in subdir.
531 failed=0
532 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
533 ${common_objpfx}posix/globtest -c "$testdir" "*/blahblah" |
534 sort > $testout
535 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
536 `dir1/blahblah'
537 `dir2/blahblah'
538 `noread/blahblah'
540 if test $failed -ne 0; then
541 echo "No check2 test failed" >> $logfile
542 result=1
545 if test $result -eq 0; then
546 chmod 777 $testdir/noread
547 rm -fr $testdir $testout
548 echo "All OK." > $logfile
551 exit $result
553 # Preserve executable bits for this shell script.
554 Local Variables:
555 eval:(defun frobme () (set-file-modes buffer-file-name file-mode))
556 eval:(make-local-variable 'file-mode)
557 eval:(setq file-mode (file-modes (buffer-file-name)))
558 eval:(make-local-variable 'after-save-hook)
559 eval:(add-hook 'after-save-hook 'frobme)
560 End: