Fix disassembly of some VST1 instructions.
[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
50   global ocamlopt
51   global link shlibext
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 %link with C++ link command
61   regsub -all {%link} $new_line "$link" new_line
62   #replace %shlibext with shared library extension
63   regsub -all {%shlibext} $new_line "$shlibext" new_line
64   #replace %ocamlopt with ocaml compiler command
65   regsub -all {%ocamlopt} $new_line "$ocamlopt" new_line
66   #replace %p with path to source,
67   regsub -all {%p} $new_line [file join $srcdir $subdir] new_line
68   #replace %s with filename
69   regsub -all {%s} $new_line $test new_line
70   #replace %t with temp filenames
71   regsub -all {%t} $new_line $tmpFile new_line
72   #replace %abs_tmp with absolute temp filenames
73   regsub -all {%abs_tmp} $new_line [file join [pwd] $tmpFile] new_line
74   #replace _#MARKER#_ with %
75   regsub -all {_#MARKER#_} $new_line % new_line
76
77   #replace grep with GNU grep
78   regsub -all { grep } $new_line " $grep " new_line
79   #replace as with GNU as
80   regsub -all {\| as } $new_line "| $gas " new_line
81
82   #valgind related stuff
83 # regsub -all {bugpoint } $new_line "$valgrind bugpoint " new_line
84   regsub -all {llc } $new_line "$valgrind llc " new_line
85   regsub -all {lli } $new_line "$valgrind lli " new_line
86   regsub -all {llvm-ar } $new_line "$valgrind llvm-ar " new_line
87   regsub -all {llvm-as } $new_line "$valgrind llvm-as " new_line
88   regsub -all {llvm-bcanalyzer } $new_line "$valgrind llvm-bcanalyzer " new_line
89   regsub -all {llvm-dis } $new_line "$valgrind llvm-dis " new_line
90   regsub -all {llvm-extract } $new_line "$valgrind llvm-extract " new_line
91   regsub -all {llvm-ld } $new_line "$valgrind llvm-ld " new_line
92   regsub -all {llvm-link } $new_line "$valgrind llvm-link " new_line
93   regsub -all {llvm-nm } $new_line "$valgrind llvm-nm " new_line
94   regsub -all {llvm-prof } $new_line "$valgrind llvm-prof " new_line
95   regsub -all {llvm-ranlib } $new_line "$valgrind llvm-ranlib " new_line
96   regsub -all {([^a-zA-Z_-])opt } $new_line "\\1$valgrind opt " new_line
97   regsub -all {^opt } $new_line "$valgrind opt " new_line
98   regsub -all {llvm-tblgen } $new_line "$valgrind llvm-tblgen " new_line
99   regsub -all "not $valgrind " $new_line "$valgrind not " new_line
100
101   return $new_line
102 }
103
104 # This procedure runs the set of tests for the test_source_files array.
105 proc RunLLVMTests { test_source_files } {
106   global srcroot objroot srcdir objdir subdir target_triplet
107   set timeout 60
108
109   set path [file join $objdir $subdir]
110
111   #Make Output Directory if it does not exist already
112   if { [file exists path] } {
113     cd $path
114   } else {
115     file mkdir $path
116     cd $path
117   }
118
119   file mkdir Output
120   cd Output
121
122   foreach test $test_source_files {
123     #Should figure out best way to set the timeout
124     #set timeout 40
125
126     set filename [file tail $test]
127     verbose "ABOUT TO RUN: $filename" 2
128     set outcome PASS
129     set tmpFile "$filename.tmp"
130
131     # Mark that it should not be XFAIL for this target.
132     set targetPASS 0
133
134     #set hasRunline bool to check if testcase has a runline
135     set numLines 0
136
137     # Open the test file and start reading lines
138     set testFileId [ open $test r]
139     set runline ""
140     set PRNUMS ""
141     foreach line [split [read $testFileId] \n] {
142
143       # if its the END. line then stop parsing (optimization for big files)
144       if {[regexp {END.[[:space:]]*$} $line match endofscript]} {
145         break
146
147       # if the line is continued, concatenate and continue the loop
148       } elseif {[regexp {RUN: *(.+)(\\)$} $line match oneline suffix]} {
149         set runline "$runline$oneline "
150
151       # if its a terminating RUN: line then do substitution on the whole line
152       # and then save the line.
153       } elseif {[regexp {RUN: *(.+)$} $line match oneline suffix]} {
154         set runline "$runline$oneline"
155         set runline [ substitute $runline $test $tmpFile ]
156         set lines($numLines) $runline
157         set numLines [expr $numLines + 1]
158         set runline ""
159
160       # if its an PR line, save the problem report number
161       } elseif {[regexp {PR([0-9]+)} $line match prnum]} {
162         if {$PRNUMS == ""} {
163           set PRNUMS "PR$prnum"
164         } else {
165           set PRNUMS "$PRNUMS,$prnum"
166         }
167       # if its an XFAIL line, see if we should be XFAILing or not.
168       } elseif {[regexp {XFAIL:[ *](.+)} $line match targets]} {
169         set targets
170
171         #split up target if more then 1 specified
172         foreach target [split $targets ,] {
173           if { $target == "*" } {
174               if {$targetPASS != 1} {
175                  set outcome XFAIL
176               }
177           } elseif { [regexp $target $target_triplet match] } {
178               if {$targetPASS != 1} {
179                  set outcome XFAIL
180               }
181           }
182         }
183       } elseif {[regexp {XTARGET:[ *](.+)} $line match targets]} {
184         set targets
185
186         #split up target if more then 1 specified
187         foreach target [split $targets ,] {
188           if { [regexp {\*} $target match] } {
189               set targetPASS 1
190               set outcome PASS
191           } elseif { [regexp $target $target_triplet match] } {
192               set targetPASS 1
193               set outcome PASS
194           }
195         }
196       }
197     }
198
199     # Done reading the script
200     close $testFileId
201
202
203     if { $numLines == 0 } {
204       fail "$test: \nDoes not have a RUN line\n"
205     } else {
206       set failed 0
207       for { set i 0 } { $i < $numLines } { set i [ expr $i + 1 ] } {
208         regsub ^.*RUN:(.*) $lines($i) \1 theLine
209         set resultmsg [execOneLine $test $PRNUMS $outcome $i $theLine ]
210         if { $resultmsg != "" } {
211           if { $outcome == "XFAIL" } {
212             xfail "$resultmsg"
213           } else {
214             fail "$resultmsg"
215           }
216           set failed 1
217           break
218         }
219       }
220       if { $failed } {
221         continue
222       } else {
223         if { $PRNUMS != "" } {
224           set PRNUMS " for $PRNUMS"
225         }
226         if { $outcome == "XFAIL" } {
227           xpass "$test$PRNUMS"
228         } else {
229           pass "$test$PRNUMS"
230         }
231       }
232     }
233   }
234 }
235
236 # This procedure provides an interface to check the TARGETS_TO_BUILD makefile
237 # variable to see if a particular target has been configured to build. This
238 # helps avoid running tests for targets that aren't available.
239 proc llvm_supports_target { tgtName } {
240   global TARGETS_TO_BUILD
241   foreach target [split $TARGETS_TO_BUILD] {
242     if { [regexp $tgtName $target match] } {
243       return 1
244     }
245   }
246   return 0
247 }
248
249 proc llvm_supports_darwin_and_target { tgtName } {
250   global target_triplet
251   if { [ llvm_supports_target $tgtName ] } {
252     if { [regexp darwin $target_triplet match] } {
253       return 1
254     }
255   }
256   return 0
257 }
258
259 # This procedure provides an interface to check the BINDINGS_TO_BUILD makefile
260 # variable to see if a particular binding has been configured to build.
261 proc llvm_supports_binding { name } {
262   global llvm_bindings
263   foreach item [split $llvm_bindings] {
264     if { [regexp $name $item match] } {
265       return 1
266     }
267   }
268   return 0
269 }