Automatic Copyright Year update after running gdb/copyright.py
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / tui-window-disabled.exp
1 # Copyright (C) 2021-2022 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 # Create a TUI window in Python that responds to GDB event. Each
17 # event will trigger the TUI window to redraw itself.
18 #
19 # This test is checking how GDB behaves if the user first displays a
20 # Python based tui window, and then does 'tui disable'. At one point
21 # it was possible that GDB would try to redraw the tui window even
22 # though the tui should be disabled.
23
24 load_lib gdb-python.exp
25 tuiterm_env
26
27 standard_testfile
28
29 if {[build_executable "failed to prepare" ${testfile} ${srcfile}] == -1} {
30 return -1
31 }
32
33 # Copy the Python script to where the tests are being run.
34 set remote_python_file [gdb_remote_download host \
35 ${srcdir}/${subdir}/${testfile}.py]
36
37 proc clean_restart_and_setup { prefix } {
38 global testfile
39 global remote_python_file
40
41 with_test_prefix $prefix {
42
43 Term::clean_restart 24 80 $testfile
44
45 # Skip all tests if Python scripting is not enabled.
46 if { [skip_python_tests] } { return 0 }
47
48 # Now source the python script.
49 gdb_test_no_output "source ${remote_python_file}" \
50 "source ${testfile}.py"
51
52 # Create a new layout making use of our new event window.
53 gdb_test_no_output "tui new-layout test events 1 cmd 1"
54
55 # Disable source code highlighting.
56 gdb_test_no_output "set style sources off"
57
58 if {![runto_main]} {
59 perror "test suppressed"
60 return
61 }
62 }
63
64 return 1
65 }
66
67 # Run the test. CLEANUP_PROPERLY is either true or false. This is
68 # used to set a flag in the Python code which controls whether the
69 # Python TUI window cleans up properly or not.
70 #
71 # When the Python window does not cleanup properly then it retains a
72 # cyclic reference to itself, this means that it is still possible for
73 # the object to try and redraw itself even when the tui is disabled.
74 proc run_test { cleanup_properly } {
75
76 if { ![clean_restart_and_setup "initial restart"] } {
77 unsupported "couldn't restart GDB"
78 return
79 }
80
81 if { $cleanup_properly } {
82 gdb_test_no_output "python cleanup_properly = True"
83 } else {
84 gdb_test_no_output "python cleanup_properly = False"
85 }
86
87 if {![Term::enter_tui]} {
88 unsupported "TUI not supported"
89 return
90 }
91
92 Term::command "layout test"
93
94 # Confirm that the events box is initially empty, then perform two
95 # actions that will add two events to the window.
96 Term::check_box_contents "no events yet" 0 0 80 16 ""
97 Term::command "next"
98 Term::check_box_contents "single stop event" 0 0 80 16 "stop"
99 Term::command "next"
100 Term::check_box_contents "two stop events" 0 0 80 16 \
101 "stop\[^\n\]+\nstop"
102
103 # Now disable the tui, we should end up back at a standard GDB prompt.
104 Term::command "tui disable"
105
106 # Do something just so we know that the CLI is working.
107 gdb_test "print 1 + 1 + 1" " = 3"
108
109 # Now perform an action that would trigger an event. At one point
110 # there was a bug where the TUI window might try to redraw itself.
111 # This is why we use GDB_TEST_MULTIPLE here, so we can spot the tui
112 # window title and know that things have gone wrong.
113 gdb_test_multiple "next" "next at cli" {
114 -re -wrap "func \\(3\\);" {
115 pass $gdb_test_name
116 }
117
118 -re "This Is The Event Window" {
119 fail $gdb_test_name
120 }
121 }
122
123 # Do something just so we know that the CLI is still working. This
124 # also serves to drain the expect buffer if the above test failed.
125 gdb_test "print 2 + 2 + 2" " = 6"
126
127 # Now tell the Python code not to check the window is valid before
128 # calling rerended. The result is the Python code will try to draw to
129 # the screen. This should throw a Python exception.
130 gdb_test_no_output "python perform_valid_check = False"
131 set exception_pattern "\r\nPython Exception\[^\n\r\]+TUI window is invalid\[^\n\r\]+"
132 gdb_test_multiple "next" "next at cli, with an exception" {
133 -re -wrap "func \\(4\\);${exception_pattern}" {
134 pass $gdb_test_name
135 }
136
137 -re "This Is The Event Window" {
138 fail $gdb_test_name
139 }
140 }
141
142 # Do something just so we know that the CLI is still working. This
143 # also serves to drain the expect buffer if the above test failed.
144 gdb_test "print 3 + 3 + 3" " = 9"
145
146 # Set 'update_title' to True. The Python script will now try to set
147 # the window title when an event occurs (instead of trying to redraw
148 # the window). As the window is still not displayed this will again
149 # through an exception.
150 gdb_test_no_output "python update_title = True"
151 gdb_test_multiple "next" "next at cli, with an exception for setting the title" {
152 -re -wrap "func \\(5\\);${exception_pattern}" {
153 pass $gdb_test_name
154 }
155
156 -re "This Is The Event Window" {
157 fail $gdb_test_name
158 }
159 }
160
161 # We need to perform a restart here as the TUI library we use for
162 # testing doesn't seem to handle output in the command window
163 # correctly, and gets really upset as we approach the bottom of
164 # the screen.
165 #
166 # Restart GDB, enable tui mode, select the new layout. Then
167 # disable tui and re-enable again.
168 if { ![clean_restart_and_setup "second restart"] } {
169 unsupported "couldn't restart GDB"
170 return
171 }
172
173 with_test_prefix "enter tui again" {
174 if {![Term::enter_tui]} {
175 unsupported "TUI not supported"
176 return
177 }
178 }
179
180 Term::command "layout test"
181 Term::command "tui disable"
182 send_gdb "tui enable\n"
183 Term::check_box "check for python window" 0 0 80 16
184 }
185
186 # Run the tests in both cleanup modes.
187 foreach_with_prefix cleanup_properly { True False } {
188 run_test $cleanup_properly
189 }
This page took 0.033351 seconds and 4 git commands to generate.