Result of strlen is size_t which is either uint or ulong, not int.
[oota-llvm.git] / test / lib / llvm-dg.exp
1 proc llvm-runtest { programs objdir srcdir subdir target_triplet llvmgcc llvmgxx prcontext} {
2
3     set timeout 60
4
5     set path [file join $objdir $subdir]
6     
7     #Make Output Directory if it does not exist already
8     if { [file exists path] } {
9         cd $path
10     } else {
11         file mkdir $path
12         cd $path
13     }
14     
15     file mkdir Output
16  
17     foreach test $programs {
18         
19         #Should figure out best way to set the timeout
20         #set timeout 40
21         
22         set filename [file tail $test]
23         set output [file join Output $filename.out]
24         set script $output.script
25         set outcome PASS
26         set tmpFile testscript.
27         append tmpFile $filename .tmp
28
29         #set hasRunline bool to check if testcase has a runline
30         set hasRunline 0
31
32         #check if script files exists, and delete if it does
33         if { [file exists $script] } {
34             file delete $script
35         }
36         
37         #create script file and write run line out to it
38         set scriptFileId [open $script w 0700]
39         set testFileId [ open $test r]
40         foreach line [split [read $testFileId] \n] {
41             
42             #see if this is our run line
43             if {[regexp {RUN:(.+)} $line match runline]} {
44                 set runline
45                 set hasRunline 1
46
47                 #replace %s with filename
48                 regsub -all {%s} $runline $test new_runline
49
50                 #replace %t with temp filenames
51                 regsub -all {%t} $new_runline [file join Output $tmpFile] new_runline
52
53                 #replace %prcontext with prcontext.tcl (Must replace before %p)
54                 regsub -all {%prcontext} $new_runline $prcontext new_runline
55
56                 #replace %p with path to source, 
57                 regsub -all {%p} $new_runline [file join $srcdir $subdir] new_runline
58
59                 #replace %llvmgcc with actual path to llvmgcc
60                 regsub -all {%llvmgcc} $new_runline $llvmgcc new_runline
61
62                 #replace %llvmgxx with actual path to llvmg++
63                 regsub -all {%llvmgxx} $new_runline $llvmgxx new_runline
64                 
65                 puts $scriptFileId $new_runline
66             } elseif {[regexp {XFAIL:[ *](.+)} $line match targets]} {
67                 set targets
68                 
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                     }
77                     
78                 }
79             }
80             
81         }
82         
83         close $testFileId
84         close $scriptFileId
85         
86         
87         if { $hasRunline == 0 } {
88             fail "$test: \nDoes not have a RUN line\n"
89         } else {
90
91             #run script and catch errors
92             set retval [ catch {exec /bin/sh $script >& $output} ]
93             
94             if { $retval == 1 } {
95                 #Get output
96                 set outputFile [open $output {RDONLY}]
97                 set result [read $outputFile]
98                 close $outputFile
99                 file delete $outputFile
100                 
101                 switch $outcome {
102                     PASS {
103                         file delete $output
104                         fail "$test: \n$result"
105                     }
106                     XFAIL {
107                         xfail "$test: \n$result"
108                     }
109                     default {
110                         file delete $output
111                         fail "$test: $result"
112                     }
113                 }
114             } else {
115                 switch $outcome {
116                     XFAIL {
117                         xpass "$test"
118                     }
119                     default {
120                         pass "$test"}
121                 }
122             }
123         }
124     }
125 }
126
127