Made changes to support objdir!=srcdir.
[oota-llvm.git] / test / lib / llvm-dg.exp
1 proc llvm-runtest { programs objdir subdir target_triplet llvmgcc llvmgxx prcontext} {
2
3     set path [file join $objdir $subdir]
4     
5     #Make Output Directory if it does not exist already
6     cd $path
7     
8     file mkdir Output
9  
10     foreach test $programs {
11         
12         set timeout 40
13         set filename [file tail $test]
14         set output [file join Output $filename.out]
15         set script $output.script
16         set outcome PASS
17         set tmpFile testscript.
18         append tmpFile $filename .tmp
19
20         #set hasRunline bool to check if testcase has a runline
21         set hasRunline 0
22
23         #check if script files exists, and delete if it does
24         if { [file exists $script] } {
25             file delete $script
26         }
27         
28         #create script file and write run line out to it
29         set scriptFileId [open $script w 0700]
30         set testFileId [ open $test r]
31         foreach line [split [read $testFileId] \n] {
32             
33             #see if this is our run line
34             if {[regexp {RUN:(.+)} $line match runline]} {
35                 set runline
36                 set hasRunline 1
37
38                 #replace %s with filename
39                 regsub -all {%s} $runline $test new_runline
40
41                 #replace %t with temp filenames
42                 regsub -all {%t} $new_runline [file join Output $tmpFile] new_runline
43
44                 #replace %llvmgcc with actual path to llvmgcc
45                 regsub -all {%llvmgcc} $new_runline $llvmgcc new_runline
46
47                 #replace %llvmgxx with actual path to llvmg++
48                 regsub -all {%llvmgxx} $new_runline $llvmgxx new_runline
49                 
50                 #replace %prcontext with actual path to llvmg++ (Goes away when we remove qmtest)
51                 regsub -all {%prcontext} $new_runline "python $prcontext" new_runline
52
53                 puts $scriptFileId $new_runline
54             } elseif {[regexp {XFAIL:[ *](.+)} $line match targets]} {
55                 set targets
56                 
57
58                 #split up target if more then 1 specified
59                 foreach target [split $targets ,] {
60                     if { [regexp {\*} $target match] } {
61                         set outcome XFAIL
62                     } elseif { [regexp $target $target_triplet match] } {
63                         set outcome XFAIL
64                     }
65                     
66                 }
67             }
68             
69         }
70         
71         close $testFileId
72         close $scriptFileId
73         
74         
75         if { $hasRunline == 0 } {
76             fail "$test: \nDoes not have a RUN line\n"
77         } else {
78
79             #run script and catch errors
80             set retval [ catch {exec /bin/sh $script >& $output} ]
81             
82             if { $retval == 1 } {
83                 #Get output
84                 set outputFile [open $output {RDONLY}]
85                 set result [read $outputFile]
86                 close $outputFile
87                 file delete $outputFile
88                 
89                 switch $outcome {
90                     PASS {
91                         file delete $output
92                         fail "$test: \n$result"
93                     }
94                     XFAIL {
95                         xfail "$test: \n$result"
96                     }
97                     default {
98                         file delete $output
99                         fail "$test: $result"
100                     }
101                 }
102             } else {
103                 switch $outcome {
104                     XFAIL {
105                         xpass "$test"
106                     }
107                     default {
108                         pass "$test"}
109                 }
110             }
111         }
112     }
113 }
114
115