Commit | Line | Data |
---|---|---|
618f726f | 1 | # Copyright (C) 2010-2016 Free Software Foundation, Inc. |
99e7ae30 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 | ||
b521dba8 DE |
16 | # This file is part of the GDB testsuite. |
17 | # It tests gdb.parameter and gdb.Parameter. | |
99e7ae30 | 18 | |
99e7ae30 DE |
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. | |
10c5f0a8 YQ |
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 { | |
2631b16a AW |
35 | set escaped_directory [string_to_regexp "$srcdir/$subdir"] |
36 | set directories "$escaped_directory.\\\$cdir.\\\$cwd" | |
10c5f0a8 YQ |
37 | } |
38 | gdb_test "python print (gdb.parameter ('directories'))" $directories | |
b521dba8 DE |
39 | |
40 | # Test a simple boolean parameter. | |
41 | gdb_py_test_multiple "Simple gdb booleanparameter" \ | |
42 | "python" "" \ | |
43 | "class TestParam (gdb.Parameter):" "" \ | |
44 | " \"\"\"When enabled, test param does something useful. When disabled, does nothing.\"\"\"" "" \ | |
ecec24e6 PM |
45 | " show_doc = \"Show the state of the boolean test-param\"" ""\ |
46 | " set_doc = \"Set the state of the boolean test-param\"" "" \ | |
47 | " def get_show_string (self, pvalue):" ""\ | |
48 | " return \"The state of the Test Parameter is \" + pvalue" ""\ | |
49 | " def get_set_string (self):" ""\ | |
50 | " val = \"on\"" ""\ | |
51 | " if (self.value == False):" ""\ | |
52 | " val = \"off\"" ""\ | |
53 | " return \"Test Parameter has been set to \" + val" ""\ | |
b521dba8 DE |
54 | " def __init__ (self, name):" "" \ |
55 | " super (TestParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \ | |
56 | " self.value = True" "" \ | |
57 | "test_param = TestParam ('print test-param')" ""\ | |
58 | "end" | |
59 | ||
cdc7edd7 LM |
60 | gdb_test "python print (test_param.value)" "True" "test parameter value" |
61 | gdb_test "show print test-param" "The state of the Test Parameter is on.*" "show parameter on" | |
62 | gdb_test "set print test-param off" "Test Parameter has been set to off" "turn off parameter" | |
63 | gdb_test "show print test-param" "The state of the Test Parameter is off.*" "show parameter off" | |
64 | gdb_test "python print (test_param.value)" "False" "test parameter value" | |
65 | gdb_test "help show print test-param" "Show the state of the boolean test-param.*" "test show help" | |
66 | gdb_test "help set print test-param" "Set the state of the boolean test-param.*" "test set help" | |
67 | gdb_test "help set print" "set print test-param -- Set the state of the boolean test-param.*" "test general help" | |
ecec24e6 | 68 | |
b521dba8 DE |
69 | |
70 | # Test an enum parameter. | |
71 | gdb_py_test_multiple "enum gdb parameter" \ | |
72 | "python" "" \ | |
73 | "class TestEnumParam (gdb.Parameter):" "" \ | |
74 | " \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \ | |
75 | " show_doc = \"Show the state of the enum\"" ""\ | |
76 | " set_doc = \"Set the state of the enum\"" "" \ | |
ecec24e6 PM |
77 | " def get_show_string (self, pvalue):" ""\ |
78 | " return \"The state of the enum is \" + pvalue" ""\ | |
79 | " def get_set_string (self):" ""\ | |
80 | " return \"The state of the enum has been set to \" + self.value" ""\ | |
b521dba8 DE |
81 | " def __init__ (self, name):" "" \ |
82 | " super (TestEnumParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_ENUM, \[\"one\", \"two\"\])" "" \ | |
83 | " self.value = \"one\"" "" \ | |
84 | "test_enum_param = TestEnumParam ('print test-enum-param')" ""\ | |
85 | "end" | |
86 | ||
cdc7edd7 LM |
87 | gdb_test "python print (test_enum_param.value)" "one" "test enum parameter value" |
88 | gdb_test "show print test-enum-param" "The state of the enum is one.*" "show parameter is initial value" | |
89 | gdb_test "set print test-enum-param two" "The state of the enum has been set to two" "set enum to two" | |
90 | gdb_test "show print test-enum-param" "The state of the enum is two.*" "show parameter is new value" | |
91 | gdb_test "python print (test_enum_param.value)" "two" "test enum parameter value" | |
92 | gdb_test "set print test-enum-param three" "Undefined item: \"three\".*" "set invalid enum parameter" | |
b521dba8 DE |
93 | |
94 | # Test a file parameter. | |
95 | gdb_py_test_multiple "file gdb parameter" \ | |
96 | "python" "" \ | |
97 | "class TestFileParam (gdb.Parameter):" "" \ | |
98 | " \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \ | |
99 | " show_doc = \"Show the name of the file\"" ""\ | |
100 | " set_doc = \"Set the name of the file\"" "" \ | |
ecec24e6 PM |
101 | " def get_show_string (self, pvalue):" ""\ |
102 | " return \"The name of the file is \" + pvalue" ""\ | |
103 | " def get_set_string (self):" ""\ | |
104 | " return \"The name of the file has been changed to \" + self.value" ""\ | |
b521dba8 DE |
105 | " def __init__ (self, name):" "" \ |
106 | " super (TestFileParam, self).__init__ (name, gdb.COMMAND_FILES, gdb.PARAM_FILENAME)" "" \ | |
107 | " self.value = \"foo.txt\"" "" \ | |
108 | "test_file_param = TestFileParam ('test-file-param')" ""\ | |
109 | "end" | |
110 | ||
cdc7edd7 LM |
111 | gdb_test "python print (test_file_param.value)" "foo.txt" "test file parameter value" |
112 | gdb_test "show test-file-param" "The name of the file is foo.txt.*" "show initial file value" | |
113 | gdb_test "set test-file-param bar.txt" "The name of the file has been changed to bar.txt" "set new file parameter" 1 | |
114 | gdb_test "show test-file-param" "The name of the file is bar.txt.*" "show new file value" | |
115 | gdb_test "python print (test_file_param.value)" "bar.txt" "test new file parameter value" | |
b521dba8 DE |
116 | gdb_test "set test-file-param" "Argument required.*" |
117 | ||
ecec24e6 PM |
118 | # Test a parameter that is not documented. |
119 | gdb_py_test_multiple "Simple gdb booleanparameter" \ | |
b521dba8 | 120 | "python" "" \ |
ecec24e6 PM |
121 | "class TestUndocParam (gdb.Parameter):" "" \ |
122 | " def get_show_string (self, pvalue):" ""\ | |
123 | " return \"The state of the Test Parameter is \" + pvalue" ""\ | |
124 | " def get_set_string (self):" ""\ | |
125 | " val = \"on\"" ""\ | |
126 | " if (self.value == False):" ""\ | |
127 | " val = \"off\"" ""\ | |
128 | " return \"Test Parameter has been set to \" + val" ""\ | |
b521dba8 | 129 | " def __init__ (self, name):" "" \ |
ecec24e6 PM |
130 | " super (TestUndocParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \ |
131 | " self.value = True" "" \ | |
132 | "test_undoc_param = TestUndocParam ('print test-undoc-param')" ""\ | |
b521dba8 DE |
133 | "end" |
134 | ||
cdc7edd7 LM |
135 | gdb_test "show print test-undoc-param" "The state of the Test Parameter is on.*" "show parameter on" |
136 | gdb_test "set print test-undoc-param off" "Test Parameter has been set to off" "turn off parameter" | |
137 | gdb_test "show print test-undoc-param" "The state of the Test Parameter is off.*" "show parameter off" | |
138 | gdb_test "python print (test_undoc_param.value)" "False" "test parameter value" | |
139 | gdb_test "help show print test-undoc-param" "This command is not documented.*" "test show help" | |
140 | gdb_test "help set print test-undoc-param" "This command is not documented.*" "test set help" | |
141 | gdb_test "help set print" "set print test-undoc-param -- This command is not documented.*" "test general help" | |
ecec24e6 PM |
142 | |
143 | # Test a parameter that is not documented in any way.. | |
144 | gdb_py_test_multiple "Simple gdb booleanparameter" \ | |
145 | "python" "" \ | |
146 | "class TestNodocParam (gdb.Parameter):" "" \ | |
147 | " def __init__ (self, name):" "" \ | |
148 | " super (TestNodocParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \ | |
149 | " self.value = True" "" \ | |
150 | "test_nodoc_param = TestNodocParam ('print test-nodoc-param')" ""\ | |
151 | "end" | |
152 | ||
cdc7edd7 LM |
153 | gdb_test "show print test-nodoc-param" "This command is not documented.*" "show parameter on" |
154 | gdb_test "set print test-nodoc-param off" "This command is not documented.*" "turn off parameter" | |
155 | gdb_test "show print test-nodoc-param" "This command is not documented.*.*" "show parameter off" | |
156 | gdb_test "python print (test_nodoc_param.value)" "False" "test parameter value" | |
157 | gdb_test "help show print test-nodoc-param" "This command is not documented.*" "test show help" | |
158 | gdb_test "help set print test-nodoc-param" "This command is not documented.*" "test set help" | |
159 | gdb_test "help set print" "set print test-nodoc-param -- This command is not documented.*" "test general help" | |
ecec24e6 PM |
160 | |
161 | # Test deprecated API. Do not use in your own implementations. | |
162 | gdb_py_test_multiple "Simple gdb booleanparameter" \ | |
163 | "python" "" \ | |
164 | "class TestParam (gdb.Parameter):" "" \ | |
165 | " \"\"\"When enabled, test param does something useful. When disabled, does nothing.\"\"\"" "" \ | |
166 | " show_doc = \"State of the Test Parameter\"" ""\ | |
167 | " set_doc = \"Set the state of the Test Parameter\"" "" \ | |
168 | " def __init__ (self, name):" "" \ | |
169 | " super (TestParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \ | |
170 | " self.value = True" "" \ | |
171 | "test_param = TestParam ('print test-param')" ""\ | |
172 | "end" | |
173 | ||
cdc7edd7 LM |
174 | gdb_test "python print (test_param.value)" "True" "test parameter value" |
175 | gdb_test "show print test-param" "State of the Test Parameter on.*" "show parameter on" | |
176 | gdb_test "set print test-param off" "Set the state of the Test Parameter.*" "turn off parameter" | |
177 | gdb_test "show print test-param" "State of the Test Parameter off.*" "show parameter off" | |
178 | gdb_test "python print (test_param.value)" "False" "test parameter value" | |
179 | gdb_test "help show print test-param" "State of the Test Parameter.*" "test show help" | |
180 | gdb_test "help set print test-param" "Set the state of the Test Parameter.*" "test set help" | |
181 | gdb_test "help set print" "set print test-param -- Set the state of the Test Parameter.*" "test general help" |