1# Copyright 1988-2020 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 <http://www.gnu.org/licenses/>. 15 16# This file was written by Rob Savoye. (rob@cygnus.com) 17 18# Can't do this test without stdio support. 19if [gdb_skip_stdio_test "a2run.exp"] { 20 return 21} 22 23# 24# test running programs 25# 26 27standard_testfile run.c 28 29if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } { 30 return -1 31} 32 33# Run with no arguments. 34gdb_run_cmd 35 36set saw_usage 0 37set saw_exit_wrapper 0 38set saw_spurious_output 0 39 40set test "run \"$testfile\" with no args" 41 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. 45set inferior_spawn_list "$inferior_spawn_id" 46set gdb_spawn_list "$gdb_spawn_id" 47 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. 69set res [gdb_test_multiple "" $test { 70 -i inferior_spawn_list 71 -re "usage: factorial <number>" { 72 set saw_usage 1 73 maybe_exp_continue inferior 74 } 75 -re "EXIT code 1" { 76 set saw_exit_wrapper 1 77 maybe_exp_continue inferior 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. 84 maybe_exp_continue inferior 85 } else { 86 # GDB crash. 87 fail "$test (eof)" 88 } 89 } 90 91 -i gdb_spawn_list 92 93 -re "$inferior_exited_re with code 01.\r\n$gdb_prompt $" { 94 maybe_exp_continue gdb 95 } 96 -re "$inferior_exited_re with code 01.*$gdb_prompt $" { 97 set saw_spurious_output 1 98 maybe_exp_continue gdb 99 } 100 101 -re "$inferior_exited_re normally.\r\n$gdb_prompt $" { 102 # This is only considered a pass if we see the exit wrapper 103 # status. 104 maybe_exp_continue gdb 105 } 106 -re "$inferior_exited_re normally.*$gdb_prompt $" { 107 set saw_spurious_output 1 108 maybe_exp_continue gdb 109 } 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 123} 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 132# Now run with some arguments 133setup_xfail "arm-*-coff" 134gdb_run_cmd 5 135gdb_test_stdio "" "120" "" "run \"$testfile\" with arg" 136 137# Run again with same arguments. 138gdb_run_cmd 5 139 140setup_xfail "arm-*-coff" 141gdb_test_stdio "" "120" "" "run \"$testfile\" again with same args" 142 143# Use "set args" command to specify no arguments as default and run again. 144gdb_test_no_output "set args" 145 146gdb_run_cmd 147 148gdb_test_stdio "" "usage: factorial <number>" "" "run after setting args to nil" 149 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 159# Use "set args" command to specify an argument and run again. 160gdb_test_no_output "set args 6" 161 162gdb_run_cmd 163 164setup_xfail "arm-*-coff" 165gdb_test_stdio "" "720" "" "run \"$testfile\" again after setting args" 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. 169if ![is_remote target] then { 170 gdb_test_stdio "run `echo 8`" \ 171 "40320" "" "run \"$testfile\" with shell" 172} 173