blob: a844152bf23d8861351db46737324d9424a19223 [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
Nuno Lopes2bdc07b2008-10-07 14:48:14 +000052 global valgrind
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
87 #valgind related stuff
88# regsub -all {bugpoint } $new_line "$valgrind bugpoint " new_line
89 regsub -all {llc } $new_line "$valgrind llc " new_line
90 regsub -all {lli } $new_line "$valgrind lli " new_line
91 regsub -all {llvm-ar } $new_line "$valgrind llvm-ar " new_line
92 regsub -all {llvm-as } $new_line "$valgrind llvm-as " new_line
93 regsub -all {llvm-bcanalyzer } $new_line "$valgrind llvm-bcanalyzer " new_line
94 regsub -all {llvm-dis } $new_line "$valgrind llvm-dis " new_line
95 regsub -all {llvm-extract } $new_line "$valgrind llvm-extract " new_line
96 regsub -all {llvm-ld } $new_line "$valgrind llvm-ld " new_line
97 regsub -all {llvm-link } $new_line "$valgrind llvm-link " new_line
98 regsub -all {llvm-nm } $new_line "$valgrind llvm-nm " new_line
99 regsub -all {llvm-prof } $new_line "$valgrind llvm-prof " new_line
100 regsub -all {llvm-ranlib } $new_line "$valgrind llvm-ranlib " new_line
101 regsub -all {([^a-zA-Z_-])opt } $new_line "\\1$valgrind opt " new_line
102 regsub -all {^opt } $new_line "$valgrind opt " new_line
103 regsub -all {tblgen } $new_line "$valgrind tblgen " new_line
104 regsub -all "not $valgrind " $new_line "$valgrind not " new_line
105
Reid Spencer316abe42007-04-14 09:39:28 +0000106 return $new_line
107}
108
Reid Spencer12d81f32007-04-21 21:45:51 +0000109# This procedure runs the set of tests for the test_source_files array.
Reid Spencer78fb2ac2007-04-14 22:51:29 +0000110proc RunLLVMTests { test_source_files } {
Reid Spencerfb7653e2007-04-15 20:43:36 +0000111 global srcroot objroot srcdir objdir subdir target_triplet llvmgcc_version
Reid Spencer316abe42007-04-14 09:39:28 +0000112 set timeout 60
113
114 set path [file join $objdir $subdir]
115
116 #Make Output Directory if it does not exist already
117 if { [file exists path] } {
118 cd $path
119 } else {
120 file mkdir $path
121 cd $path
122 }
123
124 file mkdir Output
Duncan Sands6c7ada42007-07-23 15:23:35 +0000125 cd Output
Reid Spencer316abe42007-04-14 09:39:28 +0000126
Reid Spencer78fb2ac2007-04-14 22:51:29 +0000127 foreach test $test_source_files {
Reid Spencer316abe42007-04-14 09:39:28 +0000128 #Should figure out best way to set the timeout
129 #set timeout 40
130
131 set filename [file tail $test]
Gabor Greif684ed3d2008-02-26 12:08:55 +0000132 verbose "ABOUT TO RUN: $filename" 2
Reid Spencer316abe42007-04-14 09:39:28 +0000133 set outcome PASS
134 set tmpFile "$filename.tmp"
Tanya Lattnera57506e2007-11-06 22:32:17 +0000135
136 # Mark that it should not be XFAIL for this target.
137 set targetPASS 0
138
Reid Spencer316abe42007-04-14 09:39:28 +0000139 #set hasRunline bool to check if testcase has a runline
140 set numLines 0
141
142 # Open the test file and start reading lines
143 set testFileId [ open $test r]
144 set runline ""
Reid Spencer90016c72007-04-14 19:37:22 +0000145 set PRNUMS ""
Reid Spencerfb7653e2007-04-15 20:43:36 +0000146 foreach line [split [read $testFileId] \n] {
Reid Spencer316abe42007-04-14 09:39:28 +0000147
Reid Spencer90016c72007-04-14 19:37:22 +0000148 # if its the END. line then stop parsing (optimization for big files)
Tanya Lattner200d6072008-03-13 22:02:51 +0000149 if {[regexp {END.[[:space:]]*$} $line match endofscript]} {
Reid Spencer316abe42007-04-14 09:39:28 +0000150 break
Reid Spencer90016c72007-04-14 19:37:22 +0000151
Duncan Sands3724df32007-04-16 21:19:45 +0000152 # if the line is continued, concatenate and continue the loop
Reid Spencer601e8452007-04-15 18:38:42 +0000153 } elseif {[regexp {RUN: *(.+)(\\)$} $line match oneline suffix]} {
Reid Spencer316abe42007-04-14 09:39:28 +0000154 set runline "$runline$oneline "
Reid Spencer90016c72007-04-14 19:37:22 +0000155
156 # if its a terminating RUN: line then do substitution on the whole line
Tanya Lattner727842e2007-11-28 04:57:00 +0000157 # and then save the line.
158 } elseif {[regexp {RUN: *(.+)$} $line match oneline suffix]} {
Reid Spencer316abe42007-04-14 09:39:28 +0000159 set runline "$runline$oneline"
160 set runline [ substitute $runline $test $tmpFile ]
161 set lines($numLines) $runline
162 set numLines [expr $numLines + 1]
163 set runline ""
Reid Spencer90016c72007-04-14 19:37:22 +0000164
165 # if its an PR line, save the problem report number
166 } elseif {[regexp {PR([0-9]+)} $line match prnum]} {
167 if {$PRNUMS == ""} {
Reid Spencer66959ce2007-04-15 10:27:54 +0000168 set PRNUMS "PR$prnum"
Reid Spencer90016c72007-04-14 19:37:22 +0000169 } else {
170 set PRNUMS "$PRNUMS,$prnum"
171 }
172 # if its an XFAIL line, see if we should be XFAILing or not.
Reid Spencer316abe42007-04-14 09:39:28 +0000173 } elseif {[regexp {XFAIL:[ *](.+)} $line match targets]} {
174 set targets
175
176 #split up target if more then 1 specified
177 foreach target [split $targets ,] {
178 if { [regexp {\*} $target match] } {
Tanya Lattnera57506e2007-11-06 22:32:17 +0000179 if {$targetPASS != 1} {
180 set outcome XFAIL
181 }
Reid Spencer316abe42007-04-14 09:39:28 +0000182 } elseif { [regexp $target $target_triplet match] } {
Tanya Lattnera57506e2007-11-06 22:32:17 +0000183 if {$targetPASS != 1} {
184 set outcome XFAIL
185 }
Reid Spencer316abe42007-04-14 09:39:28 +0000186 } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2] } {
187 if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
Tanya Lattnera57506e2007-11-06 22:32:17 +0000188 if {$targetPASS != 1} {
189 set outcome XFAIL
190 }
191 }
192 }
193 }
194 } elseif {[regexp {XTARGET:[ *](.+)} $line match targets]} {
195 set targets
196
197 #split up target if more then 1 specified
198 foreach target [split $targets ,] {
199 if { [regexp {\*} $target match] } {
200 set targetPASS 1
201 set outcome PASS
202 } elseif { [regexp $target $target_triplet match] } {
203 set targetPASS 1
204 set outcome PASS
205 } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2] } {
206 if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
207 set targetPASS 1
208 set outcome PASS
Reid Spencer316abe42007-04-14 09:39:28 +0000209 }
210 }
211 }
212 }
213 }
214
215 # Done reading the script
216 close $testFileId
217
218
219 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
270 # checks here. First, we need to run llvm-gcc -print-prog-name=$file to
271 # get the path to the compiler. If we don't get a path, the language isn't
272 # properly configured or built. If we do get a path, we should check to
273 # 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}