]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/testsuite/gdb.python/py-strfns.exp
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-strfns.exp
CommitLineData
1d506c26 1# Copyright (C) 2012-2024 Free Software Foundation, Inc.
a72c3253
DE
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 convenience
17# functions in strfns.py.
18
19load_lib gdb-python.exp
20
d82e5429 21require allow_python_tests
79749205 22
a72c3253
DE
23standard_testfile
24
5b362f04 25if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
a72c3253
DE
26 return -1
27}
28
29if ![runto_main] {
30 return 0
31}
32
a72c3253
DE
33proc test_all_strfns { } {
34 gdb_test "p \$_streq (str1, str2)" " = 1"
35 gdb_test "p \$_streq (str1, str3)" " = 0"
36
37 gdb_test "p \$_strlen (str1)" " = 6"
38 gdb_test "p \$_strlen (buf1)" " = 0"
39
40 gdb_test "p \$_memeq (buf1, buf2, 4)" " = 1"
41 gdb_test "p \$_memeq (buf1, buf3, 4)" " = 0"
42
43 gdb_test {p $_regex (str1, "Hello")} " = 1"
44 gdb_test {p $_regex (str1, "Help")} " = 0"
45 gdb_test {p $_regex (str1, "^Hello")} " = 1"
46 gdb_test {p $_regex (str1, "^Hello.$")} " = 1"
47}
48
49test_all_strfns
50
51# Verify use in a conditional breakpoint.
52
53gdb_breakpoint [gdb_get_line_number "Break func here."]
54gdb_test_no_output "condition \$bpnum \$_streq (arg, \"Goodbye.\")"
55gdb_continue_to_breakpoint "Break func here."
56gdb_test "p arg" "= $hex <str3> \"Goodbye.\""
57
58gdb_breakpoint [gdb_get_line_number "Break bfunc here."]
59gdb_test_no_output "condition \$bpnum \$_memeq (arg, buf3, 4)"
60gdb_continue_to_breakpoint "Break bfunc here."
61gdb_test "p /d {char\[4\]} arg" "= \\{0, 1, 2, 4\\}"
62
63# Verify use on a core file.
64
65proc test_strfns_core_file { } {
8448e842 66 global gdb_prompt testfile
a72c3253 67
8448e842 68 set filename [standard_output_file py-strfns.core]
a72c3253 69
2d338fa9
TT
70 if {![gdb_gcore_cmd "$filename" "save a corefile"]} {
71 # No use proceeding from here.
72 return
73 }
a72c3253
DE
74
75 clean_restart $testfile
76
77 gdb_test_multiple "core $filename" \
78 "re-load generated corefile" \
79 {
80 -re "Core was generated by .*$gdb_prompt $" {
81 pass "re-load generated corefile"
82 }
83 -re ".*$gdb_prompt $" {
84 fail "re-load generated corefile"
85 # No use proceeding from here.
86 return
87 }
88 }
89
22d3e7f6
AB
90 with_test_prefix "for corefile" {
91 test_all_strfns
92 }
a72c3253
DE
93}
94
95test_strfns_core_file