blob: 55813c9b33ff14663ef5c96f3210ee92eb004461 [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 Lattnere243e2f2004-11-07 22:04:21 +00003 set path [file join $objdir $subdir]
Tanya Lattner3bdb2f52004-11-06 21:07:41 +00004
5 #Make Output Directory if it does not exist already
Tanya Lattner808fafa2004-11-07 23:21:50 +00006 if { [file exists path] } {
7 cd $path
8 } else {
9 file mkdir $path
10 cd $path
11 }
Tanya Lattner3bdb2f52004-11-06 21:07:41 +000012
13 file mkdir Output
14
15 foreach test $programs {
16
Tanya Lattnerf9e79432004-11-19 22:46:23 +000017 #Should figure out best way to set the timeout
18 #set timeout 40
19
Tanya Lattner3bdb2f52004-11-06 21:07:41 +000020 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 Lattnere243e2f2004-11-07 22:04:21 +000046 regsub -all {%s} $runline $test new_runline
Tanya Lattner70053a52004-11-07 05:02:56 +000047
48 #replace %t with temp filenames
Tanya Lattner3bdb2f52004-11-06 21:07:41 +000049 regsub -all {%t} $new_runline [file join Output $tmpFile] new_runline
Tanya Lattner70053a52004-11-07 05:02:56 +000050
Tanya Lattnerf9e79432004-11-19 22:46:23 +000051 #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 Lattner93972042004-11-19 23:00:19 +000055 regsub -all {%p} $new_runline [file join $srcdir $subdir] new_runline
Tanya Lattnerf9e79432004-11-19 22:46:23 +000056
Tanya Lattner70053a52004-11-07 05:02:56 +000057 #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 Lattner3bdb2f52004-11-06 21:07:41 +000063 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 Lattnere243e2f2004-11-07 22:04:21 +0000123}
124
125