blob: 07dffae29c1014c42667205bff843fc9dec62c0f [file] [log] [blame]
Tanya Lattner97275552006-04-12 21:57:40 +00001proc llvm-runtest { programs objdir srcdir subdir target_triplet llvmgcc llvmgxx prcontext llvmgcc_version} {
2
Tanya Lattner3bdb2f52004-11-06 21:07:41 +00003
Tanya Lattnerb7614332004-11-30 06:29:45 +00004 set timeout 60
5
Tanya Lattnere243e2f2004-11-07 22:04:21 +00006 set path [file join $objdir $subdir]
Tanya Lattner3bdb2f52004-11-06 21:07:41 +00007
8 #Make Output Directory if it does not exist already
Tanya Lattner808fafa2004-11-07 23:21:50 +00009 if { [file exists path] } {
10 cd $path
11 } else {
12 file mkdir $path
13 cd $path
14 }
Tanya Lattner3bdb2f52004-11-06 21:07:41 +000015
16 file mkdir Output
17
18 foreach test $programs {
19
Tanya Lattnerf9e79432004-11-19 22:46:23 +000020 #Should figure out best way to set the timeout
21 #set timeout 40
22
Tanya Lattner3bdb2f52004-11-06 21:07:41 +000023 set filename [file tail $test]
24 set output [file join Output $filename.out]
25 set script $output.script
26 set outcome PASS
27 set tmpFile testscript.
28 append tmpFile $filename .tmp
29
30 #set hasRunline bool to check if testcase has a runline
31 set hasRunline 0
32
33 #check if script files exists, and delete if it does
34 if { [file exists $script] } {
35 file delete $script
36 }
37
38 #create script file and write run line out to it
39 set scriptFileId [open $script w 0700]
40 set testFileId [ open $test r]
41 foreach line [split [read $testFileId] \n] {
42
43 #see if this is our run line
44 if {[regexp {RUN:(.+)} $line match runline]} {
45 set runline
46 set hasRunline 1
47
48 #replace %s with filename
Tanya Lattnere243e2f2004-11-07 22:04:21 +000049 regsub -all {%s} $runline $test new_runline
Tanya Lattner70053a52004-11-07 05:02:56 +000050
51 #replace %t with temp filenames
Tanya Lattner3bdb2f52004-11-06 21:07:41 +000052 regsub -all {%t} $new_runline [file join Output $tmpFile] new_runline
Tanya Lattner70053a52004-11-07 05:02:56 +000053
Tanya Lattnerf9e79432004-11-19 22:46:23 +000054 #replace %prcontext with prcontext.tcl (Must replace before %p)
55 regsub -all {%prcontext} $new_runline $prcontext new_runline
56
57 #replace %p with path to source,
Tanya Lattner93972042004-11-19 23:00:19 +000058 regsub -all {%p} $new_runline [file join $srcdir $subdir] new_runline
Tanya Lattnerf9e79432004-11-19 22:46:23 +000059
Tanya Lattner70053a52004-11-07 05:02:56 +000060 #replace %llvmgcc with actual path to llvmgcc
Chris Lattner3726ff02006-03-08 22:32:20 +000061 regsub -all {%llvmgcc} $new_runline "$llvmgcc -emit-llvm" new_runline
Tanya Lattner70053a52004-11-07 05:02:56 +000062
63 #replace %llvmgxx with actual path to llvmg++
Chris Lattner3726ff02006-03-08 22:32:20 +000064 regsub -all {%llvmgxx} $new_runline "$llvmgxx -emit-llvm" new_runline
Tanya Lattner70053a52004-11-07 05:02:56 +000065
Tanya Lattner3bdb2f52004-11-06 21:07:41 +000066 puts $scriptFileId $new_runline
67 } elseif {[regexp {XFAIL:[ *](.+)} $line match targets]} {
68 set targets
Tanya Lattner3bdb2f52004-11-06 21:07:41 +000069
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
Tanya Lattner97275552006-04-12 21:57:40 +000076 } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2] } {
77 if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
78 set outcome XFAIL
79 }
Tanya Lattner3bdb2f52004-11-06 21:07:41 +000080 }
81
82 }
83 }
84
85 }
86
87 close $testFileId
88 close $scriptFileId
89
90
91 if { $hasRunline == 0 } {
92 fail "$test: \nDoes not have a RUN line\n"
93 } else {
94
95 #run script and catch errors
Reid Spencer8b437e02006-05-18 19:42:16 +000096 set retval [ catch {exec /bin/sh $script >& $output} errmsg ]
Tanya Lattner3bdb2f52004-11-06 21:07:41 +000097
98 if { $retval == 1 } {
99 #Get output
100 set outputFile [open $output {RDONLY}]
101 set result [read $outputFile]
102 close $outputFile
103 file delete $outputFile
104
105 switch $outcome {
106 PASS {
107 file delete $output
Reid Spencer8b437e02006-05-18 19:42:16 +0000108 fail "$test: \n$errmsg\n$result"
Tanya Lattner3bdb2f52004-11-06 21:07:41 +0000109 }
110 XFAIL {
Reid Spencer8b437e02006-05-18 19:42:16 +0000111 xfail "$test: \n$errmsg\n$result"
Tanya Lattner3bdb2f52004-11-06 21:07:41 +0000112 }
113 default {
114 file delete $output
115 fail "$test: $result"
116 }
117 }
118 } else {
119 switch $outcome {
120 XFAIL {
121 xpass "$test"
122 }
123 default {
124 pass "$test"}
125 }
126 }
127 }
128 }
Tanya Lattnere243e2f2004-11-07 22:04:21 +0000129}
130
131