summaryrefslogtreecommitdiff
path: root/gdb/testsuite/gdb.ada/operator_call.exp
blob: 4a35c5c60009b6d074db65d4c4dadd854c871bb3 (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
# Copyright 2021 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

load_lib "ada.exp"

if { [skip_ada_tests] } { return -1 }

standard_ada_testfile opcall

if {[gdb_compile_ada "${srcfile}" "${binfile}" executable {debug}] != ""} {
    return -1
}

clean_restart ${testfile}

set bp_location [gdb_get_line_number "STOP" ${testdir}/opcall.adb]
runto "opcall.adb:$bp_location"

gdb_test "print p" " = \\(x => 4, y => 5\\)"

proc test_with_menu {command result} {
    global expect_out

    set rxcmd [string_to_regexp $command]

    set num {}
    send_gdb "$command\n"
    gdb_expect 30 {
	-re "^$rxcmd\r\n" {
	    exp_continue
	}
	-re "Multiple matches for \[^\r\n\]*\r\n" {
	    exp_continue
	}
	-re "^\\\[(\[0-9\]+)\\\] twovecs\\.*\[^\r\n\]*\r\n" {
	    set num $expect_out(1,string)
	    exp_continue
	}
	-re "^\\\[\[0-9\]+\\\] \[^\r\n\]*\r\n" {
	    # Any other match, we don't want.
	    exp_continue
	}
	-re "^> " {
	    if {$num == ""} {
		fail $command
		set num 0
	    }
	    send_gdb "$num\n"
	    exp_continue
	}
	-re "^\[0-9\]+\r\n" {
	    # The number we just sent, ignore.
	    exp_continue
	}
	-re "\\\$\[0-9\]+ = (\[^\r\n\]+)\r\n" {
	    if {[regexp $result $expect_out(1,string)]} {
		pass $command
	    } else {
		fail $command
	    }
	}
	timeout {
	    fail "$command (timeout)"
	}
    }
}

test_with_menu "print p + p" "\\(x => 8, y => 10\\)"
test_with_menu "print p - p" "\\(x => 0, y => 0\\)"
test_with_menu "print p * p" "\\(x => 16, y => 25\\)"
test_with_menu "print p / p" "\\(x => 1, y => 1\\)"

# See the code to understand the weird numbers here.
test_with_menu "print p mod p" "\\(x => 17, y => 18\\)"
test_with_menu "print p rem p" "\\(x => 38, y => 39\\)"
test_with_menu "print p ** p" "\\(x => 84, y => 105\\)"

test_with_menu "print p < p" "false"
test_with_menu "print p < p2" "true"
test_with_menu "print p <= p" "true"
test_with_menu "print p <= p2" "true"
test_with_menu "print p > p" "false"
test_with_menu "print p2 > p" "true"
test_with_menu "print p >= p" "true"
test_with_menu "print p2 >= p" "true"
test_with_menu "print p = p" "true"
test_with_menu "print p = p2" "false"
test_with_menu "print p /= p" "false"
test_with_menu "print p /= p2" "true"

test_with_menu "print p and p2" "\\(x => 4, y => 4\\)"
test_with_menu "print p or p2" "\\(x => 12, y => 13\\)"
test_with_menu "print p xor p2" "\\(x => 8, y => 9\\)"

# See the code to understand the weird numbers here.
test_with_menu "print p & p" "\\(x => 44, y => 55\\)"

test_with_menu "print -p" "\\(x => 65532, y => 65531\\)"
test_with_menu "print abs(-p)" "\\(x => 65532, y => 65531\\)"
test_with_menu "print not(p)" "\\(x => 65531, y => 65530\\)"

# See the code to understand the weird numbers here.
test_with_menu "print +(p)" "\\(x => 5, y => 4\\)"