blob: 8363af7807badc0a54e1f6f1647ca9db0ffe6ef0 [file] [log] [blame]
Tanya Lattnere243e2f2004-11-07 22:04:21 +00001proc llvm-runtest { programs objdir 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
17 set timeout 40
18 set filename [file tail $test]
19 set output [file join Output $filename.out]
20 set script $output.script
21 set outcome PASS
22 set tmpFile testscript.
23 append tmpFile $filename .tmp
24
25 #set hasRunline bool to check if testcase has a runline
26 set hasRunline 0
27
28 #check if script files exists, and delete if it does
29 if { [file exists $script] } {
30 file delete $script
31 }
32
33 #create script file and write run line out to it
34 set scriptFileId [open $script w 0700]
35 set testFileId [ open $test r]
36 foreach line [split [read $testFileId] \n] {
37
38 #see if this is our run line
39 if {[regexp {RUN:(.+)} $line match runline]} {
40 set runline
41 set hasRunline 1
42
43 #replace %s with filename
Tanya Lattnere243e2f2004-11-07 22:04:21 +000044 regsub -all {%s} $runline $test new_runline
Tanya Lattner70053a52004-11-07 05:02:56 +000045
46 #replace %t with temp filenames
Tanya Lattner3bdb2f52004-11-06 21:07:41 +000047 regsub -all {%t} $new_runline [file join Output $tmpFile] new_runline
Tanya Lattner70053a52004-11-07 05:02:56 +000048
49 #replace %llvmgcc with actual path to llvmgcc
50 regsub -all {%llvmgcc} $new_runline $llvmgcc new_runline
51
52 #replace %llvmgxx with actual path to llvmg++
53 regsub -all {%llvmgxx} $new_runline $llvmgxx new_runline
54
Tanya Lattnerde942dc2004-11-13 22:55:51 +000055 #replace %prcontext with prcontext.tcl (Goes away when we remove qmtest)
Tanya Lattnerd85f0af2004-11-13 23:36:18 +000056 regsub -all {%prcontext} $new_runline $prcontext new_runline
Tanya Lattner70053a52004-11-07 05:02:56 +000057
Tanya Lattner3bdb2f52004-11-06 21:07:41 +000058 puts $scriptFileId $new_runline
59 } elseif {[regexp {XFAIL:[ *](.+)} $line match targets]} {
60 set targets
61
62
63 #split up target if more then 1 specified
64 foreach target [split $targets ,] {
65 if { [regexp {\*} $target match] } {
66 set outcome XFAIL
67 } elseif { [regexp $target $target_triplet match] } {
68 set outcome XFAIL
69 }
70
71 }
72 }
73
74 }
75
76 close $testFileId
77 close $scriptFileId
78
79
80 if { $hasRunline == 0 } {
81 fail "$test: \nDoes not have a RUN line\n"
82 } else {
83
84 #run script and catch errors
85 set retval [ catch {exec /bin/sh $script >& $output} ]
86
87 if { $retval == 1 } {
88 #Get output
89 set outputFile [open $output {RDONLY}]
90 set result [read $outputFile]
91 close $outputFile
92 file delete $outputFile
93
94 switch $outcome {
95 PASS {
96 file delete $output
97 fail "$test: \n$result"
98 }
99 XFAIL {
100 xfail "$test: \n$result"
101 }
102 default {
103 file delete $output
104 fail "$test: $result"
105 }
106 }
107 } else {
108 switch $outcome {
109 XFAIL {
110 xpass "$test"
111 }
112 default {
113 pass "$test"}
114 }
115 }
116 }
117 }
Tanya Lattnere243e2f2004-11-07 22:04:21 +0000118}
119
120