blob: 13df64ba408fef762309267645fcea8c63caa539 [file] [log] [blame]
Tanya Lattnerf9e79432004-11-19 22:46:23 +00001proc llvm-runtest { programs objdir srcdir subdir target_triplet llvmgcc llvmgxx prcontext} {
Tanya Lattner3bdb2f52004-11-06 21:07:41 +00002
Tanya Lattnerb7614332004-11-30 06:29:45 +00003 set timeout 60
4
Tanya Lattnere243e2f2004-11-07 22:04:21 +00005 set path [file join $objdir $subdir]
Tanya Lattner3bdb2f52004-11-06 21:07:41 +00006
7 #Make Output Directory if it does not exist already
Tanya Lattner808fafa2004-11-07 23:21:50 +00008 if { [file exists path] } {
9 cd $path
10 } else {
11 file mkdir $path
12 cd $path
13 }
Tanya Lattner3bdb2f52004-11-06 21:07:41 +000014
15 file mkdir Output
16
17 foreach test $programs {
18
Tanya Lattnerf9e79432004-11-19 22:46:23 +000019 #Should figure out best way to set the timeout
20 #set timeout 40
21
Tanya Lattner3bdb2f52004-11-06 21:07:41 +000022 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 Lattnere243e2f2004-11-07 22:04:21 +000048 regsub -all {%s} $runline $test new_runline
Tanya Lattner70053a52004-11-07 05:02:56 +000049
50 #replace %t with temp filenames
Tanya Lattner3bdb2f52004-11-06 21:07:41 +000051 regsub -all {%t} $new_runline [file join Output $tmpFile] new_runline
Tanya Lattner70053a52004-11-07 05:02:56 +000052
Tanya Lattnerf9e79432004-11-19 22:46:23 +000053 #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 Lattner93972042004-11-19 23:00:19 +000057 regsub -all {%p} $new_runline [file join $srcdir $subdir] new_runline
Tanya Lattnerf9e79432004-11-19 22:46:23 +000058
Tanya Lattner70053a52004-11-07 05:02:56 +000059 #replace %llvmgcc with actual path to llvmgcc
Chris Lattner3726ff02006-03-08 22:32:20 +000060 regsub -all {%llvmgcc} $new_runline "$llvmgcc -emit-llvm" new_runline
Tanya Lattner70053a52004-11-07 05:02:56 +000061
62 #replace %llvmgxx with actual path to llvmg++
Chris Lattner3726ff02006-03-08 22:32:20 +000063 regsub -all {%llvmgxx} $new_runline "$llvmgxx -emit-llvm" new_runline
Tanya Lattner70053a52004-11-07 05:02:56 +000064
Tanya Lattner3bdb2f52004-11-06 21:07:41 +000065 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 Lattnere243e2f2004-11-07 22:04:21 +0000125}
126
127