OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [gdb-7.2/] [gdb-7.2-or32-1.0rc1/] [gdb/] [testsuite/] [gdb.python/] [py-cmd.exp] - Blame information for rev 341

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 330 jeremybenn
# Copyright (C) 2009, 2010 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 .
15
 
16
# This file is part of the GDB testsuite.  It tests the mechanism
17
# for defining new GDB commands in Python.
18
 
19
if $tracelevel then {
20
    strace $tracelevel
21
}
22
 
23
# Usage: gdb_py_test_multiple NAME INPUT RESULT {INPUT RESULT}...
24
# Run a test named NAME, consisting of multiple lines of input.
25
# After each input line INPUT, search for result line RESULT.
26
# Succeed if all results are seen; fail otherwise.
27
proc gdb_py_test_multiple {name args} {
28
    global gdb_prompt
29
    foreach {input result} $args {
30
        if {[gdb_test_multiple $input "$name - $input" {
31
            -re "\[\r\n\]*($result)\[\r\n\]+($gdb_prompt | *>)$" {
32
                pass "$name - $input"
33
            }
34
        }]} {
35
            return 1
36
        }
37
    }
38
    return 0
39
}
40
 
41
# Start with a fresh gdb.
42
 
43
gdb_exit
44
gdb_start
45
gdb_reinitialize_dir $srcdir/$subdir
46
 
47
# Skip all tests if Python scripting is not enabled.
48
if { [skip_python_tests] } { continue }
49
 
50
# Test a simple command.
51
 
52
gdb_py_test_multiple "input simple command" \
53
  "python" "" \
54
  "class test_cmd (gdb.Command):" "" \
55
  "  def __init__ (self):" "" \
56
  "    super (test_cmd, self).__init__ (\"test_cmd\", gdb.COMMAND_OBSCURE)" "" \
57
  "  def invoke (self, arg, from_tty):" "" \
58
  "    print \"test_cmd output, arg = %s\" % arg" "" \
59
  "test_cmd ()" "" \
60
  "end" ""
61
 
62
gdb_test "test_cmd ugh" "test_cmd output, arg = ugh" "call simple command"
63
 
64
# Test a prefix command, and a subcommand within it.
65
 
66
gdb_py_test_multiple "input prefix command" \
67
  "python" "" \
68
  "class prefix_cmd (gdb.Command):" "" \
69
  "  def __init__ (self):" "" \
70
  "    super (prefix_cmd, self).__init__ (\"prefix_cmd\", gdb.COMMAND_OBSCURE, gdb.COMPLETE_NONE, True)" "" \
71
  "  def invoke (self, arg, from_tty):" "" \
72
  "    print \"prefix_cmd output, arg = %s\" % arg" "" \
73
  "prefix_cmd ()" "" \
74
  "end" ""
75
 
76
gdb_test "prefix_cmd ugh" "prefix_cmd output, arg = ugh" "call prefix command"
77
 
78
gdb_py_test_multiple "input subcommand" \
79
  "python" "" \
80
  "class subcmd (gdb.Command):" "" \
81
  "  def __init__ (self):" "" \
82
  "    super (subcmd, self).__init__ (\"prefix_cmd subcmd\", gdb.COMMAND_OBSCURE)" "" \
83
  "  def invoke (self, arg, from_tty):" "" \
84
  "    print \"subcmd output, arg = %s\" % arg" "" \
85
  "subcmd ()" "" \
86
  "end" ""
87
 
88
gdb_test "prefix_cmd subcmd ugh" "subcmd output, arg = ugh" "call subcmd"
89
 
90
# Test prefix command using keyword arguments.
91
 
92
gdb_py_test_multiple "input prefix command, keyword arguments" \
93
  "python" "" \
94
  "class prefix_cmd2 (gdb.Command):" "" \
95
  "  def __init__ (self):" "" \
96
  "    super (prefix_cmd2, self).__init__ (\"prefix_cmd2\", gdb.COMMAND_OBSCURE, prefix = True, completer_class = gdb.COMPLETE_FILENAME)" "" \
97
  "  def invoke (self, arg, from_tty):" "" \
98
  "    print \"prefix_cmd2 output, arg = %s\" % arg" "" \
99
  "prefix_cmd2 ()" "" \
100
  "end" ""
101
 
102
gdb_test "prefix_cmd2 argh" "prefix_cmd2 output, arg = argh" "call prefix command, keyword arguments"
103
 
104
gdb_py_test_multiple "input subcommand under prefix_cmd2" \
105
  "python" "" \
106
  "class subcmd (gdb.Command):" "" \
107
  "  def __init__ (self):" "" \
108
  "    super (subcmd, self).__init__ (\"prefix_cmd2 subcmd\", gdb.COMMAND_OBSCURE)" "" \
109
  "  def invoke (self, arg, from_tty):" "" \
110
  "    print \"subcmd output, arg = %s\" % arg" "" \
111
  "subcmd ()" "" \
112
  "end" ""
113
 
114
gdb_test "prefix_cmd2 subcmd ugh" "subcmd output, arg = ugh" "call subcmd under prefix_cmd2"
115
 
116
# Test a subcommand in an existing GDB prefix.
117
 
118
gdb_py_test_multiple "input new subcommand" \
119
  "python" "" \
120
  "class newsubcmd (gdb.Command):" "" \
121
  "  def __init__ (self):" "" \
122
  "    super (newsubcmd, self).__init__ (\"info newsubcmd\", gdb.COMMAND_OBSCURE)" "" \
123
  "  def invoke (self, arg, from_tty):" "" \
124
  "    print \"newsubcmd output, arg = %s\" % arg" "" \
125
  "newsubcmd ()" "" \
126
  "end" ""
127
 
128
gdb_test "info newsubcmd ugh" "newsubcmd output, arg = ugh" "call newsubcmd"
129
 
130
# Test a command that throws gdb.GdbError.
131
 
132
gdb_py_test_multiple "input command to throw error" \
133
  "python" "" \
134
  "class test_error_cmd (gdb.Command):" "" \
135
  "  def __init__ (self):" "" \
136
  "    super (test_error_cmd, self).__init__ (\"test_error_cmd\", gdb.COMMAND_OBSCURE)" "" \
137
  "  def invoke (self, arg, from_tty):" "" \
138
  "    raise gdb.GdbError ('you lose!')" "" \
139
  "test_error_cmd ()" "" \
140
  "end" ""
141
 
142
gdb_test "test_error_cmd ugh" "you lose!" "call error command"
143
 
144
# Test gdb.string_to_argv.
145
 
146
gdb_test "python print gdb.string_to_argv (\"1 2 3\")" \
147
  {\['1', '2', '3'\]} \
148
  "string_to_argv (\"1 2 3\")"
149
 
150
gdb_test "python print gdb.string_to_argv (\"'1 2' 3\")" \
151
  {\['1 2', '3'\]} \
152
  "string_to_argv (\"'1 2' 3\")"
153
 
154
gdb_test "python print gdb.string_to_argv ('\"1 2\" 3')" \
155
  {\['1 2', '3'\]} \
156
  "string_to_argv ('\"1 2\" 3')"
157
 
158
gdb_test "python print gdb.string_to_argv ('1\\ 2 3')" \
159
  {\['1 2', '3'\]} \
160
    "string_to_argv ('1\\ 2 3')"

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.