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 llvmdsymutil
52 global valgrind grep gas
53 set path [file join $srcdir $subdir]
55 # Substitute all Tcl variables.
56 set new_line [subst $line ]
58 #replace %% with _#MARKER#_ to make the replacement of %% more predictable
59 regsub -all {%%} $new_line {_#MARKER#_} new_line
60 #replace %prcontext with prcontext.tcl (Must replace before %p)
61 regsub -all {%prcontext} $new_line $prcontext new_line
62 #replace %llvmgcc with actual path to llvmgcc
63 regsub -all {%llvmgcc} $new_line "$llvmgcc -emit-llvm -w" new_line
64 #replace %llvmgxx with actual path to llvmg++
65 regsub -all {%llvmgxx} $new_line "$llvmgxx -emit-llvm -w" new_line
66 #replace %compile_cxx with C++ compilation command
67 regsub -all {%compile_cxx} $new_line "$compile_cxx" new_line
68 #replace %compile_c with C compilation command
69 regsub -all {%compile_c} $new_line "$compile_c" new_line
70 #replace %link with C++ link command
71 regsub -all {%link} $new_line "$link" new_line
72 #replace %shlibext with shared library extension
73 regsub -all {%shlibext} $new_line "$shlibext" new_line
74 #replace %ocamlc with ocaml compiler command
75 regsub -all {%ocamlc} $new_line "$ocamlc" new_line
76 #replace %llvmdsymutil with dsymutil command
77 regsub -all {%llvmdsymutil} $new_line "$llvmdsymutil" new_line
78 #replace %llvmlibsdir with configure library directory
79 regsub -all {%llvmlibsdir} $new_line "$llvmlibsdir" new_line
80 #replace %p with path to source,
81 regsub -all {%p} $new_line [file join $srcdir $subdir] new_line
82 #replace %s with filename
83 regsub -all {%s} $new_line $test new_line
84 #replace %t with temp filenames
85 regsub -all {%t} $new_line $tmpFile new_line
86 #replace _#MARKER#_ with %
87 regsub -all {_#MARKER#_} $new_line % new_line
89 #replace grep with GNU grep
90 regsub -all { grep } $new_line " $grep " new_line
91 #replace as with GNU as
92 regsub -all {\| as } $new_line "| $gas " new_line
94 #valgind related stuff
95 # regsub -all {bugpoint } $new_line "$valgrind bugpoint " new_line
96 regsub -all {llc } $new_line "$valgrind llc " new_line
97 regsub -all {lli } $new_line "$valgrind lli " new_line
98 regsub -all {llvm-ar } $new_line "$valgrind llvm-ar " new_line
99 regsub -all {llvm-as } $new_line "$valgrind llvm-as " new_line
100 regsub -all {llvm-bcanalyzer } $new_line "$valgrind llvm-bcanalyzer " new_line
101 regsub -all {llvm-dis } $new_line "$valgrind llvm-dis " new_line
102 regsub -all {llvm-extract } $new_line "$valgrind llvm-extract " new_line
103 regsub -all {llvm-ld } $new_line "$valgrind llvm-ld " new_line
104 regsub -all {llvm-link } $new_line "$valgrind llvm-link " new_line
105 regsub -all {llvm-nm } $new_line "$valgrind llvm-nm " new_line
106 regsub -all {llvm-prof } $new_line "$valgrind llvm-prof " new_line
107 regsub -all {llvm-ranlib } $new_line "$valgrind llvm-ranlib " new_line
108 regsub -all {([^a-zA-Z_-])opt } $new_line "\\1$valgrind opt " new_line
109 regsub -all {^opt } $new_line "$valgrind opt " new_line
110 regsub -all {tblgen } $new_line "$valgrind tblgen " new_line
111 regsub -all "not $valgrind " $new_line "$valgrind not " new_line
116 # This procedure runs the set of tests for the test_source_files array.
117 proc RunLLVMTests { test_source_files } {
118 global srcroot objroot srcdir objdir subdir target_triplet llvmgcc_version
121 set path [file join $objdir $subdir]
123 #Make Output Directory if it does not exist already
124 if { [file exists path] } {
134 foreach test $test_source_files {
135 #Should figure out best way to set the timeout
138 set filename [file tail $test]
139 verbose "ABOUT TO RUN: $filename" 2
141 set tmpFile "$filename.tmp"
143 # Mark that it should not be XFAIL for this target.
146 #set hasRunline bool to check if testcase has a runline
149 # Open the test file and start reading lines
150 set testFileId [ open $test r]
153 foreach line [split [read $testFileId] \n] {
155 # if its the END. line then stop parsing (optimization for big files)
156 if {[regexp {END.[[:space:]]*$} $line match endofscript]} {
159 # if the line is continued, concatenate and continue the loop
160 } elseif {[regexp {RUN: *(.+)(\\)$} $line match oneline suffix]} {
161 set runline "$runline$oneline "
163 # if its a terminating RUN: line then do substitution on the whole line
164 # and then save the line.
165 } elseif {[regexp {RUN: *(.+)$} $line match oneline suffix]} {
166 set runline "$runline$oneline"
167 set runline [ substitute $runline $test $tmpFile ]
168 set lines($numLines) $runline
169 set numLines [expr $numLines + 1]
172 # if its an PR line, save the problem report number
173 } elseif {[regexp {PR([0-9]+)} $line match prnum]} {
175 set PRNUMS "PR$prnum"
177 set PRNUMS "$PRNUMS,$prnum"
179 # if its an XFAIL line, see if we should be XFAILing or not.
180 } elseif {[regexp {XFAIL:[ *](.+)} $line match targets]} {
183 #split up target if more then 1 specified
184 foreach target [split $targets ,] {
185 if { [regexp {\*} $target match] } {
186 if {$targetPASS != 1} {
189 } elseif { [regexp $target $target_triplet match] } {
190 if {$targetPASS != 1} {
193 } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2] } {
194 if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
195 if {$targetPASS != 1} {
201 } elseif {[regexp {XTARGET:[ *](.+)} $line match targets]} {
204 #split up target if more then 1 specified
205 foreach target [split $targets ,] {
206 if { [regexp {\*} $target match] } {
209 } elseif { [regexp $target $target_triplet match] } {
212 } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2] } {
213 if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
222 # Done reading the script
226 if { $numLines == 0 } {
227 fail "$test: \nDoes not have a RUN line\n"
230 for { set i 0 } { $i < $numLines } { set i [ expr $i + 1 ] } {
231 regsub ^.*RUN:(.*) $lines($i) \1 theLine
232 set resultmsg [execOneLine $test $PRNUMS $outcome $i $theLine ]
233 if { $resultmsg != "" } {
234 if { $outcome == "XFAIL" } {
246 if { $PRNUMS != "" } {
247 set PRNUMS " for $PRNUMS"
249 if { $outcome == "XFAIL" } {
259 # This procedure provides an interface to check the LLVMGCC_LANGS makefile
260 # variable to see if llvm-gcc supports compilation of a particular language.
261 proc llvm_gcc_supports { lang } {
262 global llvmgcc llvmgcc_langs
263 # validate the language choices and determine the name of the compiler
264 # component responsible for determining if the compiler has been built.
266 ada { set file gnat1 }
268 c++ { set file cc1plus }
269 objc { set file cc1obj }
270 obj-c++ { set file cc1objplus }
271 fortran { set file f951 }
274 foreach supported_lang [split "$llvmgcc_langs" ,] {
275 if { "$lang" == "$supported_lang" } {
276 # FIXME: Knowing it is configured is not enough. We should do two more
277 # checks here. First, we need to run llvm-gcc -print-prog-name=$file to
278 # get the path to the compiler. If we don't get a path, the language isn't
279 # properly configured or built. If we do get a path, we should check to
280 # make sure that it is executable and perhaps even try executing it.
287 # This procedure provides an interface to check the TARGETS_TO_BUILD makefile
288 # variable to see if a particular target has been configured to build. This
289 # helps avoid running tests for targets that aren't available.
290 proc llvm_supports_target { tgtName } {
291 global TARGETS_TO_BUILD
292 foreach target [split $TARGETS_TO_BUILD] {
293 if { [regexp $tgtName $target match] } {