source: vendor/glibc-tests/glibc/posix/globtest.sh

Last change on this file was 2036, checked in by bird, 20 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 17.0 KB
Line 
1#! /bin/sh
2
3common_objpfx=$1; shift
4elf_objpfx=$1; shift
5rtld_installed_name=$1; shift
6logfile=$common_objpfx/posix/globtest.out
7
8#CMP=cmp
9CMP="diff -u"
10
11# We have to make the paths `common_objpfx' absolute.
12case "$common_objpfx" in
13 .*)
14 common_objpfx="`pwd`/$common_objpfx"
15 ;;
16 *)
17 ;;
18esac
19
20# We have to find the libc and the NSS modules.
21library_path=${common_objpfx}:${common_objpfx}nss:${common_objpfx}nis:${common_objpfx}db2:${common_objpfx}hesiod
22
23# Since we use `sort' we must make sure to use the same locale everywhere.
24LC_ALL=C
25export LC_ALL
26LANG=C
27export LANG
28
29# Create the arena
30: ${TMPDIR=/tmp}
31testdir=$TMPDIR/globtest-dir
32testout=$TMPDIR/globtest-out
33
34trap 'chmod 777 $testdir/noread; rm -fr $testdir $testout' 1 2 3 15
35
36test -d $testdir/noread && chmod 777 $testdir/noread
37rm -fr $testdir 2>/dev/null
38mkdir $testdir
39echo 1 > $testdir/file1
40echo 2 > $testdir/file2
41echo 3 > $testdir/-file3
42echo 4 > $testdir/~file4
43echo 5 > $testdir/.file5
44echo 6 > $testdir/'*file6'
45echo 7 > $testdir/'{file7,}'
46echo 8 > $testdir/'\{file8\}'
47echo 9 > $testdir/'\{file9\,file9b\}'
48echo 9 > $testdir/'\file9b\' #'
49echo a > $testdir/'filea,'
50echo a > $testdir/'fileb}c'
51mkdir $testdir/dir1
52mkdir $testdir/dir2
53test -d $testdir/noread || mkdir $testdir/noread
54chmod a-r $testdir/noread
55echo 1_1 > $testdir/dir1/file1_1
56echo 1_2 > $testdir/dir1/file1_2
57ln -fs dir1 $testdir/link1
58
59# Run some tests.
60result=0
61rm -f $logfile
62
63# Normal test
64failed=0
65${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
66${common_objpfx}posix/globtest "$testdir" "*" |
67sort > $testout
68cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
69`*file6'
70`-file3'
71`\file9b\'
72`\{file8\}'
73`\{file9\,file9b\}'
74`dir1'
75`dir2'
76`file1'
77`file2'
78`filea,'
79`fileb}c'
80`link1'
81`noread'
82`{file7,}'
83`~file4'
84EOF
85if test $failed -ne 0; then
86 echo "Normal test failed" >> $logfile
87 result=1
88fi
89
90# Don't let glob sort it
91failed=0
92${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
93${common_objpfx}posix/globtest -s "$testdir" "*" |
94sort > $testout
95cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
96`*file6'
97`-file3'
98`\file9b\'
99`\{file8\}'
100`\{file9\,file9b\}'
101`dir1'
102`dir2'
103`file1'
104`file2'
105`filea,'
106`fileb}c'
107`link1'
108`noread'
109`{file7,}'
110`~file4'
111EOF
112if test $failed -ne 0; then
113 echo "No sort test failed" >> $logfile
114 result=1
115fi
116
117# Mark directories
118failed=0
119${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
120${common_objpfx}posix/globtest -m "$testdir" "*" |
121sort > $testout
122cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
123`*file6'
124`-file3'
125`\file9b\'
126`\{file8\}'
127`\{file9\,file9b\}'
128`dir1/'
129`dir2/'
130`file1'
131`file2'
132`filea,'
133`fileb}c'
134`link1/'
135`noread/'
136`{file7,}'
137`~file4'
138EOF
139if test $failed -ne 0; then
140 echo "Mark directories test failed" >> $logfile
141 result=1
142fi
143
144# Find files starting with .
145failed=0
146${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
147${common_objpfx}posix/globtest -p "$testdir" "*" |
148sort > $testout
149cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
150`*file6'
151`-file3'
152`.'
153`..'
154`.file5'
155`\file9b\'
156`\{file8\}'
157`\{file9\,file9b\}'
158`dir1'
159`dir2'
160`file1'
161`file2'
162`filea,'
163`fileb}c'
164`link1'
165`noread'
166`{file7,}'
167`~file4'
168EOF
169if test $failed -ne 0; then
170 echo "Leading period test failed" >> $logfile
171 result=1
172fi
173
174# Test braces
175failed=0
176${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
177${common_objpfx}posix/globtest -b "$testdir" "file{1,2}" |
178sort > $testout
179cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
180`file1'
181`file2'
182EOF
183if test $failed -ne 0; then
184 echo "Braces test failed" >> $logfile
185 result=1
186fi
187
188failed=0
189${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
190${common_objpfx}posix/globtest -b "$testdir" "{file{1,2},-file3}" |
191sort > $testout
192cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
193`-file3'
194`file1'
195`file2'
196EOF
197if test $failed -ne 0; then
198 echo "Braces test 2 failed" >> $logfile
199 result=1
200fi
201
202failed=0
203${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
204${common_objpfx}posix/globtest -b "$testdir" "{" |
205sort > $testout
206cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
207GLOB_NOMATCH
208EOF
209if test $failed -ne 0; then
210 echo "Braces test 3 failed" >> $logfile
211 result=1
212fi
213
214# Test NOCHECK
215failed=0
216${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
217${common_objpfx}posix/globtest -c "$testdir" "abc" |
218sort > $testout
219cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
220`abc'
221EOF
222if test $failed -ne 0; then
223 echo "No check test failed" >> $logfile
224 result=1
225fi
226
227# Test NOMAGIC without magic characters
228failed=0
229${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
230${common_objpfx}posix/globtest -g "$testdir" "abc" |
231sort > $testout
232cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
233`abc'
234EOF
235if test $failed -ne 0; then
236 echo "No magic test failed" >> $logfile
237 result=1
238fi
239
240# Test NOMAGIC with magic characters
241failed=0
242${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
243${common_objpfx}posix/globtest -g "$testdir" "abc*" |
244sort > $testout
245cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
246GLOB_NOMATCH
247EOF
248if test $failed -ne 0; then
249 echo "No magic w/ magic chars test failed" >> $logfile
250 result=1
251fi
252
253# Test NOMAGIC for subdirs
254failed=0
255${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
256${common_objpfx}posix/globtest -g "$testdir" "*/does-not-exist" |
257sort > $testout
258cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
259GLOB_NOMATCH
260EOF
261if test $failed -ne 0; then
262 echo "No magic in subdir test failed" >> $logfile
263 result=1
264fi
265
266# Test subdirs correctly
267failed=0
268${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
269${common_objpfx}posix/globtest "$testdir" "*/*" |
270sort > $testout
271cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
272`dir1/file1_1'
273`dir1/file1_2'
274`link1/file1_1'
275`link1/file1_2'
276EOF
277if test $failed -ne 0; then
278 echo "Subdirs test failed" >> $logfile
279 result=1
280fi
281
282# Test subdirs for invalid names
283failed=0
284${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
285${common_objpfx}posix/globtest "$testdir" "*/1" |
286sort > $testout
287cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
288GLOB_NOMATCH
289EOF
290if test $failed -ne 0; then
291 echo "Invalid subdir test failed" >> $logfile
292 result=1
293fi
294
295# Test subdirs with wildcard
296failed=0
297${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
298${common_objpfx}posix/globtest "$testdir" "*/*1_1" |
299sort > $testout
300cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
301`dir1/file1_1'
302`link1/file1_1'
303EOF
304if test $failed -ne 0; then
305 echo "Wildcard subdir test failed" >> $logfile
306 result=1
307fi
308
309# Test subdirs with ?
310failed=0
311${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
312${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
313sort > $testout
314cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
315`dir1/file1_1'
316`dir1/file1_2'
317`link1/file1_1'
318`link1/file1_2'
319EOF
320if test $failed -ne 0; then
321 echo "Wildcard2 subdir test failed" >> $logfile
322 result=1
323fi
324
325failed=0
326${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
327${common_objpfx}posix/globtest "$testdir" "*/file1_1" |
328sort > $testout
329cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
330`dir1/file1_1'
331`link1/file1_1'
332EOF
333if test $failed -ne 0; then
334 echo "Wildcard3 subdir test failed" >> $logfile
335 result=1
336fi
337
338failed=0
339${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
340${common_objpfx}posix/globtest "$testdir" "*-/*" |
341sort > $testout
342cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
343GLOB_NOMATCH
344EOF
345if test $failed -ne 0; then
346 echo "Wildcard4 subdir test failed" >> $logfile
347 result=1
348fi
349
350failed=0
351${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
352${common_objpfx}posix/globtest "$testdir" "*-" |
353sort > $testout
354cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
355GLOB_NOMATCH
356EOF
357if test $failed -ne 0; then
358 echo "Wildcard5 subdir test failed" >> $logfile
359 result=1
360fi
361
362# Test subdirs with ?
363failed=0
364${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
365${common_objpfx}posix/globtest "$testdir" "*/*?_?" |
366sort > $testout
367cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
368`dir1/file1_1'
369`dir1/file1_2'
370`link1/file1_1'
371`link1/file1_2'
372EOF
373if test $failed -ne 0; then
374 echo "Wildcard6 subdir test failed" >> $logfile
375 result=1
376fi
377
378# Test subdirs with [ .. ]
379failed=0
380${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
381${common_objpfx}posix/globtest "$testdir" "*/file1_[12]" |
382sort > $testout
383cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
384`dir1/file1_1'
385`dir1/file1_2'
386`link1/file1_1'
387`link1/file1_2'
388EOF
389if test $failed -ne 0; then
390 echo "Brackets test failed" >> $logfile
391 result=1
392fi
393
394# Test ']' inside bracket expression
395failed=0
396${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
397${common_objpfx}posix/globtest "$testdir" "dir1/file1_[]12]" |
398sort > $testout
399cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
400`dir1/file1_1'
401`dir1/file1_2'
402EOF
403if test $failed -ne 0; then
404 echo "Brackets2 test failed" >> $logfile
405 result=1
406fi
407
408# Test tilde expansion
409failed=0
410${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
411${common_objpfx}posix/globtest -q -t "$testdir" "~" |
412sort >$testout
413echo ~ | $CMP - $testout >> $logfile || failed=1
414if test $failed -ne 0; then
415 if test -d ~; then
416 echo "Tilde test failed" >> $logfile
417 result=1
418 else
419 echo "Tilde test could not be run" >> $logfile
420 fi
421fi
422
423# Test tilde expansion with trailing slash
424failed=0
425${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
426${common_objpfx}posix/globtest -q -t "$testdir" "~/" |
427sort > $testout
428# Some shell incorrectly(?) convert ~/ into // if ~ expands to /.
429if test ~/ = //; then
430 echo / | $CMP - $testout >> $logfile || failed=1
431else
432 echo ~/ | $CMP - $testout >> $logfile || failed=1
433fi
434if test $failed -ne 0; then
435 if test -d ~/; then
436 echo "Tilde2 test failed" >> $logfile
437 result=1
438 else
439 echo "Tilde2 test could not be run" >> $logfile
440 fi
441fi
442
443# Test tilde expansion with username
444failed=0
445${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
446${common_objpfx}posix/globtest -q -t "$testdir" "~"$USER |
447sort > $testout
448eval echo ~$USER | $CMP - $testout >> $logfile || failed=1
449if test $failed -ne 0; then
450 if eval test -d ~$USER; then
451 echo "Tilde3 test failed" >> $logfile
452 result=1
453 else
454 echo "Tilde3 test could not be run" >> $logfile
455 fi
456fi
457
458# Tilde expansion shouldn't match a file
459failed=0
460${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
461${common_objpfx}posix/globtest -T "$testdir" "~file4" |
462sort > $testout
463cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
464GLOB_NOMATCH
465EOF
466if test $failed -ne 0; then
467 echo "Tilde4 test failed" >> $logfile
468 result=1
469fi
470
471# Matching \** should only find *file6
472failed=0
473${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
474${common_objpfx}posix/globtest "$testdir" "\**" |
475sort > $testout
476cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
477`*file6'
478EOF
479if test $failed -ne 0; then
480 echo "Star test failed" >> $logfile
481 result=1
482fi
483
484# ... unless NOESCAPE is used, in which case it should entries with a
485# leading \.
486failed=0
487${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
488${common_objpfx}posix/globtest -e "$testdir" "\**" |
489sort > $testout
490cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
491`\file9b\'
492`\{file8\}'
493`\{file9\,file9b\}'
494EOF
495if test $failed -ne 0; then
496 echo "Star2 test failed" >> $logfile
497 result=1
498fi
499
500# Matching \*file6 should find *file6
501failed=0
502${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
503${common_objpfx}posix/globtest "$testdir" "\*file6" |
504sort > $testout
505cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
506`*file6'
507EOF
508if test $failed -ne 0; then
509 echo "Star3 test failed" >> $logfile
510 result=1
511fi
512
513# GLOB_BRACE alone
514failed=0
515${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
516${common_objpfx}posix/globtest -b "$testdir" '\{file7\,\}' |
517sort > $testout
518cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
519`{file7,}'
520EOF
521if test $failed -ne 0; then
522 echo "Brace4 test failed" >> $logfile
523 result=1
524fi
525
526# GLOB_BRACE and GLOB_NOESCAPE
527failed=0
528${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
529${common_objpfx}posix/globtest -b -e "$testdir" '\{file9\,file9b\}' |
530sort > $testout
531cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
532`\file9b\'
533EOF
534if test $failed -ne 0; then
535 echo "Brace5 test failed" >> $logfile
536 result=1
537fi
538
539# Escaped comma
540failed=0
541${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
542${common_objpfx}posix/globtest -b "$testdir" '{filea\,}' |
543sort > $testout
544cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
545`filea,'
546EOF
547if test $failed -ne 0; then
548 echo "Brace6 test failed" >> $logfile
549 result=1
550fi
551
552# Escaped closing brace
553failed=0
554${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
555${common_objpfx}posix/globtest -b "$testdir" '{fileb\}c}' |
556sort > $testout
557cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
558`fileb}c'
559EOF
560if test $failed -ne 0; then
561 echo "Brace7 test failed" >> $logfile
562 result=1
563fi
564
565# Try a recursive failed search
566failed=0
567${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
568${common_objpfx}posix/globtest -e "$testdir" "a*/*" |
569sort > $testout
570cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
571GLOB_NOMATCH
572EOF
573if test $failed -ne 0; then
574 echo "Star4 test failed" >> $logfile
575 result=1
576fi
577
578# ... with GLOB_ERR
579failed=0
580${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
581${common_objpfx}posix/globtest -E "$testdir" "a*/*" |
582sort > $testout
583cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
584GLOB_NOMATCH
585EOF
586if test $failed -ne 0; then
587 echo "Star5 test failed" >> $logfile
588 result=1
589fi
590
591# Try a recursive search in unreadable directory
592failed=0
593${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
594${common_objpfx}posix/globtest "$testdir" "noread/*" |
595sort > $testout
596cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
597GLOB_NOMATCH
598EOF
599if test $failed -ne 0; then
600 echo "Star6 test failed" >> $logfile
601 result=1
602fi
603
604failed=0
605${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
606${common_objpfx}posix/globtest "$testdir" "noread*/*" |
607sort > $testout
608cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
609GLOB_NOMATCH
610EOF
611if test $failed -ne 0; then
612 echo "Star6 test failed" >> $logfile
613 result=1
614fi
615
616# The following tests will fail if run as root.
617user=`id -un 2> /dev/null`
618if test -z "$user"; then
619 uid="$USER"
620fi
621if test "$user" != root; then
622 # ... with GLOB_ERR
623 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
624 ${common_objpfx}posix/globtest -E "$testdir" "noread/*" |
625 sort > $testout
626 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
627GLOB_ABORTED
628EOF
629
630 ${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
631 ${common_objpfx}posix/globtest -E "$testdir" "noread*/*" |
632 sort > $testout
633 cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
634GLOB_ABORTED
635EOF
636if test $failed -ne 0; then
637 echo "GLOB_ERR test failed" >> $logfile
638 result=1
639fi
640fi # not run as root
641
642# Try multiple patterns (GLOB_APPEND)
643failed=0
644${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
645${common_objpfx}posix/globtest "$testdir" "file1" "*/*" |
646sort > $testout
647cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
648`dir1/file1_1'
649`dir1/file1_2'
650`file1'
651`link1/file1_1'
652`link1/file1_2'
653EOF
654if test $failed -ne 0; then
655 echo "GLOB_APPEND test failed" >> $logfile
656 result=1
657fi
658
659# Try multiple patterns (GLOB_APPEND) with offset (GLOB_DOOFFS)
660failed=0
661${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
662${common_objpfx}posix/globtest -o "$testdir" "file1" "*/*" |
663sort > $testout
664cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
665`abc'
666`dir1/file1_1'
667`dir1/file1_2'
668`file1'
669`link1/file1_1'
670`link1/file1_2'
671EOF
672if test $failed -ne 0; then
673 echo "GLOB_APPEND2 test failed" >> $logfile
674 result=1
675fi
676
677# Test NOCHECK with non-existing file in subdir.
678failed=0
679${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
680${common_objpfx}posix/globtest -c "$testdir" "*/blahblah" |
681sort > $testout
682cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
683`*/blahblah'
684EOF
685if test $failed -ne 0; then
686 echo "No check2 test failed" >> $logfile
687 result=1
688fi
689
690# Test [[:punct:]] not matching leading period.
691failed=0
692${elf_objpfx}${rtld_installed_name} --library-path ${library_path} \
693${common_objpfx}posix/globtest -c "$testdir" "[[:punct:]]*" |
694sort > $testout
695cat <<"EOF" | $CMP - $testout >> $logfile || failed=1
696`*file6'
697`-file3'
698`\file9b\'
699`\{file8\}'
700`\{file9\,file9b\}'
701`{file7,}'
702`~file4'
703EOF
704if test $failed -ne 0; then
705 echo "Punct test failed" >> $logfile
706 result=1
707fi
708
709if test $result -eq 0; then
710 chmod 777 $testdir/noread
711 rm -fr $testdir $testout
712 echo "All OK." > $logfile
713fi
714
715exit $result
716
717# Preserve executable bits for this shell script.
718Local Variables:
719eval:(defun frobme () (set-file-modes buffer-file-name file-mode))
720eval:(make-local-variable 'file-mode)
721eval:(setq file-mode (file-modes (buffer-file-name)))
722eval:(make-local-variable 'after-save-hook)
723eval:(add-hook 'after-save-hook 'frobme)
724End:
Note: See TracBrowser for help on using the repository browser.