aboutsummaryrefslogtreecommitdiff
path: root/test/lib/llvm-dg.exp
blob: 593108af4a5f1d84df94621c107319f68263976f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
proc llvm-runtest { programs } { 
    global objdir srcdir subdir target_triplet llvmgcc llvmgxx prcontext
    global llvmgcc_version srcroot objroot llvmlibsdir

    set timeout 60

    set path [file join $objdir $subdir]
    
    #Make Output Directory if it does not exist already
    if { [file exists path] } {
	cd $path
    } else {
	file mkdir $path
	cd $path
    }
    
    file mkdir Output
 
    foreach test $programs {
	
	#Should figure out best way to set the timeout
	#set timeout 40
	
	set filename [file tail $test]
	set output [file join Output $filename.out]
	set script $output.script
	set outcome PASS
	set tmpFile testscript.
	append tmpFile $filename .tmp

	#set hasRunline bool to check if testcase has a runline
	set hasRunline 0

	#check if script files exists, and delete if it does
	if { [file exists $script] } {
	    file delete $script
	}
	
	#create script file and write run line out to it
	set scriptFileId [open $script w 0700]
	set testFileId [ open $test r]
	foreach line [split [read $testFileId] \n] {
	    
	    #see if this is our run line
	    if {[regexp {RUN:(.+)} $line match runline]} {
		set runline
		set hasRunline 1

		#replace %s with filename
		regsub -all {%s} $runline $test new_runline

		#replace %t with temp filenames
		regsub -all {%t} $new_runline [file join Output $tmpFile] new_runline

		#replace %prcontext with prcontext.tcl (Must replace before %p)
		regsub -all {%prcontext} $new_runline $prcontext new_runline

		#replace %p with path to source, 
		regsub -all {%p} $new_runline [file join $srcdir $subdir] new_runline

		#replace %llvmgcc with actual path to llvmgcc
		regsub -all {%llvmgcc} $new_runline "$llvmgcc -emit-llvm" new_runline

		#replace %llvmgxx with actual path to llvmg++
		regsub -all {%llvmgxx} $new_runline "$llvmgxx -emit-llvm" new_runline
		
		#replace %L with path to libraries
		regsub -all {%L} $new_runline "$llvmlibsdir" new_runline

		#replace %I with path to includes
		regsub -all {%I} $new_runline "$srcroot/include" new_runline

		puts $scriptFileId $new_runline
	    } elseif {[regexp {XFAIL:[ *](.+)} $line match targets]} {
		set targets

		#split up target if more then 1 specified
		foreach target [split $targets ,] {
		    if { [regexp {\*} $target match] } {
			set outcome XFAIL
		    } elseif { [regexp $target $target_triplet match] } {
			set outcome XFAIL
		    } elseif { [regexp {llvmgcc(([0-9]+)|([0-9]+[.][0-9]+))} $target match submatch submatch2]  } {
		if { [regexp ^($submatch)$|^(($submatch)(\.)) $llvmgcc_version match] } {
			  set outcome XFAIL
		    	}
		    }
		    
		}
	    }
	    
	}
	
	close $testFileId
	close $scriptFileId
	
	
	if { $hasRunline == 0 } {
	    fail "$test: \nDoes not have a RUN line\n"
	} else {

	    #run script and catch errors
	    set retval [ catch {exec /bin/sh $script >& $output} errmsg ]
	    
	    if { $retval == 1 } {
		#Get output
		set outputFile [open $output {RDONLY}]
		set result [read $outputFile]
		close $outputFile
		file delete $outputFile
		
		switch $outcome {
		    PASS {
			file delete $output
			fail "$test: \n$errmsg\n$result"
		    }
		    XFAIL {
			xfail "$test: \n$errmsg\n$result"
		    }
		    default {
			file delete $output
			fail "$test: $result"
		    }
		}
	    } else {
		switch $outcome {
		    XFAIL {
			xpass "$test"
		    }
		    default {
			pass "$test"}
		}
	    }
	}
    }
}