blob: 97eb05822eb0fb2950f9c5ac31caf57ee298f47e [file] [log] [blame]
Reid Spencer90016c72007-04-14 19:37:22 +00001proc execOneLine { test PRS outcome lineno line } {
Reid Spencer316abe42007-04-14 09:39:28 +00002 set status 0
3 set resultmsg ""
4 set retval [ catch { eval exec -keepnewline -- $line } errmsg ]
5 if { $retval != 0 } {
6 set code [lindex $::errorCode 0]
Reid Spencer520b4872007-04-14 16:41:39 +00007 set lineno [expr $lineno + 1]
Reid Spencer90016c72007-04-14 19:37:22 +00008 if { $PRS != ""} {
9 set PRS " for $PRS"
10 }
Reid Spencer6cdf4a92007-04-21 18:53:12 +000011 set errmsg " at line $lineno\nwhile running: $line\n$errmsg"
Reid Spencer316abe42007-04-14 09:39:28 +000012 switch "$code" {
13 CHILDSTATUS {
14 set status [lindex $::errorCode 2]
Duncan Sands25d50d62007-04-16 15:37:00 +000015 if { $status != 0 } {
Reid Spencer6cdf4a92007-04-21 18:53:12 +000016 set resultmsg "$test$PRS\nFailed with exit($status)$errmsg"
Reid Spencer316abe42007-04-14 09:39:28 +000017 }
18 }
19 CHILDKILLED {
20 set signal [lindex $::errorCode 2]
Reid Spencer6cdf4a92007-04-21 18:53:12 +000021 set resultmsg "$test$PRS\nFailed with signal($signal)$errmsg"
Reid Spencer316abe42007-04-14 09:39:28 +000022 }
23 CHILDSUSP {
24 set signal [lindex $::errorCode 2]
Reid Spencer6cdf4a92007-04-21 18:53:12 +000025 set resultmsg "$test$PRS\nFailed with suspend($signal)$errmsg"
Reid Spencer316abe42007-04-14 09:39:28 +000026 }
27 POSIX {
28 set posixNum [lindex $::errorCode 1]
29 set posixMsg [lindex $::errorCode 2]
Reid Spencer6cdf4a92007-04-21 18:53:12 +000030 set resultmsg "$test$PRS\nFailed with posix($posixNum,$posixMsg)$errmsg"
Reid Spencer316abe42007-04-14 09:39:28 +000031 }
32 NONE {
33 }
34 default {
35 }
36 }
37 }
38 return $resultmsg
39}
40
41proc substitute { line test tmpFile } {
42 global srcroot objroot srcdir objdir subdir target_triplet prcontext
Reid Spencer78fb2ac2007-04-14 22:51:29 +000043 global llvmgcc llvmgxx llvmgcc_version llvmgccmajvers
Reid Spencer316abe42007-04-14 09:39:28 +000044 global gccpath gxxpath compile_c compile_cxx link shlibext llvmlibsdir
Reid Spencer78fb2ac2007-04-14 22:51:29 +000045 set path [file join $srcdir $subdir]
46 set tmp [file join Output $tmpFile]
Reid Spencer316abe42007-04-14 09:39:28 +000047
Reid Spencer0947df42007-04-15 07:21:26 +000048 # Substitute all Tcl variables.
49 set new_line [subst $line ]
50
Reid Spencer316abe42007-04-14 09:39:28 +000051 #replace %prcontext with prcontext.tcl (Must replace before %p)
52 regsub -all {%prcontext} $new_line $prcontext new_line
53 #replace %llvmgcc with actual path to llvmgcc
54 regsub -all {%llvmgcc} $new_line "$llvmgcc -emit-llvm" new_line
55 #replace %llvmgxx with actual path to llvmg++
56 regsub -all {%llvmgxx} $new_line "$llvmgxx -emit-llvm" new_line
57 #replace %compile_c with C compilation command
58 regsub -all {%compile_c} $new_line "$compile_c" new_line
59 #replace %compile_cxx with C++ compilation command
60 regsub -all {%compile_cxx} $new_line "$compile_cxx" new_line
61 #replace %link with C++ link command
62 regsub -all {%link} $new_line "$link" new_line
63 #replace %shlibext with shared library extension
64 regsub -all {%shlibext} $new_line "$shlibext" new_line
65 #replace %llvmlibsdir with configure library directory
66 regsub -all {%llvmlibsdir} $new_line "$llvmlibsdir" new_line
67 #replace %p with path to source,
68 regsub -all {%p} $new_line [file join $srcdir $subdir] new_line
69 #replace %s with filename
70 regsub -all {%s} $new_line $test new_line
71 #replace %t with temp filenames
72 regsub -all {%t} $new_line [file join Output $tmpFile] new_line
Reid Spencer12ca929c2007-04-15 04:57:03 +000073 #replace %% with %
74 regsub -all {%%} $new_line % new_line
Reid Spencer316abe42007-04-14 09:39:28 +000075 return $new_line
76}
77
Reid Spencer78fb2ac2007-04-14 22:51:29 +000078proc RunLLVMTests { test_source_files } {
Reid Spencerfb7653e2007-04-15 20:43:36 +000079 global srcroot objroot srcdir objdir subdir target_triplet llvmgcc_version
Reid Spencer316abe42007-04-14 09:39:28 +000080 set timeout 60
81
82 set path [file join $objdir $subdir]
83
84 #Make Output Directory if it does not exist already
85 if { [file exists path] } {
86 cd $path
87 } else {
88 file mkdir $path
89 cd $path
90 }
91
92 file mkdir Output
93
Reid Spencer78fb2ac2007-04-14 22:51:29 +000094 foreach test $test_source_files {
Reid Spencer316abe42007-04-14 09:39:28 +000095 #Should figure out best way to set the timeout
96 #set timeout 40
97
98 set filename [file tail $test]
99 set outcome PASS
100 set tmpFile "$filename.tmp"
101
102 #set hasRunline bool to check if testcase has a runline
103 set numLines 0
104
105 # Open the test file and start reading lines
106 set testFileId [ open $test r]
107 set runline ""
Reid Spencer90016c72007-04-14 19:37:22 +0000108 set PRNUMS ""
Reid Spencerfb7653e2007-04-15 20:43:36 +0000109 foreach line [split [read $testFileId] \n] {
Reid Spencer316abe42007-04-14 09:39:28 +0000110
Reid Spencer90016c72007-04-14 19:37:22 +0000111 # if its the END. line then stop parsing (optimization for big files)
Reid Spencer316abe42007-04-14 09:39:28 +0000112 if {[regexp {END.[ *]$} $line match endofscript]} {
113 break
Reid Spencer90016c72007-04-14 19:37:22 +0000114
Duncan Sands3724df32007-04-16 21:19:45 +0000115 # if the line is continued, concatenate and continue the loop
Reid Spencer601e8452007-04-15 18:38:42 +0000116 } elseif {[regexp {RUN: *(.+)(\\)$} $line match oneline suffix]} {
Reid Spencer316abe42007-04-14 09:39:28 +0000117 set runline "$runline$oneline "
Reid Spencer90016c72007-04-14 19:37:22 +0000118
119 # if its a terminating RUN: line then do substitution on the whole line
120 # and then save the line.
Reid Spencer316abe42007-04-14 09:39:28 +0000121 } elseif {[regexp {RUN: *([^&]+)(&&)?} $line match oneline suffix]} {
122 set runline "$runline$oneline"
123 set runline [ substitute $runline $test $tmpFile ]
124 set lines($numLines) $runline
125 set numLines [expr $numLines + 1]
126 set runline ""
Reid Spencer90016c72007-04-14 19:37:22 +0000127
128 # if its an PR line, save the problem report number
129 } elseif {[regexp {PR([0-9]+)} $line match prnum]} {
130 if {$PRNUMS == ""} {
Reid Spencer66959ce2007-04-15 10:27:54 +0000131 set PRNUMS "PR$prnum"
Reid Spencer90016c72007-04-14 19:37:22 +0000132 } else {
133 set PRNUMS "$PRNUMS,$prnum"
134 }
135 # if its an XFAIL line, see if we should be XFAILing or not.
Reid Spencer316abe42007-04-14 09:39:28 +0000136 } elseif {[regexp {XFAIL:[ *](.+)} $line match targets]} {
137 set targets
138
139 #split up target if more then 1 specified
140 foreach target [split $targets ,] {
141 if { [regexp {\*} $target match] } {
142 set outcome XFAIL
143 } elseif { [regexp $target $target_triplet match] } {
144 set outcome XFAIL
145 } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2] } {
146 if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
147 set outcome XFAIL
148 }
149 }
150 }
151 }
152 }
153
154 # Done reading the script
155 close $testFileId
156
157
158 if { $numLines == 0 } {
159 fail "$test: \nDoes not have a RUN line\n"
160 } else {
161 set failed 0
162 for { set i 0 } { $i < $numLines } { set i [ expr $i + 1 ] } {
163 regsub ^.*RUN:(.*) $lines($i) \1 theLine
Reid Spencer90016c72007-04-14 19:37:22 +0000164 set resultmsg [execOneLine $test $PRNUMS $outcome $i $theLine ]
Reid Spencer316abe42007-04-14 09:39:28 +0000165 if { $resultmsg != "" } {
166 if { $outcome == "XFAIL" } {
167 xfail "$resultmsg"
168 } else {
169 fail "$resultmsg"
170 }
171 set failed 1
172 break
173 }
174 }
Reid Spencer0947df42007-04-15 07:21:26 +0000175 if { $failed } {
Reid Spencerb0feffa2007-04-15 07:34:58 +0000176 continue
Reid Spencer0947df42007-04-15 07:21:26 +0000177 } else {
178 if { $PRNUMS != "" } {
Reid Spencer90016c72007-04-14 19:37:22 +0000179 set PRNUMS " for $PRNUMS"
180 }
Reid Spencer316abe42007-04-14 09:39:28 +0000181 if { $outcome == "XFAIL" } {
Reid Spencer90016c72007-04-14 19:37:22 +0000182 xpass "$test$PRNUMS"
Reid Spencer316abe42007-04-14 09:39:28 +0000183 } else {
Reid Spencer90016c72007-04-14 19:37:22 +0000184 pass "$test$PRNUMS"
Reid Spencer316abe42007-04-14 09:39:28 +0000185 }
186 }
187 }
188 }
189}
Devang Patel9fe99072007-04-20 21:24:01 +0000190
191proc llvm_gcc_supports_objc { } {
192 global llvmgcc
193 catch { set file_h [ open "/tmp/llvm_obj_check.m" w] }
194 set R [ catch { exec $llvmgcc -c "/tmp/llvm_obj_check.m" -o /dev/null >& /tmp/llvm_obj_check.out } ]
195 set RESULT [ file size "/tmp/llvm_obj_check.out" ]
196 catch { file delete "/tmp/llvm_obj_check.m" }
197 if { $RESULT == 0 } {
198 return 1
199 } else {
200 return 0
201 }
202}
203