2 # Test-specific TCL procedures required by DejaGNU.
3 # Copyright (C) 1994, 2003, 2004, 2005, 2006, 2007, 2010, 2011 Free
4 # Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 # Modified by David MacKenzie <djm@gnu.org> from the gcc files
21 # written by Rob Savoye <rob@cygnus.com>.
24 # use the local version of find for updatedb
26 # We normalise (normalize for those over the water) pathnames
27 # because the updatedb shell script uses "cd", which means that
28 # any relative paths no longer point where we thought they did.
29 # Because "file normalize" requires tcl 8.4, we have a plan B
30 # for normalising the name of a directory, but it is slower.
32 proc normalize_dir { dir } {
33 if [ catch { file normalize $dir } result ] then {
34 return [ exec /bin/sh -c "cd $dir && /bin/pwd" ]
40 set fulldir [ normalize_dir "../../find" ]
41 set env{find} "$fulldir/find"
43 # use the local help commands for updatedb
44 set env(LIBEXECDIR) [ normalize_dir .. ]
45 # use our local version of find, too.
47 # do not ignore any file systems for this test
55 set UPDATEDB [findfile $base_dir/../updatedb $base_dir/../updatedb [transform updatedb]]
56 set FRCODE [findfile $base_dir/../frcode $base_dir/../frcode [transform frcode ]]
57 set LOCATE [findfile $base_dir/../locate $base_dir/../locate [transform locate ]]
58 set FIND [findfile $base_dir/../../find/find $base_dir/../../find/find [transform find ]]
59 verbose "UPDATEDB is $UPDATEDB" 1
60 verbose "FRCODE is $FRCODE" 1
61 verbose "LOCATE is $LOCATE" 1
62 verbose "FIND is $FIND" 1
65 foreach exe "$UPDATEDB $FRCODE $LOCATE $FIND" {
66 if ![ string match "/*" $exe ] {
67 error "Failed to find a binary to test for $exe"
72 if ![info exists UPDATEDBFLAGS] then {
79 if ![info exists LOCATEFLAGS] then {
84 # Extract and print the version number of locate.
85 proc locate_version {} {
91 if {[which $LOCATE] != 0} then {
92 set tmp [ eval exec $LOCATE $LOCATEFLAGS --version </dev/null | sed 1q]
95 warning "$LOCATE, program does not exist"
100 # Run locate and leave the output in $comp_output.
101 # Called by individual test scripts.
102 proc locate_textonly { passfail id intext locateoptions outtext } {
106 set fail_good [string match "f*" $passfail]
108 set scriptname [uplevel {info script}]
109 set testbase [file rootname $scriptname]
110 set testname [file tail $testbase]
111 set listfile "updatedb-paths.txt"
112 set dbfile "locate.db"
113 set outfile "locate.out"
115 # Generate the "frcode" input.
116 catch { file delete -force $listfle }
117 set f [open $listfile w]
122 exec $FRCODE < $listfile > $dbfile
125 set locatecmd "$LOCATE -d $dbfile $locateoptions"
126 send_log "Running $locatecmd \n"
127 catch "exec $locatecmd > $outfile"
130 set f [open "$outfile" r]
131 while { [ gets $f line ] >= 0 } {
132 # send_log "Output fragment is $line\n"
133 append result "$line\n"
137 # send_log "Output is $result\n"
139 if {[string equal $result $outtext]} {
146 send_log "Output mismatch.\n"
147 send_log "Expected: $outtext\n"
148 send_log "Got : $result\n"
154 # Do a test in which we expect an input text file to be preserved unchanged.
155 proc locate_roundtrip { id intext } {
156 if ![regexp "\n$" $intext] {
157 # We like the items to be terminated by newlines.
158 error "The input text is not terminated by newline"
161 locate_textonly p $id $intext "-r ." $intext
166 # Run locate and leave the output in $comp_output.
167 # Called by individual test scripts.
168 proc locate_start { passfail updatedb_options locate_options
169 {updatedb_infile ""} {locate_infile ""}
179 set fail_good [string match "f*" $passfail]
181 set scriptname [uplevel {info script}]
182 set testbase [file rootname $scriptname]
183 set testname [file tail $testbase]
185 set outfile "$testbase.xo"
186 if {"$updatedb_infile" != ""} then {
187 set updatedb_infile "[file dirname [file dirname $testbase]]/inputs/$updatedb_infile"
189 set updatedb_infile /dev/null
191 if {"$locate_infile" != ""} then {
192 set locate_infile "[file dirname [file dirname $testbase]]/inputs/$locate_infile"
194 set locate_infile /dev/null
197 catch "exec rm -f locate.out"
199 set updatedb_cmd "$UPDATEDB $UPDATEDBFLAGS $updatedb_options < $updatedb_infile"
200 send_log "$updatedb_cmd\n"
202 send_user "Spawning \"$updatedb_cmd\"\n"
204 catch "exec $updatedb_cmd" comp_output
206 if {$comp_output != ""} then {
207 send_log "$comp_output\n"
209 send_user "$comp_output\n"
211 # If fail_good is set, that refers to the exit
212 # status of locate, not updatedb...
213 fail "$testname: updatedb is supposed to be silent, $comp_output"
216 send_log "updatedb: OK.\n"
222 set locate_cmd "$LOCATE $LOCATEFLAGS $locate_options < $locate_infile > locate.out"
223 send_log "$locate_cmd\n"
225 send_user "Spawning \"$locate_cmd\"\n"
228 catch "exec $locate_cmd" comp_output
229 if {$comp_output != ""} then {
230 send_log "$comp_output\n"
232 send_user "$comp_output\n"
237 fail "$testname: locate failed, $comp_output"
242 if [file exists $outfile] then {
243 set cmp_cmd "cmp locate.out $outfile"
244 send_log "$cmp_cmd\n"
245 catch "exec $cmp_cmd" cmpout
246 if {$cmpout != ""} then {
247 #catch "exec diff locate.out $outfile" diffout
249 fail "$testname, $cmpout"
253 if {[file size locate.out] != 0} then {
254 fail "$testname, output should be empty"
259 catch "exec rm -rf tmp"
264 proc locate_from_db { passfail locate_options locate_database } {
269 set fail_good [string match "f*" $passfail]
270 set scriptname [uplevel {info script}]
271 set testbase [file rootname $scriptname]
272 set testname [file tail $testbase]
273 set testdir [file dirname $scriptname]
275 set dbpath "$testdir/$locate_database"
276 set outfile "$testbase.xo"
278 set locate_cmd "$LOCATE $LOCATEFLAGS -d $dbpath $locate_options > locate.out"
279 send_log "$locate_cmd\n"
281 send_user "Spawning \"$locate_cmd\"\n"
284 catch "exec $locate_cmd 2>/dev/null" comp_output
285 if {$comp_output != ""} then {
286 send_log "$comp_output\n"
288 send_user "$comp_output\n"
291 # XXX: in general may want to compare output, too.
294 fail "$testname: locate unfortunately failed, $comp_output"
300 if [file exists $outfile] then {
301 set cmp_cmd "cmp locate.out $outfile"
302 send_log "$cmp_cmd\n"
303 catch "exec $cmp_cmd" cmpout
304 if {$cmpout != ""} then {
305 #catch "exec diff locate.out $outfile" diffout
307 fail "$testname, $cmpout"
311 if {[file size locate.out] != 0} then {
312 fail "$testname, output should be empty"
324 # Clean up (remove temporary files) before runtest exits.
325 proc locate_exit {} {
326 catch "exec rm -f locate.out updatedb-paths.txt locate.db"
330 # Extract and print the version number of updatedb.
331 proc updatedb_version {} {
335 if {[which $UPDATEDB] != 0} then {
336 set tmp [eval exec $UPDATEDB $UPDATEDBFLAGS --version </dev/null|sed 1q]
339 warning "$UPDATEDB, program does not exist"