summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/guality/guality.exp
blob: b3f3319b102f3f49ed33217e9d9f32ad287fa8b1 (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
# This harness is for tests that should be run at all optimisation levels.

load_lib gcc-dg.exp

proc check_guality {args} {
    set result [eval check_compile guality_check executable $args "-g -O0"]
    set lines [lindex $result 0]
    set output [lindex $result 1]
    set ret 0
    if {[string match "" $lines]} {
      set execout [gcc_load "./$output"]
      set ret [string match "*1 PASS, 0 FAIL, 0 UNRESOLVED*" $execout]
    }
    remote_file build delete $output
    return $ret
}

# Utility for testing variable values using gdb, invoked via dg-final.
# Call pass if variable has the desired value, otherwise fail.
#
# Argument 0 is the line number on which to put a breakpoint
# Argument 1 is the name of the variable to be checked
# Argument 2 is the expected value of the variable
# Argument 3 handles expected failures and the like
proc gdb-test { args } {
    if { ![isnative] || [is_remote target] } { return }

    if { [llength $args] >= 4 } {
	switch [dg-process-target [lindex $args 3]] {
	    "S" { }
	    "N" { return }
	    "F" { setup_xfail "*-*-*" }
	    "P" { }
	}
    }

    # This assumes that we are three frames down from dg-test, and that
    # it still stores the filename of the testcase in a local variable "name".
    # A cleaner solution would require a new DejaGnu release.
    upvar 2 name testcase
    upvar 2 prog prog

    set gdb_name $::env(GUALITY_GDB_NAME)
    set testname "$testcase line [lindex $args 0] [lindex $args 1] == [lindex $args 2]"
    set output_file "[file rootname [file tail $prog]].exe"
    set cmd_file "[file rootname [file tail $prog]].gdb"

    set fd [open $cmd_file "w"]
    puts $fd "break [lindex $args 0]"
    puts $fd "run"
    puts $fd "print [lindex $args 1]"
    puts $fd "print [lindex $args 2]"
    puts $fd "quit"
    close $fd

    send_log "Spawning: $gdb_name -nx -nw -quiet -x $cmd_file ./$output_file\n"
    set res [remote_spawn target "$gdb_name -nx -nw -quiet -x $cmd_file ./$output_file"]
    if { $res < 0 || $res == "" } {
	unsupported "$testname"
	return
    }

    remote_expect target [timeout_value] {
	-re {[\n\r]\$1 = ([^\n\r]*)[\n\r]+\$2 = ([^\n\r]*)[\n\r]} {
	    set first $expect_out(1,string)
	    set second $expect_out(2,string)
	    if { $first == $second } {
		pass "$testname"
	    } else {
		send_log "$first != $second\n"
		fail "$testname"
	    }
	    remote_close target
	    return
	}
	# Too old GDB
	-re "Unhandled dwarf expression|Error in sourced command file" {
	    unsupported "$testname"
	    remote_close target
	    return
	}
	timeout {
	    unsupported "$testname"
	    remote_close target
	    return
	}
    }

    remote_close target
    unsupported "$testname"
    return
}

dg-init

global GDB
if ![info exists ::env(GUALITY_GDB_NAME)] {
    if [info exists GDB] {
	set guality_gdb_name "$GDB"
    } else {
	set guality_gdb_name "[transform gdb]"
    }
    setenv GUALITY_GDB_NAME "$guality_gdb_name"
}

if {[check_guality "
  #include \"$srcdir/$subdir/guality.h\"
  volatile long int varl = 6;
  int main (int argc, char *argv\[\])
  {
    GUALCHKVAL (varl);
    return 0;
  }
"]} {
  gcc-dg-runtest [lsort [glob $srcdir/$subdir/*.c]] ""
}

if [info exists guality_gdb_name] {
    unsetenv GUALITY_GDB_NAME
}

dg-finish