blob: e7245064532bf6491e53b448ed46c36f6e669a24 [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
Reid Spencer12d81f32007-04-21 21:45:51 +000042# This prcoedure performs variable substitutions on the RUN: lines of a test
43# cases.
Reid Spencer316abe42007-04-14 09:39:28 +000044proc substitute { line test tmpFile } {
45 global srcroot objroot srcdir objdir subdir target_triplet prcontext
Reid Spencer78fb2ac2007-04-14 22:51:29 +000046 global llvmgcc llvmgxx llvmgcc_version llvmgccmajvers
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]
49 set tmp [file join Output $tmpFile]
Reid Spencer316abe42007-04-14 09:39:28 +000050
Reid Spencer0947df42007-04-15 07:21:26 +000051 # Substitute all Tcl variables.
52 set new_line [subst $line ]
53
Reid Spencer316abe42007-04-14 09:39:28 +000054 #replace %prcontext with prcontext.tcl (Must replace before %p)
55 regsub -all {%prcontext} $new_line $prcontext new_line
56 #replace %llvmgcc with actual path to llvmgcc
57 regsub -all {%llvmgcc} $new_line "$llvmgcc -emit-llvm" new_line
58 #replace %llvmgxx with actual path to llvmg++
59 regsub -all {%llvmgxx} $new_line "$llvmgxx -emit-llvm" new_line
60 #replace %compile_c with C compilation command
61 regsub -all {%compile_c} $new_line "$compile_c" new_line
62 #replace %compile_cxx with C++ compilation command
63 regsub -all {%compile_cxx} $new_line "$compile_cxx" new_line
64 #replace %link with C++ link command
65 regsub -all {%link} $new_line "$link" new_line
66 #replace %shlibext with shared library extension
67 regsub -all {%shlibext} $new_line "$shlibext" new_line
68 #replace %llvmlibsdir with configure library directory
69 regsub -all {%llvmlibsdir} $new_line "$llvmlibsdir" new_line
70 #replace %p with path to source,
71 regsub -all {%p} $new_line [file join $srcdir $subdir] new_line
72 #replace %s with filename
73 regsub -all {%s} $new_line $test new_line
74 #replace %t with temp filenames
75 regsub -all {%t} $new_line [file join Output $tmpFile] new_line
Reid Spencer12ca929c2007-04-15 04:57:03 +000076 #replace %% with %
77 regsub -all {%%} $new_line % new_line
Reid Spencer316abe42007-04-14 09:39:28 +000078 return $new_line
79}
80
Reid Spencer12d81f32007-04-21 21:45:51 +000081# This procedure runs the set of tests for the test_source_files array.
Reid Spencer78fb2ac2007-04-14 22:51:29 +000082proc RunLLVMTests { test_source_files } {
Reid Spencerfb7653e2007-04-15 20:43:36 +000083 global srcroot objroot srcdir objdir subdir target_triplet llvmgcc_version
Reid Spencer316abe42007-04-14 09:39:28 +000084 set timeout 60
85
86 set path [file join $objdir $subdir]
87
88 #Make Output Directory if it does not exist already
89 if { [file exists path] } {
90 cd $path
91 } else {
92 file mkdir $path
93 cd $path
94 }
95
96 file mkdir Output
97
Reid Spencer78fb2ac2007-04-14 22:51:29 +000098 foreach test $test_source_files {
Reid Spencer316abe42007-04-14 09:39:28 +000099 #Should figure out best way to set the timeout
100 #set timeout 40
101
102 set filename [file tail $test]
103 set outcome PASS
104 set tmpFile "$filename.tmp"
105
106 #set hasRunline bool to check if testcase has a runline
107 set numLines 0
108
109 # Open the test file and start reading lines
110 set testFileId [ open $test r]
111 set runline ""
Reid Spencer90016c72007-04-14 19:37:22 +0000112 set PRNUMS ""
Reid Spencerfb7653e2007-04-15 20:43:36 +0000113 foreach line [split [read $testFileId] \n] {
Reid Spencer316abe42007-04-14 09:39:28 +0000114
Reid Spencer90016c72007-04-14 19:37:22 +0000115 # if its the END. line then stop parsing (optimization for big files)
Reid Spencer316abe42007-04-14 09:39:28 +0000116 if {[regexp {END.[ *]$} $line match endofscript]} {
117 break
Reid Spencer90016c72007-04-14 19:37:22 +0000118
Duncan Sands3724df32007-04-16 21:19:45 +0000119 # if the line is continued, concatenate and continue the loop
Reid Spencer601e8452007-04-15 18:38:42 +0000120 } elseif {[regexp {RUN: *(.+)(\\)$} $line match oneline suffix]} {
Reid Spencer316abe42007-04-14 09:39:28 +0000121 set runline "$runline$oneline "
Reid Spencer90016c72007-04-14 19:37:22 +0000122
123 # if its a terminating RUN: line then do substitution on the whole line
124 # and then save the line.
Reid Spencer316abe42007-04-14 09:39:28 +0000125 } elseif {[regexp {RUN: *([^&]+)(&&)?} $line match oneline suffix]} {
126 set runline "$runline$oneline"
127 set runline [ substitute $runline $test $tmpFile ]
128 set lines($numLines) $runline
129 set numLines [expr $numLines + 1]
130 set runline ""
Reid Spencer90016c72007-04-14 19:37:22 +0000131
132 # if its an PR line, save the problem report number
133 } elseif {[regexp {PR([0-9]+)} $line match prnum]} {
134 if {$PRNUMS == ""} {
Reid Spencer66959ce2007-04-15 10:27:54 +0000135 set PRNUMS "PR$prnum"
Reid Spencer90016c72007-04-14 19:37:22 +0000136 } else {
137 set PRNUMS "$PRNUMS,$prnum"
138 }
139 # if its an XFAIL line, see if we should be XFAILing or not.
Reid Spencer316abe42007-04-14 09:39:28 +0000140 } elseif {[regexp {XFAIL:[ *](.+)} $line match targets]} {
141 set targets
142
143 #split up target if more then 1 specified
144 foreach target [split $targets ,] {
145 if { [regexp {\*} $target match] } {
146 set outcome XFAIL
147 } elseif { [regexp $target $target_triplet match] } {
148 set outcome XFAIL
149 } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2] } {
150 if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
151 set outcome XFAIL
152 }
153 }
154 }
155 }
156 }
157
158 # Done reading the script
159 close $testFileId
160
161
162 if { $numLines == 0 } {
163 fail "$test: \nDoes not have a RUN line\n"
164 } else {
165 set failed 0
166 for { set i 0 } { $i < $numLines } { set i [ expr $i + 1 ] } {
167 regsub ^.*RUN:(.*) $lines($i) \1 theLine
Reid Spencer90016c72007-04-14 19:37:22 +0000168 set resultmsg [execOneLine $test $PRNUMS $outcome $i $theLine ]
Reid Spencer316abe42007-04-14 09:39:28 +0000169 if { $resultmsg != "" } {
170 if { $outcome == "XFAIL" } {
171 xfail "$resultmsg"
172 } else {
173 fail "$resultmsg"
174 }
175 set failed 1
176 break
177 }
178 }
Reid Spencer0947df42007-04-15 07:21:26 +0000179 if { $failed } {
Reid Spencerb0feffa2007-04-15 07:34:58 +0000180 continue
Reid Spencer0947df42007-04-15 07:21:26 +0000181 } else {
182 if { $PRNUMS != "" } {
Reid Spencer90016c72007-04-14 19:37:22 +0000183 set PRNUMS " for $PRNUMS"
184 }
Reid Spencer316abe42007-04-14 09:39:28 +0000185 if { $outcome == "XFAIL" } {
Reid Spencer90016c72007-04-14 19:37:22 +0000186 xpass "$test$PRNUMS"
Reid Spencer316abe42007-04-14 09:39:28 +0000187 } else {
Reid Spencer90016c72007-04-14 19:37:22 +0000188 pass "$test$PRNUMS"
Reid Spencer316abe42007-04-14 09:39:28 +0000189 }
190 }
191 }
192 }
193}
Devang Patel9fe99072007-04-20 21:24:01 +0000194
Reid Spencer12d81f32007-04-21 21:45:51 +0000195# This procedure provides an interface to check the LLVMGCC_LANGS makefile
196# variable to see if llvm-gcc supports compilation of a particular language.
197proc llvm_gcc_supports { lang } {
198 global llvmgcc llvmgcc_langs
199 # validate the language choices and determine the name of the compiler
200 # component responsible for determining if the compiler has been built.
201 switch "$lang" {
202 ada { set file gnat1 }
203 c { set file cc1 }
204 c++ { set file cc1plus }
205 objc { set file cc1 }
206 objc++ { set file cc1 }
207 fortran { set file fcc1 }
208 default { return 0 }
209 }
Reid Spencer3dc662c2007-04-22 14:14:11 +0000210 if { [ string first "$lang" "$llvmgcc_langs" ] >= 0 } {
Reid Spencer12d81f32007-04-21 21:45:51 +0000211 # FIXME: Knowing it is configured is not enough. We should do two more
212 # checks here. First, we need to run llvm-gcc -print-prog-name=$file to get
213 # the path to the compiler. If we don't get a path, the language isn't
214 # properly configured or built. If we do get a path, we should check to make
215 # sure that it is executable and perhaps even try executing it.
216 return 1;
217 }
218 return 0;
Duncan Sands4e9471d2007-04-21 20:20:47 +0000219}
220
Reid Spencer12d81f32007-04-21 21:45:51 +0000221# This procedure provides an interface to check the TARGETS_TO_BUILD makefile
222# variable to see if a particular target has been configured to build. This
223# helps avoid running tests for targets that aren't available.
Reid Spencer40a4c612007-04-21 20:40:17 +0000224proc llvm_supports_target { tgtName } {
225 global TARGETS_TO_BUILD
226 foreach target [split $TARGETS_TO_BUILD] {
227 if { [regexp $tgtName $target match] } {
228 return 1
229 }
230 }
231 return 0
232}