Fix py-parameter.exp for remote host
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-parameter.exp
1 # Copyright (C) 2010-2014 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.
17 # It tests gdb.parameter and gdb.Parameter.
18
19 load_lib gdb-python.exp
20
21 # Start with a fresh gdb.
22 gdb_exit
23 gdb_start
24 gdb_reinitialize_dir $srcdir/$subdir
25
26 # Skip all tests if Python scripting is not enabled.
27 if { [skip_python_tests] } { continue }
28
29 # We use "." here instead of ":" so that this works on win32 too.
30 if { [is_remote host] } {
31 # Don't match $srcdir/$subdir because proc gdb_reinitialize_dir
32 # doesn't set search directories on remote host.
33 set directories ".*\\\$cdir.\\\$cwd"
34 } else {
35 set directories "$srcdir/$subdir.\\\$cdir.\\\$cwd"
36 }
37 gdb_test "python print (gdb.parameter ('directories'))" $directories
38
39 # Test a simple boolean parameter.
40 gdb_py_test_multiple "Simple gdb booleanparameter" \
41 "python" "" \
42 "class TestParam (gdb.Parameter):" "" \
43 " \"\"\"When enabled, test param does something useful. When disabled, does nothing.\"\"\"" "" \
44 " show_doc = \"Show the state of the boolean test-param\"" ""\
45 " set_doc = \"Set the state of the boolean test-param\"" "" \
46 " def get_show_string (self, pvalue):" ""\
47 " return \"The state of the Test Parameter is \" + pvalue" ""\
48 " def get_set_string (self):" ""\
49 " val = \"on\"" ""\
50 " if (self.value == False):" ""\
51 " val = \"off\"" ""\
52 " return \"Test Parameter has been set to \" + val" ""\
53 " def __init__ (self, name):" "" \
54 " super (TestParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \
55 " self.value = True" "" \
56 "test_param = TestParam ('print test-param')" ""\
57 "end"
58
59 gdb_test "python print (test_param.value)" "True" "Test parameter value"
60 gdb_test "show print test-param" "The state of the Test Parameter is on.*" "Show parameter on"
61 gdb_test "set print test-param off" "Test Parameter has been set to off" "Turn off parameter"
62 gdb_test "show print test-param" "The state of the Test Parameter is off.*" "Show parameter off"
63 gdb_test "python print (test_param.value)" "False" "Test parameter value"
64 gdb_test "help show print test-param" "Show the state of the boolean test-param.*" "Test show help"
65 gdb_test "help set print test-param" "Set the state of the boolean test-param.*" "Test set help"
66 gdb_test "help set print" "set print test-param -- Set the state of the boolean test-param.*" "Test general help"
67
68
69 # Test an enum parameter.
70 gdb_py_test_multiple "enum gdb parameter" \
71 "python" "" \
72 "class TestEnumParam (gdb.Parameter):" "" \
73 " \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \
74 " show_doc = \"Show the state of the enum\"" ""\
75 " set_doc = \"Set the state of the enum\"" "" \
76 " def get_show_string (self, pvalue):" ""\
77 " return \"The state of the enum is \" + pvalue" ""\
78 " def get_set_string (self):" ""\
79 " return \"The state of the enum has been set to \" + self.value" ""\
80 " def __init__ (self, name):" "" \
81 " super (TestEnumParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_ENUM, \[\"one\", \"two\"\])" "" \
82 " self.value = \"one\"" "" \
83 "test_enum_param = TestEnumParam ('print test-enum-param')" ""\
84 "end"
85
86 gdb_test "python print (test_enum_param.value)" "one" "Test enum parameter value"
87 gdb_test "show print test-enum-param" "The state of the enum is one.*" "Show parameter is initial value"
88 gdb_test "set print test-enum-param two" "The state of the enum has been set to two" "Set enum to two"
89 gdb_test "show print test-enum-param" "The state of the enum is two.*" "Show parameter is new value"
90 gdb_test "python print (test_enum_param.value)" "two" "Test enum parameter value"
91 gdb_test "set print test-enum-param three" "Undefined item: \"three\".*" "Set invalid enum parameter"
92
93 # Test a file parameter.
94 gdb_py_test_multiple "file gdb parameter" \
95 "python" "" \
96 "class TestFileParam (gdb.Parameter):" "" \
97 " \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \
98 " show_doc = \"Show the name of the file\"" ""\
99 " set_doc = \"Set the name of the file\"" "" \
100 " def get_show_string (self, pvalue):" ""\
101 " return \"The name of the file is \" + pvalue" ""\
102 " def get_set_string (self):" ""\
103 " return \"The name of the file has been changed to \" + self.value" ""\
104 " def __init__ (self, name):" "" \
105 " super (TestFileParam, self).__init__ (name, gdb.COMMAND_FILES, gdb.PARAM_FILENAME)" "" \
106 " self.value = \"foo.txt\"" "" \
107 "test_file_param = TestFileParam ('test-file-param')" ""\
108 "end"
109
110 gdb_test "python print (test_file_param.value)" "foo.txt" "Test file parameter value"
111 gdb_test "show test-file-param" "The name of the file is foo.txt.*" "Show initial file value"
112 gdb_test "set test-file-param bar.txt" "The name of the file has been changed to bar.txt" "Set new file parameter" 1
113 gdb_test "show test-file-param" "The name of the file is bar.txt.*" "Show new file value"
114 gdb_test "python print (test_file_param.value)" "bar.txt" "Test new file parameter value"
115 gdb_test "set test-file-param" "Argument required.*"
116
117 # Test a parameter that is not documented.
118 gdb_py_test_multiple "Simple gdb booleanparameter" \
119 "python" "" \
120 "class TestUndocParam (gdb.Parameter):" "" \
121 " def get_show_string (self, pvalue):" ""\
122 " return \"The state of the Test Parameter is \" + pvalue" ""\
123 " def get_set_string (self):" ""\
124 " val = \"on\"" ""\
125 " if (self.value == False):" ""\
126 " val = \"off\"" ""\
127 " return \"Test Parameter has been set to \" + val" ""\
128 " def __init__ (self, name):" "" \
129 " super (TestUndocParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \
130 " self.value = True" "" \
131 "test_undoc_param = TestUndocParam ('print test-undoc-param')" ""\
132 "end"
133
134 gdb_test "show print test-undoc-param" "The state of the Test Parameter is on.*" "Show parameter on"
135 gdb_test "set print test-undoc-param off" "Test Parameter has been set to off" "Turn off parameter"
136 gdb_test "show print test-undoc-param" "The state of the Test Parameter is off.*" "Show parameter off"
137 gdb_test "python print (test_undoc_param.value)" "False" "Test parameter value"
138 gdb_test "help show print test-undoc-param" "This command is not documented.*" "Test show help"
139 gdb_test "help set print test-undoc-param" "This command is not documented.*" "Test set help"
140 gdb_test "help set print" "set print test-undoc-param -- This command is not documented.*" "Test general help"
141
142 # Test a parameter that is not documented in any way..
143 gdb_py_test_multiple "Simple gdb booleanparameter" \
144 "python" "" \
145 "class TestNodocParam (gdb.Parameter):" "" \
146 " def __init__ (self, name):" "" \
147 " super (TestNodocParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \
148 " self.value = True" "" \
149 "test_nodoc_param = TestNodocParam ('print test-nodoc-param')" ""\
150 "end"
151
152 gdb_test "show print test-nodoc-param" "This command is not documented.*" "Show parameter on"
153 gdb_test "set print test-nodoc-param off" "This command is not documented.*" "Turn off parameter"
154 gdb_test "show print test-nodoc-param" "This command is not documented.*.*" "Show parameter off"
155 gdb_test "python print (test_nodoc_param.value)" "False" "Test parameter value"
156 gdb_test "help show print test-nodoc-param" "This command is not documented.*" "Test show help"
157 gdb_test "help set print test-nodoc-param" "This command is not documented.*" "Test set help"
158 gdb_test "help set print" "set print test-nodoc-param -- This command is not documented.*" "Test general help"
159
160 # Test deprecated API. Do not use in your own implementations.
161 gdb_py_test_multiple "Simple gdb booleanparameter" \
162 "python" "" \
163 "class TestParam (gdb.Parameter):" "" \
164 " \"\"\"When enabled, test param does something useful. When disabled, does nothing.\"\"\"" "" \
165 " show_doc = \"State of the Test Parameter\"" ""\
166 " set_doc = \"Set the state of the Test Parameter\"" "" \
167 " def __init__ (self, name):" "" \
168 " super (TestParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \
169 " self.value = True" "" \
170 "test_param = TestParam ('print test-param')" ""\
171 "end"
172
173 gdb_test "python print (test_param.value)" "True" "Test parameter value"
174 gdb_test "show print test-param" "State of the Test Parameter on.*" "Show parameter on"
175 gdb_test "set print test-param off" "Set the state of the Test Parameter.*" "Turn off parameter"
176 gdb_test "show print test-param" "State of the Test Parameter off.*" "Show parameter off"
177 gdb_test "python print (test_param.value)" "False" "Test parameter value"
178 gdb_test "help show print test-param" "State of the Test Parameter.*" "Test show help"
179 gdb_test "help set print test-param" "Set the state of the Test Parameter.*" "Test set help"
180 gdb_test "help set print" "set print test-param -- Set the state of the Test Parameter.*" "Test general help"
This page took 0.034607 seconds and 5 git commands to generate.