Forgot to join srcdir and subdir for complete path for input files.
[oota-llvm.git] / test / lib / llvm-dg.exp
1 proc llvm-runtest { programs objdir srcdir 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     if { [file exists path] } {
7         cd $path
8     } else {
9         file mkdir $path
10         cd $path
11     }
12     
13     file mkdir Output
14  
15     foreach test $programs {
16         
17         #Should figure out best way to set the timeout
18         #set timeout 40
19         
20         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
46                 regsub -all {%s} $runline $test new_runline
47
48                 #replace %t with temp filenames
49                 regsub -all {%t} $new_runline [file join Output $tmpFile] new_runline
50
51                 #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, 
55                 regsub -all {%p} $new_runline [file join $srcdir $subdir] new_runline
56
57                 #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                 
63                 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     }
123 }
124
125