blob: b5d5cffae1e0f7b579b88d181f7196fd65261d7d [file] [log] [blame]
Reid Spencer12d81f32007-04-21 21:45:51 +00001# This procedure executes one line of a test case's execution script.
Reid Spencer90016c72007-04-14 19:37:22 +00002proc execOneLine { test PRS outcome lineno line } {
Reid Spencer316abe42007-04-14 09:39:28 +00003 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]
Reid Spencer520b4872007-04-14 16:41:39 +00008 set lineno [expr $lineno + 1]
Reid Spencer90016c72007-04-14 19:37:22 +00009 if { $PRS != ""} {
10 set PRS " for $PRS"
11 }
Reid Spencer6cdf4a92007-04-21 18:53:12 +000012 set errmsg " at line $lineno\nwhile running: $line\n$errmsg"
Reid Spencer316abe42007-04-14 09:39:28 +000013 switch "$code" {
14 CHILDSTATUS {
15 set status [lindex $::errorCode 2]
Duncan Sands25d50d62007-04-16 15:37:00 +000016 if { $status != 0 } {
Reid Spencer6cdf4a92007-04-21 18:53:12 +000017 set resultmsg "$test$PRS\nFailed with exit($status)$errmsg"
Reid Spencer316abe42007-04-14 09:39:28 +000018 }
19 }
20 CHILDKILLED {
21 set signal [lindex $::errorCode 2]
Reid Spencer6cdf4a92007-04-21 18:53:12 +000022 set resultmsg "$test$PRS\nFailed with signal($signal)$errmsg"
Reid Spencer316abe42007-04-14 09:39:28 +000023 }
24 CHILDSUSP {
25 set signal [lindex $::errorCode 2]
Reid Spencer6cdf4a92007-04-21 18:53:12 +000026 set resultmsg "$test$PRS\nFailed with suspend($signal)$errmsg"
Reid Spencer316abe42007-04-14 09:39:28 +000027 }
28 POSIX {
29 set posixNum [lindex $::errorCode 1]
30 set posixMsg [lindex $::errorCode 2]
Reid Spencer6cdf4a92007-04-21 18:53:12 +000031 set resultmsg "$test$PRS\nFailed with posix($posixNum,$posixMsg)$errmsg"
Reid Spencer316abe42007-04-14 09:39:28 +000032 }
33 NONE {
Matthijs Kooijmanc9e00432008-06-10 12:28:43 +000034 # 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"
Reid Spencer316abe42007-04-14 09:39:28 +000037 }
38 default {
Matthijs Kooijmanc9e00432008-06-10 12:28:43 +000039 set resultmsg "$test$PRS\nFailed with unknown error$errmsg"
Reid Spencer316abe42007-04-14 09:39:28 +000040 }
41 }
42 }
43 return $resultmsg
44}
45
Duncan Sands7d841a42007-05-18 12:13:34 +000046# This procedure performs variable substitutions on the RUN: lines of a test
Reid Spencer12d81f32007-04-21 21:45:51 +000047# cases.
Reid Spencer316abe42007-04-14 09:39:28 +000048proc substitute { line test tmpFile } {
49 global srcroot objroot srcdir objdir subdir target_triplet prcontext
Gordon Henriksen8ef426b2007-09-18 12:49:39 +000050 global llvmgcc llvmgxx llvmgcc_version llvmgccmajvers ocamlc
Reid Spencer316abe42007-04-14 09:39:28 +000051 global gccpath gxxpath compile_c compile_cxx link shlibext llvmlibsdir
Torok Edwin237033e2008-10-21 17:21:32 +000052 global valgrind grep gas
Reid Spencer78fb2ac2007-04-14 22:51:29 +000053 set path [file join $srcdir $subdir]
Reid Spencer316abe42007-04-14 09:39:28 +000054
Reid Spencer0947df42007-04-15 07:21:26 +000055 # Substitute all Tcl variables.
56 set new_line [subst $line ]
57
Nuno Lopes2bdc07b2008-10-07 14:48:14 +000058 #replace %% with _#MARKER#_ to make the replacement of %% more predictable
59 regsub -all {%%} $new_line {_#MARKER#_} new_line
Reid Spencer316abe42007-04-14 09:39:28 +000060 #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
Duncan Sands53ebe352008-06-21 20:22:58 +000063 regsub -all {%llvmgcc} $new_line "$llvmgcc -emit-llvm -w" new_line
Reid Spencer316abe42007-04-14 09:39:28 +000064 #replace %llvmgxx with actual path to llvmg++
Duncan Sands53ebe352008-06-21 20:22:58 +000065 regsub -all {%llvmgxx} $new_line "$llvmgxx -emit-llvm -w" new_line
Reid Spencer316abe42007-04-14 09:39:28 +000066 #replace %compile_cxx with C++ compilation command
67 regsub -all {%compile_cxx} $new_line "$compile_cxx" new_line
Chris Lattneraadbda82008-03-10 06:45:35 +000068 #replace %compile_c with C compilation command
69 regsub -all {%compile_c} $new_line "$compile_c" new_line
Reid Spencer316abe42007-04-14 09:39:28 +000070 #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
Gordon Henriksen8ef426b2007-09-18 12:49:39 +000074 #replace %ocamlc with ocaml compiler command
75 regsub -all {%ocamlc} $new_line "$ocamlc" new_line
Reid Spencer316abe42007-04-14 09:39:28 +000076 #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
Duncan Sands6c7ada42007-07-23 15:23:35 +000083 regsub -all {%t} $new_line $tmpFile new_line
Nuno Lopes2bdc07b2008-10-07 14:48:14 +000084 #replace _#MARKER#_ with %
85 regsub -all {_#MARKER#_} $new_line % new_line
86
Torok Edwin237033e2008-10-21 17:21:32 +000087 #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
Nuno Lopes2bdc07b2008-10-07 14:48:14 +000092 #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
Reid Spencer316abe42007-04-14 09:39:28 +0000111 return $new_line
112}
113
Reid Spencer12d81f32007-04-21 21:45:51 +0000114# This procedure runs the set of tests for the test_source_files array.
Reid Spencer78fb2ac2007-04-14 22:51:29 +0000115proc RunLLVMTests { test_source_files } {
Reid Spencerfb7653e2007-04-15 20:43:36 +0000116 global srcroot objroot srcdir objdir subdir target_triplet llvmgcc_version
Reid Spencer316abe42007-04-14 09:39:28 +0000117 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
Duncan Sands6c7ada42007-07-23 15:23:35 +0000130 cd Output
Reid Spencer316abe42007-04-14 09:39:28 +0000131
Reid Spencer78fb2ac2007-04-14 22:51:29 +0000132 foreach test $test_source_files {
Reid Spencer316abe42007-04-14 09:39:28 +0000133 #Should figure out best way to set the timeout
134 #set timeout 40
135
136 set filename [file tail $test]
Gabor Greif684ed3d2008-02-26 12:08:55 +0000137 verbose "ABOUT TO RUN: $filename" 2
Reid Spencer316abe42007-04-14 09:39:28 +0000138 set outcome PASS
139 set tmpFile "$filename.tmp"
Tanya Lattnera57506e2007-11-06 22:32:17 +0000140
141 # Mark that it should not be XFAIL for this target.
142 set targetPASS 0
143
Reid Spencer316abe42007-04-14 09:39:28 +0000144 #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 ""
Reid Spencer90016c72007-04-14 19:37:22 +0000150 set PRNUMS ""
Reid Spencerfb7653e2007-04-15 20:43:36 +0000151 foreach line [split [read $testFileId] \n] {
Reid Spencer316abe42007-04-14 09:39:28 +0000152
Reid Spencer90016c72007-04-14 19:37:22 +0000153 # if its the END. line then stop parsing (optimization for big files)
Tanya Lattner200d6072008-03-13 22:02:51 +0000154 if {[regexp {END.[[:space:]]*$} $line match endofscript]} {
Reid Spencer316abe42007-04-14 09:39:28 +0000155 break
Reid Spencer90016c72007-04-14 19:37:22 +0000156
Duncan Sands3724df32007-04-16 21:19:45 +0000157 # if the line is continued, concatenate and continue the loop
Reid Spencer601e8452007-04-15 18:38:42 +0000158 } elseif {[regexp {RUN: *(.+)(\\)$} $line match oneline suffix]} {
Reid Spencer316abe42007-04-14 09:39:28 +0000159 set runline "$runline$oneline "
Reid Spencer90016c72007-04-14 19:37:22 +0000160
161 # if its a terminating RUN: line then do substitution on the whole line
Tanya Lattner727842e2007-11-28 04:57:00 +0000162 # and then save the line.
163 } elseif {[regexp {RUN: *(.+)$} $line match oneline suffix]} {
Reid Spencer316abe42007-04-14 09:39:28 +0000164 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 ""
Reid Spencer90016c72007-04-14 19:37:22 +0000169
170 # if its an PR line, save the problem report number
171 } elseif {[regexp {PR([0-9]+)} $line match prnum]} {
172 if {$PRNUMS == ""} {
Reid Spencer66959ce2007-04-15 10:27:54 +0000173 set PRNUMS "PR$prnum"
Reid Spencer90016c72007-04-14 19:37:22 +0000174 } else {
175 set PRNUMS "$PRNUMS,$prnum"
176 }
177 # if its an XFAIL line, see if we should be XFAILing or not.
Reid Spencer316abe42007-04-14 09:39:28 +0000178 } 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] } {
Tanya Lattnera57506e2007-11-06 22:32:17 +0000184 if {$targetPASS != 1} {
185 set outcome XFAIL
186 }
Reid Spencer316abe42007-04-14 09:39:28 +0000187 } elseif { [regexp $target $target_triplet match] } {
Tanya Lattnera57506e2007-11-06 22:32:17 +0000188 if {$targetPASS != 1} {
189 set outcome XFAIL
190 }
Reid Spencer316abe42007-04-14 09:39:28 +0000191 } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2] } {
192 if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
Tanya Lattnera57506e2007-11-06 22:32:17 +0000193 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
Reid Spencer316abe42007-04-14 09:39:28 +0000214 }
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
Reid Spencer90016c72007-04-14 19:37:22 +0000230 set resultmsg [execOneLine $test $PRNUMS $outcome $i $theLine ]
Reid Spencer316abe42007-04-14 09:39:28 +0000231 if { $resultmsg != "" } {
232 if { $outcome == "XFAIL" } {
233 xfail "$resultmsg"
234 } else {
235 fail "$resultmsg"
236 }
237 set failed 1
238 break
239 }
240 }
Reid Spencer0947df42007-04-15 07:21:26 +0000241 if { $failed } {
Reid Spencerb0feffa2007-04-15 07:34:58 +0000242 continue
Reid Spencer0947df42007-04-15 07:21:26 +0000243 } else {
244 if { $PRNUMS != "" } {
Reid Spencer90016c72007-04-14 19:37:22 +0000245 set PRNUMS " for $PRNUMS"
246 }
Reid Spencer316abe42007-04-14 09:39:28 +0000247 if { $outcome == "XFAIL" } {
Reid Spencer90016c72007-04-14 19:37:22 +0000248 xpass "$test$PRNUMS"
Reid Spencer316abe42007-04-14 09:39:28 +0000249 } else {
Reid Spencer90016c72007-04-14 19:37:22 +0000250 pass "$test$PRNUMS"
Reid Spencer316abe42007-04-14 09:39:28 +0000251 }
252 }
253 }
254 }
255}
Devang Patel9fe99072007-04-20 21:24:01 +0000256
Reid Spencer12d81f32007-04-21 21:45:51 +0000257# This procedure provides an interface to check the LLVMGCC_LANGS makefile
258# variable to see if llvm-gcc supports compilation of a particular language.
259proc 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 }
Duncan Sandsc93346a2008-08-07 17:59:54 +0000267 objc { set file cc1obj }
Duncan Sands96f94522008-10-06 10:31:21 +0000268 obj-c++ { set file cc1objplus }
Duncan Sands39212662008-06-27 14:22:20 +0000269 fortran { set file f951 }
Reid Spencer12d81f32007-04-21 21:45:51 +0000270 default { return 0 }
271 }
Reid Spencer4f6e9ab2007-04-23 21:21:53 +0000272 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 }
Reid Spencer12d81f32007-04-21 21:45:51 +0000281 }
282 return 0;
Duncan Sands4e9471d2007-04-21 20:20:47 +0000283}
284
Reid Spencer12d81f32007-04-21 21:45:51 +0000285# 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.
Reid Spencer40a4c612007-04-21 20:40:17 +0000288proc 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}