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