No, don't cancel all remaining tests, just the one that failed!
[oota-llvm.git] / test / lib / llvm-dg.exp
1 proc llvm-runtest { programs } { 
2     global srcroot objroot srcdir objdir subdir target_triplet prcontext 
3     global llvmgcc llvmgxx global llvmgcc_version llvmgccmajvers 
4     global gccpath gxxpath compile_c compile_cxx link shlibext llvmlibsdir
5
6     set timeout 60
7
8     set path [file join $objdir $subdir]
9     
10     #Make Output Directory if it does not exist already
11     if { [file exists path] } {
12         cd $path
13     } else {
14         file mkdir $path
15         cd $path
16     }
17     
18     file mkdir Output
19  
20     foreach test $programs {
21         
22         #Should figure out best way to set the timeout
23         #set timeout 40
24         
25         set filename [file tail $test]
26         set output [file join Output $filename.out]
27         set script $output.script
28         set outcome PASS
29         set tmpFile testscript.
30         append tmpFile $filename .tmp
31
32         #set hasRunline bool to check if testcase has a runline
33         set hasRunline 0
34
35         #check if script files exists, and delete if it does
36         if { [file exists $script] } {
37             file delete $script
38         }
39         
40         #create script file and write run line out to it
41         set scriptFileId [open $script w 0700]
42         set testFileId [ open $test r]
43         foreach line [split [read $testFileId] \n] {
44             
45             #see if this is our run line
46             if {[regexp {RUN:(.+)} $line match runline]} {
47                 set runline
48                 set hasRunline 1
49
50                 set new_runline $runline
51                 #replace %prcontext with prcontext.tcl (Must replace before %p)
52                 regsub -all {%prcontext} $new_runline $prcontext new_runline
53                 #replace %llvmgcc with actual path to llvmgcc
54                 regsub -all {%llvmgcc} $new_runline "$llvmgcc -emit-llvm" new_runline
55                 #replace %llvmgxx with actual path to llvmg++
56                 regsub -all {%llvmgxx} $new_runline "$llvmgxx -emit-llvm" new_runline
57                 #replace %compile_c with C compilation command
58                 regsub -all {%compile_c} $new_runline "$compile_c" new_runline
59                 #replace %compile_cxx with C++ compilation command
60                 regsub -all {%compile_cxx} $new_runline "$compile_cxx" new_runline
61                 #replace %link with C++ link command
62                 regsub -all {%link} $new_runline "$link" new_runline
63                 #replace %shlibext with shared library extension
64                 regsub -all {%shlibext} $new_runline "$shlibext" new_runline
65                 #replace %llvmlibsdir with configure library directory
66                 regsub -all {%llvmlibsdir} $new_runline "$llvmlibsdir" new_runline
67                 #replace %p with path to source, 
68                 regsub -all {%p} $new_runline [file join $srcdir $subdir] new_runline
69                 #replace %s with filename
70                 regsub -all {%s} $new_runline $test new_runline
71                 #replace %t with temp filenames
72                 regsub -all {%t} $new_runline [file join Output $tmpFile] new_runline
73                 puts $scriptFileId $new_runline
74             } elseif {[regexp {XFAIL:[ *](.+)} $line match targets]} {
75                 set targets
76
77                 #split up target if more then 1 specified
78                 foreach target [split $targets ,] {
79                     if { [regexp {\*} $target match] } {
80                         set outcome XFAIL
81                     } elseif { [regexp $target $target_triplet match] } {
82                         set outcome XFAIL
83                     } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2]  } {
84                 if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
85                           set outcome XFAIL
86                         }
87                     }
88                     
89                 }
90             }
91             
92         }
93         
94         close $testFileId
95         close $scriptFileId
96         
97         
98         if { $hasRunline == 0 } {
99             fail "$test: \nDoes not have a RUN line\n"
100         } else {
101
102             #run script and catch errors
103             set retval [ catch {exec /bin/sh $script >& $output} errmsg ]
104             
105             if { $retval == 1 } {
106                 #Get output
107                 set outputFile [open $output {RDONLY}]
108                 set result [read $outputFile]
109                 close $outputFile
110                 file delete $outputFile
111                 
112                 switch $outcome {
113                     PASS {
114                         file delete $output
115                         fail "$test: \n$errmsg\n$result"
116                     }
117                     XFAIL {
118                         xfail "$test: \n$errmsg\n$result"
119                     }
120                     default {
121                         file delete $output
122                         fail "$test: $result"
123                     }
124                 }
125             } else {
126                 switch $outcome {
127                     XFAIL {
128                         xpass "$test"
129                     }
130                     default {
131                         pass "$test"}
132                 }
133             }
134         }
135     }
136 }