Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / a2-run.exp
CommitLineData
88b9d363 1# Copyright 1988-2022 Free Software Foundation, Inc.
c906108c
SS
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
c906108c 6# (at your option) any later version.
e22f8b7c 7#
c906108c
SS
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.
e22f8b7c 12#
c906108c 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 15
c906108c
SS
16# This file was written by Rob Savoye. (rob@cygnus.com)
17
958a4e4c
MS
18# Can't do this test without stdio support.
19if [gdb_skip_stdio_test "a2run.exp"] {
c906108c
SS
20 return
21}
22
c906108c
SS
23#
24# test running programs
25#
c906108c 26
a64d2530
TT
27standard_testfile run.c
28
5b362f04 29if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
b60f0898 30 return -1
c906108c
SS
31}
32
c906108c 33# Run with no arguments.
c906108c
SS
34gdb_run_cmd
35
77e760c3
PA
36set saw_usage 0
37set saw_exit_wrapper 0
38set saw_spurious_output 0
39
fa43b1d7
PA
40set test "run \"$testfile\" with no args"
41
145e3ddb
PA
42# Indirect spawn id lists. Used to be able to disable the inferior
43# and gdb's spawn_ids and regexes as soon as we see the expected
44# output.
77e760c3
PA
45set inferior_spawn_list "$inferior_spawn_id"
46set gdb_spawn_list "$gdb_spawn_id"
47
145e3ddb
PA
48# Clear either the gdb or the inferior spawn_id list and iff
49# afterwards we still have any spawn id in the indirect lists,
50# continue expecting.
51proc maybe_exp_continue {which} {
52 global inferior_spawn_list gdb_spawn_list
53
54 if {$which == "gdb"} {
55 set gdb_spawn_list ""
56 } elseif {$which == "inferior"} {
57 set inferior_spawn_list ""
58 } else {
59 error "invalid parameter"
60 }
61
62 if {$inferior_spawn_list != "" || $gdb_spawn_list != ""} {
63 exp_continue
64 }
65}
66
67# Note that if $inferior_spawn_id != $gdb_spawn_id the order we pick
68# output from each spawn id is undefined.
77e760c3
PA
69set res [gdb_test_multiple "" $test {
70 -i inferior_spawn_list
71 -re "usage: factorial <number>" {
72 set saw_usage 1
145e3ddb 73 maybe_exp_continue inferior
77e760c3
PA
74 }
75 -re "EXIT code 1" {
76 set saw_exit_wrapper 1
145e3ddb 77 maybe_exp_continue inferior
77e760c3
PA
78 }
79 eof {
80 if {$inferior_spawn_id != $gdb_spawn_id} {
81 # In this case we may see the server/inferior exit before
82 # GDB's program exit output. Remove from spawn list and
83 # continue waiting.
145e3ddb
PA
84 maybe_exp_continue inferior
85 } else {
86 # GDB crash.
87 fail "$test (eof)"
77e760c3 88 }
77e760c3
PA
89 }
90
91 -i gdb_spawn_list
92
93 -re "$inferior_exited_re with code 01.\r\n$gdb_prompt $" {
145e3ddb 94 maybe_exp_continue gdb
428b16bd 95 }
77e760c3
PA
96 -re "$inferior_exited_re with code 01.*$gdb_prompt $" {
97 set saw_spurious_output 1
145e3ddb 98 maybe_exp_continue gdb
428b16bd 99 }
77e760c3
PA
100
101 -re "$inferior_exited_re normally.\r\n$gdb_prompt $" {
102 # This is only considered a pass if we see the exit wrapper
145e3ddb
PA
103 # status.
104 maybe_exp_continue gdb
428b16bd 105 }
77e760c3
PA
106 -re "$inferior_exited_re normally.*$gdb_prompt $" {
107 set saw_spurious_output 1
145e3ddb 108 maybe_exp_continue gdb
c906108c 109 }
77e760c3
PA
110}]
111
112if {$res == 0} {
113 gdb_assert ${saw_usage} $test
114
115 if {$saw_exit_wrapper} {
116 set msg "$test (exit wrapper)"
117 } else {
118 set msg $test
119 }
120
121 gdb_assert !$saw_spurious_output "no spurious messages at program exit"
122
c906108c 123}
154189a4
FF
124
125# The remaining tests don't work for targets can't take arguments...
126
127if [target_info exists noargs] then {
128 verbose "Skipping rest of a2-run.exp because of noargs."
129 return
130}
131
c906108c 132# Now run with some arguments
428b16bd
PA
133setup_xfail "arm-*-coff"
134gdb_run_cmd 5
77e760c3 135gdb_test_stdio "" "120" "" "run \"$testfile\" with arg"
c906108c
SS
136
137# Run again with same arguments.
75d04512 138gdb_run_cmd 5
c906108c 139
428b16bd 140setup_xfail "arm-*-coff"
77e760c3 141gdb_test_stdio "" "120" "" "run \"$testfile\" again with same args"
c906108c
SS
142
143# Use "set args" command to specify no arguments as default and run again.
428b16bd 144gdb_test_no_output "set args"
c906108c
SS
145
146gdb_run_cmd
147
77e760c3 148gdb_test_stdio "" "usage: factorial <number>" "" "run after setting args to nil"
c906108c 149
75d04512
SM
150# The remaining tests pass inferior arguments through GDB, so doesn't
151# work with stub targets, where GDB connects to debug an already started
152# process.
153
154if [use_gdb_stub] {
155 verbose "Skipping rest of a2-run.exp because target is a stub."
156 return
157}
158
c906108c 159# Use "set args" command to specify an argument and run again.
428b16bd 160gdb_test_no_output "set args 6"
6acb16a2 161
c906108c
SS
162gdb_run_cmd
163
428b16bd 164setup_xfail "arm-*-coff"
77e760c3 165gdb_test_stdio "" "720" "" "run \"$testfile\" again after setting args"
c906108c
SS
166
167# GOAL: Test that shell is being used with "run". For remote debugging
168# targets, there is no guarantee that a "shell" (whatever that is) is used.
676a0442 169if ![is_remote target] then {
77e760c3
PA
170 gdb_test_stdio "run `echo 8`" \
171 "40320" "" "run \"$testfile\" with shell"
c906108c 172}
This page took 2.36581 seconds and 4 git commands to generate.