blob: a90477073fcb1f4d5a95743efc7184b716e1b184 [file] [log] [blame]
Tanya Lattner3bdb2f52004-11-06 21:07:41 +00001proc llvm-runtest { programs srcdir subdir target_triplet} {
2
3 set path [file join $srcdir $subdir]
4
5 #Make Output Directory if it does not exist already
6 cd $path
7
8 file mkdir Output
9
10 foreach test $programs {
11
12 set timeout 40
13 set filename [file tail $test]
14 set output [file join Output $filename.out]
15 set script $output.script
16 set outcome PASS
17 set tmpFile testscript.
18 append tmpFile $filename .tmp
19
20 #set hasRunline bool to check if testcase has a runline
21 set hasRunline 0
22
23 #check if script files exists, and delete if it does
24 if { [file exists $script] } {
25 file delete $script
26 }
27
28 #create script file and write run line out to it
29 set scriptFileId [open $script w 0700]
30 set testFileId [ open $test r]
31 foreach line [split [read $testFileId] \n] {
32
33 #see if this is our run line
34 if {[regexp {RUN:(.+)} $line match runline]} {
35 set runline
36 set hasRunline 1
37
38 #replace %s with filename
39 regsub -all {%s} $runline $filename new_runline
40
41 regsub -all {%t} $new_runline [file join Output $tmpFile] new_runline
42
43 puts $scriptFileId $new_runline
44 } elseif {[regexp {XFAIL:[ *](.+)} $line match targets]} {
45 set targets
46
47
48 #split up target if more then 1 specified
49 foreach target [split $targets ,] {
50 if { [regexp {\*} $target match] } {
51 set outcome XFAIL
52 } elseif { [regexp $target $target_triplet match] } {
53 set outcome XFAIL
54 }
55
56 }
57 }
58
59 }
60
61 close $testFileId
62 close $scriptFileId
63
64
65 if { $hasRunline == 0 } {
66 fail "$test: \nDoes not have a RUN line\n"
67 } else {
68
69 #run script and catch errors
70 set retval [ catch {exec /bin/sh $script >& $output} ]
71
72 if { $retval == 1 } {
73 #Get output
74 set outputFile [open $output {RDONLY}]
75 set result [read $outputFile]
76 close $outputFile
77 file delete $outputFile
78
79 switch $outcome {
80 PASS {
81 file delete $output
82 fail "$test: \n$result"
83 }
84 XFAIL {
85 xfail "$test: \n$result"
86 }
87 default {
88 file delete $output
89 fail "$test: $result"
90 }
91 }
92 } else {
93 switch $outcome {
94 XFAIL {
95 xpass "$test"
96 }
97 default {
98 pass "$test"}
99 }
100 }
101 }
102 }
103}