blob: 254995bc4aeb58c9ce53ead66e35f7eafc0da42c [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
Gordon Henriksen8ef426b2007-09-18 12:49:39 +000050 global llvmgcc llvmgxx llvmgcc_version llvmgccmajvers ocamlc
Nick Lewyckyfaf880f2009-03-20 07:56:31 +000051 global gccpath gxxpath compile_c compile_cxx link shlibext llvmlibsdir llvmdsymutil
52 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
Devang Patel6748f042009-02-02 21:09:36 +000076 #replace %llvmdsymutil with dsymutil command
77 regsub -all {%llvmdsymutil} $new_line "$llvmdsymutil" new_line
Reid Spencer316abe42007-04-14 09:39:28 +000078 #replace %llvmlibsdir with configure library directory
79 regsub -all {%llvmlibsdir} $new_line "$llvmlibsdir" new_line
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +000080 #replace %p with path to source,
Reid Spencer316abe42007-04-14 09:39:28 +000081 regsub -all {%p} $new_line [file join $srcdir $subdir] new_line
82 #replace %s with filename
83 regsub -all {%s} $new_line $test new_line
84 #replace %t with temp filenames
Duncan Sands6c7ada42007-07-23 15:23:35 +000085 regsub -all {%t} $new_line $tmpFile new_line
Nuno Lopes2bdc07b2008-10-07 14:48:14 +000086 #replace _#MARKER#_ with %
87 regsub -all {_#MARKER#_} $new_line % new_line
88
Torok Edwin237033e2008-10-21 17:21:32 +000089 #replace grep with GNU grep
90 regsub -all { grep } $new_line " $grep " new_line
91 #replace as with GNU as
92 regsub -all {\| as } $new_line "| $gas " new_line
93
Nuno Lopes2bdc07b2008-10-07 14:48:14 +000094 #valgind related stuff
95# regsub -all {bugpoint } $new_line "$valgrind bugpoint " new_line
96 regsub -all {llc } $new_line "$valgrind llc " new_line
97 regsub -all {lli } $new_line "$valgrind lli " new_line
98 regsub -all {llvm-ar } $new_line "$valgrind llvm-ar " new_line
99 regsub -all {llvm-as } $new_line "$valgrind llvm-as " new_line
100 regsub -all {llvm-bcanalyzer } $new_line "$valgrind llvm-bcanalyzer " new_line
101 regsub -all {llvm-dis } $new_line "$valgrind llvm-dis " new_line
102 regsub -all {llvm-extract } $new_line "$valgrind llvm-extract " new_line
103 regsub -all {llvm-ld } $new_line "$valgrind llvm-ld " new_line
104 regsub -all {llvm-link } $new_line "$valgrind llvm-link " new_line
105 regsub -all {llvm-nm } $new_line "$valgrind llvm-nm " new_line
106 regsub -all {llvm-prof } $new_line "$valgrind llvm-prof " new_line
107 regsub -all {llvm-ranlib } $new_line "$valgrind llvm-ranlib " new_line
108 regsub -all {([^a-zA-Z_-])opt } $new_line "\\1$valgrind opt " new_line
109 regsub -all {^opt } $new_line "$valgrind opt " new_line
110 regsub -all {tblgen } $new_line "$valgrind tblgen " new_line
111 regsub -all "not $valgrind " $new_line "$valgrind not " new_line
112
Reid Spencer316abe42007-04-14 09:39:28 +0000113 return $new_line
114}
115
Reid Spencer12d81f32007-04-21 21:45:51 +0000116# This procedure runs the set of tests for the test_source_files array.
Reid Spencer78fb2ac2007-04-14 22:51:29 +0000117proc RunLLVMTests { test_source_files } {
Reid Spencerfb7653e2007-04-15 20:43:36 +0000118 global srcroot objroot srcdir objdir subdir target_triplet llvmgcc_version
Reid Spencer316abe42007-04-14 09:39:28 +0000119 set timeout 60
120
121 set path [file join $objdir $subdir]
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +0000122
Reid Spencer316abe42007-04-14 09:39:28 +0000123 #Make Output Directory if it does not exist already
124 if { [file exists path] } {
125 cd $path
126 } else {
127 file mkdir $path
128 cd $path
129 }
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +0000130
Reid Spencer316abe42007-04-14 09:39:28 +0000131 file mkdir Output
Duncan Sands6c7ada42007-07-23 15:23:35 +0000132 cd Output
Reid Spencer316abe42007-04-14 09:39:28 +0000133
Reid Spencer78fb2ac2007-04-14 22:51:29 +0000134 foreach test $test_source_files {
Reid Spencer316abe42007-04-14 09:39:28 +0000135 #Should figure out best way to set the timeout
136 #set timeout 40
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +0000137
Reid Spencer316abe42007-04-14 09:39:28 +0000138 set filename [file tail $test]
Gabor Greif684ed3d2008-02-26 12:08:55 +0000139 verbose "ABOUT TO RUN: $filename" 2
Reid Spencer316abe42007-04-14 09:39:28 +0000140 set outcome PASS
141 set tmpFile "$filename.tmp"
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +0000142
Tanya Lattnera57506e2007-11-06 22:32:17 +0000143 # Mark that it should not be XFAIL for this target.
144 set targetPASS 0
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +0000145
Reid Spencer316abe42007-04-14 09:39:28 +0000146 #set hasRunline bool to check if testcase has a runline
147 set numLines 0
148
149 # Open the test file and start reading lines
150 set testFileId [ open $test r]
151 set runline ""
Reid Spencer90016c72007-04-14 19:37:22 +0000152 set PRNUMS ""
Reid Spencerfb7653e2007-04-15 20:43:36 +0000153 foreach line [split [read $testFileId] \n] {
Reid Spencer316abe42007-04-14 09:39:28 +0000154
Reid Spencer90016c72007-04-14 19:37:22 +0000155 # if its the END. line then stop parsing (optimization for big files)
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +0000156 if {[regexp {END.[[:space:]]*$} $line match endofscript]} {
Reid Spencer316abe42007-04-14 09:39:28 +0000157 break
Reid Spencer90016c72007-04-14 19:37:22 +0000158
Duncan Sands3724df32007-04-16 21:19:45 +0000159 # if the line is continued, concatenate and continue the loop
Reid Spencer601e8452007-04-15 18:38:42 +0000160 } elseif {[regexp {RUN: *(.+)(\\)$} $line match oneline suffix]} {
Reid Spencer316abe42007-04-14 09:39:28 +0000161 set runline "$runline$oneline "
Reid Spencer90016c72007-04-14 19:37:22 +0000162
163 # if its a terminating RUN: line then do substitution on the whole line
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +0000164 # and then save the line.
Tanya Lattner727842e2007-11-28 04:57:00 +0000165 } elseif {[regexp {RUN: *(.+)$} $line match oneline suffix]} {
Reid Spencer316abe42007-04-14 09:39:28 +0000166 set runline "$runline$oneline"
167 set runline [ substitute $runline $test $tmpFile ]
168 set lines($numLines) $runline
169 set numLines [expr $numLines + 1]
170 set runline ""
Reid Spencer90016c72007-04-14 19:37:22 +0000171
172 # if its an PR line, save the problem report number
173 } elseif {[regexp {PR([0-9]+)} $line match prnum]} {
174 if {$PRNUMS == ""} {
Reid Spencer66959ce2007-04-15 10:27:54 +0000175 set PRNUMS "PR$prnum"
Reid Spencer90016c72007-04-14 19:37:22 +0000176 } else {
177 set PRNUMS "$PRNUMS,$prnum"
178 }
179 # if its an XFAIL line, see if we should be XFAILing or not.
Reid Spencer316abe42007-04-14 09:39:28 +0000180 } elseif {[regexp {XFAIL:[ *](.+)} $line match targets]} {
181 set targets
182
183 #split up target if more then 1 specified
184 foreach target [split $targets ,] {
185 if { [regexp {\*} $target match] } {
Tanya Lattnera57506e2007-11-06 22:32:17 +0000186 if {$targetPASS != 1} {
187 set outcome XFAIL
188 }
Reid Spencer316abe42007-04-14 09:39:28 +0000189 } elseif { [regexp $target $target_triplet match] } {
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 {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2] } {
194 if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
Tanya Lattnera57506e2007-11-06 22:32:17 +0000195 if {$targetPASS != 1} {
196 set outcome XFAIL
197 }
198 }
199 }
200 }
201 } elseif {[regexp {XTARGET:[ *](.+)} $line match targets]} {
202 set targets
203
204 #split up target if more then 1 specified
205 foreach target [split $targets ,] {
206 if { [regexp {\*} $target match] } {
207 set targetPASS 1
208 set outcome PASS
209 } elseif { [regexp $target $target_triplet match] } {
210 set targetPASS 1
211 set outcome PASS
212 } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2] } {
213 if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
214 set targetPASS 1
215 set outcome PASS
Reid Spencer316abe42007-04-14 09:39:28 +0000216 }
217 }
218 }
219 }
220 }
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +0000221
Reid Spencer316abe42007-04-14 09:39:28 +0000222 # Done reading the script
223 close $testFileId
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +0000224
225
Reid Spencer316abe42007-04-14 09:39:28 +0000226 if { $numLines == 0 } {
227 fail "$test: \nDoes not have a RUN line\n"
228 } else {
229 set failed 0
230 for { set i 0 } { $i < $numLines } { set i [ expr $i + 1 ] } {
231 regsub ^.*RUN:(.*) $lines($i) \1 theLine
Reid Spencer90016c72007-04-14 19:37:22 +0000232 set resultmsg [execOneLine $test $PRNUMS $outcome $i $theLine ]
Reid Spencer316abe42007-04-14 09:39:28 +0000233 if { $resultmsg != "" } {
234 if { $outcome == "XFAIL" } {
235 xfail "$resultmsg"
236 } else {
237 fail "$resultmsg"
238 }
239 set failed 1
240 break
241 }
242 }
Reid Spencer0947df42007-04-15 07:21:26 +0000243 if { $failed } {
Reid Spencerb0feffa2007-04-15 07:34:58 +0000244 continue
Reid Spencer0947df42007-04-15 07:21:26 +0000245 } else {
246 if { $PRNUMS != "" } {
Reid Spencer90016c72007-04-14 19:37:22 +0000247 set PRNUMS " for $PRNUMS"
248 }
Reid Spencer316abe42007-04-14 09:39:28 +0000249 if { $outcome == "XFAIL" } {
Reid Spencer90016c72007-04-14 19:37:22 +0000250 xpass "$test$PRNUMS"
Reid Spencer316abe42007-04-14 09:39:28 +0000251 } else {
Reid Spencer90016c72007-04-14 19:37:22 +0000252 pass "$test$PRNUMS"
Reid Spencer316abe42007-04-14 09:39:28 +0000253 }
254 }
255 }
256 }
257}
Devang Patel9fe99072007-04-20 21:24:01 +0000258
Reid Spencer12d81f32007-04-21 21:45:51 +0000259# This procedure provides an interface to check the LLVMGCC_LANGS makefile
260# variable to see if llvm-gcc supports compilation of a particular language.
261proc llvm_gcc_supports { lang } {
262 global llvmgcc llvmgcc_langs
263 # validate the language choices and determine the name of the compiler
264 # component responsible for determining if the compiler has been built.
265 switch "$lang" {
266 ada { set file gnat1 }
267 c { set file cc1 }
268 c++ { set file cc1plus }
Duncan Sandsc93346a2008-08-07 17:59:54 +0000269 objc { set file cc1obj }
Duncan Sands96f94522008-10-06 10:31:21 +0000270 obj-c++ { set file cc1objplus }
Duncan Sands39212662008-06-27 14:22:20 +0000271 fortran { set file f951 }
Reid Spencer12d81f32007-04-21 21:45:51 +0000272 default { return 0 }
273 }
Reid Spencer4f6e9ab2007-04-23 21:21:53 +0000274 foreach supported_lang [split "$llvmgcc_langs" ,] {
275 if { "$lang" == "$supported_lang" } {
276 # FIXME: Knowing it is configured is not enough. We should do two more
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +0000277 # checks here. First, we need to run llvm-gcc -print-prog-name=$file to
Reid Spencer4f6e9ab2007-04-23 21:21:53 +0000278 # get the path to the compiler. If we don't get a path, the language isn't
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +0000279 # properly configured or built. If we do get a path, we should check to
Reid Spencer4f6e9ab2007-04-23 21:21:53 +0000280 # make sure that it is executable and perhaps even try executing it.
281 return 1;
282 }
Reid Spencer12d81f32007-04-21 21:45:51 +0000283 }
284 return 0;
Duncan Sands4e9471d2007-04-21 20:20:47 +0000285}
286
Reid Spencer12d81f32007-04-21 21:45:51 +0000287# This procedure provides an interface to check the TARGETS_TO_BUILD makefile
288# variable to see if a particular target has been configured to build. This
289# helps avoid running tests for targets that aren't available.
Reid Spencer40a4c612007-04-21 20:40:17 +0000290proc llvm_supports_target { tgtName } {
291 global TARGETS_TO_BUILD
292 foreach target [split $TARGETS_TO_BUILD] {
293 if { [regexp $tgtName $target match] } {
294 return 1
295 }
296 }
297 return 0
298}