1 # Copyright 1988-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 # This file was written by Rob Savoye. (rob@cygnus.com)
18 # Can't do this test without stdio support.
19 if [gdb_skip_stdio_test "a2run.exp"] {
24 # test running programs
27 standard_testfile run.c
29 if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
33 # Run with no arguments.
37 set saw_exit_wrapper 0
38 set saw_spurious_output 0
40 set test "run \"$testfile\" with no args"
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
45 set inferior_spawn_list "$inferior_spawn_id"
46 set gdb_spawn_list "$gdb_spawn_id"
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,
51 proc maybe_exp_continue {which} {
52 global inferior_spawn_list gdb_spawn_list
54 if {$which == "gdb"} {
56 } elseif {$which == "inferior"} {
57 set inferior_spawn_list ""
59 error "invalid parameter"
62 if {$inferior_spawn_list != "" || $gdb_spawn_list != ""} {
67 # Note that if $inferior_spawn_id != $gdb_spawn_id the order we pick
68 # output from each spawn id is undefined.
69 set res [gdb_test_multiple "" $test {
70 -i inferior_spawn_list
71 -re "usage: factorial <number>" {
73 maybe_exp_continue inferior
76 set saw_exit_wrapper 1
77 maybe_exp_continue inferior
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
84 maybe_exp_continue inferior
93 -re "$inferior_exited_re with code 01.\r\n$gdb_prompt $" {
94 maybe_exp_continue gdb
96 -re "$inferior_exited_re with code 01.*$gdb_prompt $" {
97 set saw_spurious_output 1
98 maybe_exp_continue gdb
101 -re "$inferior_exited_re normally.\r\n$gdb_prompt $" {
102 # This is only considered a pass if we see the exit wrapper
104 maybe_exp_continue gdb
106 -re "$inferior_exited_re normally.*$gdb_prompt $" {
107 set saw_spurious_output 1
108 maybe_exp_continue gdb
113 gdb_assert ${saw_usage} $test
115 if {$saw_exit_wrapper} {
116 set msg "$test (exit wrapper)"
121 gdb_assert !$saw_spurious_output "no spurious messages at program exit"
125 # The remaining tests don't work for targets can't take arguments...
127 if [target_info exists noargs] then {
128 verbose "Skipping rest of a2-run.exp because of noargs."
132 # Now run with some arguments
133 setup_xfail "arm-*-coff"
135 gdb_test_stdio "" "120" "" "run \"$testfile\" with arg"
137 # Run again with same arguments.
140 setup_xfail "arm-*-coff"
141 gdb_test_stdio "" "120" "" "run \"$testfile\" again with same args"
143 # Use "set args" command to specify no arguments as default and run again.
144 gdb_test_no_output "set args"
148 gdb_test_stdio "" "usage: factorial <number>" "" "run after setting args to nil"
150 # Use "set args" command to specify an argument and run again.
151 gdb_test_no_output "set args 6"
155 setup_xfail "arm-*-coff"
156 gdb_test_stdio "" "720" "" "run \"$testfile\" again after setting args"
158 # GOAL: Test that shell is being used with "run". For remote debugging
159 # targets, there is no guarantee that a "shell" (whatever that is) is used.
160 if ![is_remote target] then {
161 gdb_test_stdio "run `echo 8`" \
162 "40320" "" "run \"$testfile\" with shell"