blob: 78e3e836840fc12b3c3dcfba89fbfe907b2617a3 [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 {
34 }
35 default {
36 }
37 }
38 }
39 return $resultmsg
40}
41
42# This procedure performs variable substitutions on the RUN: lines of a test
43# cases.
44proc substitute { line test tmpFile } {
45 global srcroot objroot srcdir objdir subdir target_triplet prcontext
Gordon Henriksenc6606c62007-09-18 12:49:39 +000046 global llvmgcc llvmgxx llvmgcc_version llvmgccmajvers ocamlc
Dan Gohmanf17a25c2007-07-18 16:29:46 +000047 global gccpath gxxpath compile_c compile_cxx link shlibext llvmlibsdir
48 set path [file join $srcdir $subdir]
Dan Gohmanf17a25c2007-07-18 16:29:46 +000049
50 # Substitute all Tcl variables.
51 set new_line [subst $line ]
52
53 #replace %prcontext with prcontext.tcl (Must replace before %p)
54 regsub -all {%prcontext} $new_line $prcontext new_line
55 #replace %llvmgcc with actual path to llvmgcc
56 regsub -all {%llvmgcc} $new_line "$llvmgcc -emit-llvm" new_line
57 #replace %llvmgxx with actual path to llvmg++
58 regsub -all {%llvmgxx} $new_line "$llvmgxx -emit-llvm" new_line
Dan Gohmanf17a25c2007-07-18 16:29:46 +000059 #replace %compile_cxx with C++ compilation command
60 regsub -all {%compile_cxx} $new_line "$compile_cxx" new_line
Chris Lattnered04bb22008-03-10 06:45:35 +000061 #replace %compile_c with C compilation command
62 regsub -all {%compile_c} $new_line "$compile_c" new_line
Dan Gohmanf17a25c2007-07-18 16:29:46 +000063 #replace %link with C++ link command
64 regsub -all {%link} $new_line "$link" new_line
65 #replace %shlibext with shared library extension
66 regsub -all {%shlibext} $new_line "$shlibext" new_line
Gordon Henriksenc6606c62007-09-18 12:49:39 +000067 #replace %ocamlc with ocaml compiler command
68 regsub -all {%ocamlc} $new_line "$ocamlc" new_line
Dan Gohmanf17a25c2007-07-18 16:29:46 +000069 #replace %llvmlibsdir with configure library directory
70 regsub -all {%llvmlibsdir} $new_line "$llvmlibsdir" new_line
71 #replace %p with path to source,
72 regsub -all {%p} $new_line [file join $srcdir $subdir] new_line
73 #replace %s with filename
74 regsub -all {%s} $new_line $test new_line
75 #replace %t with temp filenames
Duncan Sandsa524e0e2007-07-23 15:23:35 +000076 regsub -all {%t} $new_line $tmpFile new_line
Dan Gohmanf17a25c2007-07-18 16:29:46 +000077 #replace %% with %
78 regsub -all {%%} $new_line % new_line
79 return $new_line
80}
81
82# This procedure runs the set of tests for the test_source_files array.
83proc RunLLVMTests { test_source_files } {
84 global srcroot objroot srcdir objdir subdir target_triplet llvmgcc_version
85 set timeout 60
86
87 set path [file join $objdir $subdir]
88
89 #Make Output Directory if it does not exist already
90 if { [file exists path] } {
91 cd $path
92 } else {
93 file mkdir $path
94 cd $path
95 }
96
97 file mkdir Output
Duncan Sandsa524e0e2007-07-23 15:23:35 +000098 cd Output
Dan Gohmanf17a25c2007-07-18 16:29:46 +000099
100 foreach test $test_source_files {
101 #Should figure out best way to set the timeout
102 #set timeout 40
103
104 set filename [file tail $test]
Gabor Greif9f99a9f2008-02-26 12:08:55 +0000105 verbose "ABOUT TO RUN: $filename" 2
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000106 set outcome PASS
107 set tmpFile "$filename.tmp"
Tanya Lattner090659d2007-11-06 22:32:17 +0000108
109 # Mark that it should not be XFAIL for this target.
110 set targetPASS 0
111
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000112 #set hasRunline bool to check if testcase has a runline
113 set numLines 0
114
115 # Open the test file and start reading lines
116 set testFileId [ open $test r]
117 set runline ""
118 set PRNUMS ""
119 foreach line [split [read $testFileId] \n] {
120
121 # if its the END. line then stop parsing (optimization for big files)
122 if {[regexp {END.[ *]$} $line match endofscript]} {
123 break
124
125 # if the line is continued, concatenate and continue the loop
126 } elseif {[regexp {RUN: *(.+)(\\)$} $line match oneline suffix]} {
127 set runline "$runline$oneline "
128
129 # if its a terminating RUN: line then do substitution on the whole line
Tanya Lattner8b074702007-11-28 04:57:00 +0000130 # and then save the line.
131 } elseif {[regexp {RUN: *(.+)$} $line match oneline suffix]} {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000132 set runline "$runline$oneline"
133 set runline [ substitute $runline $test $tmpFile ]
134 set lines($numLines) $runline
135 set numLines [expr $numLines + 1]
136 set runline ""
137
138 # if its an PR line, save the problem report number
139 } elseif {[regexp {PR([0-9]+)} $line match prnum]} {
140 if {$PRNUMS == ""} {
141 set PRNUMS "PR$prnum"
142 } else {
143 set PRNUMS "$PRNUMS,$prnum"
144 }
145 # if its an XFAIL line, see if we should be XFAILing or not.
146 } elseif {[regexp {XFAIL:[ *](.+)} $line match targets]} {
147 set targets
148
149 #split up target if more then 1 specified
150 foreach target [split $targets ,] {
151 if { [regexp {\*} $target match] } {
Tanya Lattner090659d2007-11-06 22:32:17 +0000152 if {$targetPASS != 1} {
153 set outcome XFAIL
154 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000155 } elseif { [regexp $target $target_triplet 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 {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2] } {
160 if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
Tanya Lattner090659d2007-11-06 22:32:17 +0000161 if {$targetPASS != 1} {
162 set outcome XFAIL
163 }
164 }
165 }
166 }
167 } elseif {[regexp {XTARGET:[ *](.+)} $line match targets]} {
168 set targets
169
170 #split up target if more then 1 specified
171 foreach target [split $targets ,] {
172 if { [regexp {\*} $target match] } {
173 set targetPASS 1
174 set outcome PASS
175 } elseif { [regexp $target $target_triplet match] } {
176 set targetPASS 1
177 set outcome PASS
178 } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2] } {
179 if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
180 set targetPASS 1
181 set outcome PASS
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000182 }
183 }
184 }
185 }
186 }
187
188 # Done reading the script
189 close $testFileId
190
191
192 if { $numLines == 0 } {
193 fail "$test: \nDoes not have a RUN line\n"
194 } else {
195 set failed 0
196 for { set i 0 } { $i < $numLines } { set i [ expr $i + 1 ] } {
197 regsub ^.*RUN:(.*) $lines($i) \1 theLine
198 set resultmsg [execOneLine $test $PRNUMS $outcome $i $theLine ]
199 if { $resultmsg != "" } {
200 if { $outcome == "XFAIL" } {
201 xfail "$resultmsg"
202 } else {
203 fail "$resultmsg"
204 }
205 set failed 1
206 break
207 }
208 }
209 if { $failed } {
210 continue
211 } else {
212 if { $PRNUMS != "" } {
213 set PRNUMS " for $PRNUMS"
214 }
215 if { $outcome == "XFAIL" } {
216 xpass "$test$PRNUMS"
217 } else {
218 pass "$test$PRNUMS"
219 }
220 }
221 }
222 }
223}
224
225# This procedure provides an interface to check the LLVMGCC_LANGS makefile
226# variable to see if llvm-gcc supports compilation of a particular language.
227proc llvm_gcc_supports { lang } {
228 global llvmgcc llvmgcc_langs
229 # validate the language choices and determine the name of the compiler
230 # component responsible for determining if the compiler has been built.
231 switch "$lang" {
232 ada { set file gnat1 }
233 c { set file cc1 }
234 c++ { set file cc1plus }
235 objc { set file cc1 }
236 objc++ { set file cc1 }
237 fortran { set file fcc1 }
238 default { return 0 }
239 }
240 foreach supported_lang [split "$llvmgcc_langs" ,] {
241 if { "$lang" == "$supported_lang" } {
242 # FIXME: Knowing it is configured is not enough. We should do two more
243 # checks here. First, we need to run llvm-gcc -print-prog-name=$file to
244 # get the path to the compiler. If we don't get a path, the language isn't
245 # properly configured or built. If we do get a path, we should check to
246 # make sure that it is executable and perhaps even try executing it.
247 return 1;
248 }
249 }
250 return 0;
251}
252
253# This procedure provides an interface to check the TARGETS_TO_BUILD makefile
254# variable to see if a particular target has been configured to build. This
255# helps avoid running tests for targets that aren't available.
256proc llvm_supports_target { tgtName } {
257 global TARGETS_TO_BUILD
258 foreach target [split $TARGETS_TO_BUILD] {
259 if { [regexp $tgtName $target match] } {
260 return 1
261 }
262 }
263 return 0
264}