b3f3319b102f3f49ed33217e9d9f32ad287fa8b1
[gcc.git] / gcc / testsuite / gcc.dg / guality / guality.exp
1 # This harness is for tests that should be run at all optimisation levels.
2
3 load_lib gcc-dg.exp
4
5 proc check_guality {args} {
6 set result [eval check_compile guality_check executable $args "-g -O0"]
7 set lines [lindex $result 0]
8 set output [lindex $result 1]
9 set ret 0
10 if {[string match "" $lines]} {
11 set execout [gcc_load "./$output"]
12 set ret [string match "*1 PASS, 0 FAIL, 0 UNRESOLVED*" $execout]
13 }
14 remote_file build delete $output
15 return $ret
16 }
17
18 # Utility for testing variable values using gdb, invoked via dg-final.
19 # Call pass if variable has the desired value, otherwise fail.
20 #
21 # Argument 0 is the line number on which to put a breakpoint
22 # Argument 1 is the name of the variable to be checked
23 # Argument 2 is the expected value of the variable
24 # Argument 3 handles expected failures and the like
25 proc gdb-test { args } {
26 if { ![isnative] || [is_remote target] } { return }
27
28 if { [llength $args] >= 4 } {
29 switch [dg-process-target [lindex $args 3]] {
30 "S" { }
31 "N" { return }
32 "F" { setup_xfail "*-*-*" }
33 "P" { }
34 }
35 }
36
37 # This assumes that we are three frames down from dg-test, and that
38 # it still stores the filename of the testcase in a local variable "name".
39 # A cleaner solution would require a new DejaGnu release.
40 upvar 2 name testcase
41 upvar 2 prog prog
42
43 set gdb_name $::env(GUALITY_GDB_NAME)
44 set testname "$testcase line [lindex $args 0] [lindex $args 1] == [lindex $args 2]"
45 set output_file "[file rootname [file tail $prog]].exe"
46 set cmd_file "[file rootname [file tail $prog]].gdb"
47
48 set fd [open $cmd_file "w"]
49 puts $fd "break [lindex $args 0]"
50 puts $fd "run"
51 puts $fd "print [lindex $args 1]"
52 puts $fd "print [lindex $args 2]"
53 puts $fd "quit"
54 close $fd
55
56 send_log "Spawning: $gdb_name -nx -nw -quiet -x $cmd_file ./$output_file\n"
57 set res [remote_spawn target "$gdb_name -nx -nw -quiet -x $cmd_file ./$output_file"]
58 if { $res < 0 || $res == "" } {
59 unsupported "$testname"
60 return
61 }
62
63 remote_expect target [timeout_value] {
64 -re {[\n\r]\$1 = ([^\n\r]*)[\n\r]+\$2 = ([^\n\r]*)[\n\r]} {
65 set first $expect_out(1,string)
66 set second $expect_out(2,string)
67 if { $first == $second } {
68 pass "$testname"
69 } else {
70 send_log "$first != $second\n"
71 fail "$testname"
72 }
73 remote_close target
74 return
75 }
76 # Too old GDB
77 -re "Unhandled dwarf expression|Error in sourced command file" {
78 unsupported "$testname"
79 remote_close target
80 return
81 }
82 timeout {
83 unsupported "$testname"
84 remote_close target
85 return
86 }
87 }
88
89 remote_close target
90 unsupported "$testname"
91 return
92 }
93
94 dg-init
95
96 global GDB
97 if ![info exists ::env(GUALITY_GDB_NAME)] {
98 if [info exists GDB] {
99 set guality_gdb_name "$GDB"
100 } else {
101 set guality_gdb_name "[transform gdb]"
102 }
103 setenv GUALITY_GDB_NAME "$guality_gdb_name"
104 }
105
106 if {[check_guality "
107 #include \"$srcdir/$subdir/guality.h\"
108 volatile long int varl = 6;
109 int main (int argc, char *argv\[\])
110 {
111 GUALCHKVAL (varl);
112 return 0;
113 }
114 "]} {
115 gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.c]] ""
116 }
117
118 if [info exists guality_gdb_name] {
119 unsetenv GUALITY_GDB_NAME
120 }
121
122 dg-finish