blob: c5d4ffe9bfe6ff59d4d322cfd41e01ffc64b02e1 [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
43 global llvmgcc llvmgxx global llvmgcc_version llvmgccmajvers
44 global gccpath gxxpath compile_c compile_cxx link shlibext llvmlibsdir
45
46 set new_line $line
47 #replace %prcontext with prcontext.tcl (Must replace before %p)
48 regsub -all {%prcontext} $new_line $prcontext new_line
49 #replace %llvmgcc with actual path to llvmgcc
50 regsub -all {%llvmgcc} $new_line "$llvmgcc -emit-llvm" new_line
51 #replace %llvmgxx with actual path to llvmg++
52 regsub -all {%llvmgxx} $new_line "$llvmgxx -emit-llvm" new_line
53 #replace %compile_c with C compilation command
54 regsub -all {%compile_c} $new_line "$compile_c" new_line
55 #replace %compile_cxx with C++ compilation command
56 regsub -all {%compile_cxx} $new_line "$compile_cxx" new_line
57 #replace %link with C++ link command
58 regsub -all {%link} $new_line "$link" new_line
59 #replace %shlibext with shared library extension
60 regsub -all {%shlibext} $new_line "$shlibext" new_line
61 #replace %llvmlibsdir with configure library directory
62 regsub -all {%llvmlibsdir} $new_line "$llvmlibsdir" new_line
63 #replace %p with path to source,
64 regsub -all {%p} $new_line [file join $srcdir $subdir] new_line
65 #replace %s with filename
66 regsub -all {%s} $new_line $test new_line
67 #replace %t with temp filenames
68 regsub -all {%t} $new_line [file join Output $tmpFile] new_line
69 return $new_line
70}
71
72proc llvm-runtest { programs } {
73 global srcroot objroot srcdir objdir subdir target_triplet
74 set timeout 60
75
76 set path [file join $objdir $subdir]
77
78 #Make Output Directory if it does not exist already
79 if { [file exists path] } {
80 cd $path
81 } else {
82 file mkdir $path
83 cd $path
84 }
85
86 file mkdir Output
87
88 foreach test $programs {
89 #Should figure out best way to set the timeout
90 #set timeout 40
91
92 set filename [file tail $test]
93 set outcome PASS
94 set tmpFile "$filename.tmp"
95
96 #set hasRunline bool to check if testcase has a runline
97 set numLines 0
98
99 # Open the test file and start reading lines
100 set testFileId [ open $test r]
101 set runline ""
Reid Spencer90016c72007-04-14 19:37:22 +0000102 set PRNUMS ""
Reid Spencer316abe42007-04-14 09:39:28 +0000103 foreach line [split [read $testFileId] \n] {
104
Reid Spencer90016c72007-04-14 19:37:22 +0000105 # if its the END. line then stop parsing (optimization for big files)
Reid Spencer316abe42007-04-14 09:39:28 +0000106 if {[regexp {END.[ *]$} $line match endofscript]} {
107 break
Reid Spencer90016c72007-04-14 19:37:22 +0000108
109 # if the line is continued, concatente and continue the loop
Reid Spencer9a03bda2007-04-14 18:51:19 +0000110 } elseif {[regexp {RUN: *([^\\]+)(\\)$} $line match oneline suffix]} {
Reid Spencer316abe42007-04-14 09:39:28 +0000111 set runline "$runline$oneline "
Reid Spencer90016c72007-04-14 19:37:22 +0000112
113 # if its a terminating RUN: line then do substitution on the whole line
114 # and then save the line.
Reid Spencer316abe42007-04-14 09:39:28 +0000115 } elseif {[regexp {RUN: *([^&]+)(&&)?} $line match oneline suffix]} {
116 set runline "$runline$oneline"
117 set runline [ substitute $runline $test $tmpFile ]
118 set lines($numLines) $runline
119 set numLines [expr $numLines + 1]
120 set runline ""
Reid Spencer90016c72007-04-14 19:37:22 +0000121
122 # if its an PR line, save the problem report number
123 } elseif {[regexp {PR([0-9]+)} $line match prnum]} {
124 if {$PRNUMS == ""} {
125 set PRNUMS $prnum
126 } else {
127 set PRNUMS "$PRNUMS,$prnum"
128 }
129 # if its an XFAIL line, see if we should be XFAILing or not.
Reid Spencer316abe42007-04-14 09:39:28 +0000130 } elseif {[regexp {XFAIL:[ *](.+)} $line match targets]} {
131 set targets
132
133 #split up target if more then 1 specified
134 foreach target [split $targets ,] {
135 if { [regexp {\*} $target match] } {
136 set outcome XFAIL
137 } elseif { [regexp $target $target_triplet match] } {
138 set outcome XFAIL
139 } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2] } {
140 if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
141 set outcome XFAIL
142 }
143 }
144 }
145 }
146 }
147
148 # Done reading the script
149 close $testFileId
150
151
152 if { $numLines == 0 } {
153 fail "$test: \nDoes not have a RUN line\n"
154 } else {
155 set failed 0
156 for { set i 0 } { $i < $numLines } { set i [ expr $i + 1 ] } {
157 regsub ^.*RUN:(.*) $lines($i) \1 theLine
158 set theLine [subst $theLine ]
Reid Spencer90016c72007-04-14 19:37:22 +0000159 set resultmsg [execOneLine $test $PRNUMS $outcome $i $theLine ]
Reid Spencer316abe42007-04-14 09:39:28 +0000160 if { $resultmsg != "" } {
161 if { $outcome == "XFAIL" } {
162 xfail "$resultmsg"
163 } else {
164 fail "$resultmsg"
165 }
166 set failed 1
167 break
168 }
169 }
170 if { !$failed } {
Reid Spencer90016c72007-04-14 19:37:22 +0000171 if {$PRNUMS != ""} {
172 set PRNUMS " for $PRNUMS"
173 }
Reid Spencer316abe42007-04-14 09:39:28 +0000174 if { $outcome == "XFAIL" } {
Reid Spencer90016c72007-04-14 19:37:22 +0000175 xpass "$test$PRNUMS"
Reid Spencer316abe42007-04-14 09:39:28 +0000176 } else {
Reid Spencer90016c72007-04-14 19:37:22 +0000177 pass "$test$PRNUMS"
Reid Spencer316abe42007-04-14 09:39:28 +0000178 }
179 }
180 }
181 }
182}