Include <string.h>.
[glibc.git] / posix / globtest.sh
blobb85a8e529b33220dadd8f06520a104667e830248
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 subdirs correctly
215 failed=0
216 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
217 ${common_objpfx}posix/globtest "$testdir" "*/*" |
218 sort > $testout
219 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
220 `dir1/file1_1'
221 `dir1/file1_2'
223 if test $failed -ne 0; then
224 echo "Subdirs test failed" >> $logfile
225 result=1
228 # Test subdirs for invalid names
229 failed=0
230 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
231 ${common_objpfx}posix/globtest "$testdir" "*/1" |
232 sort > $testout
233 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
234 GLOB_NOMATCH
236 if test $failed -ne 0; then
237 echo "Invalid subdir test failed" >> $logfile
238 result=1
241 # Test subdirs with wildcard
242 failed=0
243 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
244 ${common_objpfx}posix/globtest "$testdir" "*/*1_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 "Wildcard subdir test failed" >> $logfile
251 result=1
254 # Test subdirs with ?
255 failed=0
256 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
257 ${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
258 sort > $testout
259 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
260 `dir1/file1_1'
261 `dir1/file1_2'
263 if test $failed -ne 0; then
264 echo "Wildcard2 subdir test failed" >> $logfile
265 result=1
268 failed=0
269 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
270 ${common_objpfx}posix/globtest "$testdir" "*/file1_1" |
271 sort > $testout
272 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
273 `dir1/file1_1'
275 if test $failed -ne 0; then
276 echo "Wildcard3 subdir test failed" >> $logfile
277 result=1
280 failed=0
281 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
282 ${common_objpfx}posix/globtest "$testdir" "*-/*" |
283 sort > $testout
284 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
285 GLOB_NOMATCH
287 if test $failed -ne 0; then
288 echo "Wildcard4 subdir test failed" >> $logfile
289 result=1
292 failed=0
293 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
294 ${common_objpfx}posix/globtest "$testdir" "*-" |
295 sort > $testout
296 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
297 GLOB_NOMATCH
299 if test $failed -ne 0; then
300 echo "Wildcard5 subdir test failed" >> $logfile
301 result=1
304 # Test subdirs with ?
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 `dir1/file1_1'
311 `dir1/file1_2'
313 if test $failed -ne 0; then
314 echo "Wildcard6 subdir test failed" >> $logfile
315 result=1
318 # Test subdirs with [ .. ]
319 failed=0
320 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
321 ${common_objpfx}posix/globtest "$testdir" "*/file1_[12]" |
322 sort > $testout
323 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
324 `dir1/file1_1'
325 `dir1/file1_2'
327 if test $failed -ne 0; then
328 echo "Brackets test failed" >> $logfile
329 result=1
332 # Test ']' inside bracket expression
333 failed=0
334 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
335 ${common_objpfx}posix/globtest "$testdir" "dir1/file1_[]12]" |
336 sort > $testout
337 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
338 `dir1/file1_1'
339 `dir1/file1_2'
341 if test $failed -ne 0; then
342 echo "Brackets2 test failed" >> $logfile
343 result=1
346 # Test tilde expansion
347 failed=0
348 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
349 ${common_objpfx}posix/globtest -q -t "$testdir" "~" |
350 sort >$testout
351 echo ~ | cmp - $testout >> $logfile || failed=1
352 if test $failed -ne 0; then
353 if test -d ~; then
354 echo "Tilde test failed" >> $logfile
355 result=1
356 else
357 echo "Tilde test could not be run" >> $logfile
361 # Test tilde expansion with trailing slash
362 failed=0
363 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
364 ${common_objpfx}posix/globtest -q -t "$testdir" "~/" |
365 sort > $testout
366 # Some shell incorrectly(?) convert ~/ into // if ~ expands to /.
367 if test ~/ = //; then
368 echo / | cmp - $testout >> $logfile || failed=1
369 else
370 echo ~/ | cmp - $testout >> $logfile || failed=1
372 if test $failed -ne 0; then
373 if test -d ~/; then
374 echo "Tilde2 test failed" >> $logfile
375 result=1
376 else
377 echo "Tilde2 test could not be run" >> $logfile
381 # Test tilde expansion with username
382 failed=0
383 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
384 ${common_objpfx}posix/globtest -q -t "$testdir" "~"$USER |
385 sort > $testout
386 eval echo ~$USER | cmp - $testout >> $logfile || failed=1
387 if test $failed -ne 0; then
388 if eval test -d ~$USER; then
389 echo "Tilde3 test failed" >> $logfile
390 result=1
391 else
392 echo "Tilde3 test could not be run" >> $logfile
396 # Tilde expansion shouldn't match a file
397 failed=0
398 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
399 ${common_objpfx}posix/globtest -T "$testdir" "~file4" |
400 sort > $testout
401 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
402 GLOB_NOMATCH
404 if test $failed -ne 0; then
405 echo "Tilde4 test failed" >> $logfile
406 result=1
409 # Matching \** should only find *file6
410 failed=0
411 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
412 ${common_objpfx}posix/globtest "$testdir" "\**" |
413 sort > $testout
414 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
415 `*file6'
417 if test $failed -ne 0; then
418 echo "Star test failed" >> $logfile
419 result=1
422 # ... unless NOESCAPE is used, in which case it shouldn't match anything.
423 failed=0
424 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
425 ${common_objpfx}posix/globtest -e "$testdir" "\**" |
426 sort > $testout
427 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
428 GLOB_NOMATCH
430 if test $failed -ne 0; then
431 echo "Star2 test failed" >> $logfile
432 result=1
435 # Matching \*file6 should find *file6
436 failed=0
437 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
438 ${common_objpfx}posix/globtest "$testdir" "\*file6" |
439 sort > $testout
440 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
441 `*file6'
443 if test $failed -ne 0; then
444 echo "Star3 test failed" >> $logfile
445 result=1
448 # Try a recursive failed search
449 failed=0
450 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
451 ${common_objpfx}posix/globtest -e "$testdir" "a*/*" |
452 sort > $testout
453 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
454 GLOB_NOMATCH
456 if test $failed -ne 0; then
457 echo "Star4 test failed" >> $logfile
458 result=1
461 # ... with GLOB_ERR
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 "Star5 test failed" >> $logfile
471 result=1
474 # Try a recursive search in unreadable directory
475 failed=0
476 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
477 ${common_objpfx}posix/globtest "$testdir" "noread/*" |
478 sort > $testout
479 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
480 GLOB_NOMATCH
482 if test $failed -ne 0; then
483 echo "Star6 test failed" >> $logfile
484 result=1
487 failed=0
488 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
489 ${common_objpfx}posix/globtest "$testdir" "noread*/*" |
490 sort > $testout
491 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
492 GLOB_NOMATCH
494 if test $failed -ne 0; then
495 echo "Star6 test failed" >> $logfile
496 result=1
499 # The following tests will fail if run as root.
500 user=`id -un 2> /dev/null`
501 if test -z "$user"; then
502 uid="$USER"
504 if test "$user" != root; then
505 # ... with GLOB_ERR
506 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
507 ${common_objpfx}posix/globtest -E "$testdir" "noread/*" |
508 sort > $testout
509 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
510 GLOB_ABORTED
513 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
514 ${common_objpfx}posix/globtest -E "$testdir" "noread*/*" |
515 sort > $testout
516 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
517 GLOB_ABORTED
519 if test $failed -ne 0; then
520 echo "GLOB_ERR test failed" >> $logfile
521 result=1
523 fi # not run as root
525 # Try multiple patterns (GLOB_APPEND)
526 failed=0
527 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
528 ${common_objpfx}posix/globtest "$testdir" "file1" "*/*" |
529 sort > $testout
530 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
531 `dir1/file1_1'
532 `dir1/file1_2'
533 `file1'
535 if test $failed -ne 0; then
536 echo "GLOB_APPEND test failed" >> $logfile
537 result=1
540 # Try multiple patterns (GLOB_APPEND) with offset (GLOB_DOOFFS)
541 failed=0
542 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
543 ${common_objpfx}posix/globtest -o "$testdir" "file1" "*/*" |
544 sort > $testout
545 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
546 `abc'
547 `dir1/file1_1'
548 `dir1/file1_2'
549 `file1'
551 if test $failed -ne 0; then
552 echo "GLOB_APPEND2 test failed" >> $logfile
553 result=1
556 # Test NOCHECK with non-existing file in subdir.
557 failed=0
558 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
559 ${common_objpfx}posix/globtest -c "$testdir" "*/blahblah" |
560 sort > $testout
561 cat <<"EOF" | cmp - $testout >> $logfile || failed=1
562 `dir1/blahblah'
563 `dir2/blahblah'
564 `noread/blahblah'
566 if test $failed -ne 0; then
567 echo "No check2 test failed" >> $logfile
568 result=1
571 if test $result -eq 0; then
572 chmod 777 $testdir/noread
573 rm -fr $testdir $testout
574 echo "All OK." > $logfile
577 exit $result
579 # Preserve executable bits for this shell script.
580 Local Variables:
581 eval:(defun frobme () (set-file-modes buffer-file-name file-mode))
582 eval:(make-local-variable 'file-mode)
583 eval:(setq file-mode (file-modes (buffer-file-name)))
584 eval:(make-local-variable 'after-save-hook)
585 eval:(add-hook 'after-save-hook 'frobme)
586 End: