blob: 4ee300b2b36889092c2d0905547979d6b26718ea [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
Reid Spencer78fb2ac2007-04-14 22:51:29 +000052 set path [file join $srcdir $subdir]
Reid Spencer316abe42007-04-14 09:39:28 +000053
Reid Spencer0947df42007-04-15 07:21:26 +000054 # Substitute all Tcl variables.
55 set new_line [subst $line ]
56
Reid Spencer316abe42007-04-14 09:39:28 +000057 #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 Sands53ebe352008-06-21 20:22:58 +000060 regsub -all {%llvmgcc} $new_line "$llvmgcc -emit-llvm -w" new_line
Reid Spencer316abe42007-04-14 09:39:28 +000061 #replace %llvmgxx with actual path to llvmg++
Duncan Sands53ebe352008-06-21 20:22:58 +000062 regsub -all {%llvmgxx} $new_line "$llvmgxx -emit-llvm -w" new_line
Reid Spencer316abe42007-04-14 09:39:28 +000063 #replace %compile_cxx with C++ compilation command
64 regsub -all {%compile_cxx} $new_line "$compile_cxx" new_line
Chris Lattneraadbda82008-03-10 06:45:35 +000065 #replace %compile_c with C compilation command
66 regsub -all {%compile_c} $new_line "$compile_c" new_line
Reid Spencer316abe42007-04-14 09:39:28 +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 Henriksen8ef426b2007-09-18 12:49:39 +000071 #replace %ocamlc with ocaml compiler command
72 regsub -all {%ocamlc} $new_line "$ocamlc" new_line
Reid Spencer316abe42007-04-14 09:39:28 +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 Sands6c7ada42007-07-23 15:23:35 +000080 regsub -all {%t} $new_line $tmpFile new_line
Reid Spencer12ca929c2007-04-15 04:57:03 +000081 #replace %% with %
82 regsub -all {%%} $new_line % new_line
Reid Spencer316abe42007-04-14 09:39:28 +000083 return $new_line
84}
85
Reid Spencer12d81f32007-04-21 21:45:51 +000086# This procedure runs the set of tests for the test_source_files array.
Reid Spencer78fb2ac2007-04-14 22:51:29 +000087proc RunLLVMTests { test_source_files } {
Reid Spencerfb7653e2007-04-15 20:43:36 +000088 global srcroot objroot srcdir objdir subdir target_triplet llvmgcc_version
Reid Spencer316abe42007-04-14 09:39:28 +000089 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 Sands6c7ada42007-07-23 15:23:35 +0000102 cd Output
Reid Spencer316abe42007-04-14 09:39:28 +0000103
Reid Spencer78fb2ac2007-04-14 22:51:29 +0000104 foreach test $test_source_files {
Reid Spencer316abe42007-04-14 09:39:28 +0000105 #Should figure out best way to set the timeout
106 #set timeout 40
107
108 set filename [file tail $test]
Gabor Greif684ed3d2008-02-26 12:08:55 +0000109 verbose "ABOUT TO RUN: $filename" 2
Reid Spencer316abe42007-04-14 09:39:28 +0000110 set outcome PASS
111 set tmpFile "$filename.tmp"
Tanya Lattnera57506e2007-11-06 22:32:17 +0000112
113 # Mark that it should not be XFAIL for this target.
114 set targetPASS 0
115
Reid Spencer316abe42007-04-14 09:39:28 +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 ""
Reid Spencer90016c72007-04-14 19:37:22 +0000122 set PRNUMS ""
Reid Spencerfb7653e2007-04-15 20:43:36 +0000123 foreach line [split [read $testFileId] \n] {
Reid Spencer316abe42007-04-14 09:39:28 +0000124
Reid Spencer90016c72007-04-14 19:37:22 +0000125 # if its the END. line then stop parsing (optimization for big files)
Tanya Lattner200d6072008-03-13 22:02:51 +0000126 if {[regexp {END.[[:space:]]*$} $line match endofscript]} {
Reid Spencer316abe42007-04-14 09:39:28 +0000127 break
Reid Spencer90016c72007-04-14 19:37:22 +0000128
Duncan Sands3724df32007-04-16 21:19:45 +0000129 # if the line is continued, concatenate and continue the loop
Reid Spencer601e8452007-04-15 18:38:42 +0000130 } elseif {[regexp {RUN: *(.+)(\\)$} $line match oneline suffix]} {
Reid Spencer316abe42007-04-14 09:39:28 +0000131 set runline "$runline$oneline "
Reid Spencer90016c72007-04-14 19:37:22 +0000132
133 # if its a terminating RUN: line then do substitution on the whole line
Tanya Lattner727842e2007-11-28 04:57:00 +0000134 # and then save the line.
135 } elseif {[regexp {RUN: *(.+)$} $line match oneline suffix]} {
Reid Spencer316abe42007-04-14 09:39:28 +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 ""
Reid Spencer90016c72007-04-14 19:37:22 +0000141
142 # if its an PR line, save the problem report number
143 } elseif {[regexp {PR([0-9]+)} $line match prnum]} {
144 if {$PRNUMS == ""} {
Reid Spencer66959ce2007-04-15 10:27:54 +0000145 set PRNUMS "PR$prnum"
Reid Spencer90016c72007-04-14 19:37:22 +0000146 } else {
147 set PRNUMS "$PRNUMS,$prnum"
148 }
149 # if its an XFAIL line, see if we should be XFAILing or not.
Reid Spencer316abe42007-04-14 09:39:28 +0000150 } 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 Lattnera57506e2007-11-06 22:32:17 +0000156 if {$targetPASS != 1} {
157 set outcome XFAIL
158 }
Reid Spencer316abe42007-04-14 09:39:28 +0000159 } elseif { [regexp $target $target_triplet match] } {
Tanya Lattnera57506e2007-11-06 22:32:17 +0000160 if {$targetPASS != 1} {
161 set outcome XFAIL
162 }
Reid Spencer316abe42007-04-14 09:39:28 +0000163 } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2] } {
164 if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
Tanya Lattnera57506e2007-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
Reid Spencer316abe42007-04-14 09:39:28 +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
Reid Spencer90016c72007-04-14 19:37:22 +0000202 set resultmsg [execOneLine $test $PRNUMS $outcome $i $theLine ]
Reid Spencer316abe42007-04-14 09:39:28 +0000203 if { $resultmsg != "" } {
204 if { $outcome == "XFAIL" } {
205 xfail "$resultmsg"
206 } else {
207 fail "$resultmsg"
208 }
209 set failed 1
210 break
211 }
212 }
Reid Spencer0947df42007-04-15 07:21:26 +0000213 if { $failed } {
Reid Spencerb0feffa2007-04-15 07:34:58 +0000214 continue
Reid Spencer0947df42007-04-15 07:21:26 +0000215 } else {
216 if { $PRNUMS != "" } {
Reid Spencer90016c72007-04-14 19:37:22 +0000217 set PRNUMS " for $PRNUMS"
218 }
Reid Spencer316abe42007-04-14 09:39:28 +0000219 if { $outcome == "XFAIL" } {
Reid Spencer90016c72007-04-14 19:37:22 +0000220 xpass "$test$PRNUMS"
Reid Spencer316abe42007-04-14 09:39:28 +0000221 } else {
Reid Spencer90016c72007-04-14 19:37:22 +0000222 pass "$test$PRNUMS"
Reid Spencer316abe42007-04-14 09:39:28 +0000223 }
224 }
225 }
226 }
227}
Devang Patel9fe99072007-04-20 21:24:01 +0000228
Reid Spencer12d81f32007-04-21 21:45:51 +0000229# 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 }
239 objc { set file cc1 }
240 objc++ { set file cc1 }
Duncan Sands39212662008-06-27 14:22:20 +0000241 fortran { set file f951 }
Reid Spencer12d81f32007-04-21 21:45:51 +0000242 default { return 0 }
243 }
Reid Spencer4f6e9ab2007-04-23 21:21:53 +0000244 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 }
Reid Spencer12d81f32007-04-21 21:45:51 +0000253 }
254 return 0;
Duncan Sands4e9471d2007-04-21 20:20:47 +0000255}
256
Reid Spencer12d81f32007-04-21 21:45:51 +0000257# 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.
Reid Spencer40a4c612007-04-21 20:40:17 +0000260proc 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}