Tanya Lattner | f9e7943 | 2004-11-19 22:46:23 +0000 | [diff] [blame] | 1 | proc llvm-runtest { programs objdir srcdir subdir target_triplet llvmgcc llvmgxx prcontext} { |
Tanya Lattner | 3bdb2f5 | 2004-11-06 21:07:41 +0000 | [diff] [blame] | 2 | |
Tanya Lattner | b761433 | 2004-11-30 06:29:45 +0000 | [diff] [blame] | 3 | set timeout 60 |
| 4 | |
Tanya Lattner | e243e2f | 2004-11-07 22:04:21 +0000 | [diff] [blame] | 5 | set path [file join $objdir $subdir] |
Tanya Lattner | 3bdb2f5 | 2004-11-06 21:07:41 +0000 | [diff] [blame] | 6 | |
| 7 | #Make Output Directory if it does not exist already |
Tanya Lattner | 808fafa | 2004-11-07 23:21:50 +0000 | [diff] [blame] | 8 | if { [file exists path] } { |
| 9 | cd $path |
| 10 | } else { |
| 11 | file mkdir $path |
| 12 | cd $path |
| 13 | } |
Tanya Lattner | 3bdb2f5 | 2004-11-06 21:07:41 +0000 | [diff] [blame] | 14 | |
| 15 | file mkdir Output |
| 16 | |
| 17 | foreach test $programs { |
| 18 | |
Tanya Lattner | f9e7943 | 2004-11-19 22:46:23 +0000 | [diff] [blame] | 19 | #Should figure out best way to set the timeout |
| 20 | #set timeout 40 |
| 21 | |
Tanya Lattner | 3bdb2f5 | 2004-11-06 21:07:41 +0000 | [diff] [blame] | 22 | set filename [file tail $test] |
| 23 | set output [file join Output $filename.out] |
| 24 | set script $output.script |
| 25 | set outcome PASS |
| 26 | set tmpFile testscript. |
| 27 | append tmpFile $filename .tmp |
| 28 | |
| 29 | #set hasRunline bool to check if testcase has a runline |
| 30 | set hasRunline 0 |
| 31 | |
| 32 | #check if script files exists, and delete if it does |
| 33 | if { [file exists $script] } { |
| 34 | file delete $script |
| 35 | } |
| 36 | |
| 37 | #create script file and write run line out to it |
| 38 | set scriptFileId [open $script w 0700] |
| 39 | set testFileId [ open $test r] |
| 40 | foreach line [split [read $testFileId] \n] { |
| 41 | |
| 42 | #see if this is our run line |
| 43 | if {[regexp {RUN:(.+)} $line match runline]} { |
| 44 | set runline |
| 45 | set hasRunline 1 |
| 46 | |
| 47 | #replace %s with filename |
Tanya Lattner | e243e2f | 2004-11-07 22:04:21 +0000 | [diff] [blame] | 48 | regsub -all {%s} $runline $test new_runline |
Tanya Lattner | 70053a5 | 2004-11-07 05:02:56 +0000 | [diff] [blame] | 49 | |
| 50 | #replace %t with temp filenames |
Tanya Lattner | 3bdb2f5 | 2004-11-06 21:07:41 +0000 | [diff] [blame] | 51 | regsub -all {%t} $new_runline [file join Output $tmpFile] new_runline |
Tanya Lattner | 70053a5 | 2004-11-07 05:02:56 +0000 | [diff] [blame] | 52 | |
Tanya Lattner | f9e7943 | 2004-11-19 22:46:23 +0000 | [diff] [blame] | 53 | #replace %prcontext with prcontext.tcl (Must replace before %p) |
| 54 | regsub -all {%prcontext} $new_runline $prcontext new_runline |
| 55 | |
| 56 | #replace %p with path to source, |
Tanya Lattner | 9397204 | 2004-11-19 23:00:19 +0000 | [diff] [blame] | 57 | regsub -all {%p} $new_runline [file join $srcdir $subdir] new_runline |
Tanya Lattner | f9e7943 | 2004-11-19 22:46:23 +0000 | [diff] [blame] | 58 | |
Tanya Lattner | 70053a5 | 2004-11-07 05:02:56 +0000 | [diff] [blame] | 59 | #replace %llvmgcc with actual path to llvmgcc |
Chris Lattner | 3726ff0 | 2006-03-08 22:32:20 +0000 | [diff] [blame] | 60 | regsub -all {%llvmgcc} $new_runline "$llvmgcc -emit-llvm" new_runline |
Tanya Lattner | 70053a5 | 2004-11-07 05:02:56 +0000 | [diff] [blame] | 61 | |
| 62 | #replace %llvmgxx with actual path to llvmg++ |
Chris Lattner | 3726ff0 | 2006-03-08 22:32:20 +0000 | [diff] [blame] | 63 | regsub -all {%llvmgxx} $new_runline "$llvmgxx -emit-llvm" new_runline |
Tanya Lattner | 70053a5 | 2004-11-07 05:02:56 +0000 | [diff] [blame] | 64 | |
Tanya Lattner | 3bdb2f5 | 2004-11-06 21:07:41 +0000 | [diff] [blame] | 65 | puts $scriptFileId $new_runline |
| 66 | } elseif {[regexp {XFAIL:[ *](.+)} $line match targets]} { |
| 67 | set targets |
| 68 | |
| 69 | |
| 70 | #split up target if more then 1 specified |
| 71 | foreach target [split $targets ,] { |
| 72 | if { [regexp {\*} $target match] } { |
| 73 | set outcome XFAIL |
| 74 | } elseif { [regexp $target $target_triplet match] } { |
| 75 | set outcome XFAIL |
| 76 | } |
| 77 | |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | } |
| 82 | |
| 83 | close $testFileId |
| 84 | close $scriptFileId |
| 85 | |
| 86 | |
| 87 | if { $hasRunline == 0 } { |
| 88 | fail "$test: \nDoes not have a RUN line\n" |
| 89 | } else { |
| 90 | |
| 91 | #run script and catch errors |
| 92 | set retval [ catch {exec /bin/sh $script >& $output} ] |
| 93 | |
| 94 | if { $retval == 1 } { |
| 95 | #Get output |
| 96 | set outputFile [open $output {RDONLY}] |
| 97 | set result [read $outputFile] |
| 98 | close $outputFile |
| 99 | file delete $outputFile |
| 100 | |
| 101 | switch $outcome { |
| 102 | PASS { |
| 103 | file delete $output |
| 104 | fail "$test: \n$result" |
| 105 | } |
| 106 | XFAIL { |
| 107 | xfail "$test: \n$result" |
| 108 | } |
| 109 | default { |
| 110 | file delete $output |
| 111 | fail "$test: $result" |
| 112 | } |
| 113 | } |
| 114 | } else { |
| 115 | switch $outcome { |
| 116 | XFAIL { |
| 117 | xpass "$test" |
| 118 | } |
| 119 | default { |
| 120 | pass "$test"} |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | } |
Tanya Lattner | e243e2f | 2004-11-07 22:04:21 +0000 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | |