Commit | Line | Data |
---|---|---|
a72c3253 DE |
1 | # Copyright (C) 2012 Free Software Foundation, Inc. |
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 | ||
19 | load_lib gdb-python.exp | |
20 | ||
21 | standard_testfile | |
22 | ||
23 | if { [prepare_for_testing ${testfile}.exp ${testfile} ${srcfile}] } { | |
24 | return -1 | |
25 | } | |
26 | ||
27 | if ![runto_main] { | |
28 | return 0 | |
29 | } | |
30 | ||
31 | # Skip all tests if Python scripting is not enabled. | |
32 | if { [skip_python_tests] } { continue } | |
33 | ||
34 | proc test_all_strfns { } { | |
35 | gdb_test "p \$_streq (str1, str2)" " = 1" | |
36 | gdb_test "p \$_streq (str1, str3)" " = 0" | |
37 | ||
38 | gdb_test "p \$_strlen (str1)" " = 6" | |
39 | gdb_test "p \$_strlen (buf1)" " = 0" | |
40 | ||
41 | gdb_test "p \$_memeq (buf1, buf2, 4)" " = 1" | |
42 | gdb_test "p \$_memeq (buf1, buf3, 4)" " = 0" | |
43 | ||
44 | gdb_test {p $_regex (str1, "Hello")} " = 1" | |
45 | gdb_test {p $_regex (str1, "Help")} " = 0" | |
46 | gdb_test {p $_regex (str1, "^Hello")} " = 1" | |
47 | gdb_test {p $_regex (str1, "^Hello.$")} " = 1" | |
48 | } | |
49 | ||
50 | test_all_strfns | |
51 | ||
52 | # Verify use in a conditional breakpoint. | |
53 | ||
54 | gdb_breakpoint [gdb_get_line_number "Break func here."] | |
55 | gdb_test_no_output "condition \$bpnum \$_streq (arg, \"Goodbye.\")" | |
56 | gdb_continue_to_breakpoint "Break func here." | |
57 | gdb_test "p arg" "= $hex <str3> \"Goodbye.\"" | |
58 | ||
59 | gdb_breakpoint [gdb_get_line_number "Break bfunc here."] | |
60 | gdb_test_no_output "condition \$bpnum \$_memeq (arg, buf3, 4)" | |
61 | gdb_continue_to_breakpoint "Break bfunc here." | |
62 | gdb_test "p /d {char\[4\]} arg" "= \\{0, 1, 2, 4\\}" | |
63 | ||
64 | # Verify use on a core file. | |
65 | ||
66 | proc test_strfns_core_file { } { | |
67 | global objdir subdir gdb_prompt testfile | |
68 | ||
69 | set filename "${objdir}/${subdir}/py-strfns.core" | |
70 | set escapedfilename [string_to_regexp $filename] | |
71 | ||
72 | gdb_test_multiple "gcore $filename" \ | |
73 | "save a corefile" \ | |
74 | { | |
75 | -re "Saved corefile ${escapedfilename}\[\r\n\]+$gdb_prompt $" { | |
76 | pass "save a corefile" | |
77 | } | |
78 | -re "Can't create a corefile\[\r\n\]+$gdb_prompt $" { | |
79 | unsupported "save a corefile" | |
80 | # No use proceeding from here. | |
81 | return | |
82 | } | |
83 | } | |
84 | ||
85 | clean_restart $testfile | |
86 | ||
87 | gdb_test_multiple "core $filename" \ | |
88 | "re-load generated corefile" \ | |
89 | { | |
90 | -re "Core was generated by .*$gdb_prompt $" { | |
91 | pass "re-load generated corefile" | |
92 | } | |
93 | -re ".*$gdb_prompt $" { | |
94 | fail "re-load generated corefile" | |
95 | # No use proceeding from here. | |
96 | return | |
97 | } | |
98 | } | |
99 | ||
100 | test_all_strfns | |
101 | } | |
102 | ||
103 | test_strfns_core_file |