* sysdeps/powerpc/fpu/w_sqrt.c: Add sqrtl alias.
[glibc.git] / posix / globtest.sh
blobd5032562eab91abf40963b3f73386b811a74c7e6
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 failed=0
150 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
151 ${common_objpfx}posix/globtest -b "$testdir" "{file{1,2},-file3}" |
152 sort > $testout
153 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
154 `-file3'
155 `file1'
156 `file2'
158 if test $failed -ne 0; then
159 echo "Braces test 2 failed" >> $logfile
160 result=1
163 failed=0
164 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
165 ${common_objpfx}posix/globtest -b "$testdir" "{" |
166 sort > $testout
167 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
168 GLOB_NOMATCH
170 if test $failed -ne 0; then
171 echo "Braces test 3 failed" >> $logfile
172 result=1
175 # Test NOCHECK
176 failed=0
177 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
178 ${common_objpfx}posix/globtest -c "$testdir" "abc" |
179 sort > $testout
180 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
181 `abc'
183 if test $failed -ne 0; then
184 echo "No check test failed" >> $logfile
185 result=1
188 # Test NOMAGIC without magic characters
189 failed=0
190 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
191 ${common_objpfx}posix/globtest -g "$testdir" "abc" |
192 sort > $testout
193 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
194 `abc'
196 if test $failed -ne 0; then
197 echo "No magic test failed" >> $logfile
198 result=1
201 # Test NOMAGIC with magic characters
202 failed=0
203 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
204 ${common_objpfx}posix/globtest -g "$testdir" "abc*" |
205 sort > $testout
206 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
207 GLOB_NOMATCH
209 if test $failed -ne 0; then
210 echo "No magic w/ magic chars test failed" >> $logfile
211 result=1
214 # Test NOMAGIC for subdirs
215 failed=0
216 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
217 ${common_objpfx}posix/globtest -g "$testdir" "*/does-not-exist" |
218 sort > $testout
219 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
220 GLOB_NOMATCH
222 if test $failed -ne 0; then
223 echo "No magic in subdir test failed" >> $logfile
224 result=1
227 # Test subdirs correctly
228 failed=0
229 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
230 ${common_objpfx}posix/globtest "$testdir" "*/*" |
231 sort > $testout
232 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
233 `dir1/file1_1'
234 `dir1/file1_2'
236 if test $failed -ne 0; then
237 echo "Subdirs test failed" >> $logfile
238 result=1
241 # Test subdirs for invalid names
242 failed=0
243 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
244 ${common_objpfx}posix/globtest "$testdir" "*/1" |
245 sort > $testout
246 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
247 GLOB_NOMATCH
249 if test $failed -ne 0; then
250 echo "Invalid subdir test failed" >> $logfile
251 result=1
254 # Test subdirs with wildcard
255 failed=0
256 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
257 ${common_objpfx}posix/globtest "$testdir" "*/*1_1" |
258 sort > $testout
259 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
260 `dir1/file1_1'
262 if test $failed -ne 0; then
263 echo "Wildcard subdir test failed" >> $logfile
264 result=1
267 # Test subdirs with ?
268 failed=0
269 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
270 ${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
271 sort > $testout
272 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
273 `dir1/file1_1'
274 `dir1/file1_2'
276 if test $failed -ne 0; then
277 echo "Wildcard2 subdir test failed" >> $logfile
278 result=1
281 failed=0
282 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
283 ${common_objpfx}posix/globtest "$testdir" "*/file1_1" |
284 sort > $testout
285 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
286 `dir1/file1_1'
288 if test $failed -ne 0; then
289 echo "Wildcard3 subdir test failed" >> $logfile
290 result=1
293 failed=0
294 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
295 ${common_objpfx}posix/globtest "$testdir" "*-/*" |
296 sort > $testout
297 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
298 GLOB_NOMATCH
300 if test $failed -ne 0; then
301 echo "Wildcard4 subdir test failed" >> $logfile
302 result=1
305 failed=0
306 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
307 ${common_objpfx}posix/globtest "$testdir" "*-" |
308 sort > $testout
309 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
310 GLOB_NOMATCH
312 if test $failed -ne 0; then
313 echo "Wildcard5 subdir test failed" >> $logfile
314 result=1
317 # Test subdirs with ?
318 failed=0
319 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
320 ${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
321 sort > $testout
322 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
323 `dir1/file1_1'
324 `dir1/file1_2'
326 if test $failed -ne 0; then
327 echo "Wildcard6 subdir test failed" >> $logfile
328 result=1
331 # Test subdirs with [ .. ]
332 failed=0
333 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
334 ${common_objpfx}posix/globtest "$testdir" "*/file1_[12]" |
335 sort > $testout
336 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
337 `dir1/file1_1'
338 `dir1/file1_2'
340 if test $failed -ne 0; then
341 echo "Brackets test failed" >> $logfile
342 result=1
345 # Test ']' inside bracket expression
346 failed=0
347 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
348 ${common_objpfx}posix/globtest "$testdir" "dir1/file1_[]12]" |
349 sort > $testout
350 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
351 `dir1/file1_1'
352 `dir1/file1_2'
354 if test $failed -ne 0; then
355 echo "Brackets2 test failed" >> $logfile
356 result=1
359 # Test tilde expansion
360 failed=0
361 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
362 ${common_objpfx}posix/globtest -q -t "$testdir" "~" |
363 sort >$testout
364 echo ~ | cmp - $testout >> $logfile || failed=1
365 if test $failed -ne 0; then
366 if test -d ~; then
367 echo "Tilde test failed" >> $logfile
368 result=1
369 else
370 echo "Tilde test could not be run" >> $logfile
374 # Test tilde expansion with trailing slash
375 failed=0
376 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
377 ${common_objpfx}posix/globtest -q -t "$testdir" "~/" |
378 sort > $testout
379 # Some shell incorrectly(?) convert ~/ into // if ~ expands to /.
380 if test ~/ = //; then
381 echo / | cmp - $testout >> $logfile || failed=1
382 else
383 echo ~/ | cmp - $testout >> $logfile || failed=1
385 if test $failed -ne 0; then
386 if test -d ~/; then
387 echo "Tilde2 test failed" >> $logfile
388 result=1
389 else
390 echo "Tilde2 test could not be run" >> $logfile
394 # Test tilde expansion with username
395 failed=0
396 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
397 ${common_objpfx}posix/globtest -q -t "$testdir" "~"$USER |
398 sort > $testout
399 eval echo ~$USER | cmp - $testout >> $logfile || failed=1
400 if test $failed -ne 0; then
401 if eval test -d ~$USER; then
402 echo "Tilde3 test failed" >> $logfile
403 result=1
404 else
405 echo "Tilde3 test could not be run" >> $logfile
409 # Tilde expansion shouldn't match a file
410 failed=0
411 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
412 ${common_objpfx}posix/globtest -T "$testdir" "~file4" |
413 sort > $testout
414 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
415 GLOB_NOMATCH
417 if test $failed -ne 0; then
418 echo "Tilde4 test failed" >> $logfile
419 result=1
422 # Matching \** should only find *file6
423 failed=0
424 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
425 ${common_objpfx}posix/globtest "$testdir" "\**" |
426 sort > $testout
427 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
428 `*file6'
430 if test $failed -ne 0; then
431 echo "Star test failed" >> $logfile
432 result=1
435 # ... unless NOESCAPE is used, in which case it shouldn't match anything.
436 failed=0
437 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
438 ${common_objpfx}posix/globtest -e "$testdir" "\**" |
439 sort > $testout
440 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
441 GLOB_NOMATCH
443 if test $failed -ne 0; then
444 echo "Star2 test failed" >> $logfile
445 result=1
448 # Matching \*file6 should find *file6
449 failed=0
450 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
451 ${common_objpfx}posix/globtest "$testdir" "\*file6" |
452 sort > $testout
453 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
454 `*file6'
456 if test $failed -ne 0; then
457 echo "Star3 test failed" >> $logfile
458 result=1
461 # Try a recursive failed search
462 failed=0
463 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
464 ${common_objpfx}posix/globtest -e "$testdir" "a*/*" |
465 sort > $testout
466 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
467 GLOB_NOMATCH
469 if test $failed -ne 0; then
470 echo "Star4 test failed" >> $logfile
471 result=1
474 # ... with GLOB_ERR
475 failed=0
476 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
477 ${common_objpfx}posix/globtest -E "$testdir" "a*/*" |
478 sort > $testout
479 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
480 GLOB_NOMATCH
482 if test $failed -ne 0; then
483 echo "Star5 test failed" >> $logfile
484 result=1
487 # Try a recursive search in unreadable directory
488 failed=0
489 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
490 ${common_objpfx}posix/globtest "$testdir" "noread/*" |
491 sort > $testout
492 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
493 GLOB_NOMATCH
495 if test $failed -ne 0; then
496 echo "Star6 test failed" >> $logfile
497 result=1
500 failed=0
501 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
502 ${common_objpfx}posix/globtest "$testdir" "noread*/*" |
503 sort > $testout
504 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
505 GLOB_NOMATCH
507 if test $failed -ne 0; then
508 echo "Star6 test failed" >> $logfile
509 result=1
512 # The following tests will fail if run as root.
513 user=`id -un 2> /dev/null`
514 if test -z "$user"; then
515 uid="$USER"
517 if test "$user" != root; then
518 # ... with GLOB_ERR
519 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
520 ${common_objpfx}posix/globtest -E "$testdir" "noread/*" |
521 sort > $testout
522 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
523 GLOB_ABORTED
526 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
527 ${common_objpfx}posix/globtest -E "$testdir" "noread*/*" |
528 sort > $testout
529 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
530 GLOB_ABORTED
532 if test $failed -ne 0; then
533 echo "GLOB_ERR test failed" >> $logfile
534 result=1
536 fi # not run as root
538 # Try multiple patterns (GLOB_APPEND)
539 failed=0
540 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
541 ${common_objpfx}posix/globtest "$testdir" "file1" "*/*" |
542 sort > $testout
543 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
544 `dir1/file1_1'
545 `dir1/file1_2'
546 `file1'
548 if test $failed -ne 0; then
549 echo "GLOB_APPEND test failed" >> $logfile
550 result=1
553 # Try multiple patterns (GLOB_APPEND) with offset (GLOB_DOOFFS)
554 failed=0
555 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
556 ${common_objpfx}posix/globtest -o "$testdir" "file1" "*/*" |
557 sort > $testout
558 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
559 `abc'
560 `dir1/file1_1'
561 `dir1/file1_2'
562 `file1'
564 if test $failed -ne 0; then
565 echo "GLOB_APPEND2 test failed" >> $logfile
566 result=1
569 # Test NOCHECK with non-existing file in subdir.
570 failed=0
571 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
572 ${common_objpfx}posix/globtest -c "$testdir" "*/blahblah" |
573 sort > $testout
574 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
575 `*/blahblah'
577 if test $failed -ne 0; then
578 echo "No check2 test failed" >> $logfile
579 result=1
582 if test $result -eq 0; then
583 chmod 777 $testdir/noread
584 rm -fr $testdir $testout
585 echo "All OK." > $logfile
588 exit $result
590 # Preserve executable bits for this shell script.
591 Local Variables:
592 eval:(defun frobme () (set-file-modes buffer-file-name file-mode))
593 eval:(make-local-variable 'file-mode)
594 eval:(setq file-mode (file-modes (buffer-file-name)))
595 eval:(make-local-variable 'after-save-hook)
596 eval:(add-hook 'after-save-hook 'frobme)
597 End: