blob: 3d7588dd6e2984ef0bce8f0ebd07cacda0a4c83c [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001# This procedure executes one line of a test case's execution script.
2proc execOneLine { test PRS outcome lineno line } {
3 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]
8 set lineno [expr $lineno + 1]
9 if { $PRS != ""} {
10 set PRS " for $PRS"
11 }
12 set errmsg " at line $lineno\nwhile running: $line\n$errmsg"
13 switch "$code" {
14 CHILDSTATUS {
15 set status [lindex $::errorCode 2]
16 if { $status != 0 } {
17 set resultmsg "$test$PRS\nFailed with exit($status)$errmsg"
18 }
19 }
20 CHILDKILLED {
21 set signal [lindex $::errorCode 2]
22 set resultmsg "$test$PRS\nFailed with signal($signal)$errmsg"
23 }
24 CHILDSUSP {
25 set signal [lindex $::errorCode 2]
26 set resultmsg "$test$PRS\nFailed with suspend($signal)$errmsg"
27 }
28 POSIX {
29 set posixNum [lindex $::errorCode 1]
30 set posixMsg [lindex $::errorCode 2]
31 set resultmsg "$test$PRS\nFailed with posix($posixNum,$posixMsg)$errmsg"
32 }
33 NONE {
Matthijs Kooijmana2fa19a2008-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"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000037 }
38 default {
Matthijs Kooijmana2fa19a2008-06-10 12:28:43 +000039 set resultmsg "$test$PRS\nFailed with unknown error$errmsg"
Dan Gohmanf17a25c2007-07-18 16:29:46 +000040 }
41 }
42 }
43 return $resultmsg
44}
45
46# This procedure performs variable substitutions on the RUN: lines of a test
47# cases.
48proc substitute { line test tmpFile } {
49 global srcroot objroot srcdir objdir subdir target_triplet prcontext
Gordon Henriksenc6606c62007-09-18 12:49:39 +000050 global llvmgcc llvmgxx llvmgcc_version llvmgccmajvers ocamlc
Dan Gohmanf17a25c2007-07-18 16:29:46 +000051 global gccpath gxxpath compile_c compile_cxx link shlibext llvmlibsdir
52 set path [file join $srcdir $subdir]
Dan Gohmanf17a25c2007-07-18 16:29:46 +000053
54 # Substitute all Tcl variables.
55 set new_line [subst $line ]
56
57 #replace %prcontext with prcontext.tcl (Must replace before %p)
58 regsub -all {%prcontext} $new_line $prcontext new_line
59 #replace %llvmgcc with actual path to llvmgcc
Duncan Sands2048ba02008-06-21 20:22:58 +000060 regsub -all {%llvmgcc} $new_line "$llvmgcc -emit-llvm -w" new_line
Dan Gohmanf17a25c2007-07-18 16:29:46 +000061 #replace %llvmgxx with actual path to llvmg++
Duncan Sands2048ba02008-06-21 20:22:58 +000062 regsub -all {%llvmgxx} $new_line "$llvmgxx -emit-llvm -w" new_line
Dan Gohmanf17a25c2007-07-18 16:29:46 +000063 #replace %compile_cxx with C++ compilation command
64 regsub -all {%compile_cxx} $new_line "$compile_cxx" new_line
Chris Lattnered04bb22008-03-10 06:45:35 +000065 #replace %compile_c with C compilation command
66 regsub -all {%compile_c} $new_line "$compile_c" new_line
Dan Gohmanf17a25c2007-07-18 16:29:46 +000067 #replace %link with C++ link command
68 regsub -all {%link} $new_line "$link" new_line
69 #replace %shlibext with shared library extension
70 regsub -all {%shlibext} $new_line "$shlibext" new_line
Gordon Henriksenc6606c62007-09-18 12:49:39 +000071 #replace %ocamlc with ocaml compiler command
72 regsub -all {%ocamlc} $new_line "$ocamlc" new_line
Dan Gohmanf17a25c2007-07-18 16:29:46 +000073 #replace %llvmlibsdir with configure library directory
74 regsub -all {%llvmlibsdir} $new_line "$llvmlibsdir" new_line
75 #replace %p with path to source,
76 regsub -all {%p} $new_line [file join $srcdir $subdir] new_line
77 #replace %s with filename
78 regsub -all {%s} $new_line $test new_line
79 #replace %t with temp filenames
Duncan Sandsa524e0e2007-07-23 15:23:35 +000080 regsub -all {%t} $new_line $tmpFile new_line
Dan Gohmanf17a25c2007-07-18 16:29:46 +000081 #replace %% with %
82 regsub -all {%%} $new_line % new_line
83 return $new_line
84}
85
86# This procedure runs the set of tests for the test_source_files array.
87proc RunLLVMTests { test_source_files } {
88 global srcroot objroot srcdir objdir subdir target_triplet llvmgcc_version
89 set timeout 60
90
91 set path [file join $objdir $subdir]
92
93 #Make Output Directory if it does not exist already
94 if { [file exists path] } {
95 cd $path
96 } else {
97 file mkdir $path
98 cd $path
99 }
100
101 file mkdir Output
Duncan Sandsa524e0e2007-07-23 15:23:35 +0000102 cd Output
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000103
104 foreach test $test_source_files {
105 #Should figure out best way to set the timeout
106 #set timeout 40
107
108 set filename [file tail $test]
Gabor Greif9f99a9f2008-02-26 12:08:55 +0000109 verbose "ABOUT TO RUN: $filename" 2
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000110 set outcome PASS
111 set tmpFile "$filename.tmp"
Tanya Lattner090659d2007-11-06 22:32:17 +0000112
113 # Mark that it should not be XFAIL for this target.
114 set targetPASS 0
115
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000116 #set hasRunline bool to check if testcase has a runline
117 set numLines 0
118
119 # Open the test file and start reading lines
120 set testFileId [ open $test r]
121 set runline ""
122 set PRNUMS ""
123 foreach line [split [read $testFileId] \n] {
124
125 # if its the END. line then stop parsing (optimization for big files)
Tanya Lattnered5fb3b2008-03-13 22:02:51 +0000126 if {[regexp {END.[[:space:]]*$} $line match endofscript]} {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000127 break
128
129 # if the line is continued, concatenate and continue the loop
130 } elseif {[regexp {RUN: *(.+)(\\)$} $line match oneline suffix]} {
131 set runline "$runline$oneline "
132
133 # if its a terminating RUN: line then do substitution on the whole line
Tanya Lattner8b074702007-11-28 04:57:00 +0000134 # and then save the line.
135 } elseif {[regexp {RUN: *(.+)$} $line match oneline suffix]} {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000136 set runline "$runline$oneline"
137 set runline [ substitute $runline $test $tmpFile ]
138 set lines($numLines) $runline
139 set numLines [expr $numLines + 1]
140 set runline ""
141
142 # if its an PR line, save the problem report number
143 } elseif {[regexp {PR([0-9]+)} $line match prnum]} {
144 if {$PRNUMS == ""} {
145 set PRNUMS "PR$prnum"
146 } else {
147 set PRNUMS "$PRNUMS,$prnum"
148 }
149 # if its an XFAIL line, see if we should be XFAILing or not.
150 } elseif {[regexp {XFAIL:[ *](.+)} $line match targets]} {
151 set targets
152
153 #split up target if more then 1 specified
154 foreach target [split $targets ,] {
155 if { [regexp {\*} $target match] } {
Tanya Lattner090659d2007-11-06 22:32:17 +0000156 if {$targetPASS != 1} {
157 set outcome XFAIL
158 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000159 } elseif { [regexp $target $target_triplet match] } {
Tanya Lattner090659d2007-11-06 22:32:17 +0000160 if {$targetPASS != 1} {
161 set outcome XFAIL
162 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000163 } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2] } {
164 if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
Tanya Lattner090659d2007-11-06 22:32:17 +0000165 if {$targetPASS != 1} {
166 set outcome XFAIL
167 }
168 }
169 }
170 }
171 } elseif {[regexp {XTARGET:[ *](.+)} $line match targets]} {
172 set targets
173
174 #split up target if more then 1 specified
175 foreach target [split $targets ,] {
176 if { [regexp {\*} $target match] } {
177 set targetPASS 1
178 set outcome PASS
179 } elseif { [regexp $target $target_triplet match] } {
180 set targetPASS 1
181 set outcome PASS
182 } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2] } {
183 if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
184 set targetPASS 1
185 set outcome PASS
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000186 }
187 }
188 }
189 }
190 }
191
192 # Done reading the script
193 close $testFileId
194
195
196 if { $numLines == 0 } {
197 fail "$test: \nDoes not have a RUN line\n"
198 } else {
199 set failed 0
200 for { set i 0 } { $i < $numLines } { set i [ expr $i + 1 ] } {
201 regsub ^.*RUN:(.*) $lines($i) \1 theLine
202 set resultmsg [execOneLine $test $PRNUMS $outcome $i $theLine ]
203 if { $resultmsg != "" } {
204 if { $outcome == "XFAIL" } {
205 xfail "$resultmsg"
206 } else {
207 fail "$resultmsg"
208 }
209 set failed 1
210 break
211 }
212 }
213 if { $failed } {
214 continue
215 } else {
216 if { $PRNUMS != "" } {
217 set PRNUMS " for $PRNUMS"
218 }
219 if { $outcome == "XFAIL" } {
220 xpass "$test$PRNUMS"
221 } else {
222 pass "$test$PRNUMS"
223 }
224 }
225 }
226 }
227}
228
229# This procedure provides an interface to check the LLVMGCC_LANGS makefile
230# variable to see if llvm-gcc supports compilation of a particular language.
231proc llvm_gcc_supports { lang } {
232 global llvmgcc llvmgcc_langs
233 # validate the language choices and determine the name of the compiler
234 # component responsible for determining if the compiler has been built.
235 switch "$lang" {
236 ada { set file gnat1 }
237 c { set file cc1 }
238 c++ { set file cc1plus }
Duncan Sands86427262008-08-07 17:59:54 +0000239 objc { set file cc1obj }
Duncan Sandsd85a7092008-10-06 10:31:21 +0000240 obj-c++ { set file cc1objplus }
Duncan Sandsb78424e2008-06-27 14:22:20 +0000241 fortran { set file f951 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000242 default { return 0 }
243 }
244 foreach supported_lang [split "$llvmgcc_langs" ,] {
245 if { "$lang" == "$supported_lang" } {
246 # FIXME: Knowing it is configured is not enough. We should do two more
247 # checks here. First, we need to run llvm-gcc -print-prog-name=$file to
248 # get the path to the compiler. If we don't get a path, the language isn't
249 # properly configured or built. If we do get a path, we should check to
250 # make sure that it is executable and perhaps even try executing it.
251 return 1;
252 }
253 }
254 return 0;
255}
256
257# This procedure provides an interface to check the TARGETS_TO_BUILD makefile
258# variable to see if a particular target has been configured to build. This
259# helps avoid running tests for targets that aren't available.
260proc llvm_supports_target { tgtName } {
261 global TARGETS_TO_BUILD
262 foreach target [split $TARGETS_TO_BUILD] {
263 if { [regexp $tgtName $target match] } {
264 return 1
265 }
266 }
267 return 0
268}