Run prcontext.tcl with tclsh and let it be found in the path. This should be found...
[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     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         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
44                 regsub -all {%s} $runline $test new_runline
45
46                 #replace %t with temp filenames
47                 regsub -all {%t} $new_runline [file join Output $tmpFile] new_runline
48
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                 
55                 #replace %prcontext with prcontext.tcl (Goes away when we remove qmtest)
56                 regsub -all {%prcontext} $new_runline "tclsh prcontext.tcl" new_runline
57
58                 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     }
118 }
119
120