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"
42 # This procedure performs variable substitutions on the RUN: lines of a test
44 proc substitute { line test tmpFile } {
45 global srcroot objroot srcdir objdir subdir target_triplet prcontext
46 global llvmgcc llvmgxx llvmgcc_version llvmgccmajvers ocamlc
47 global gccpath gxxpath compile_c compile_cxx link shlibext llvmlibsdir
48 set path [file join $srcdir $subdir]
50 # Substitute all Tcl variables.
51 set new_line [subst $line ]
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
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
67 #replace %ocamlc with ocaml compiler command
68 regsub -all {%ocamlc} $new_line "$ocamlc" new_line
69 #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
76 regsub -all {%t} $new_line $tmpFile new_line
78 regsub -all {%%} $new_line % new_line
82 # This procedure runs the set of tests for the test_source_files array.
83 proc RunLLVMTests { test_source_files } {
84 global srcroot objroot srcdir objdir subdir target_triplet llvmgcc_version
87 set path [file join $objdir $subdir]
89 #Make Output Directory if it does not exist already
90 if { [file exists path] } {
100 foreach test $test_source_files {
101 #Should figure out best way to set the timeout
104 set filename [file tail $test]
106 set tmpFile "$filename.tmp"
108 # Mark that it should not be XFAIL for this target.
111 #set hasRunline bool to check if testcase has a runline
114 # Open the test file and start reading lines
115 set testFileId [ open $test r]
118 foreach line [split [read $testFileId] \n] {
120 # if its the END. line then stop parsing (optimization for big files)
121 if {[regexp {END.[ *]$} $line match endofscript]} {
124 # if the line is continued, concatenate and continue the loop
125 } elseif {[regexp {RUN: *(.+)(\\)$} $line match oneline suffix]} {
126 set runline "$runline$oneline "
128 # if its a terminating RUN: line then do substitution on the whole line
129 # and then save the line.
130 } elseif {[regexp {RUN: *([^&]+)(&&)?} $line match oneline suffix]} {
131 set runline "$runline$oneline"
132 set runline [ substitute $runline $test $tmpFile ]
133 set lines($numLines) $runline
134 set numLines [expr $numLines + 1]
137 # if its an PR line, save the problem report number
138 } elseif {[regexp {PR([0-9]+)} $line match prnum]} {
140 set PRNUMS "PR$prnum"
142 set PRNUMS "$PRNUMS,$prnum"
144 # if its an XFAIL line, see if we should be XFAILing or not.
145 } elseif {[regexp {XFAIL:[ *](.+)} $line match targets]} {
148 #split up target if more then 1 specified
149 foreach target [split $targets ,] {
150 if { [regexp {\*} $target match] } {
151 if {$targetPASS != 1} {
154 } elseif { [regexp $target $target_triplet match] } {
155 if {$targetPASS != 1} {
158 } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2] } {
159 if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
160 if {$targetPASS != 1} {
166 } elseif {[regexp {XTARGET:[ *](.+)} $line match targets]} {
169 #split up target if more then 1 specified
170 foreach target [split $targets ,] {
171 if { [regexp {\*} $target match] } {
174 } elseif { [regexp $target $target_triplet match] } {
177 } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2] } {
178 if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
187 # Done reading the script
191 if { $numLines == 0 } {
192 fail "$test: \nDoes not have a RUN line\n"
195 for { set i 0 } { $i < $numLines } { set i [ expr $i + 1 ] } {
196 regsub ^.*RUN:(.*) $lines($i) \1 theLine
197 set resultmsg [execOneLine $test $PRNUMS $outcome $i $theLine ]
198 if { $resultmsg != "" } {
199 if { $outcome == "XFAIL" } {
211 if { $PRNUMS != "" } {
212 set PRNUMS " for $PRNUMS"
214 if { $outcome == "XFAIL" } {
224 # This procedure provides an interface to check the LLVMGCC_LANGS makefile
225 # variable to see if llvm-gcc supports compilation of a particular language.
226 proc 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.
231 ada { set file gnat1 }
233 c++ { set file cc1plus }
234 objc { set file cc1 }
235 objc++ { set file cc1 }
236 fortran { set file fcc1 }
239 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.
252 # 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.
255 proc llvm_supports_target
{ tgtName
} {
256 global TARGETS_TO_BUILD
257 foreach target
[split $TARGETS_TO_BUILD
] {
258 if { [regexp $tgtName $target match
] } {