1 # Copyright
1988-2023 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 # This file was written by Rob Savoye.
(rob@cygnus.com
)
18 # Can
't do this test without stdio support.
19 require {!gdb_skip_stdio_test "a2run.exp"}
22 # test running programs
25 standard_testfile run.c
29 lappend_include_file flags $srcdir/lib/unbuffer_output.c
31 if { [prepare_for_testing "failed to prepare" $testfile $srcfile $flags] } {
35 # Run with no arguments.
39 set saw_exit_wrapper 0
40 set saw_spurious_output 0
42 set test "run \"$testfile\" with no args"
44 # Indirect spawn id lists. Used to be able to disable the inferior
45 # and gdb's spawn_ids and regexes as soon as we see the expected
47 set inferior_spawn_list
"$inferior_spawn_id"
48 set gdb_spawn_list
"$gdb_spawn_id"
50 # Clear either the gdb or the inferior spawn_id list and iff
51 # afterwards we still have
any spawn id in the indirect lists
,
53 proc maybe_exp_continue
{which
} {
54 global inferior_spawn_list gdb_spawn_list
56 if {$which
== "gdb"} {
58 } elseif
{$which
== "inferior"} {
59 set inferior_spawn_list
""
61 error
"invalid parameter"
64 if {$inferior_spawn_list
!= "" || $gdb_spawn_list != ""} {
69 # Note that
if $inferior_spawn_id
!= $gdb_spawn_id the order we pick
70 # output from each spawn id is undefined.
71 set res
[gdb_test_multiple
"" $test {
72 -i inferior_spawn_list
73 -re
"usage: factorial <number>" {
75 maybe_exp_continue inferior
78 set saw_exit_wrapper
1
79 maybe_exp_continue inferior
82 if {$inferior_spawn_id
!= $gdb_spawn_id
} {
83 # In this case we may see the server
/inferior exit before
84 # GDB
's program exit output. Remove from spawn list and
86 maybe_exp_continue inferior
95 -re "$inferior_exited_re with code 01.\r\n$gdb_prompt $" {
96 maybe_exp_continue gdb
98 -re "$inferior_exited_re with code 01.*$gdb_prompt $" {
99 set saw_spurious_output 1
100 maybe_exp_continue gdb
103 -re "$inferior_exited_re normally.\r\n$gdb_prompt $" {
104 # This is only considered a pass if we see the exit wrapper
106 maybe_exp_continue gdb
108 -re "$inferior_exited_re normally.*$gdb_prompt $" {
109 set saw_spurious_output 1
110 maybe_exp_continue gdb
115 gdb_assert ${saw_usage} $test
117 if {$saw_exit_wrapper} {
118 set msg "$test (exit wrapper)"
123 gdb_assert !$saw_spurious_output "no spurious messages at program exit"
127 # The remaining tests don't work
for targets can
't take arguments...
129 if {[target_info exists noargs]} {
130 verbose "Skipping rest of a2-run.exp because of noargs."
134 # Now run with some arguments
135 setup_xfail "arm-*-coff"
137 gdb_test_stdio "" "120" "" "run \"$testfile\" with arg"
139 # Run again with same arguments.
142 setup_xfail "arm-*-coff"
143 gdb_test_stdio "" "120" "" "run \"$testfile\" again with same args"
145 # Use "set args" command to specify no arguments as default and run again.
146 gdb_test_no_output "set args"
150 gdb_test_stdio "" "usage: factorial <number>" "" "run after setting args to nil"
152 # The remaining tests pass inferior arguments through GDB, so doesn't
153 # work with stub targets
, where GDB connects to debug an already started
157 verbose
"Skipping rest of a2-run.exp because target is a stub."
161 # Use
"set args" command to specify an argument and run again.
162 gdb_test_no_output
"set args 6"
166 setup_xfail
"arm-*-coff"
167 gdb_test_stdio
"" "720" "" "run \"$testfile\" again after setting args"
169 # GOAL
: Test that
shell is being used with
"run". For remote debugging
170 # targets
, there is no guarantee that a
"shell" (whatever that is) is used.
171 if {![is_remote target
]} {
172 gdb_test_stdio
"run `echo 8`" \
173 "40320" "" "run \"$testfile\" with shell"