blob: ab7c994948a42c580153009681df8f5d66eb95bd [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 }
11 set errmsg " at line $lineno$PRS\nwhile running: $line\n$errmsg"
Reid Spencer316abe42007-04-14 09:39:28 +000012 switch "$code" {
13 CHILDSTATUS {
14 set status [lindex $::errorCode 2]
15 if { $status ne 0 } {
Reid Spencer520b4872007-04-14 16:41:39 +000016 set resultmsg "$test: exit($status)$errmsg"
Reid Spencer316abe42007-04-14 09:39:28 +000017 }
18 }
19 CHILDKILLED {
20 set signal [lindex $::errorCode 2]
Reid Spencer520b4872007-04-14 16:41:39 +000021 set resultmsg "$test: signal($signal)$errmsg"
Reid Spencer316abe42007-04-14 09:39:28 +000022 }
23 CHILDSUSP {
24 set signal [lindex $::errorCode 2]
Reid Spencer520b4872007-04-14 16:41:39 +000025 set resultmsg "$test: 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 Spencer520b4872007-04-14 16:41:39 +000030 set resultmsg "$test: 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
48 set new_line $line
49 #replace %prcontext with prcontext.tcl (Must replace before %p)
50 regsub -all {%prcontext} $new_line $prcontext new_line
51 #replace %llvmgcc with actual path to llvmgcc
52 regsub -all {%llvmgcc} $new_line "$llvmgcc -emit-llvm" new_line
53 #replace %llvmgxx with actual path to llvmg++
54 regsub -all {%llvmgxx} $new_line "$llvmgxx -emit-llvm" new_line
55 #replace %compile_c with C compilation command
56 regsub -all {%compile_c} $new_line "$compile_c" new_line
57 #replace %compile_cxx with C++ compilation command
58 regsub -all {%compile_cxx} $new_line "$compile_cxx" new_line
59 #replace %link with C++ link command
60 regsub -all {%link} $new_line "$link" new_line
61 #replace %shlibext with shared library extension
62 regsub -all {%shlibext} $new_line "$shlibext" new_line
63 #replace %llvmlibsdir with configure library directory
64 regsub -all {%llvmlibsdir} $new_line "$llvmlibsdir" new_line
65 #replace %p with path to source,
66 regsub -all {%p} $new_line [file join $srcdir $subdir] new_line
67 #replace %s with filename
68 regsub -all {%s} $new_line $test new_line
69 #replace %t with temp filenames
70 regsub -all {%t} $new_line [file join Output $tmpFile] new_line
71 return $new_line
72}
73
Reid Spencer78fb2ac2007-04-14 22:51:29 +000074proc RunLLVMTests { test_source_files } {
Reid Spencer316abe42007-04-14 09:39:28 +000075 global srcroot objroot srcdir objdir subdir target_triplet
76 set timeout 60
77
78 set path [file join $objdir $subdir]
79
80 #Make Output Directory if it does not exist already
81 if { [file exists path] } {
82 cd $path
83 } else {
84 file mkdir $path
85 cd $path
86 }
87
88 file mkdir Output
89
Reid Spencer78fb2ac2007-04-14 22:51:29 +000090 foreach test $test_source_files {
Reid Spencer316abe42007-04-14 09:39:28 +000091 #Should figure out best way to set the timeout
92 #set timeout 40
93
94 set filename [file tail $test]
95 set outcome PASS
96 set tmpFile "$filename.tmp"
97
98 #set hasRunline bool to check if testcase has a runline
99 set numLines 0
100
101 # Open the test file and start reading lines
102 set testFileId [ open $test r]
103 set runline ""
Reid Spencer90016c72007-04-14 19:37:22 +0000104 set PRNUMS ""
Reid Spencer316abe42007-04-14 09:39:28 +0000105 foreach line [split [read $testFileId] \n] {
106
Reid Spencer90016c72007-04-14 19:37:22 +0000107 # if its the END. line then stop parsing (optimization for big files)
Reid Spencer316abe42007-04-14 09:39:28 +0000108 if {[regexp {END.[ *]$} $line match endofscript]} {
109 break
Reid Spencer90016c72007-04-14 19:37:22 +0000110
111 # if the line is continued, concatente and continue the loop
Reid Spencer9a03bda2007-04-14 18:51:19 +0000112 } elseif {[regexp {RUN: *([^\\]+)(\\)$} $line match oneline suffix]} {
Reid Spencer316abe42007-04-14 09:39:28 +0000113 set runline "$runline$oneline "
Reid Spencer90016c72007-04-14 19:37:22 +0000114
115 # if its a terminating RUN: line then do substitution on the whole line
116 # and then save the line.
Reid Spencer316abe42007-04-14 09:39:28 +0000117 } elseif {[regexp {RUN: *([^&]+)(&&)?} $line match oneline suffix]} {
118 set runline "$runline$oneline"
119 set runline [ substitute $runline $test $tmpFile ]
120 set lines($numLines) $runline
121 set numLines [expr $numLines + 1]
122 set runline ""
Reid Spencer90016c72007-04-14 19:37:22 +0000123
124 # if its an PR line, save the problem report number
125 } elseif {[regexp {PR([0-9]+)} $line match prnum]} {
126 if {$PRNUMS == ""} {
127 set PRNUMS $prnum
128 } else {
129 set PRNUMS "$PRNUMS,$prnum"
130 }
131 # if its an XFAIL line, see if we should be XFAILing or not.
Reid Spencer316abe42007-04-14 09:39:28 +0000132 } elseif {[regexp {XFAIL:[ *](.+)} $line match targets]} {
133 set targets
134
135 #split up target if more then 1 specified
136 foreach target [split $targets ,] {
137 if { [regexp {\*} $target match] } {
138 set outcome XFAIL
139 } elseif { [regexp $target $target_triplet match] } {
140 set outcome XFAIL
141 } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2] } {
142 if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
143 set outcome XFAIL
144 }
145 }
146 }
147 }
148 }
149
150 # Done reading the script
151 close $testFileId
152
153
154 if { $numLines == 0 } {
155 fail "$test: \nDoes not have a RUN line\n"
156 } else {
157 set failed 0
158 for { set i 0 } { $i < $numLines } { set i [ expr $i + 1 ] } {
159 regsub ^.*RUN:(.*) $lines($i) \1 theLine
160 set theLine [subst $theLine ]
Reid Spencer90016c72007-04-14 19:37:22 +0000161 set resultmsg [execOneLine $test $PRNUMS $outcome $i $theLine ]
Reid Spencer316abe42007-04-14 09:39:28 +0000162 if { $resultmsg != "" } {
163 if { $outcome == "XFAIL" } {
164 xfail "$resultmsg"
165 } else {
166 fail "$resultmsg"
167 }
168 set failed 1
169 break
170 }
171 }
172 if { !$failed } {
Reid Spencer90016c72007-04-14 19:37:22 +0000173 if {$PRNUMS != ""} {
174 set PRNUMS " for $PRNUMS"
175 }
Reid Spencer316abe42007-04-14 09:39:28 +0000176 if { $outcome == "XFAIL" } {
Reid Spencer90016c72007-04-14 19:37:22 +0000177 xpass "$test$PRNUMS"
Reid Spencer316abe42007-04-14 09:39:28 +0000178 } else {
Reid Spencer90016c72007-04-14 19:37:22 +0000179 pass "$test$PRNUMS"
Reid Spencer316abe42007-04-14 09:39:28 +0000180 }
181 }
182 }
183 }
184}