blob: cd36c61b5e754b75a9e372d3431afa79e6f35d18 [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 != ""} {
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +000010 set PRS " for $PRS"
Reid Spencer90016c72007-04-14 19:37:22 +000011 }
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.
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +000036 set resultmsg "$test$PRS\nFailed with unknown error (or has stderr output)$errmsg"
Reid Spencer316abe42007-04-14 09:39:28 +000037 }
38 default {
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +000039 set resultmsg "$test$PRS\nFailed with unknown error$errmsg"
Reid Spencer316abe42007-04-14 09:39:28 +000040 }
41 }
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +000042 }
Reid Spencer316abe42007-04-14 09:39:28 +000043 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 } {
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +000049 global srcroot objroot srcdir objdir subdir target_triplet prcontext
Erick Tryzelaarb405bbe2009-09-03 23:27:31 +000050 global llvmgcc llvmgxx llvmgcc_version llvmgccmajvers ocamlopt
Evan Cheng802cd842009-03-21 18:12:24 +000051 global gccpath gxxpath compile_c compile_cxx link shlibext llvmlibsdir
52 global llvmdsymutil valgrind grep gas bugpoint_topts
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
Daniel Dunbarb25f32b2009-09-07 19:25:54 +000062 #replace %llvmgcc_only with actual path to llvmgcc
63 regsub -all {%llvmgcc_only} $new_line "$llvmgcc" new_line
Reid Spencer316abe42007-04-14 09:39:28 +000064 #replace %llvmgcc with actual path to llvmgcc
Duncan Sands53ebe352008-06-21 20:22:58 +000065 regsub -all {%llvmgcc} $new_line "$llvmgcc -emit-llvm -w" new_line
Reid Spencer316abe42007-04-14 09:39:28 +000066 #replace %llvmgxx with actual path to llvmg++
Duncan Sands53ebe352008-06-21 20:22:58 +000067 regsub -all {%llvmgxx} $new_line "$llvmgxx -emit-llvm -w" new_line
Reid Spencer316abe42007-04-14 09:39:28 +000068 #replace %compile_cxx with C++ compilation command
69 regsub -all {%compile_cxx} $new_line "$compile_cxx" new_line
Chris Lattneraadbda82008-03-10 06:45:35 +000070 #replace %compile_c with C compilation command
71 regsub -all {%compile_c} $new_line "$compile_c" new_line
Reid Spencer316abe42007-04-14 09:39:28 +000072 #replace %link with C++ link command
73 regsub -all {%link} $new_line "$link" new_line
74 #replace %shlibext with shared library extension
75 regsub -all {%shlibext} $new_line "$shlibext" new_line
Erick Tryzelaarb405bbe2009-09-03 23:27:31 +000076 #replace %ocamlopt with ocaml compiler command
77 regsub -all {%ocamlopt} $new_line "$ocamlopt" new_line
Devang Patel6748f042009-02-02 21:09:36 +000078 #replace %llvmdsymutil with dsymutil command
79 regsub -all {%llvmdsymutil} $new_line "$llvmdsymutil" new_line
Reid Spencer316abe42007-04-14 09:39:28 +000080 #replace %llvmlibsdir with configure library directory
81 regsub -all {%llvmlibsdir} $new_line "$llvmlibsdir" new_line
Evan Cheng802cd842009-03-21 18:12:24 +000082 #replace %bugpoint_topts with actual bugpoint target options
83 regsub -all {%bugpoint_topts} $new_line "$bugpoint_topts" new_line
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +000084 #replace %p with path to source,
Reid Spencer316abe42007-04-14 09:39:28 +000085 regsub -all {%p} $new_line [file join $srcdir $subdir] new_line
86 #replace %s with filename
87 regsub -all {%s} $new_line $test new_line
88 #replace %t with temp filenames
Duncan Sands6c7ada42007-07-23 15:23:35 +000089 regsub -all {%t} $new_line $tmpFile new_line
Nuno Lopes2bdc07b2008-10-07 14:48:14 +000090 #replace _#MARKER#_ with %
91 regsub -all {_#MARKER#_} $new_line % new_line
92
Torok Edwin237033e2008-10-21 17:21:32 +000093 #replace grep with GNU grep
94 regsub -all { grep } $new_line " $grep " new_line
95 #replace as with GNU as
96 regsub -all {\| as } $new_line "| $gas " new_line
97
Nuno Lopes2bdc07b2008-10-07 14:48:14 +000098 #valgind related stuff
99# regsub -all {bugpoint } $new_line "$valgrind bugpoint " new_line
100 regsub -all {llc } $new_line "$valgrind llc " new_line
101 regsub -all {lli } $new_line "$valgrind lli " new_line
102 regsub -all {llvm-ar } $new_line "$valgrind llvm-ar " new_line
103 regsub -all {llvm-as } $new_line "$valgrind llvm-as " new_line
104 regsub -all {llvm-bcanalyzer } $new_line "$valgrind llvm-bcanalyzer " new_line
105 regsub -all {llvm-dis } $new_line "$valgrind llvm-dis " new_line
106 regsub -all {llvm-extract } $new_line "$valgrind llvm-extract " new_line
107 regsub -all {llvm-ld } $new_line "$valgrind llvm-ld " new_line
108 regsub -all {llvm-link } $new_line "$valgrind llvm-link " new_line
109 regsub -all {llvm-nm } $new_line "$valgrind llvm-nm " new_line
110 regsub -all {llvm-prof } $new_line "$valgrind llvm-prof " new_line
111 regsub -all {llvm-ranlib } $new_line "$valgrind llvm-ranlib " new_line
112 regsub -all {([^a-zA-Z_-])opt } $new_line "\\1$valgrind opt " new_line
113 regsub -all {^opt } $new_line "$valgrind opt " new_line
114 regsub -all {tblgen } $new_line "$valgrind tblgen " new_line
115 regsub -all "not $valgrind " $new_line "$valgrind not " new_line
116
Reid Spencer316abe42007-04-14 09:39:28 +0000117 return $new_line
118}
119
Reid Spencer12d81f32007-04-21 21:45:51 +0000120# This procedure runs the set of tests for the test_source_files array.
Reid Spencer78fb2ac2007-04-14 22:51:29 +0000121proc RunLLVMTests { test_source_files } {
Reid Spencerfb7653e2007-04-15 20:43:36 +0000122 global srcroot objroot srcdir objdir subdir target_triplet llvmgcc_version
Reid Spencer316abe42007-04-14 09:39:28 +0000123 set timeout 60
124
125 set path [file join $objdir $subdir]
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +0000126
Reid Spencer316abe42007-04-14 09:39:28 +0000127 #Make Output Directory if it does not exist already
128 if { [file exists path] } {
129 cd $path
130 } else {
131 file mkdir $path
132 cd $path
133 }
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +0000134
Reid Spencer316abe42007-04-14 09:39:28 +0000135 file mkdir Output
Duncan Sands6c7ada42007-07-23 15:23:35 +0000136 cd Output
Reid Spencer316abe42007-04-14 09:39:28 +0000137
Reid Spencer78fb2ac2007-04-14 22:51:29 +0000138 foreach test $test_source_files {
Reid Spencer316abe42007-04-14 09:39:28 +0000139 #Should figure out best way to set the timeout
140 #set timeout 40
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +0000141
Reid Spencer316abe42007-04-14 09:39:28 +0000142 set filename [file tail $test]
Gabor Greif684ed3d2008-02-26 12:08:55 +0000143 verbose "ABOUT TO RUN: $filename" 2
Reid Spencer316abe42007-04-14 09:39:28 +0000144 set outcome PASS
145 set tmpFile "$filename.tmp"
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +0000146
Tanya Lattnera57506e2007-11-06 22:32:17 +0000147 # Mark that it should not be XFAIL for this target.
148 set targetPASS 0
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +0000149
Reid Spencer316abe42007-04-14 09:39:28 +0000150 #set hasRunline bool to check if testcase has a runline
151 set numLines 0
152
153 # Open the test file and start reading lines
154 set testFileId [ open $test r]
155 set runline ""
Reid Spencer90016c72007-04-14 19:37:22 +0000156 set PRNUMS ""
Reid Spencerfb7653e2007-04-15 20:43:36 +0000157 foreach line [split [read $testFileId] \n] {
Reid Spencer316abe42007-04-14 09:39:28 +0000158
Reid Spencer90016c72007-04-14 19:37:22 +0000159 # if its the END. line then stop parsing (optimization for big files)
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +0000160 if {[regexp {END.[[:space:]]*$} $line match endofscript]} {
Reid Spencer316abe42007-04-14 09:39:28 +0000161 break
Reid Spencer90016c72007-04-14 19:37:22 +0000162
Duncan Sands3724df32007-04-16 21:19:45 +0000163 # if the line is continued, concatenate and continue the loop
Reid Spencer601e8452007-04-15 18:38:42 +0000164 } elseif {[regexp {RUN: *(.+)(\\)$} $line match oneline suffix]} {
Reid Spencer316abe42007-04-14 09:39:28 +0000165 set runline "$runline$oneline "
Reid Spencer90016c72007-04-14 19:37:22 +0000166
167 # if its a terminating RUN: line then do substitution on the whole line
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +0000168 # and then save the line.
Tanya Lattner727842e2007-11-28 04:57:00 +0000169 } elseif {[regexp {RUN: *(.+)$} $line match oneline suffix]} {
Reid Spencer316abe42007-04-14 09:39:28 +0000170 set runline "$runline$oneline"
171 set runline [ substitute $runline $test $tmpFile ]
172 set lines($numLines) $runline
173 set numLines [expr $numLines + 1]
174 set runline ""
Reid Spencer90016c72007-04-14 19:37:22 +0000175
176 # if its an PR line, save the problem report number
177 } elseif {[regexp {PR([0-9]+)} $line match prnum]} {
178 if {$PRNUMS == ""} {
Reid Spencer66959ce2007-04-15 10:27:54 +0000179 set PRNUMS "PR$prnum"
Reid Spencer90016c72007-04-14 19:37:22 +0000180 } else {
181 set PRNUMS "$PRNUMS,$prnum"
182 }
183 # if its an XFAIL line, see if we should be XFAILing or not.
Reid Spencer316abe42007-04-14 09:39:28 +0000184 } elseif {[regexp {XFAIL:[ *](.+)} $line match targets]} {
185 set targets
186
187 #split up target if more then 1 specified
188 foreach target [split $targets ,] {
Nick Lewycky084f7bf2009-06-12 05:18:32 +0000189 if { $target == "*" } {
Tanya Lattnera57506e2007-11-06 22:32:17 +0000190 if {$targetPASS != 1} {
191 set outcome XFAIL
192 }
Reid Spencer316abe42007-04-14 09:39:28 +0000193 } elseif { [regexp $target $target_triplet match] } {
Tanya Lattnera57506e2007-11-06 22:32:17 +0000194 if {$targetPASS != 1} {
195 set outcome XFAIL
196 }
Reid Spencer316abe42007-04-14 09:39:28 +0000197 } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2] } {
198 if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
Tanya Lattnera57506e2007-11-06 22:32:17 +0000199 if {$targetPASS != 1} {
200 set outcome XFAIL
201 }
202 }
203 }
204 }
205 } elseif {[regexp {XTARGET:[ *](.+)} $line match targets]} {
206 set targets
207
208 #split up target if more then 1 specified
209 foreach target [split $targets ,] {
210 if { [regexp {\*} $target match] } {
211 set targetPASS 1
212 set outcome PASS
213 } elseif { [regexp $target $target_triplet match] } {
214 set targetPASS 1
215 set outcome PASS
216 } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2] } {
217 if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
218 set targetPASS 1
219 set outcome PASS
Reid Spencer316abe42007-04-14 09:39:28 +0000220 }
221 }
222 }
223 }
224 }
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +0000225
Reid Spencer316abe42007-04-14 09:39:28 +0000226 # Done reading the script
227 close $testFileId
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +0000228
229
Reid Spencer316abe42007-04-14 09:39:28 +0000230 if { $numLines == 0 } {
231 fail "$test: \nDoes not have a RUN line\n"
232 } else {
233 set failed 0
234 for { set i 0 } { $i < $numLines } { set i [ expr $i + 1 ] } {
235 regsub ^.*RUN:(.*) $lines($i) \1 theLine
Reid Spencer90016c72007-04-14 19:37:22 +0000236 set resultmsg [execOneLine $test $PRNUMS $outcome $i $theLine ]
Reid Spencer316abe42007-04-14 09:39:28 +0000237 if { $resultmsg != "" } {
238 if { $outcome == "XFAIL" } {
239 xfail "$resultmsg"
240 } else {
241 fail "$resultmsg"
242 }
243 set failed 1
244 break
245 }
246 }
Reid Spencer0947df42007-04-15 07:21:26 +0000247 if { $failed } {
Reid Spencerb0feffa2007-04-15 07:34:58 +0000248 continue
Reid Spencer0947df42007-04-15 07:21:26 +0000249 } else {
250 if { $PRNUMS != "" } {
Reid Spencer90016c72007-04-14 19:37:22 +0000251 set PRNUMS " for $PRNUMS"
252 }
Reid Spencer316abe42007-04-14 09:39:28 +0000253 if { $outcome == "XFAIL" } {
Reid Spencer90016c72007-04-14 19:37:22 +0000254 xpass "$test$PRNUMS"
Reid Spencer316abe42007-04-14 09:39:28 +0000255 } else {
Reid Spencer90016c72007-04-14 19:37:22 +0000256 pass "$test$PRNUMS"
Reid Spencer316abe42007-04-14 09:39:28 +0000257 }
258 }
259 }
260 }
261}
Devang Patel9fe99072007-04-20 21:24:01 +0000262
Reid Spencer12d81f32007-04-21 21:45:51 +0000263# This procedure provides an interface to check the LLVMGCC_LANGS makefile
264# variable to see if llvm-gcc supports compilation of a particular language.
265proc llvm_gcc_supports { lang } {
266 global llvmgcc llvmgcc_langs
267 # validate the language choices and determine the name of the compiler
268 # component responsible for determining if the compiler has been built.
269 switch "$lang" {
270 ada { set file gnat1 }
271 c { set file cc1 }
272 c++ { set file cc1plus }
Duncan Sandsc93346a2008-08-07 17:59:54 +0000273 objc { set file cc1obj }
Duncan Sands96f94522008-10-06 10:31:21 +0000274 obj-c++ { set file cc1objplus }
Duncan Sands39212662008-06-27 14:22:20 +0000275 fortran { set file f951 }
Reid Spencer12d81f32007-04-21 21:45:51 +0000276 default { return 0 }
277 }
Reid Spencer4f6e9ab2007-04-23 21:21:53 +0000278 foreach supported_lang [split "$llvmgcc_langs" ,] {
279 if { "$lang" == "$supported_lang" } {
280 # FIXME: Knowing it is configured is not enough. We should do two more
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +0000281 # checks here. First, we need to run llvm-gcc -print-prog-name=$file to
Reid Spencer4f6e9ab2007-04-23 21:21:53 +0000282 # get the path to the compiler. If we don't get a path, the language isn't
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +0000283 # properly configured or built. If we do get a path, we should check to
Reid Spencer4f6e9ab2007-04-23 21:21:53 +0000284 # make sure that it is executable and perhaps even try executing it.
285 return 1;
286 }
Reid Spencer12d81f32007-04-21 21:45:51 +0000287 }
288 return 0;
Duncan Sands4e9471d2007-04-21 20:20:47 +0000289}
290
Reid Spencer12d81f32007-04-21 21:45:51 +0000291# This procedure provides an interface to check the TARGETS_TO_BUILD makefile
292# variable to see if a particular target has been configured to build. This
293# helps avoid running tests for targets that aren't available.
Reid Spencer40a4c612007-04-21 20:40:17 +0000294proc llvm_supports_target { tgtName } {
295 global TARGETS_TO_BUILD
296 foreach target [split $TARGETS_TO_BUILD] {
297 if { [regexp $tgtName $target match] } {
298 return 1
299 }
300 }
301 return 0
302}