]>
Commit | Line | Data |
---|---|---|
213516ef | 1 | # Copyright (C) 2018-2023 Free Software Foundation, Inc. |
b0f492b9 GB |
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 | # Check that "gdb -batch" exits with appropriate status. | |
17 | ||
18 | standard_testfile | |
19 | ||
20 | set good_commands "$srcdir/$subdir/batch-exit-status.good-commands" | |
21 | set bad_commands "$srcdir/$subdir/batch-exit-status.bad-commands" | |
22 | ||
003fa0df | 23 | proc _test_exit_status {expect_status cmdline_opts {re ""}} { |
b0f492b9 GB |
24 | global gdb_spawn_id |
25 | ||
26 | gdb_exit | |
27 | if {[gdb_spawn_with_cmdline_opts $cmdline_opts] != 0} { | |
28 | fail "spawn" | |
29 | return | |
30 | } | |
31 | ||
003fa0df TV |
32 | set has_re [expr ![string equal $re ""]] |
33 | if { ! $has_re } { | |
34 | set re "\$FOOBAR^" | |
35 | } | |
36 | set re_matched 0 | |
dd083ee2 | 37 | gdb_test_multiple "" "run til exit" { |
003fa0df TV |
38 | -re $re { |
39 | set re_matched 1 | |
40 | exp_continue | |
41 | } | |
dd083ee2 GB |
42 | eof { |
43 | set result [wait -i $gdb_spawn_id] | |
44 | verbose $result | |
45 | ||
46 | gdb_assert { [lindex $result 2] == 0 } | |
47 | gdb_assert { [lindex $result 3] == $expect_status } | |
48 | ||
49 | remote_close host | |
50 | clear_gdb_spawn_id | |
51 | } | |
52 | } | |
003fa0df TV |
53 | if { $has_re } { |
54 | gdb_assert { $re_matched } "output matched" | |
55 | } | |
b0f492b9 GB |
56 | } |
57 | ||
003fa0df | 58 | proc test_exit_status {expect_status cmdline_opts prefix args} { |
0eba165a PFC |
59 | if { $prefix == "" } { |
60 | set prefix $cmdline_opts | |
61 | } | |
62 | ||
63 | with_test_prefix $prefix { | |
003fa0df | 64 | _test_exit_status $expect_status $cmdline_opts {*}$args |
b0f492b9 GB |
65 | } |
66 | } | |
67 | ||
68 | # gdb -batch with nothing to do should exit 0. | |
0eba165a | 69 | test_exit_status 0 "-batch" "" |
b0f492b9 GB |
70 | |
71 | # Bad command-line options should cause exit 1. | |
0eba165a | 72 | test_exit_status 1 "-batch -jslkflsdjlkfjlksdjf" "" |
b0f492b9 GB |
73 | |
74 | # gdb -batch with good commands should exit 0. | |
0eba165a PFC |
75 | test_exit_status 0 "-batch -ex \"info source\"" "" |
76 | test_exit_status 0 "-batch -x $good_commands" "-batch -x good-commands" | |
b0f492b9 GB |
77 | |
78 | # gdb -batch with bad commands should exit 1. | |
0eba165a PFC |
79 | test_exit_status 1 "-batch -ex \"set not-a-thing 4\"" "" |
80 | test_exit_status 1 "-batch -x $bad_commands" "-batch -x bad-commands" | |
b0f492b9 GB |
81 | |
82 | # Success or failure of the last thing determines the exit code. | |
0eba165a PFC |
83 | test_exit_status 0 "-batch -ex \"set not-a-thing 4\" -x $good_commands" \ |
84 | "-batch -ex \"set not-a-thing 4\" -x good-commands" | |
85 | test_exit_status 0 "-batch -x $bad_commands -ex \"info source\"" \ | |
86 | "-batch -x bad-commands -ex \"info source\"" | |
87 | test_exit_status 1 "-batch -x $good_commands -x $bad_commands" \ | |
88 | "-batch -x good-commands -x bad-commands" | |
89 | test_exit_status 1 "-batch -x $good_commands -ex \"set not-a-thing 4\"" \ | |
90 | "-batch -x good-commands -ex \"set not-a-thing 4\"" | |
f947f967 | 91 | |
003fa0df TV |
92 | set test "No such file or directory" |
93 | set no_such_re ": $test\\." | |
94 | test_exit_status 1 "-batch \"\"" "1x: $test" ^[multi_line $no_such_re ""]$ | |
95 | test_exit_status 1 "-batch \"\" \"\"" "2x: $test" \ | |
96 | ^[multi_line $no_such_re $no_such_re ""]$ |