1 # Copyright
2015-2019 Free Software Foundation
, Inc.
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.
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.
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
/>.
16 # Generic
/oft used support routines
for testing GDB
's compile feature.
18 # Return 1 if we should skip tests of the "compile" feature.
19 # This must be invoked after the inferior has been started.
21 proc skip_compile_feature_tests {} {
25 gdb_test_multiple "compile code -- ;" "check for working compile command" {
26 "Could not load libcc1.*\r\n$gdb_prompt $" {
29 -re "Command not supported on this host\\..*\r\n$gdb_prompt $" {
32 -re "\r\n$gdb_prompt $" {
38 # This namespace provides some convenience functions for running
39 # "compile code" and "compile print" tests.
41 # Exported functions are defined inline below.
45 # Start a new session, noting that the variable "var" will be used for
46 # "compile code" expressions. This variable /must/ exist in the stopped
49 # CompileExpression::new "var"
51 # Test the implicit expression "foo;" with result/value 3.
52 # CompileExpression::test "foo" 3
53 # ---> Runs the following tests (name of tests ignored for illustration)
54 # gdb_test_no_output "compile code var = foo"
55 # gdb_test "p var" "= 3"
56 # gdb_test "compile print foo;" "= 3"
58 # Test the explicit expression "a = function (3); var = a;" with the result 21.
59 # CompileExpression::test "a = function (3); var = a;" 21 -explicit
60 # ---> Runs the following tests (name of tests ignored for illustration)
61 # gdb_test_no_output "compile code a = function (3); var = a;"
62 # gdb_test "p var" "= 21"
64 # Additional option flags may be passed to test to control the behavior
65 # of the test harness:
67 # Pass -explicit to specify that the test uses an explicit expression,
68 # one which sets the value of the variable (see above). Only the code test
71 # Pass -value and/or -print to indicate that the value and/or print steps
72 # will optionally fail. Specify "xfail" or "kfail" to indicate how
73 # particular step will fail. These may be followed by any accepted DejaGNU
74 # parameters such as architecture and bug#. [See examples below.]
76 # To specify that the compile (and consequently print and value tests) is
77 # expected to kfail/xfail, use -kfail or -xfail with any appropriate
78 # DejaGNU parameters. Both options override -print and -value.
79 # [-xfail is given precedence over -kfail should both be given.]
81 # -value is used when a "code" test is run, specifying that the "compile
82 # code" and "print VAR" steps will fail in the prescribed manner.
83 # [If the print step generates a PASS, the test is considered invalidly
84 # written. VAR's value should
/always
/ be invalidated before a test is
87 #
-print is used to specify that an expression will fail in the prescribed
88 # manner when
"print" test is executed.
90 # Pass
"-name NAME" to set an optional test name. If not specified,
91 # the harness will use test names such as
"compile code EXPR" and
92 #
"result of compile code EXPR".
94 # Pass
"-noprint" or "-nocode" to suppress print or code tests, respectively,
95 # This is useful when the expression being tested modifies the object
96 # being tested
, e.g.
, "a++".
98 # These options must be passed LAST to CompileExpression
::test.
102 # Both
"code" and "print" tests are expected to xfail:
103 # CompileExpression add_imp
"foo" 3 -compile {xfail *-*-*} -print {xfail *-*-*}
105 # The
"print $VARIABLE" portion of the "code" test is expected to kfail
106 #
(the actual
"compile code" GDB command will succeed), but the "print"
108 # CompileExpression add_imp
"foo" 3 -value {kfail *-*-* gdb/1234}
110 namespace eval
::CompileExpression
{
112 # The
variable name to check testing results. This
variable
113 # must be in scope when tests are run.
116 # Start a new expression list. VARNAME is the
name of the
variable
117 # that will be printed to check
if the result of the test was
122 set varName_ $varname
125 # Test an expression.
127 # See the preamble
for a list of valid optional arguments.
129 # Implicit expressions will be sent to GDB in the form
130 #
"$varName = $EXP". "p $varName" will be used to decide the pass
131 # or fail
status of the test.
133 # Explicit expressions will be sent to GDB as
-is and tested using only
134 #
"compile code". The expression should set the value of the variable
135 # $varName
, which is
then printed to determine whether the test passed
138 # Unlike explicit expressions
, implicit expressions are tested with both
139 #
"compile print" and "compile code".
141 proc test
{exp result
args} {
142 parse_args
{{value
{"" ""}} {print {"" ""}} {name ""}
143 {noprint} {nocode
} {explicit
} {xfail
{"" ""}} {kfail {"" ""}}}
145 if {[lindex $xfail
0] != ""} {
147 } elseif
{[lindex $kfail
0] != ""} {
160 do_test_ code $exp $result $explicit $
name \
161 [list $
compile $value $print
]
164 do_test_ print $exp $result $explicit $
name \
165 [list $
compile $value $print
]
169 # Run a
compile test
for CMD
("print" or "code").
171 proc do_test_
{cmd exp result is_explicit tst fail_list
} {
174 if {![string match $cmd
"code"]
175 && ![string match $cmd
"print"]} {
176 error
"invalid command, $cmd; should be \"print\" or \"compile\""
179 #
Get expected result of test. Will be
"" if test is
181 lassign $fail_list fail_compile fail_value fail_print
183 #
Set a test
name if one hasn
't been provided.
185 set tst "compile $cmd $exp"
188 if {[string match $cmd "print"]} {
190 eval setup_failures_ $fail_print
191 gdb_test "compile print $exp" $result $tst
195 set command "compile code $exp"
197 set command "compile code $varName_ = $exp"
199 eval setup_failures_ $fail_compile
200 gdb_test_no_output $command $tst
201 eval setup_failures_ $fail_value
202 gdb_test "p $varName_" "= $result" "result of $tst"
206 # A convenience proc used to set up xfail and kfail tests.
207 # HOW is either xfail or kfail (case is ignored). ARGS is any
208 # optional architecture, bug number, or other string to pass to
209 # respective DejaGNU setup_$how routines.
211 proc setup_failures_ {how args} {
212 switch -nocase $how {
214 eval setup_xfail $args
218 eval setup_kfail $args
222 # Do nothing. Either the test is expected to PASS
223 # or we have an unhandled failure mode.