Reid Spencer | 90016c7 | 2007-04-14 19:37:22 +0000 | [diff] [blame] | 1 | proc execOneLine { test PRS outcome lineno line } { |
Reid Spencer | 316abe4 | 2007-04-14 09:39:28 +0000 | [diff] [blame] | 2 | 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 Spencer | 520b487 | 2007-04-14 16:41:39 +0000 | [diff] [blame] | 7 | set lineno [expr $lineno + 1] |
Reid Spencer | 90016c7 | 2007-04-14 19:37:22 +0000 | [diff] [blame] | 8 | if { $PRS != ""} { |
| 9 | set PRS " for $PRS" |
| 10 | } |
| 11 | set errmsg " at line $lineno$PRS\nwhile running: $line\n$errmsg" |
Reid Spencer | 316abe4 | 2007-04-14 09:39:28 +0000 | [diff] [blame] | 12 | switch "$code" { |
| 13 | CHILDSTATUS { |
| 14 | set status [lindex $::errorCode 2] |
| 15 | if { $status ne 0 } { |
Reid Spencer | 520b487 | 2007-04-14 16:41:39 +0000 | [diff] [blame] | 16 | set resultmsg "$test: exit($status)$errmsg" |
Reid Spencer | 316abe4 | 2007-04-14 09:39:28 +0000 | [diff] [blame] | 17 | } |
| 18 | } |
| 19 | CHILDKILLED { |
| 20 | set signal [lindex $::errorCode 2] |
Reid Spencer | 520b487 | 2007-04-14 16:41:39 +0000 | [diff] [blame] | 21 | set resultmsg "$test: signal($signal)$errmsg" |
Reid Spencer | 316abe4 | 2007-04-14 09:39:28 +0000 | [diff] [blame] | 22 | } |
| 23 | CHILDSUSP { |
| 24 | set signal [lindex $::errorCode 2] |
Reid Spencer | 520b487 | 2007-04-14 16:41:39 +0000 | [diff] [blame] | 25 | set resultmsg "$test: suspend($signal)$errmsg" |
Reid Spencer | 316abe4 | 2007-04-14 09:39:28 +0000 | [diff] [blame] | 26 | } |
| 27 | POSIX { |
| 28 | set posixNum [lindex $::errorCode 1] |
| 29 | set posixMsg [lindex $::errorCode 2] |
Reid Spencer | 520b487 | 2007-04-14 16:41:39 +0000 | [diff] [blame] | 30 | set resultmsg "$test: posix($posixNum,$posixMsg)$errmsg" |
Reid Spencer | 316abe4 | 2007-04-14 09:39:28 +0000 | [diff] [blame] | 31 | } |
| 32 | NONE { |
| 33 | } |
| 34 | default { |
| 35 | } |
| 36 | } |
| 37 | } |
| 38 | return $resultmsg |
| 39 | } |
| 40 | |
| 41 | proc substitute { line test tmpFile } { |
| 42 | global srcroot objroot srcdir objdir subdir target_triplet prcontext |
Reid Spencer | 78fb2ac | 2007-04-14 22:51:29 +0000 | [diff] [blame] | 43 | global llvmgcc llvmgxx llvmgcc_version llvmgccmajvers |
Reid Spencer | 316abe4 | 2007-04-14 09:39:28 +0000 | [diff] [blame] | 44 | global gccpath gxxpath compile_c compile_cxx link shlibext llvmlibsdir |
Reid Spencer | 78fb2ac | 2007-04-14 22:51:29 +0000 | [diff] [blame] | 45 | set path [file join $srcdir $subdir] |
| 46 | set tmp [file join Output $tmpFile] |
Reid Spencer | 316abe4 | 2007-04-14 09:39:28 +0000 | [diff] [blame] | 47 | |
| 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 |
Reid Spencer | 12ca929c | 2007-04-15 04:57:03 +0000 | [diff] [blame^] | 71 | #replace %% with % |
| 72 | regsub -all {%%} $new_line % new_line |
Reid Spencer | 316abe4 | 2007-04-14 09:39:28 +0000 | [diff] [blame] | 73 | return $new_line |
| 74 | } |
| 75 | |
Reid Spencer | 78fb2ac | 2007-04-14 22:51:29 +0000 | [diff] [blame] | 76 | proc RunLLVMTests { test_source_files } { |
Reid Spencer | 316abe4 | 2007-04-14 09:39:28 +0000 | [diff] [blame] | 77 | global srcroot objroot srcdir objdir subdir target_triplet |
| 78 | set timeout 60 |
| 79 | |
| 80 | set path [file join $objdir $subdir] |
| 81 | |
| 82 | #Make Output Directory if it does not exist already |
| 83 | if { [file exists path] } { |
| 84 | cd $path |
| 85 | } else { |
| 86 | file mkdir $path |
| 87 | cd $path |
| 88 | } |
| 89 | |
| 90 | file mkdir Output |
| 91 | |
Reid Spencer | 78fb2ac | 2007-04-14 22:51:29 +0000 | [diff] [blame] | 92 | foreach test $test_source_files { |
Reid Spencer | 316abe4 | 2007-04-14 09:39:28 +0000 | [diff] [blame] | 93 | #Should figure out best way to set the timeout |
| 94 | #set timeout 40 |
| 95 | |
| 96 | set filename [file tail $test] |
| 97 | set outcome PASS |
| 98 | set tmpFile "$filename.tmp" |
| 99 | |
| 100 | #set hasRunline bool to check if testcase has a runline |
| 101 | set numLines 0 |
| 102 | |
| 103 | # Open the test file and start reading lines |
| 104 | set testFileId [ open $test r] |
| 105 | set runline "" |
Reid Spencer | 90016c7 | 2007-04-14 19:37:22 +0000 | [diff] [blame] | 106 | set PRNUMS "" |
Reid Spencer | 316abe4 | 2007-04-14 09:39:28 +0000 | [diff] [blame] | 107 | foreach line [split [read $testFileId] \n] { |
| 108 | |
Reid Spencer | 90016c7 | 2007-04-14 19:37:22 +0000 | [diff] [blame] | 109 | # if its the END. line then stop parsing (optimization for big files) |
Reid Spencer | 316abe4 | 2007-04-14 09:39:28 +0000 | [diff] [blame] | 110 | if {[regexp {END.[ *]$} $line match endofscript]} { |
| 111 | break |
Reid Spencer | 90016c7 | 2007-04-14 19:37:22 +0000 | [diff] [blame] | 112 | |
| 113 | # if the line is continued, concatente and continue the loop |
Reid Spencer | 9a03bda | 2007-04-14 18:51:19 +0000 | [diff] [blame] | 114 | } elseif {[regexp {RUN: *([^\\]+)(\\)$} $line match oneline suffix]} { |
Reid Spencer | 316abe4 | 2007-04-14 09:39:28 +0000 | [diff] [blame] | 115 | set runline "$runline$oneline " |
Reid Spencer | 90016c7 | 2007-04-14 19:37:22 +0000 | [diff] [blame] | 116 | |
| 117 | # if its a terminating RUN: line then do substitution on the whole line |
| 118 | # and then save the line. |
Reid Spencer | 316abe4 | 2007-04-14 09:39:28 +0000 | [diff] [blame] | 119 | } elseif {[regexp {RUN: *([^&]+)(&&)?} $line match oneline suffix]} { |
| 120 | set runline "$runline$oneline" |
| 121 | set runline [ substitute $runline $test $tmpFile ] |
| 122 | set lines($numLines) $runline |
| 123 | set numLines [expr $numLines + 1] |
| 124 | set runline "" |
Reid Spencer | 90016c7 | 2007-04-14 19:37:22 +0000 | [diff] [blame] | 125 | |
| 126 | # if its an PR line, save the problem report number |
| 127 | } elseif {[regexp {PR([0-9]+)} $line match prnum]} { |
| 128 | if {$PRNUMS == ""} { |
| 129 | set PRNUMS $prnum |
| 130 | } else { |
| 131 | set PRNUMS "$PRNUMS,$prnum" |
| 132 | } |
| 133 | # if its an XFAIL line, see if we should be XFAILing or not. |
Reid Spencer | 316abe4 | 2007-04-14 09:39:28 +0000 | [diff] [blame] | 134 | } elseif {[regexp {XFAIL:[ *](.+)} $line match targets]} { |
| 135 | set targets |
| 136 | |
| 137 | #split up target if more then 1 specified |
| 138 | foreach target [split $targets ,] { |
| 139 | if { [regexp {\*} $target match] } { |
| 140 | set outcome XFAIL |
| 141 | } elseif { [regexp $target $target_triplet match] } { |
| 142 | set outcome XFAIL |
| 143 | } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2] } { |
| 144 | if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } { |
| 145 | set outcome XFAIL |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | # Done reading the script |
| 153 | close $testFileId |
| 154 | |
| 155 | |
| 156 | if { $numLines == 0 } { |
| 157 | fail "$test: \nDoes not have a RUN line\n" |
| 158 | } else { |
| 159 | set failed 0 |
| 160 | for { set i 0 } { $i < $numLines } { set i [ expr $i + 1 ] } { |
| 161 | regsub ^.*RUN:(.*) $lines($i) \1 theLine |
| 162 | set theLine [subst $theLine ] |
Reid Spencer | 90016c7 | 2007-04-14 19:37:22 +0000 | [diff] [blame] | 163 | set resultmsg [execOneLine $test $PRNUMS $outcome $i $theLine ] |
Reid Spencer | 316abe4 | 2007-04-14 09:39:28 +0000 | [diff] [blame] | 164 | if { $resultmsg != "" } { |
| 165 | if { $outcome == "XFAIL" } { |
| 166 | xfail "$resultmsg" |
| 167 | } else { |
| 168 | fail "$resultmsg" |
| 169 | } |
| 170 | set failed 1 |
| 171 | break |
| 172 | } |
| 173 | } |
| 174 | if { !$failed } { |
Reid Spencer | 90016c7 | 2007-04-14 19:37:22 +0000 | [diff] [blame] | 175 | if {$PRNUMS != ""} { |
| 176 | set PRNUMS " for $PRNUMS" |
| 177 | } |
Reid Spencer | 316abe4 | 2007-04-14 09:39:28 +0000 | [diff] [blame] | 178 | if { $outcome == "XFAIL" } { |
Reid Spencer | 90016c7 | 2007-04-14 19:37:22 +0000 | [diff] [blame] | 179 | xpass "$test$PRNUMS" |
Reid Spencer | 316abe4 | 2007-04-14 09:39:28 +0000 | [diff] [blame] | 180 | } else { |
Reid Spencer | 90016c7 | 2007-04-14 19:37:22 +0000 | [diff] [blame] | 181 | pass "$test$PRNUMS" |
Reid Spencer | 316abe4 | 2007-04-14 09:39:28 +0000 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | } |