DebugLoc propagation for int<->fp conversions.
[oota-llvm.git] / test / lib / llvm.exp
1 # This procedure executes one line of a test case's execution script.
2 proc execOneLine { test PRS outcome lineno line } {
3   set status 0
4   set resultmsg ""
5   set retval [ catch { eval exec -keepnewline -- $line } errmsg ]
6   if { $retval != 0 } {
7     set code [lindex $::errorCode 0]
8     set lineno [expr $lineno + 1]
9     if { $PRS != ""} {
10       set PRS " for $PRS" 
11     }
12     set errmsg " at line $lineno\nwhile running: $line\n$errmsg"
13     switch "$code" {
14       CHILDSTATUS {
15         set status [lindex $::errorCode 2]
16         if { $status != 0 } {
17           set resultmsg "$test$PRS\nFailed with exit($status)$errmsg"
18         }
19       }
20       CHILDKILLED {
21         set signal [lindex $::errorCode 2]
22         set resultmsg "$test$PRS\nFailed with signal($signal)$errmsg"
23       }
24       CHILDSUSP {
25         set signal [lindex $::errorCode 2]
26         set resultmsg "$test$PRS\nFailed with suspend($signal)$errmsg"
27       }
28       POSIX {
29         set posixNum [lindex $::errorCode 1]
30         set posixMsg [lindex $::errorCode 2]
31         set resultmsg "$test$PRS\nFailed with posix($posixNum,$posixMsg)$errmsg"
32       }
33       NONE {
34         # Any other error such as stderr output of a program, or syntax error in
35         # the RUN line.
36         set resultmsg "$test$PRS\nFailed with unknown error (or has stderr output)$errmsg" 
37       }
38       default {
39         set resultmsg "$test$PRS\nFailed with unknown error$errmsg" 
40       }
41     }
42   } 
43   return $resultmsg
44 }
45
46 # This procedure performs variable substitutions on the RUN: lines of a test
47 # cases.
48 proc substitute { line test tmpFile } {
49   global srcroot objroot srcdir objdir subdir target_triplet prcontext 
50   global llvmgcc llvmgxx llvmgcc_version llvmgccmajvers ocamlc
51   global gccpath gxxpath compile_c compile_cxx link shlibext llvmlibsdir
52   global valgrind grep gas
53   set path [file join $srcdir $subdir]
54
55   # Substitute all Tcl variables.
56   set new_line [subst $line ]
57
58   #replace %% with _#MARKER#_ to make the replacement of %% more predictable
59   regsub -all {%%} $new_line {_#MARKER#_} new_line
60   #replace %prcontext with prcontext.tcl (Must replace before %p)
61   regsub -all {%prcontext} $new_line $prcontext new_line
62   #replace %llvmgcc with actual path to llvmgcc
63   regsub -all {%llvmgcc} $new_line "$llvmgcc -emit-llvm -w" new_line
64   #replace %llvmgxx with actual path to llvmg++
65   regsub -all {%llvmgxx} $new_line "$llvmgxx -emit-llvm -w" new_line
66   #replace %compile_cxx with C++ compilation command
67   regsub -all {%compile_cxx} $new_line "$compile_cxx" new_line
68   #replace %compile_c with C compilation command
69   regsub -all {%compile_c} $new_line "$compile_c" new_line
70   #replace %link with C++ link command
71   regsub -all {%link} $new_line "$link" new_line
72   #replace %shlibext with shared library extension
73   regsub -all {%shlibext} $new_line "$shlibext" new_line
74   #replace %ocamlc with ocaml compiler command
75   regsub -all {%ocamlc} $new_line "$ocamlc" new_line
76   #replace %llvmlibsdir with configure library directory
77   regsub -all {%llvmlibsdir} $new_line "$llvmlibsdir" new_line
78   #replace %p with path to source, 
79   regsub -all {%p} $new_line [file join $srcdir $subdir] new_line
80   #replace %s with filename
81   regsub -all {%s} $new_line $test new_line
82   #replace %t with temp filenames
83   regsub -all {%t} $new_line $tmpFile new_line
84   #replace _#MARKER#_ with %
85   regsub -all {_#MARKER#_} $new_line % new_line
86
87   #replace grep with GNU grep
88   regsub -all { grep } $new_line " $grep " new_line
89   #replace as with GNU as
90   regsub -all {\| as } $new_line "| $gas " new_line
91
92   #valgind related stuff
93 # regsub -all {bugpoint } $new_line "$valgrind bugpoint " new_line
94   regsub -all {llc } $new_line "$valgrind llc " new_line
95   regsub -all {lli } $new_line "$valgrind lli " new_line
96   regsub -all {llvm-ar } $new_line "$valgrind llvm-ar " new_line
97   regsub -all {llvm-as } $new_line "$valgrind llvm-as " new_line
98   regsub -all {llvm-bcanalyzer } $new_line "$valgrind llvm-bcanalyzer " new_line
99   regsub -all {llvm-dis } $new_line "$valgrind llvm-dis " new_line
100   regsub -all {llvm-extract } $new_line "$valgrind llvm-extract " new_line
101   regsub -all {llvm-ld } $new_line "$valgrind llvm-ld " new_line
102   regsub -all {llvm-link } $new_line "$valgrind llvm-link " new_line
103   regsub -all {llvm-nm } $new_line "$valgrind llvm-nm " new_line
104   regsub -all {llvm-prof } $new_line "$valgrind llvm-prof " new_line
105   regsub -all {llvm-ranlib } $new_line "$valgrind llvm-ranlib " new_line
106   regsub -all {([^a-zA-Z_-])opt } $new_line "\\1$valgrind opt " new_line
107   regsub -all {^opt } $new_line "$valgrind opt " new_line
108   regsub -all {tblgen } $new_line "$valgrind tblgen " new_line
109   regsub -all "not $valgrind " $new_line "$valgrind not " new_line
110
111   return $new_line
112 }
113
114 # This procedure runs the set of tests for the test_source_files array.
115 proc RunLLVMTests { test_source_files } {
116   global srcroot objroot srcdir objdir subdir target_triplet llvmgcc_version
117   set timeout 60
118
119   set path [file join $objdir $subdir]
120   
121   #Make Output Directory if it does not exist already
122   if { [file exists path] } {
123     cd $path
124   } else {
125     file mkdir $path
126     cd $path
127   }
128   
129   file mkdir Output
130   cd Output
131
132   foreach test $test_source_files {
133     #Should figure out best way to set the timeout
134     #set timeout 40
135     
136     set filename [file tail $test]
137     verbose "ABOUT TO RUN: $filename" 2
138     set outcome PASS
139     set tmpFile "$filename.tmp"
140     
141     # Mark that it should not be XFAIL for this target.
142     set targetPASS 0
143     
144     #set hasRunline bool to check if testcase has a runline
145     set numLines 0
146
147     # Open the test file and start reading lines
148     set testFileId [ open $test r]
149     set runline ""
150     set PRNUMS ""
151     foreach line [split [read $testFileId] \n] {
152
153       # if its the END. line then stop parsing (optimization for big files)
154       if {[regexp {END.[[:space:]]*$} $line match endofscript]} {        
155         break
156
157       # if the line is continued, concatenate and continue the loop
158       } elseif {[regexp {RUN: *(.+)(\\)$} $line match oneline suffix]} {
159         set runline "$runline$oneline "
160
161       # if its a terminating RUN: line then do substitution on the whole line
162       # and then save the line. 
163       } elseif {[regexp {RUN: *(.+)$} $line match oneline suffix]} {
164         set runline "$runline$oneline"
165         set runline [ substitute $runline $test $tmpFile ]
166         set lines($numLines) $runline
167         set numLines [expr $numLines + 1]
168         set runline ""
169
170       # if its an PR line, save the problem report number
171       } elseif {[regexp {PR([0-9]+)} $line match prnum]} {
172         if {$PRNUMS == ""} {
173           set PRNUMS "PR$prnum"
174         } else {
175           set PRNUMS "$PRNUMS,$prnum"
176         }
177       # if its an XFAIL line, see if we should be XFAILing or not.
178       } elseif {[regexp {XFAIL:[ *](.+)} $line match targets]} {
179         set targets
180
181         #split up target if more then 1 specified
182         foreach target [split $targets ,] {
183           if { [regexp {\*} $target match] } {
184               if {$targetPASS != 1} {
185                  set outcome XFAIL
186               }
187           } elseif { [regexp $target $target_triplet match] } {
188               if {$targetPASS != 1} {
189                  set outcome XFAIL
190               }
191           } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2]  } {
192             if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
193               if {$targetPASS != 1} {
194                  set outcome XFAIL
195               }
196             }
197           }
198         }
199       } elseif {[regexp {XTARGET:[ *](.+)} $line match targets]} {
200         set targets
201
202         #split up target if more then 1 specified
203         foreach target [split $targets ,] {
204           if { [regexp {\*} $target match] } {
205               set targetPASS 1
206               set outcome PASS
207           } elseif { [regexp $target $target_triplet match] } {
208               set targetPASS 1
209               set outcome PASS
210           } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2]  } {
211             if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
212               set targetPASS 1
213               set outcome PASS
214             }
215           }
216         }
217       }
218     }
219     
220     # Done reading the script
221     close $testFileId
222     
223     
224     if { $numLines == 0 } {
225       fail "$test: \nDoes not have a RUN line\n"
226     } else {
227       set failed 0
228       for { set i 0 } { $i < $numLines } { set i [ expr $i + 1 ] } {
229         regsub ^.*RUN:(.*) $lines($i) \1 theLine
230         set resultmsg [execOneLine $test $PRNUMS $outcome $i $theLine ]
231         if { $resultmsg != "" } {
232           if { $outcome == "XFAIL" } {
233             xfail "$resultmsg"
234           } else {
235             fail "$resultmsg"
236           }
237           set failed 1
238           break
239         }
240       }
241       if { $failed } {
242         continue
243       } else {
244         if { $PRNUMS != "" } {
245           set PRNUMS " for $PRNUMS"
246         }
247         if { $outcome == "XFAIL" } {
248           xpass "$test$PRNUMS"
249         } else {
250           pass "$test$PRNUMS"
251         }
252       }
253     }
254   }
255 }
256
257 # This procedure provides an interface to check the LLVMGCC_LANGS makefile
258 # variable to see if llvm-gcc supports compilation of a particular language.
259 proc llvm_gcc_supports { lang } {
260   global llvmgcc llvmgcc_langs
261   # validate the language choices and determine the name of the compiler
262   # component responsible for determining if the compiler has been built.
263   switch "$lang" {
264     ada     { set file gnat1 }
265     c       { set file cc1 }
266     c++     { set file cc1plus }
267     objc    { set file cc1obj }
268     obj-c++ { set file cc1objplus }
269     fortran { set file f951 }
270     default { return 0 }
271   }
272   foreach supported_lang [split "$llvmgcc_langs" ,] {
273     if { "$lang" == "$supported_lang" } {
274       # FIXME: Knowing it is configured is not enough. We should do two more
275       # checks here. First, we need to run llvm-gcc -print-prog-name=$file to 
276       # get the path to the compiler. If we don't get a path, the language isn't
277       # properly configured or built. If we do get a path, we should check to 
278       # make sure that it is executable and perhaps even try executing it.
279       return 1;
280     }
281   }
282   return 0;
283 }
284
285 # This procedure provides an interface to check the TARGETS_TO_BUILD makefile
286 # variable to see if a particular target has been configured to build. This
287 # helps avoid running tests for targets that aren't available.
288 proc llvm_supports_target { tgtName } {
289   global TARGETS_TO_BUILD
290   foreach target [split $TARGETS_TO_BUILD] {
291     if { [regexp $tgtName $target match] } {
292       return 1
293     }
294   }
295   return 0
296 }