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