Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.base / term.exp
CommitLineData
88b9d363 1# Copyright 1988-2022 Free Software Foundation, Inc.
c906108c
SS
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
e22f8b7c 5# the Free Software Foundation; either version 3 of the License, or
c906108c 6# (at your option) any later version.
e22f8b7c 7#
c906108c
SS
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.
e22f8b7c 12#
c906108c 13# You should have received a copy of the GNU General Public License
e22f8b7c 14# along with this program. If not, see <http://www.gnu.org/licenses/>.
c906108c 15
ae739fe7
SM
16# Test that GDB saves and restores terminal settings correctly. Also check
17# the output of the "info terminal" command.
18
5b362f04 19if { [prepare_for_testing "failed to prepare" term term.c] } {
5f8cefd7 20 return -1
c1d88655
UW
21}
22
5f8cefd7
PA
23# Once before running the program.
24gdb_test "info terminal" \
25 "No saved terminal information.*" \
ae739fe7 26 "test info terminal pre-execution"
c906108c 27
ae739fe7
SM
28if ![runto break_here] then {
29 fail "can't run to break_here"
5f8cefd7 30 return 0
c906108c
SS
31}
32
ae739fe7
SM
33# Read the inferior's terminal settings, saved in the T global variable.
34
35proc read_term_settings_from_inferior {} {
36 set termios(c_iflag) [get_hexadecimal_valueof "t.c_iflag" oops]
37 set termios(c_oflag) [get_hexadecimal_valueof "t.c_oflag" oops]
38 set termios(c_cflag) [get_hexadecimal_valueof "t.c_cflag" oops]
39 set termios(c_lflag) [get_hexadecimal_valueof "t.c_lflag" oops]
40
41 return [array get termios]
42}
43
44# Validate that gdb's notion of the inferior's terminal settings are consistent
45# with the values read from the inferior.
46
47proc compare_gdb_and_inferior_settings { t } {
48 global decimal
49 array set termios $t
50
51 gdb_test "info terminal" \
52 [multi_line "Inferior's terminal status .currently saved by GDB.:" \
53 "File descriptor flags = .*" \
54 "Process group = $decimal" \
55 "c_iflag = ${termios(c_iflag)}, c_oflag = ${termios(c_oflag)}," \
56 "c_cflag = ${termios(c_cflag)}, c_lflag = ${termios(c_lflag)}.*" ]
57}
7594f623 58
7594f623 59if {[target_info gdb_protocol] == ""} {
ae739fe7
SM
60 # Record the initial terminal settings. Verify that GDB's version of the
61 # inferior's terminal settings is right.
62 with_test_prefix "initial" {
63 array set termios1 [read_term_settings_from_inferior]
64 compare_gdb_and_inferior_settings [array get termios1]
65 }
66
67 # Continue until after the inferior removes ECHO from its terminal settings.
68 gdb_continue_to_breakpoint "continue until after tcsetattr"
69
70 # After the inferior has changed its terminal settings, check that GDB's
71 # saved version reflects the new settings correctly.
72 with_test_prefix "post tcsetattr" {
73 array set termios2 [read_term_settings_from_inferior]
74 compare_gdb_and_inferior_settings [array get termios2]
75
76 # Make sure that the current settings are different than the initial
77 # settings... otherwise this test is meaningless.
78 gdb_assert {${termios1(c_lflag)} != ${termios2(c_lflag)}}
79 }
80
81 # Continue again...
82 gdb_continue_to_breakpoint "continue again"
83
84 # ... and verify again, to validate that when resuming, GDB restored the
85 # inferior's terminal settings correctly.
86 with_test_prefix "after last resume" {
87 array set termios3 [read_term_settings_from_inferior]
88 compare_gdb_and_inferior_settings [array get termios3]
89 gdb_assert {${termios2(c_iflag)} == ${termios3(c_iflag)}}
90 gdb_assert {${termios2(c_oflag)} == ${termios3(c_oflag)}}
91 gdb_assert {${termios2(c_cflag)} == ${termios3(c_cflag)}}
92 gdb_assert {${termios2(c_lflag)} == ${termios3(c_lflag)}}
93 }
7594f623 94} else {
ae739fe7
SM
95 # While only native targets save terminal status, we still test
96 # that the command doesn't misbehave.
97 gdb_test "info terminal" "No saved terminal information\\." "info terminal at breakpoint"
7594f623
PA
98}
99
ae739fe7 100delete_breakpoints
5f8cefd7
PA
101gdb_continue_to_end
102
103# One last time after the program having exited.
104gdb_test "info terminal" \
105 "No saved terminal information.*" \
ae739fe7 106 "test info terminal post-execution"
This page took 2.383468 seconds and 4 git commands to generate.