blob: d92503a37337068d38eca899b3c88024f54b67ac [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 } {
Daniel Dunbarf3e2d802009-09-10 04:56:59 +000049 global srcroot objroot srcdir objdir subdir target_triplet
Duncan Sands48f296d2010-11-25 21:19:52 +000050 global llvmgcc llvmgxx emitir 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
Daniel Dunbarb25f32b2009-09-07 19:25:54 +000060 #replace %llvmgcc_only with actual path to llvmgcc
61 regsub -all {%llvmgcc_only} $new_line "$llvmgcc" new_line
Reid Spencer316abe42007-04-14 09:39:28 +000062 #replace %llvmgcc with actual path to llvmgcc
Duncan Sands48f296d2010-11-25 21:19:52 +000063 regsub -all {%llvmgcc} $new_line "$llvmgcc $emitir -w" new_line
Reid Spencer316abe42007-04-14 09:39:28 +000064 #replace %llvmgxx with actual path to llvmg++
Duncan Sands48f296d2010-11-25 21:19:52 +000065 regsub -all {%llvmgxx} $new_line "$llvmgxx $emitir -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
Erick Tryzelaarb405bbe2009-09-03 23:27:31 +000074 #replace %ocamlopt with ocaml compiler command
75 regsub -all {%ocamlopt} $new_line "$ocamlopt" 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
Evan Cheng802cd842009-03-21 18:12:24 +000080 #replace %bugpoint_topts with actual bugpoint target options
81 regsub -all {%bugpoint_topts} $new_line "$bugpoint_topts" new_line
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +000082 #replace %p with path to source,
Reid Spencer316abe42007-04-14 09:39:28 +000083 regsub -all {%p} $new_line [file join $srcdir $subdir] new_line
84 #replace %s with filename
85 regsub -all {%s} $new_line $test new_line
86 #replace %t with temp filenames
Duncan Sands6c7ada42007-07-23 15:23:35 +000087 regsub -all {%t} $new_line $tmpFile new_line
Daniel Dunbar51106092009-09-13 01:39:50 +000088 #replace %abs_tmp with absolute temp filenames
89 regsub -all {%abs_tmp} $new_line [file join [pwd] $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 } {
Daniel Dunbar3d4d01b2010-02-23 07:56:28 +0000122 global srcroot objroot srcdir objdir subdir target_triplet
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 }
Tanya Lattnera57506e2007-11-06 22:32:17 +0000197 }
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
Reid Spencer316abe42007-04-14 09:39:28 +0000210 }
211 }
212 }
213 }
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +0000214
Reid Spencer316abe42007-04-14 09:39:28 +0000215 # Done reading the script
216 close $testFileId
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +0000217
218
Reid Spencer316abe42007-04-14 09:39:28 +0000219 if { $numLines == 0 } {
220 fail "$test: \nDoes not have a RUN line\n"
221 } else {
222 set failed 0
223 for { set i 0 } { $i < $numLines } { set i [ expr $i + 1 ] } {
224 regsub ^.*RUN:(.*) $lines($i) \1 theLine
Reid Spencer90016c72007-04-14 19:37:22 +0000225 set resultmsg [execOneLine $test $PRNUMS $outcome $i $theLine ]
Reid Spencer316abe42007-04-14 09:39:28 +0000226 if { $resultmsg != "" } {
227 if { $outcome == "XFAIL" } {
228 xfail "$resultmsg"
229 } else {
230 fail "$resultmsg"
231 }
232 set failed 1
233 break
234 }
235 }
Reid Spencer0947df42007-04-15 07:21:26 +0000236 if { $failed } {
Reid Spencerb0feffa2007-04-15 07:34:58 +0000237 continue
Reid Spencer0947df42007-04-15 07:21:26 +0000238 } else {
239 if { $PRNUMS != "" } {
Reid Spencer90016c72007-04-14 19:37:22 +0000240 set PRNUMS " for $PRNUMS"
241 }
Reid Spencer316abe42007-04-14 09:39:28 +0000242 if { $outcome == "XFAIL" } {
Reid Spencer90016c72007-04-14 19:37:22 +0000243 xpass "$test$PRNUMS"
Reid Spencer316abe42007-04-14 09:39:28 +0000244 } else {
Reid Spencer90016c72007-04-14 19:37:22 +0000245 pass "$test$PRNUMS"
Reid Spencer316abe42007-04-14 09:39:28 +0000246 }
247 }
248 }
249 }
250}
Devang Patel9fe99072007-04-20 21:24:01 +0000251
Reid Spencer12d81f32007-04-21 21:45:51 +0000252# This procedure provides an interface to check the LLVMGCC_LANGS makefile
253# variable to see if llvm-gcc supports compilation of a particular language.
254proc llvm_gcc_supports { lang } {
255 global llvmgcc llvmgcc_langs
256 # validate the language choices and determine the name of the compiler
257 # component responsible for determining if the compiler has been built.
258 switch "$lang" {
259 ada { set file gnat1 }
260 c { set file cc1 }
261 c++ { set file cc1plus }
Duncan Sandsc93346a2008-08-07 17:59:54 +0000262 objc { set file cc1obj }
Duncan Sands96f94522008-10-06 10:31:21 +0000263 obj-c++ { set file cc1objplus }
Duncan Sands39212662008-06-27 14:22:20 +0000264 fortran { set file f951 }
Reid Spencer12d81f32007-04-21 21:45:51 +0000265 default { return 0 }
266 }
Reid Spencer4f6e9ab2007-04-23 21:21:53 +0000267 foreach supported_lang [split "$llvmgcc_langs" ,] {
268 if { "$lang" == "$supported_lang" } {
269 # FIXME: Knowing it is configured is not enough. We should do two more
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +0000270 # checks here. First, we need to run llvm-gcc -print-prog-name=$file to
Reid Spencer4f6e9ab2007-04-23 21:21:53 +0000271 # get the path to the compiler. If we don't get a path, the language isn't
Mikhail Glushenkov922b2a22009-03-06 12:21:40 +0000272 # properly configured or built. If we do get a path, we should check to
Reid Spencer4f6e9ab2007-04-23 21:21:53 +0000273 # make sure that it is executable and perhaps even try executing it.
274 return 1;
275 }
Reid Spencer12d81f32007-04-21 21:45:51 +0000276 }
277 return 0;
Duncan Sands4e9471d2007-04-21 20:20:47 +0000278}
279
Reid Spencer12d81f32007-04-21 21:45:51 +0000280# This procedure provides an interface to check the TARGETS_TO_BUILD makefile
281# variable to see if a particular target has been configured to build. This
282# helps avoid running tests for targets that aren't available.
Reid Spencer40a4c612007-04-21 20:40:17 +0000283proc llvm_supports_target { tgtName } {
284 global TARGETS_TO_BUILD
285 foreach target [split $TARGETS_TO_BUILD] {
286 if { [regexp $tgtName $target match] } {
287 return 1
288 }
289 }
290 return 0
291}
Daniel Dunbar840a7182009-09-13 01:41:18 +0000292
Daniel Dunbar9e2556c2010-02-03 18:43:46 +0000293proc llvm_supports_darwin_and_target { tgtName } {
294 global target_triplet
295 if { [ llvm_supports_target $tgtName ] } {
296 if { [regexp darwin $target_triplet match] } {
297 return 1
298 }
299 }
300 return 0
301}
302
Daniel Dunbar840a7182009-09-13 01:41:18 +0000303# This procedure provides an interface to check the BINDINGS_TO_BUILD makefile
304# variable to see if a particular binding has been configured to build.
305proc llvm_supports_binding { name } {
306 global llvm_bindings
307 foreach item [split $llvm_bindings] {
308 if { [regexp $name $item match] } {
309 return 1
310 }
311 }
312 return 0
313}