Update copyright year range in all GDB files
[external/binutils.git] / gdb / testsuite / gdb.mi / mi-exit-code.exp
1 # Copyright 1999-2018 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 load_lib mi-support.exp
17 set MIFLAGS "-i=mi"
18
19 gdb_exit
20 if [mi_gdb_start] {
21     continue
22 }
23
24 standard_testfile
25
26 if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug}] != "" } {
27     untested "failed to compile"
28     return -1
29 }
30
31 proc test_list_thread_groups { } {
32     global hex
33     global decimal
34
35     # Before any run, exit-code should not be present.
36     mi_gdb_test \
37         "122-list-thread-groups" \
38         "122\\^done,groups=\\\[\{id=\"i1\",type=\"process\"\}\]" \
39         "-list-thread-groups before run shows no exit-code"
40
41     with_test_prefix "first run" {
42         mi_run_to_main
43
44         # During the run, exit-code should not be present.
45         mi_gdb_test \
46             "123-list-thread-groups" \
47             "123\\^done,groups=\\\[\{id=\"i1\",type=\"process\",pid=\"$decimal\",executable=\".*\".*" \
48             "-list-thread-groups during run shows no exit-code"
49
50         # Exit the inferior.
51         mi_send_resuming_command "exec-continue" "continuing to inferior exit"
52         mi_expect_stop "exited-normally" "" "" "" "" "" "exit normally"
53
54         # After the run, exit-code should be present.
55         mi_gdb_test \
56             "124-list-thread-groups" \
57             "124\\^done,groups=\\\[\{id=\"i1\",type=\"process\",exit-code=\"0\",executable=\".*\"\}\]" \
58             "-list-thread-groups after exit shows exit-code"
59     }
60
61     with_test_prefix "second run" {
62         mi_run_to_main
63
64         # Write the exit code we want in the global var
65         mi_gdb_test "set var exit_code = 8" ".*\\^done" "write exit code"
66
67         # During the second run, exit-code should not be present.
68         mi_gdb_test \
69             "125-list-thread-groups" \
70             "125\\^done,groups=\\\[\{id=\"i1\",type=\"process\",pid=\"$decimal\",executable=\".*\".*" \
71             "-list-thread-groups during run shows no exit-code"
72
73         # Exit the inferior.
74         mi_send_resuming_command "exec-continue" "continuing to inferior exit"
75         mi_expect_stop "exited" "" "" "" "" "" "exit with code"
76
77         # After the second run, exit-code should be present.
78         mi_gdb_test \
79             "126-list-thread-groups" \
80             "126\\^done,groups=\\\[\{id=\"i1\",type=\"process\",exit-code=\"010\",executable=\".*\"\}\]" \
81             "-list-thread-groups after exit shows exit-code"
82     }
83 }
84
85 test_list_thread_groups
86
87 mi_gdb_exit
88 return 0