1 # This procedure executes one line of a test case's execution script.
2 proc execOneLine { test PRS outcome lineno line } {
5 set retval [ catch { eval exec -keepnewline -- $line } errmsg ]
7 set code [lindex $::errorCode 0]
8 set lineno [expr $lineno + 1]
12 set errmsg " at line $lineno\nwhile running: $line\n$errmsg"
15 set status [lindex $::errorCode 2]
17 set resultmsg "$test$PRS\nFailed with exit($status)$errmsg"
21 set signal [lindex $::errorCode 2]
22 set resultmsg "$test$PRS\nFailed with signal($signal)$errmsg"
25 set signal [lindex $::errorCode 2]
26 set resultmsg "$test$PRS\nFailed with suspend($signal)$errmsg"
29 set posixNum [lindex $::errorCode 1]
30 set posixMsg [lindex $::errorCode 2]
31 set resultmsg "$test$PRS\nFailed with posix($posixNum,$posixMsg)$errmsg"
34 # Any other error such as stderr output of a program, or syntax error in
36 set resultmsg "$test$PRS\nFailed with unknown error (or has stderr output)$errmsg"
39 set resultmsg "$test$PRS\nFailed with unknown error$errmsg"
46 # This procedure performs variable substitutions on the RUN: lines of a test
48 proc substitute { line test tmpFile } {
49 global srcroot objroot srcdir objdir subdir target_triplet prcontext
50 global llvmgcc llvmgxx llvmgcc_version llvmgccmajvers ocamlc
51 global gccpath gxxpath compile_c compile_cxx link shlibext llvmlibsdir
52 set path [file join $srcdir $subdir]
54 # Substitute all Tcl variables.
55 set new_line [subst $line ]
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
60 regsub -all {%llvmgcc} $new_line "$llvmgcc -emit-llvm -w" new_line
61 #replace %llvmgxx with actual path to llvmg++
62 regsub -all {%llvmgxx} $new_line "$llvmgxx -emit-llvm -w" new_line
63 #replace %compile_cxx with C++ compilation command
64 regsub -all {%compile_cxx} $new_line "$compile_cxx" new_line
65 #replace %compile_c with C compilation command
66 regsub -all {%compile_c} $new_line "$compile_c" new_line
67 #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
71 #replace %ocamlc with ocaml compiler command
72 regsub -all {%ocamlc} $new_line "$ocamlc" new_line
73 #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
80 regsub -all {%t} $new_line $tmpFile new_line
82 regsub -all {%%} $new_line % new_line
86 # This procedure runs the set of tests for the test_source_files array.
87 proc RunLLVMTests { test_source_files } {
88 global srcroot objroot srcdir objdir subdir target_triplet llvmgcc_version
91 set path [file join $objdir $subdir]
93 #Make Output Directory if it does not exist already
94 if { [file exists path] } {
104 foreach test $test_source_files {
105 #Should figure out best way to set the timeout
108 set filename [file tail $test]
109 verbose "ABOUT TO RUN: $filename" 2
111 set tmpFile "$filename.tmp"
113 # Mark that it should not be XFAIL for this target.
116 #set hasRunline bool to check if testcase has a runline
119 # Open the test file and start reading lines
120 set testFileId [ open $test r]
123 foreach line [split [read $testFileId] \n] {
125 # if its the END. line then stop parsing (optimization for big files)
126 if {[regexp {END.[[:space:]]*$} $line match endofscript]} {
129 # if the line is continued, concatenate and continue the loop
130 } elseif {[regexp {RUN: *(.+)(\\)$} $line match oneline suffix]} {
131 set runline "$runline$oneline "
133 # if its a terminating RUN: line then do substitution on the whole line
134 # and then save the line.
135 } elseif {[regexp {RUN: *(.+)$} $line match oneline suffix]} {
136 set runline "$runline$oneline"
137 set runline [ substitute $runline $test $tmpFile ]
138 set lines($numLines) $runline
139 set numLines [expr $numLines + 1]
142 # if its an PR line, save the problem report number
143 } elseif {[regexp {PR([0-9]+)} $line match prnum]} {
145 set PRNUMS "PR$prnum"
147 set PRNUMS "$PRNUMS,$prnum"
149 # if its an XFAIL line, see if we should be XFAILing or not.
150 } elseif {[regexp {XFAIL:[ *](.+)} $line match targets]} {
153 #split up target if more then 1 specified
154 foreach target [split $targets ,] {
155 if { [regexp {\*} $target match] } {
156 if {$targetPASS != 1} {
159 } elseif { [regexp $target $target_triplet match] } {
160 if {$targetPASS != 1} {
163 } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2] } {
164 if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
165 if {$targetPASS != 1} {
171 } elseif {[regexp {XTARGET:[ *](.+)} $line match targets]} {
174 #split up target if more then 1 specified
175 foreach target [split $targets ,] {
176 if { [regexp {\*} $target match] } {
179 } elseif { [regexp $target $target_triplet match] } {
182 } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2] } {
183 if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
192 # Done reading the script
196 if { $numLines == 0 } {
197 fail "$test: \nDoes not have a RUN line\n"
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" } {
216 if { $PRNUMS != "" } {
217 set PRNUMS " for $PRNUMS"
219 if { $outcome == "XFAIL" } {
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.
231 proc 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.
236 ada { set file gnat1 }
238 c++ { set file cc1plus }
239 objc { set file cc1 }
240 objc++ { set file cc1 }
241 fortran { set file fcc1 }
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.
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.
260 proc llvm_supports_target { tgtName } {
261 global TARGETS_TO_BUILD
262 foreach target [split $TARGETS_TO_BUILD] {
263 if { [regexp $tgtName $target match] } {