1# Copyright 1988-2013 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 27set testfile a2-run 28if { [prepare_for_testing ${testfile}.exp $testfile run.c] } { 29 return -1 30} 31 32# Run with no arguments. 33# On VxWorks this justs make sure the program was run. 34gdb_run_cmd 35 36if [istarget "*-*-vxworks*"] then { 37 set timeout 120 38 verbose "Timeout is now $timeout seconds" 2 39 gdb_expect { 40 "$inferior_exited_re normally" { 41 unresolved "run \"$testfile\" with no args" 42 } 43 -re "usage: factorial <number>" { 44 pass "run \"$testfile\" with no args" 45 } 46 timeout { 47 fail "(timeout) run \"$testfile\" with no args" 48 } 49 } 50 set timeout 10 51 verbose "Timeout is now $timeout seconds" 2 52 gdb_expect -re "$gdb_prompt $" {} 53} else { 54 gdb_expect { 55 -re ".*usage: factorial <number>.*$inferior_exited_re with code 01.\r\n$gdb_prompt $" { 56 pass "run \"$testfile\" with no args" 57 pass "no spurious messages at program exit" 58 } 59 -re ".*usage: factorial <number>.*$inferior_exited_re with code 01.*$gdb_prompt $" { 60 pass "run \"$testfile\" with no args" 61 fail "no spurious messages at program exit" 62 } 63 -re ".*usage: factorial <number>.* EXIT code 1.*$inferior_exited_re normally.\r\n$gdb_prompt $" { 64 pass "run \"$testfile\" with no args (exit wrapper)" 65 pass "no spurious messages at program exit" 66 } 67 -re ".*usage: factorial <number>.* EXIT code 1.*$inferior_exited_re normally.*$gdb_prompt $" { 68 pass "run \"$testfile\" with no args (exit wrapper)" 69 fail "no spurious messages at program exit" 70 } 71 -re ".*$gdb_prompt $" { 72 fail "run \"$testfile\" with no args" 73 verbose "expect_out is $expect_out(buffer)" 2 74 } 75 timeout { 76 fail "(timeout) run \"$testfile\" no args" 77 } 78 } 79} 80 81# The remaining tests don't work for targets can't take arguments... 82 83if [target_info exists noargs] then { 84 verbose "Skipping rest of a2-run.exp because of noargs." 85 return 86} 87 88# Now run with some arguments 89if [istarget "*-*-vxworks*"] then { 90 send_gdb "run vxmain \"5\"\n" 91 gdb_expect -re "run vxmain \"5\"\r\n" {} 92 set timeout 120 93 verbose "Timeout is now $timeout seconds" 2 94 gdb_expect { 95 "$inferior_exited_re normally" { 96 unresolved "run \"$testfile\" with arg" 97 } 98 "120" { 99 pass "run \"$testfile\" with arg" 100 } 101 timeout { 102 fail "(timeout) run \"$testfile\" with arg" 103 } 104 } 105 set timeout 10 106 verbose "Timeout is now $timeout seconds" 2 107 gdb_expect -re "$gdb_prompt $" {} 108} else { 109 setup_xfail "arm-*-coff" 110 gdb_run_cmd 5 111 gdb_expect { 112 -re ".*120.*$gdb_prompt $"\ 113 { pass "run \"$testfile\" with arg" } 114 -re ".*$gdb_prompt $" { fail "run \"$testfile\" with arg" } 115 timeout { fail "(timeout) run \"$testfile\" with arg" } 116 } 117} 118 119# Run again with same arguments. 120gdb_run_cmd 121 122if [istarget "*-*-vxworks*"] then { 123 set timeout 120 124 verbose "Timeout is now $timeout seconds" 2 125 gdb_expect { 126 "$inferior_exited_re normally" { 127 unresolved "run \"$testfile\" again with same args" 128 } 129 "120" { pass "run \"$testfile\" again with same args" } 130 timeout { fail "(timeout) run \"$testfile\" again with same args" } 131 } 132 set timeout 10 133 verbose "Timeout is now $timeout seconds" 2 134 gdb_expect -re "$gdb_prompt $" {} 135} else { 136 setup_xfail "arm-*-coff" 137 gdb_expect { 138 -re ".*120.*$gdb_prompt $"\ 139 { pass "run \"$testfile\" again with same args" } 140 -re ".*$gdb_prompt $" { fail "run \"$testfile\" again with same args" } 141 timeout { fail "(timeout) run \"$testfile\" again with same args" } 142 } 143} 144 145# Use "set args" command to specify no arguments as default and run again. 146if [istarget "*-*-vxworks*"] then { 147 gdb_test_no_output "set args main" 148} else { 149 gdb_test_no_output "set args" 150} 151 152gdb_run_cmd 153 154if [istarget "*-*-vxworks*"] then { 155 set timeout 120 156 verbose "Timeout is now $timeout seconds" 2 157 gdb_expect { 158 "$inferior_exited_re normally" { 159 unresolved "run after setting args to nil" 160 } 161 "usage: factorial <number>" { 162 pass "run after setting args to nil" 163 } 164 timeout { 165 fail "(timeout) run after setting args to nil" 166 } 167 } 168 set timeout 10 169 verbose "Timeout is now $timeout seconds" 2 170 gdb_expect -re "$gdb_prompt $" {} 171} else { 172 gdb_expect { 173 -re ".*usage: factorial <number>.*$gdb_prompt $" { 174 pass "run after setting args to nil" 175 } 176 -re ".*$gdb_prompt $" { 177 fail "run after setting args to nil" 178 } 179 timeout { 180 fail "(timeout) run after setting args to nil" 181 } 182 } 183} 184 185# Use "set args" command to specify an argument and run again. 186if [istarget "*-*-vxworks*"] then { 187 gdb_test_no_output "set args vxmain \"6\"" 188} else { 189 gdb_test_no_output "set args 6" 190} 191 192gdb_run_cmd 193 194if [istarget "*-*-vxworks*"] then { 195 set timeout 120 196 verbose "Timeout is now $timeout seconds" 2 197 gdb_expect { 198 "$inferior_exited_re normally" { 199 unresolved "run \"$testfile\" again after setting args" 200 } 201 "720" { 202 pass "run \"$testfile\" again after setting args" 203 } 204 timeout { 205 fail "(timeout) run \"$testfile\" again after setting args" 206 } 207 } 208 set timeout 10 209 verbose "Timeout is now $timeout seconds" 2 210 gdb_expect -re "$gdb_prompt $" {} 211} else { 212 setup_xfail "arm-*-coff" 213 gdb_expect { 214 -re ".*720.*$gdb_prompt $" { 215 pass "run \"$testfile\" again after setting args" 216 } 217 -re ".*$gdb_prompt $" { 218 fail "run \"$testfile\" again after setting args" 219 } 220 timeout { 221 fail "(timeout) run \"$testfile\" again after setting args" 222 } 223 } 224} 225 226# GOAL: Test that shell is being used with "run". For remote debugging 227# targets, there is no guarantee that a "shell" (whatever that is) is used. 228if ![is_remote target] then { 229 gdb_test "run `echo 8`" \ 230 "Starting program.*40320.*" \ 231 "run \"$testfile\" with shell" 232} 233 234# Reset the default arguments for VxWorks 235if [istarget "*-*-vxworks*"] then { 236 gdb_test_no_output "set args main" 237} 238