1#   Copyright 1988, 1990, 1991, 1992, 1994, 1995, 1996, 1997, 1999, 2000,
2#   2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
3
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17# This file was written by Rob Savoye. (rob@cygnus.com)
18
19# Can't do this test without stdio support.
20if [gdb_skip_stdio_test "a2run.exp"] {
21    return
22}
23
24if $tracelevel then {
25    strace $tracelevel
26}
27
28#
29# test running programs
30#
31
32set testfile a2-run
33if { [prepare_for_testing ${testfile}.exp $testfile run.c] } {
34    return -1
35}
36
37# Run with no arguments.
38# On VxWorks this justs make sure the program was run.
39gdb_run_cmd
40
41if [istarget "*-*-vxworks*"] then {
42    set timeout 120
43    verbose "Timeout is now $timeout seconds" 2
44    gdb_expect {
45	 "$inferior_exited_re normally" {
46	    unresolved "run \"$testfile\" with no args"
47	}
48	 -re "usage:  factorial <number>" {
49	    pass "run \"$testfile\" with no args"
50	}
51	timeout	{
52	    fail "(timeout) run \"$testfile\" with no args"
53	}
54    }
55    set timeout 10
56    verbose "Timeout is now $timeout seconds" 2
57    gdb_expect -re "$gdb_prompt $" {}
58} else {
59    gdb_expect {
60	-re ".*usage:  factorial <number>.*$inferior_exited_re with code 01.\r\n$gdb_prompt $" {
61	    pass "run \"$testfile\" with no args"
62	    pass "no spurious messages at program exit"
63	}
64	-re ".*usage:  factorial <number>.*$inferior_exited_re with code 01.*$gdb_prompt $" {
65	    pass "run \"$testfile\" with no args"
66	    fail "no spurious messages at program exit"
67	}
68	-re ".*usage:  factorial <number>.* EXIT code 1.*$inferior_exited_re normally.\r\n$gdb_prompt $" {
69	    pass "run \"$testfile\" with no args (exit wrapper)"
70	    pass "no spurious messages at program exit"
71	}
72	-re ".*usage:  factorial <number>.* EXIT code 1.*$inferior_exited_re normally.*$gdb_prompt $" {
73	    pass "run \"$testfile\" with no args (exit wrapper)"
74	    fail "no spurious messages at program exit"
75	}
76	-re ".*$gdb_prompt $" {
77	    fail "run \"$testfile\" with no args"
78	    verbose "expect_out is $expect_out(buffer)" 2
79	}
80	timeout	{
81	    fail "(timeout) run \"$testfile\" no args"
82	}
83    }
84}
85
86# The remaining tests don't work for targets can't take arguments...
87
88if [target_info exists noargs] then {
89    verbose "Skipping rest of a2-run.exp because of noargs."
90    return
91}
92
93# Now run with some arguments
94if [istarget "*-*-vxworks*"] then {
95    send_gdb "run vxmain \"5\"\n"
96    gdb_expect -re "run vxmain \"5\"\r\n" {}
97    set timeout 120
98    verbose "Timeout is now $timeout seconds" 2
99    gdb_expect {
100	 "$inferior_exited_re normally" {
101	    unresolved "run \"$testfile\" with arg"
102	}
103	 "120" {
104	    pass "run \"$testfile\" with arg"
105	}
106	timeout {
107	    fail "(timeout) run \"$testfile\" with arg"
108	}
109    }
110    set timeout 10
111    verbose "Timeout is now $timeout seconds" 2
112    gdb_expect -re "$gdb_prompt $" {}
113} else {
114	setup_xfail "mips-idt-*" "arm-*-coff strongarm-*-coff"
115	gdb_run_cmd 5
116	gdb_expect {
117	    -re ".*120.*$gdb_prompt $"\
118				{ pass "run \"$testfile\" with arg" }
119	    -re ".*$gdb_prompt $"	{ fail "run \"$testfile\" with arg" }
120	    timeout		{ fail "(timeout) run \"$testfile\" with arg" }
121	}
122}
123
124# Run again with same arguments.
125setup_xfail "mips-idt-*"
126gdb_run_cmd
127
128if [istarget "*-*-vxworks*"] then {
129    set timeout 120
130    verbose "Timeout is now $timeout seconds" 2
131    gdb_expect {
132	 "$inferior_exited_re normally" {
133	    unresolved "run \"$testfile\" again with same args"
134	}
135	 "120" { pass "run \"$testfile\" again with same args" }
136	timeout { fail "(timeout) run \"$testfile\" again with same args" }
137    }
138    set timeout 10
139    verbose "Timeout is now $timeout seconds" 2
140    gdb_expect -re "$gdb_prompt $" {}
141} else {
142    setup_xfail "arm-*-coff strongarm-*-coff"
143    gdb_expect {
144	    -re ".*120.*$gdb_prompt $"\
145				{ pass "run \"$testfile\" again with same args" }
146	    -re ".*$gdb_prompt $"	{ fail "run \"$testfile\" again with same args" }
147	    timeout		{ fail "(timeout) run \"$testfile\" again with same args" }
148	}
149}
150
151# Use "set args" command to specify no arguments as default and run again.
152if [istarget "*-*-vxworks*"] then {
153    gdb_test_no_output "set args main"
154} else {
155    gdb_test_no_output "set args"
156}
157
158gdb_run_cmd
159
160if [istarget "*-*-vxworks*"] then {
161    set timeout 120
162    verbose "Timeout is now $timeout seconds" 2
163    gdb_expect {
164	 "$inferior_exited_re normally" {
165	    unresolved "run after setting args to nil"
166	}
167	 "usage:  factorial <number>" {
168	    pass "run after setting args to nil"
169	}
170	timeout {
171	    fail "(timeout) run after setting args to nil"
172	}
173    }
174    set timeout 10
175    verbose "Timeout is now $timeout seconds" 2
176    gdb_expect -re "$gdb_prompt $" {}
177} else {
178    gdb_expect {
179	-re ".*usage:  factorial <number>.*$gdb_prompt $" {
180	    pass "run after setting args to nil"
181	}
182	-re ".*$gdb_prompt $" {
183	    fail "run after setting args to nil"
184	}
185	timeout {
186	    fail "(timeout) run after setting args to nil"
187	}
188    }
189}
190
191# Use "set args" command to specify an argument and run again.
192setup_xfail "mips-idt-*"
193if [istarget "*-*-vxworks*"] then {
194    gdb_test_no_output "set args vxmain \"6\""
195} else {
196    gdb_test_no_output "set args 6"
197}
198
199gdb_run_cmd
200
201if [istarget "*-*-vxworks*"] then {
202    set timeout 120
203    verbose "Timeout is now $timeout seconds" 2
204    gdb_expect {
205	 "$inferior_exited_re normally" {
206	    unresolved "run \"$testfile\" again after setting args"
207	}
208	 "720" {
209	    pass "run \"$testfile\" again after setting args"
210	}
211	timeout {
212	    fail "(timeout) run \"$testfile\" again after setting args"
213	}
214    }
215    set timeout 10
216    verbose "Timeout is now $timeout seconds" 2
217    gdb_expect -re "$gdb_prompt $" {}
218} else {
219    setup_xfail "arm-*-coff strongarm-*-coff"
220    gdb_expect {
221	    -re ".*720.*$gdb_prompt $" {
222		pass "run \"$testfile\" again after setting args"
223	    }
224	    -re ".*$gdb_prompt $" {
225		fail "run \"$testfile\" again after setting args"
226	    }
227	    timeout {
228		fail "(timeout) run \"$testfile\" again after setting args"
229	    }
230	}
231}
232
233# GOAL: Test that shell is being used with "run".  For remote debugging
234# targets, there is no guarantee that a "shell" (whatever that is) is used.
235if ![is_remote target] then {
236    gdb_test "run `echo 8`" \
237	"Starting program.*40320.*" \
238	"run \"$testfile\" with shell"
239}
240
241# Reset the default arguments for VxWorks
242if [istarget "*-*-vxworks*"] then {
243    gdb_test_no_output "set args main"
244}
245