blob: 05c910771ad16ba5b3849178d9ed9d76294c1a93 [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 {
34 }
35 default {
36 }
37 }
38 }
39 return $resultmsg
40}
41
Duncan Sands7d841a42007-05-18 12:13:34 +000042# This procedure performs variable substitutions on the RUN: lines of a test
Reid Spencer12d81f32007-04-21 21:45:51 +000043# cases.
Reid Spencer316abe42007-04-14 09:39:28 +000044proc substitute { line test tmpFile } {
45 global srcroot objroot srcdir objdir subdir target_triplet prcontext
Gordon Henriksen8ef426b2007-09-18 12:49:39 +000046 global llvmgcc llvmgxx llvmgcc_version llvmgccmajvers ocamlc
Reid Spencer316abe42007-04-14 09:39:28 +000047 global gccpath gxxpath compile_c compile_cxx link shlibext llvmlibsdir
Reid Spencer78fb2ac2007-04-14 22:51:29 +000048 set path [file join $srcdir $subdir]
Reid Spencer316abe42007-04-14 09:39:28 +000049
Reid Spencer0947df42007-04-15 07:21:26 +000050 # Substitute all Tcl variables.
51 set new_line [subst $line ]
52
Reid Spencer316abe42007-04-14 09:39:28 +000053 #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
59 #replace %compile_c with C compilation command
60 regsub -all {%compile_c} $new_line "$compile_c" new_line
61 #replace %compile_cxx with C++ compilation command
62 regsub -all {%compile_cxx} $new_line "$compile_cxx" new_line
63 #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 Henriksen8ef426b2007-09-18 12:49:39 +000067 #replace %ocamlc with ocaml compiler command
68 regsub -all {%ocamlc} $new_line "$ocamlc" new_line
Reid Spencer316abe42007-04-14 09:39:28 +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 Sands6c7ada42007-07-23 15:23:35 +000076 regsub -all {%t} $new_line $tmpFile new_line
Reid Spencer12ca929c2007-04-15 04:57:03 +000077 #replace %% with %
78 regsub -all {%%} $new_line % new_line
Reid Spencer316abe42007-04-14 09:39:28 +000079 return $new_line
80}
81
Reid Spencer12d81f32007-04-21 21:45:51 +000082# This procedure runs the set of tests for the test_source_files array.
Reid Spencer78fb2ac2007-04-14 22:51:29 +000083proc RunLLVMTests { test_source_files } {
Reid Spencerfb7653e2007-04-15 20:43:36 +000084 global srcroot objroot srcdir objdir subdir target_triplet llvmgcc_version
Reid Spencer316abe42007-04-14 09:39:28 +000085 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 Sands6c7ada42007-07-23 15:23:35 +000098 cd Output
Reid Spencer316abe42007-04-14 09:39:28 +000099
Reid Spencer78fb2ac2007-04-14 22:51:29 +0000100 foreach test $test_source_files {
Reid Spencer316abe42007-04-14 09:39:28 +0000101 #Should figure out best way to set the timeout
102 #set timeout 40
103
104 set filename [file tail $test]
105 set outcome PASS
106 set tmpFile "$filename.tmp"
Tanya Lattnera57506e2007-11-06 22:32:17 +0000107
108 # Mark that it should not be XFAIL for this target.
109 set targetPASS 0
110
Reid Spencer316abe42007-04-14 09:39:28 +0000111 #set hasRunline bool to check if testcase has a runline
112 set numLines 0
113
114 # Open the test file and start reading lines
115 set testFileId [ open $test r]
116 set runline ""
Reid Spencer90016c72007-04-14 19:37:22 +0000117 set PRNUMS ""
Reid Spencerfb7653e2007-04-15 20:43:36 +0000118 foreach line [split [read $testFileId] \n] {
Reid Spencer316abe42007-04-14 09:39:28 +0000119
Reid Spencer90016c72007-04-14 19:37:22 +0000120 # if its the END. line then stop parsing (optimization for big files)
Reid Spencer316abe42007-04-14 09:39:28 +0000121 if {[regexp {END.[ *]$} $line match endofscript]} {
122 break
Reid Spencer90016c72007-04-14 19:37:22 +0000123
Duncan Sands3724df32007-04-16 21:19:45 +0000124 # if the line is continued, concatenate and continue the loop
Reid Spencer601e8452007-04-15 18:38:42 +0000125 } elseif {[regexp {RUN: *(.+)(\\)$} $line match oneline suffix]} {
Reid Spencer316abe42007-04-14 09:39:28 +0000126 set runline "$runline$oneline "
Reid Spencer90016c72007-04-14 19:37:22 +0000127
128 # if its a terminating RUN: line then do substitution on the whole line
Tanya Lattner727842e2007-11-28 04:57:00 +0000129 # and then save the line.
130 } elseif {[regexp {RUN: *(.+)$} $line match oneline suffix]} {
Reid Spencer316abe42007-04-14 09:39:28 +0000131 set runline "$runline$oneline"
132 set runline [ substitute $runline $test $tmpFile ]
133 set lines($numLines) $runline
134 set numLines [expr $numLines + 1]
135 set runline ""
Reid Spencer90016c72007-04-14 19:37:22 +0000136
137 # if its an PR line, save the problem report number
138 } elseif {[regexp {PR([0-9]+)} $line match prnum]} {
139 if {$PRNUMS == ""} {
Reid Spencer66959ce2007-04-15 10:27:54 +0000140 set PRNUMS "PR$prnum"
Reid Spencer90016c72007-04-14 19:37:22 +0000141 } else {
142 set PRNUMS "$PRNUMS,$prnum"
143 }
144 # if its an XFAIL line, see if we should be XFAILing or not.
Reid Spencer316abe42007-04-14 09:39:28 +0000145 } elseif {[regexp {XFAIL:[ *](.+)} $line match targets]} {
146 set targets
147
148 #split up target if more then 1 specified
149 foreach target [split $targets ,] {
150 if { [regexp {\*} $target match] } {
Tanya Lattnera57506e2007-11-06 22:32:17 +0000151 if {$targetPASS != 1} {
152 set outcome XFAIL
153 }
Reid Spencer316abe42007-04-14 09:39:28 +0000154 } elseif { [regexp $target $target_triplet match] } {
Tanya Lattnera57506e2007-11-06 22:32:17 +0000155 if {$targetPASS != 1} {
156 set outcome XFAIL
157 }
Reid Spencer316abe42007-04-14 09:39:28 +0000158 } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2] } {
159 if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
Tanya Lattnera57506e2007-11-06 22:32:17 +0000160 if {$targetPASS != 1} {
161 set outcome XFAIL
162 }
163 }
164 }
165 }
166 } elseif {[regexp {XTARGET:[ *](.+)} $line match targets]} {
167 set targets
168
169 #split up target if more then 1 specified
170 foreach target [split $targets ,] {
171 if { [regexp {\*} $target match] } {
172 set targetPASS 1
173 set outcome PASS
174 } elseif { [regexp $target $target_triplet match] } {
175 set targetPASS 1
176 set outcome PASS
177 } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2] } {
178 if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
179 set targetPASS 1
180 set outcome PASS
Reid Spencer316abe42007-04-14 09:39:28 +0000181 }
182 }
183 }
184 }
185 }
186
187 # Done reading the script
188 close $testFileId
189
190
191 if { $numLines == 0 } {
192 fail "$test: \nDoes not have a RUN line\n"
193 } else {
194 set failed 0
195 for { set i 0 } { $i < $numLines } { set i [ expr $i + 1 ] } {
196 regsub ^.*RUN:(.*) $lines($i) \1 theLine
Reid Spencer90016c72007-04-14 19:37:22 +0000197 set resultmsg [execOneLine $test $PRNUMS $outcome $i $theLine ]
Reid Spencer316abe42007-04-14 09:39:28 +0000198 if { $resultmsg != "" } {
199 if { $outcome == "XFAIL" } {
200 xfail "$resultmsg"
201 } else {
202 fail "$resultmsg"
203 }
204 set failed 1
205 break
206 }
207 }
Reid Spencer0947df42007-04-15 07:21:26 +0000208 if { $failed } {
Reid Spencerb0feffa2007-04-15 07:34:58 +0000209 continue
Reid Spencer0947df42007-04-15 07:21:26 +0000210 } else {
211 if { $PRNUMS != "" } {
Reid Spencer90016c72007-04-14 19:37:22 +0000212 set PRNUMS " for $PRNUMS"
213 }
Reid Spencer316abe42007-04-14 09:39:28 +0000214 if { $outcome == "XFAIL" } {
Reid Spencer90016c72007-04-14 19:37:22 +0000215 xpass "$test$PRNUMS"
Reid Spencer316abe42007-04-14 09:39:28 +0000216 } else {
Reid Spencer90016c72007-04-14 19:37:22 +0000217 pass "$test$PRNUMS"
Reid Spencer316abe42007-04-14 09:39:28 +0000218 }
219 }
220 }
221 }
222}
Devang Patel9fe99072007-04-20 21:24:01 +0000223
Reid Spencer12d81f32007-04-21 21:45:51 +0000224# This procedure provides an interface to check the LLVMGCC_LANGS makefile
225# variable to see if llvm-gcc supports compilation of a particular language.
226proc llvm_gcc_supports { lang } {
227 global llvmgcc llvmgcc_langs
228 # validate the language choices and determine the name of the compiler
229 # component responsible for determining if the compiler has been built.
230 switch "$lang" {
231 ada { set file gnat1 }
232 c { set file cc1 }
233 c++ { set file cc1plus }
234 objc { set file cc1 }
235 objc++ { set file cc1 }
236 fortran { set file fcc1 }
237 default { return 0 }
238 }
Reid Spencer4f6e9ab2007-04-23 21:21:53 +0000239 foreach supported_lang [split "$llvmgcc_langs" ,] {
240 if { "$lang" == "$supported_lang" } {
241 # FIXME: Knowing it is configured is not enough. We should do two more
242 # checks here. First, we need to run llvm-gcc -print-prog-name=$file to
243 # get the path to the compiler. If we don't get a path, the language isn't
244 # properly configured or built. If we do get a path, we should check to
245 # make sure that it is executable and perhaps even try executing it.
246 return 1;
247 }
Reid Spencer12d81f32007-04-21 21:45:51 +0000248 }
249 return 0;
Duncan Sands4e9471d2007-04-21 20:20:47 +0000250}
251
Reid Spencer12d81f32007-04-21 21:45:51 +0000252# This procedure provides an interface to check the TARGETS_TO_BUILD makefile
253# variable to see if a particular target has been configured to build. This
254# helps avoid running tests for targets that aren't available.
Reid Spencer40a4c612007-04-21 20:40:17 +0000255proc llvm_supports_target { tgtName } {
256 global TARGETS_TO_BUILD
257 foreach target [split $TARGETS_TO_BUILD] {
258 if { [regexp $tgtName $target match] } {
259 return 1
260 }
261 }
262 return 0
263}