Fix test names starting with uppercase using gdb_test on a single line.
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-xmethods.exp
CommitLineData
618f726f 1# Copyright 2014-2016 Free Software Foundation, Inc.
883964a7
SC
2
3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation; either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16# This file is part of the GDB testsuite. It tests the debug methods
17# feature in the Python extension language.
18
19load_lib gdb-python.exp
20
21if { [skip_cplus_tests] } { continue }
22
23standard_testfile py-xmethods.cc
24
25if {[prepare_for_testing $testfile.exp $testfile $srcfile {debug c++}]} {
26 return -1
27}
28
29# Skip all tests if Python scripting is not enabled.
30if { [skip_python_tests] } { continue }
31
32if ![runto_main] {
33 return -1
34}
35
36set xmethods_script [gdb_remote_download host \
37 ${srcdir}/${subdir}/${testfile}.py]
38
39gdb_breakpoint [gdb_get_line_number "Break here."]
40gdb_continue_to_breakpoint "Break here" ".*Break here.*"
41
42# Tests before loading the debug methods.
cdc7edd7
LM
43gdb_test "p a1 + a2" ".* = 15" "before: a1 + a2"
44gdb_test "p a_plus_a" ".* = 1" "before: a_plus_a 1"
5d376983 45
cdc7edd7
LM
46gdb_test "p a2 - a1" ".* = 5" "before: a2 - a1"
47gdb_test "p a_minus_a" ".* = 1" "before: a_minus_a 1"
5d376983 48
cdc7edd7
LM
49gdb_test "p b1 - a1" ".* = 25" "before: b1 - a1"
50gdb_test "p a_minus_a" ".* = 2" "before: a_minus_a 2"
5d376983 51
cdc7edd7
LM
52gdb_test "p a1.geta()" ".* = 5" "before: a1.geta()"
53gdb_test "p a_geta" ".* = 1" "before: a_geta 1"
5d376983 54
cdc7edd7 55gdb_test "p ++a1" "No symbol.*" "before: ++a1"
883964a7
SC
56gdb_test "p a1.getarrayind(5)" "Couldn't find method.*" \
57 "Before: a1.getarrayind(5)"
5d376983 58
cdc7edd7
LM
59gdb_test "p a_ptr->geta()" ".* = 60" "before: a_ptr->geta()"
60gdb_test "p b_geta" ".* = 1" "before: b_geta 1"
5d376983 61
cdc7edd7
LM
62gdb_test "p e.geta()" ".* = 100" "before: e.geta()"
63gdb_test "p a_geta" ".* = 2" "before: a_geta 2"
5d376983
SC
64
65# Since g.size_diff operates of sizes of int and float, do not check for
66# actual result value as it could be different on different platforms.
cdc7edd7
LM
67gdb_test "p g.size_diff<float>()" ".*" "before: call g.size_diff<float>()"
68gdb_test "p g_size_diff" ".* = 2" "before: g_size_diff 2"
5d376983 69
883964a7
SC
70gdb_test "p g.size_diff<unsigned long>()" "Couldn't find method.*" \
71 "Before: g.size_diff<unsigned long>()"
5d376983 72
cdc7edd7
LM
73gdb_test "p g.size_mul<2>()" ".*" "before: g.size_mul<2>()"
74gdb_test "p g_size_mul" ".* = 2" "before: g_size_mul 2"
5d376983 75
883964a7
SC
76gdb_test "p g.size_mul<5>()" "Couldn't find method.*" \
77 "Before: g.size_mul<5>()"
5d376983 78
cdc7edd7
LM
79gdb_test "p g.mul<double>(2.0)" ".* = 10" "before: g.mul<double>(2.0)"
80gdb_test "p g_mul" ".* = 2" "before: g_mul 2"
5d376983 81
883964a7
SC
82gdb_test "p g.mul<char>('a')" "Couldn't find method.*" \
83 "Before: g.mul<char>('a')"
84
85# Load the script which adds the debug methods.
86gdb_test_no_output "source ${xmethods_script}" "load the script file"
87
88# Tests after loading debug methods.
cdc7edd7 89gdb_test "p a1 + a2" "From Python <A_plus_A>.*15" "after: a1 + a2"
5d376983 90
cdc7edd7
LM
91gdb_test "p a2 - a1" ".* = 5" "after: a2 - a1"
92gdb_test "p a_minus_a" ".* = 3" "after: a_minus_a 3"
5d376983 93
cdc7edd7 94gdb_test "p b1 + a1" "From Python <A_plus_A>.*35" "after: b1 + a1"
5d376983 95
cdc7edd7
LM
96gdb_test "p b1 - a1" ".* = 25" "after: b1 - a1"
97gdb_test "p a_minus_a" ".* = 4" "after: a_minus_a 4"
5d376983 98
cdc7edd7
LM
99gdb_test "p a1.geta()" "From Python <A_geta>.*5" "after: a1.geta()"
100gdb_test "p ++a1" "From Python <plus_plus_A>.*6" "after: ++a1"
883964a7
SC
101gdb_test "p a1.getarrayind(5)" "From Python <A_getarrayind>.*5" \
102 "After: a1.getarrayind(5)"
cdc7edd7
LM
103gdb_test "P a1\[6\]" ".*int &.*6" "after a1\[\]"
104gdb_test "P b1\[7\]" ".*const int &.*7" "after b1\[\]"
883964a7
SC
105# Note the following test. Xmethods on dynamc types are not looked up
106# currently. Hence, even though a_ptr points to a B object, the xmethod
107# defined for A objects is invoked.
cdc7edd7
LM
108gdb_test "p a_ptr->geta()" "From Python <A_geta>.*30" "after: a_ptr->geta()"
109gdb_test "p e.geta()" "From Python <A_geta>.*100" "after: e.geta()"
110gdb_test "p e_ptr->geta()" "From Python <A_geta>.*100" "after: e_ptr->geta()"
111gdb_test "p e_ref.geta()" "From Python <A_geta>.*100" "after: e_ref.geta()"
2ce1cdbf
DE
112gdb_test "p e.method(10)" "From Python <E_method_int>.* = void" \
113 "After: e.method(10)"
114gdb_test "p e.method('a')" "From Python <E_method_char>.* = void" \
883964a7
SC
115 "After: e.method('a')"
116gdb_test "p g.size_diff<float> ()" "From Python G<>::size_diff.*" \
117 "After: g.size_diff<float>()"
118gdb_test "p g.size_diff< unsigned long >()" "From Python G<>::size_diff.*" \
119 "After: g.size_diff<unsigned long>()"
120gdb_test "p g.size_mul<2>()" "From Python G<>::size_mul.*" \
121 "After: g.size_mul<2>()"
122gdb_test "p g.size_mul< 5 >()" "From Python G<>::size_mul.*" \
123 "After: g.size_mul< 5 >()"
124gdb_test "p g.mul<double>(2.0)" "From Python G<>::mul.*" \
125 "After: g.mul<double>(2.0)"
126gdb_test "p g.mul<char>('a')" "From Python G<>::mul.*" \
127gdb_test "p g_ptr->mul<char>('a')" "From Python G<>::mul.*" \
128 "After: g_ptr->mul<char>('a')"
129
130# Tests for 'disable/enable xmethod' command.
70afc5b7 131gdb_test_no_output "disable xmethod progspace G_methods" \
883964a7
SC
132 "Disable G_methods"
133gdb_test "p g.mul<char>('a')" "Couldn't find method.*" \
134 "g.mul<char>('a') after disabling G_methods"
70afc5b7 135gdb_test_no_output "enable xmethod progspace G_methods" \
883964a7
SC
136 "Enable G_methods"
137gdb_test "p g.mul<char>('a')" "From Python G<>::mul.*" \
138 "After enabling G_methods"
70afc5b7 139gdb_test_no_output "disable xmethod progspace G_methods;mul" \
883964a7
SC
140 "Disable G_methods;mul"
141gdb_test "p g.mul<char>('a')" "Couldn't find method.*" \
142 "g.mul<char>('a') after disabling G_methods;mul"
70afc5b7 143gdb_test_no_output "enable xmethod progspace G_methods;mul" \
883964a7
SC
144 "Enable G_methods;mul"
145gdb_test "p g.mul<char>('a')" "From Python G<>::mul.*" \
146 "After enabling G_methods;mul"
147
148# Test for 'info xmethods' command
149gdb_test "info xmethod global plus" "global.*plus_plus_A" \
150 "info xmethod global plus 1"
70afc5b7
SC
151gdb_test_no_output "disable xmethod progspace E_methods;method_int" \
152 "disable xmethod progspace E_methods;method_int"
153gdb_test "info xmethod progspace E_methods;method_int" ".* \\\[disabled\\\]" \
883964a7 154 "info xmethod xmethods E_methods;method_int"
df2eb078
SC
155gdb_test_no_output "disable xmethod progspace G_methods" "Disable G_methods 2"
156gdb_test "info xmethod progspace" ".*G_methods \\\[disabled\\\].*" \
157 "info xmethod progspace"
2ce1cdbf
DE
158
159# PR 18285
160# First make sure both are enabled.
161gdb_test_no_output "enable xmethod progspace E_methods;method_char"
162gdb_test_no_output "enable xmethod progspace E_methods;method_int"
163gdb_test "pt e.method('a')" "type = void"
164gdb_test "pt e.method(10)" \
165 "NotImplementedError.*Error while fetching result type of an xmethod worker defined in Python."
This page took 0.300486 seconds and 4 git commands to generate.