1 # Copyright (C) 2023-2024 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 # Test that GDB correctly deallocates the window factory object (a) 17 # when a window factory is replaced, and (b) during GDB shutdown. 18 # 19 # This test also ensures that when a new window is registered (via the 20 # Python API) with the same name as an existing window, then the 21 # previous window is replaced. 22 23 load_lib gdb-python.exp 24 25 tuiterm_env 26 27 clean_restart 28 29 require allow_tui_tests allow_python_tests 30 31 set pyfile [gdb_remote_download host \ 32 ${srcdir}/${subdir}/${gdb_test_file_name}.py] 33 34 Term::clean_restart 24 80 35 if { ![Term::prepare_for_tui] } { 36 unsupported "TUI not supported" 37 return 38 } 39 40 gdb_test "source ${pyfile}" "Python script imported" \ 41 "import python scripts" 42 43 gdb_test "python register_window_factory('msg_1')" \ 44 "Entering TestWindowFactory\\.__init__: msg_1" 45 46 gdb_test "python register_window_factory('msg_2')" \ 47 [multi_line \ 48 "Entering TestWindowFactory\\.__init__: msg_2" \ 49 "Entering TestWindowFactory\\.__del__: msg_1"] 50 51 gdb_test_no_output "tui new-layout test test_window 1 cmd 1 status 1" 52 53 # Load the custom window layout and ensure that the correct window 54 # factory was used. 55 with_test_prefix "msg_2" { 56 Term::command_no_prompt_prefix "layout test" 57 Term::check_box_contents "check test_window box" 0 0 80 15 \ 58 "TestWindow \\(msg_2\\)" 59 } 60 61 # Replace the existing window factory with a new one, then switch 62 # layouts so that GDB recreates the window, and check that the new 63 # window factory was used. 64 with_test_prefix "msg_3" { 65 Term::command "python register_window_factory('msg_3')" 66 Term::check_region_contents "check for python output" \ 67 0 18 80 2 \ 68 [multi_line \ 69 "Entering TestWindowFactory.__init__: msg_3\\s+" \ 70 "Entering TestWindowFactory.__del__: msg_2"] 71 Term::command "layout src" 72 Term::command "layout test" 73 74 Term::check_box_contents "check test_window box" 0 0 80 15 \ 75 "TestWindow \\(msg_3\\)" 76 } 77 78 # Restart GDB, setup a TUI window factory, and then check that the 79 # Python object is deallocated when GDB exits. 80 with_test_prefix "call __del__ at exit" { 81 clean_restart 82 83 gdb_test "source ${pyfile}" "Python script imported" \ 84 "import python scripts" 85 86 gdb_test "python register_window_factory('msg_1')" \ 87 "Entering TestWindowFactory\\.__init__: msg_1" 88 89 gdb_test "python register_window_factory('msg_2')" \ 90 [multi_line \ 91 "Entering TestWindowFactory\\.__init__: msg_2" \ 92 "Entering TestWindowFactory\\.__del__: msg_1"] 93 94 set saw_window_factory_del 0 95 gdb_test_multiple "quit" "" { 96 -re "^quit\r\n" { 97 exp_continue 98 } 99 -re "^Entering TestWindowFactory.__del__: msg_2\r\n" { 100 incr saw_window_factory_del 101 exp_continue 102 } 103 eof { 104 gdb_assert { $saw_window_factory_del == 1 } 105 pass $gdb_test_name 106 } 107 } 108 } 109