Added the ability to xfail based on llvmgcc version
[oota-llvm.git] / test / lib / llvm-dg.exp
1 proc llvm-runtest { programs objdir srcdir subdir target_triplet llvmgcc llvmgxx prcontext llvmgcc_version} {
2
3
4     set timeout 60
5
6     set path [file join $objdir $subdir]
7     
8     #Make Output Directory if it does not exist already
9     if { [file exists path] } {
10         cd $path
11     } else {
12         file mkdir $path
13         cd $path
14     }
15     
16     file mkdir Output
17  
18     foreach test $programs {
19         
20         #Should figure out best way to set the timeout
21         #set timeout 40
22         
23         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
49                 regsub -all {%s} $runline $test new_runline
50
51                 #replace %t with temp filenames
52                 regsub -all {%t} $new_runline [file join Output $tmpFile] new_runline
53
54                 #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, 
58                 regsub -all {%p} $new_runline [file join $srcdir $subdir] new_runline
59
60                 #replace %llvmgcc with actual path to llvmgcc
61                 regsub -all {%llvmgcc} $new_runline "$llvmgcc -emit-llvm" new_runline
62
63                 #replace %llvmgxx with actual path to llvmg++
64                 regsub -all {%llvmgxx} $new_runline "$llvmgxx -emit-llvm" new_runline
65                 
66                 puts $scriptFileId $new_runline
67             } elseif {[regexp {XFAIL:[ *](.+)} $line match targets]} {
68                 set targets
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                     } 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                         }
80                     }
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
96             set retval [ catch {exec /bin/sh $script >& $output} ]
97             
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
108                         fail "$test: \n$result"
109                     }
110                     XFAIL {
111                         xfail "$test: \n$result"
112                     }
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     }
129 }
130
131