diff options
author | Phil Muldoon <pmuldoon@redhat.com> | 2010-04-29 15:45:57 +0000 |
---|---|---|
committer | Phil Muldoon <pmuldoon@redhat.com> | 2010-04-29 15:45:57 +0000 |
commit | d7b32ed3aba175979887a8e870c27a6a7aa687ec (patch) | |
tree | 3f5880c7f84b784ae395fe840d88ab9634b860d2 /gdb/testsuite/gdb.python/py-param.exp | |
parent | ce72ce41398df29a9e884768ed5bcf6bcbc20b2b (diff) | |
download | gdb-d7b32ed3aba175979887a8e870c27a6a7aa687ec.zip gdb-d7b32ed3aba175979887a8e870c27a6a7aa687ec.tar.gz gdb-d7b32ed3aba175979887a8e870c27a6a7aa687ec.tar.bz2 |
2010-04-29 Phil Muldoon <pmuldoon@redhat.com>
Tom Tromey <tromey@redhat.com>
Thiago Jung Bauermann <bauerman@br.ibm.com>
* Makefile.in (SUBDIR_PYTHON_OBS): Add py-parameter.
(SUBDIR_PYTHON_SRCS): Likewise.
(py-parameter.o): New rule.
* python/py-parameter.c: New file.
* python/python-internal.h (gdbpy_initialize_parameter)
(gdbpy_parameter, gdbpy_parameter_value)
(gdbpy_parse_command_name): Declare.
* python/py-cmd.c (parse_command_name): Rename to
gdbpy_parse_command_name.
(gdbpy_parse_command_name): Accept a starting list parameter and
use over cmdlist.
(cmdpy_init): Use gdbpy_parse_command_name.
* python/python.c (parameter_to_python): Rename to
gdbpy_parameter_to_python. Accept enum var_types and value.
(gdbpy_parameter): Use gdbpy_parameter_value.
(_initialize_python): Call gdbpy_initialize_parameters.
2010-04-29 Phil Muldoon <pmuldoon@redhat.com>
* gdb.python/py-param.exp: New File.
2010-04-29 Phil Muldoon <pmuldoon@redhat.com>
Tom Tromey <tromey@redhat.com>
Thiago Jung Bauermann <bauerman@br.ibm.com>
* gdb.texinfo (Parameters In Python): New Node.
Diffstat (limited to 'gdb/testsuite/gdb.python/py-param.exp')
-rw-r--r-- | gdb/testsuite/gdb.python/py-param.exp | 140 |
1 files changed, 140 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.python/py-param.exp b/gdb/testsuite/gdb.python/py-param.exp new file mode 100644 index 0000000..6c0ff97 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-param.exp @@ -0,0 +1,140 @@ +# Copyright (C) 2010 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# This file is part of the GDB testsuite. It tests the mechanism +# exposing convenience functions to Python. + +if $tracelevel then { + strace $tracelevel +} + +# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}... +# Run a test named NAME, consisting of multiple lines of input. +# After each input line INPUT, search for result line RESULT. +# Succeed if all results are seen; fail otherwise. +proc gdb_py_test_multiple {name args} { + global gdb_prompt + foreach {input result} $args { + if {[gdb_test_multiple $input "$name - $input" { + -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" { + pass "$name - $input" + } + }]} { + return 1 + } + } + return 0 +} + +# Run a command in GDB, and report a failure if a Python exception is thrown. +# If report_pass is true, report a pass if no exception is thrown. +proc gdb_py_test_silent_cmd {cmd name report_pass} { + global gdb_prompt + + gdb_test_multiple $cmd $name { + -re "Traceback.*$gdb_prompt $" { fail $name } + -re "$gdb_prompt $" { if $report_pass { pass $name } } + } +} + +# Start with a fresh gdb. +gdb_exit +gdb_start +gdb_reinitialize_dir $srcdir/$subdir + +# Skip all tests if Python scripting is not enabled. +if { [skip_python_tests] } { continue } + +# Test a simple boolean parameter. +gdb_py_test_multiple "Simple gdb booleanparameter" \ + "python" "" \ + "class TestParam (gdb.Parameter):" "" \ + " \"\"\"When enabled, test param does something useful. When disabled, does nothing.\"\"\"" "" \ + " show_doc = \"Show whether the state of the Test Parameter does something useful\"" ""\ + " set_doc = \"Set whether the state of the Test Parameter does something useful\"" "" \ + " def __init__ (self, name):" "" \ + " super (TestParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_BOOLEAN)" "" \ + " self.value = True" "" \ + "test_param = TestParam ('print test-param')" ""\ + "end" + +gdb_test "python print test_param.value" "True" "Test parameter value" +gdb_test "show print test-param" "Whether the state of the Test Parameter does something useful is on.*" "Show parameter on" +gdb_py_test_silent_cmd "set print test-param off" "Turn off parameter" 1 +gdb_test "show print test-param" "Whether the state of the Test Parameter does something useful is off.*" "Show parameter off" +gdb_test "python print test_param.value" "False" "Test parameter value" +gdb_test "help show print test-param" "Show whether the state of the Test Parameter does something useful.*" "Test show help" +gdb_test "help set print test-param" "Set whether the state of the Test Parameter does something useful.*" "Test set help" +gdb_test "help set print" "set print test-param -- Set whether the state of the Test Parameter.*" "Test general help" + +# Test an enum parameter. +gdb_py_test_multiple "enum gdb parameter" \ + "python" "" \ + "class TestEnumParam (gdb.Parameter):" "" \ + " \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \ + " show_doc = \"Show the state of the enum\"" ""\ + " set_doc = \"Set the state of the enum\"" "" \ + " def __init__ (self, name):" "" \ + " super (TestEnumParam, self).__init__ (name, gdb.COMMAND_DATA, gdb.PARAM_ENUM, \[\"one\", \"two\"\])" "" \ + " self.value = \"one\"" "" \ + "test_enum_param = TestEnumParam ('print test-enum-param')" ""\ + "end" + +gdb_test "python print test_enum_param.value" "one" "Test enum parameter value" +gdb_test "show print test-enum-param" "The state of the enum is \"one\".*" "Show parameter is initial value" +gdb_py_test_silent_cmd "set print test-enum-param two" "Set parameter to enum value" 1 +gdb_test "show print test-enum-param" "The state of the enum is \"two\".*" "Show parameter is new value" +gdb_test "python print test_enum_param.value" "two" "Test enum parameter value" +gdb_test "set print test-enum-param three" "Undefined item: \"three\".*" "Set invalid enum parameter" + +# Test a file parameter. +gdb_py_test_multiple "file gdb parameter" \ + "python" "" \ + "class TestFileParam (gdb.Parameter):" "" \ + " \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \ + " show_doc = \"Show the name of the file\"" ""\ + " set_doc = \"Set the name of the file\"" "" \ + " def __init__ (self, name):" "" \ + " super (TestFileParam, self).__init__ (name, gdb.COMMAND_FILES, gdb.PARAM_FILENAME)" "" \ + " self.value = \"foo.txt\"" "" \ + "test_file_param = TestFileParam ('test-file-param')" ""\ + "end" + +gdb_test "python print test_file_param.value" "foo.txt" "Test file parameter value" +gdb_test "show test-file-param" "The name of the file is \"foo.txt\".*" "Show initial file value" +gdb_py_test_silent_cmd "set test-file-param bar.txt" "Set new file parameter" 1 +gdb_test "show test-file-param" "The name of the file is \"bar.txt\".*" "Show new file value" +gdb_test "python print test_file_param.value" "bar.txt" "Test new file parameter value" +gdb_test "set test-file-param" "Argument required.*" + +# Test a file parameter. +gdb_py_test_multiple "file gdb parameter" \ + "python" "" \ + "class TestFileParam (gdb.Parameter):" "" \ + " \"\"\"When set, test param does something useful. When disabled, does nothing.\"\"\"" "" \ + " show_doc = \"Show the name of the file\"" ""\ + " set_doc = \"Set the name of the file\"" "" \ + " def __init__ (self, name):" "" \ + " super (TestFileParam, self).__init__ (name, gdb.COMMAND_FILES, gdb.PARAM_FILENAME)" "" \ + " self.value = \"foo.txt\"" "" \ + "test_file_param = TestFileParam ('test-file-param')" ""\ + "end" + +gdb_test "python print test_file_param.value" "foo.txt" "Test parameter value" +gdb_test "show test-file-param" "The name of the file is \"foo.txt\".*" "Show parameter on" +gdb_py_test_silent_cmd "set test-file-param bar.txt" "Turn off parameter" 1 +gdb_test "show test-file-param" "The name of the file is \"bar.txt\".*" "Show parameter on" +gdb_test "python print test_file_param.value" "bar.txt" "Test parameter value" +gdb_test "set test-file-param" "Argument required.*" |