Commit | Line | Data |
---|---|---|
32d0add0 | 1 | # Copyright 2010-2015 Free Software Foundation, Inc. |
a2c09bd0 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 | # Utilities for python-scripting related tests. | |
17 | ||
18 | # Run a command in GDB, and report a failure if a Python exception is thrown. | |
19 | # If report_pass is true, report a pass if no exception is thrown. | |
20 | ||
21 | proc gdb_py_test_silent_cmd { cmd name report_pass } { | |
22 | global gdb_prompt | |
23 | ||
24 | gdb_test_multiple $cmd $name { | |
25 | -re "Traceback.*$gdb_prompt $" { fail $name } | |
26 | -re "$gdb_prompt $" { if $report_pass { pass $name } } | |
27 | } | |
28 | } | |
29 | ||
30 | # Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}... | |
31 | # Run a test named NAME, consisting of multiple lines of input. | |
32 | # After each input line INPUT, search for result line RESULT. | |
33 | # Succeed if all results are seen; fail otherwise. | |
34 | ||
35 | proc gdb_py_test_multiple { name args } { | |
36 | global gdb_prompt | |
37 | foreach {input result} $args { | |
38 | if {[gdb_test_multiple $input "$name - $input" { | |
39 | -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" { | |
40 | pass "$name - $input" | |
41 | } | |
42 | }]} { | |
43 | return 1 | |
44 | } | |
45 | } | |
46 | return 0 | |
47 | } | |
6dddd6a5 DE |
48 | |
49 | # Return the result of python expression EXPR. | |
50 | # DEFAULT is returned if there's an error. | |
51 | # This is modelled after get_integer_valueof. | |
52 | ||
53 | proc get_python_valueof { exp default } { | |
54 | global gdb_prompt | |
55 | ||
56 | set test "get python valueof \"${exp}\"" | |
57 | set val ${default} | |
58 | gdb_test_multiple "python print (\"valueof: %s\" % (${exp}))" "$test" { | |
59 | -re "valueof: (\[^\r\n\]*)\[\r\n\]*$gdb_prompt $" { | |
60 | set val $expect_out(1,string) | |
61 | pass "$test ($val)" | |
62 | } | |
63 | timeout { | |
64 | fail "$test (timeout)" | |
65 | } | |
66 | } | |
67 | return ${val} | |
68 | } |