aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/consistency.vlad/vlad.exp
blob: f53377e013520e717f90f04cf854567f275b927c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# Copyright (C) 1998,1999 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 

# Please email any bugs, comments, and/or additions to this file to:
# bug-gcc@prep.ai.mit.edu

# This file was created for by Vladimir Makarov (vmakarov@cygnus.com)
# on the base c-torture.exp.

# The script requires setting up BASE_COMPILER (e.g. in RUNTESTFLAGS).
# The default options can be overridden by
# CONSISTENCY_OPTIONS="option ... " (e.g. in RUNTESTFLAGS).


if $tracelevel then {
    strace $tracelevel
}

if ![info exists BASE_COMPILER] {
    fail "BASE_COMPILER is not set"  
    return
}

if ![info exists CONSISTENCY_OPTIONS] {
    set CONSISTENCY_OPTIONS "-O2"
}

if ![info exists NO_LONG_DOUBLE] {
    set NO_LONG_DOUBLE 0
}

if ![info exists NO_LIBGLOSS_LIBRARY_OPTIONS] {
    set NO_LIBGLOSS_LIBRARY_OPTIONS 0
}

puts $CONSISTENCY_OPTIONS

regsub -- -.* $target_triplet "" target_chip

#
# c-consistency-execute -- utility to compile and execute a testcase
#
# SRC is the full pathname of the testcase.
#
# If the testcase has an associated .cexp file, we source that to run the
# test instead.  We use .cexp instead of .exp so that the testcase is still
# controlled by the main .exp driver (this is useful when one wants to only
# run the compile.exp tests for example - one need only pass compile.exp to
# dejagnu, and not compile.exp, foo1.exp, foo2.exp, etc.).
#
proc c-consistency-execute { src cpp_flag out_suffix} {
    global tmpdir tool srcdir output
    global exec_output target_chip BASE_COMPILER target_triplet
    global CONSISTENCY_OPTIONS NO_LONG_DOUBLE

    set consistency_options $CONSISTENCY_OPTIONS

    set rootname [file rootname $src]
    set dirname [file dirname $src]
    set basename [file tail $rootname]
    # Check for alternate driver.
    if [file exists $rootname.cexp] {
	verbose "Using alternate driver $basename.cexp" 2
	set done_p 0
	catch "set done_p \[source $rootname.cexp\]"
	if { $done_p } {
	    return
	}
    }
   
    set executable $tmpdir/$basename.x

    regsub "^$srcdir/?" $src "" testcase
    # If we couldn't rip $srcdir out of `src' then just do the best we can.
    # The point is to reduce the unnecessary noise in the logs.  Don't strip
    # out too much because different testcases with the same name can confuse
    # `test-tool'.
    if [string match "/*" $testcase] {
	set testcase "[file tail $dirname]/[file tail $src]"
    }

    # consistency_{compile,execute}_xfail are set by the .cexp script
    # (if present)
    if [info exists consistency_compile_xfail] {
        setup_xfail $consistency_compile_xfail
    }
    remote_file build delete $executable
    verbose "Testing $testcase, $consistency_options" 1
    
    set options ""
    lappend options "additional_flags=-w $consistency_options"

    set wrap_file ""
    if {[file exists "$dirname/WRAP_FILE"] \
         && [file readable "$dirname/WRAP_FILE"]} {
      set fd [open "$dirname/WRAP_FILE"]
      set wrap_file "$dirname/[read -nonewline $fd]"
      close $fd
    }

    set comp_output [gcc_target_compile "$cpp_flag $src -x none $wrap_file" "$executable" executable $options]
    
    # Set a few common compiler messages.
    set fatal_signal "*cc: Internal compiler error: program*got fatal signal"
    
    if [string match "$fatal_signal 6" $comp_output] then {
        fail $testcase "Got Signal 6, $cpp_flag $consistency_options"
        remote_file build delete $executable
        return
    }
    
    if [string match "$fatal_signal 11" $comp_output] then {
        fail $testcase "Got Signal 11, $cpp_flag $consistency_options"
        remote_file build delete $executable
        return
    }
    
    # We shouldn't get these because of -w, but just in case.
    if [string match "*cc:*warning:*" $comp_output] then {
        warning "$testcase: (with warnings) $cpp_flag $consistency_options"
        send_log "$comp_output\n"
        unresolved "$testcase, $cpp_flag $consistency_options"
        remote_file build delete $executable
        return
    }
    
    set comp_output [prune_warnings $comp_output]
    
    if { ![file exists $executable] } {
        if ![is3way] {
   	    	fail "$testcase compilation, $cpp_flag $consistency_options"
    		untested "$testcase execution, $cpp_flag $consistency_options"
    		return
        } else {
    		# FIXME: since we can't test for the existance of a remote
    		# file without short of doing an remote file list, we assume
    		# that since we got no output, it must have compiled.
    		pass "$testcase compilation, $cpp_flag $consistency_options"
        }
    } else {
        pass "$testcase compilation, $cpp_flag $consistency_options"
    }
    
    # Check for compilation only.
    if [file exists $rootname.conly] {
      remote_file build delete $executable
      return
    }

    # See if this source file uses "long long" types, if it does, and
    # no_long_long is set, skip execution of the test.
    if [target_info exists no_long_long] then {
      if [expr [search_for $src "long long"]] then {
	untested "$testcase execution, $options"
	continue
      }
    }

    if [info exists consistency_execute_xfail] {
        setup_xfail $consistency_execute_xfail
    }
    
    set exec_output ""
    set result [consistency_load "$executable" "" ""]
    set status [lindex $result 0]
    set exec_output [lindex $result 1]

    # Strip random whitespace junk from the output.  the
    # whitejunk is an artifact of the way we get output
    # from boards.
    regsub "^\[ \t\r]+" $exec_output "" clean_output
    regsub -all "\r" $clean_output "" clean_output
    regsub -all "\[ \t]*\n\[ \t]*" $clean_output "\n" clean_output
    regsub -all "\n+" $clean_output "\n" clean_output
    regsub -all "^\n+$" $clean_output "" clean_output

    if { $status == "pass" } {
        remote_file build delete $executable
    }
    $status "$testcase execution, $cpp_flag $consistency_options"

    if { $status != "pass" } {
      return
    }

    # Now save the output of the test programs
    set outfile_name "$tmpdir/$basename.$out_suffix"
    set outf [open $outfile_name "w"]
    if { $clean_output != "" } {
      puts -nonewline $outf $clean_output
    }
    close $outf

    set base_outfile_name "$dirname/${BASE_COMPILER}-results/$basename.$out_suffix"

    # Check that the output for another processor has been saved
    if { ![file exists $base_outfile_name] } {
      untested "$testcase consistency - $base_outfile_name doesn't exist"
      return
    } elseif { ![file readable $base_outfile_name] } {
      untested "$testcase consistency - $base_outfile_name is not readable"
      return
    }

    # See if this source file uses "long double" types, if it does, and
    # NO_LONG_DOUBLE is TRUE, skip comparison of the test.
    if {$NO_LONG_DOUBLE} then {
        if [expr [search_for $src "long double"]] then {
	      setup_xfail "$target_triplet"
        }
    }

    # Compare the outputs
    if {![catch "exec diff -b $outfile_name $base_outfile_name" message]} {
      pass "$testcase consistency, $cpp_flag $consistency_options"
    } else {
      regsub "\n\[^>\n]\[^\n]*\$" $message "\n" difference
      fail "$testcase consistency, $cpp_flag $consistency_options\n$difference"
    }
}

#
# search_for -- looks for a string match in a file
#
proc search_for { file pattern } {
    set fd [open $file r]
    while { [gets $fd cur_line]>=0 } {
	if [string match "*$pattern*" $cur_line] then {
	    close $fd
	    return 1
	}
    }
    close $fd
    return 0
}

if {$NO_LIBGLOSS_LIBRARY_OPTIONS} {
    # Remove standard libgloss library paths
    set board_info(powerpc-sim,ldflags) "-msim"
}

#
# main test loop
#

foreach dir [lsort [glob -nocomplain $srcdir/$subdir/\[a-z\]*]] {
     if [file isdirectory $dir] {
          set all_sources [concat [glob -nocomplain $dir/*.c] [glob -nocomplain $dir/*.cpp]]
          foreach src [lsort $all_sources] {
             # If we're only testing specific files and this isn't one of
             # them, skip it.
             if ![runtest_file_p $runtests $src] then {
	       continue
             }
               regsub "^.*\\." $src "" suffix            
             if {$suffix != "cpp"} {
               c-consistency-execute $src "" "out"
             }
             c-consistency-execute $src "-x c++" "out++"
          }
     }
}