Fix null pointer dereference in process_debug_info()
[binutils-gdb.git] / gdb / testsuite / gdb.gdb / unittest.exp
blobe154c04660062c689f449307c779389d28e08baa
1 # Copyright 2016-2024 Free Software Foundation, Inc.
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.
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.
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/>.
16 # Do not run if gdb debug is enabled as maintenance output will be
17 # redirected to the log files.
18 require !gdb_debug_enabled
20 load_lib completion-support.exp
22 set do_xml_test [allow_xml_test]
24 standard_testfile
26 if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
27 return -1
30 proc run_selftests_1 {} {
31 global decimal gdb_prompt
33 set enabled 1
34 set num_ran 0
36 set test "maintenance selftest"
37 gdb_test_multiple $test $test {
38 -re ".*Running selftest \[^\n\r\]+\." {
39 # The selftests can take some time to complete. To prevent
40 # timeout spot the 'Running ...' lines going past, so long as
41 # these are produced quickly enough then the overall test will
42 # not timeout.
43 exp_continue
45 -re "Ran ($decimal) unit tests, ($decimal) failed\r\n$gdb_prompt $" {
46 set num_ran $expect_out(1,string)
47 set num_failed $expect_out(2,string)
48 gdb_assert "$num_ran > 0" "$test, ran some tests"
49 gdb_assert "$num_failed == 0" "$test, failed none"
51 -re "Selftests have been disabled for this build.\r\n$gdb_prompt $" {
52 unsupported $test
53 set num_ran 0
54 set enabled 0
58 return [list $enabled $num_ran]
61 proc run_selftests { binfile } {
62 if { $binfile == "" } {
63 gdb_exit
64 gdb_start
65 } else {
66 clean_restart ${binfile}
69 if { [is_remote host] } {
70 return [run_selftests_1]
71 } else {
72 # Some of the selftests create temporary files in GDB's current
73 # directory. So, while running the selftests, switch to the
74 # test's output directory to avoid leaving clutter in the
75 # gdb/testsuite root directory.
76 set dir [standard_output_file ""]
77 with_gdb_cwd $dir {
78 return [run_selftests_1]
83 # Test completion of command "maintenance selftest".
85 proc_with_prefix test_completion {} {
86 global self_tests_enabled
88 clean_restart
90 if { ![readline_is_used] } {
91 return
94 if { $self_tests_enabled } {
95 test_gdb_complete_tab_multiple "maintenance selftest copy" "_" \
96 {copy_bitwise copy_integer_to_size}
97 test_gdb_complete_tab_unique "maintenance selftest copy_bit" \
98 "maintenance selftest copy_bitwise" " "
99 } else {
100 test_gdb_complete_tab_none "maintenance selftest copy_"
101 test_gdb_complete_tab_none "maintenance selftest copy_bit"
103 test_gdb_complete_tab_unique "maintenance selftest -ver" "maintenance selftest -verbose" " "
104 test_gdb_complete_tab_none "maintenance selftest name_that_does_not_exist"
107 with_test_prefix "no executable loaded" {
108 set res [run_selftests ""]
109 set self_tests_enabled [lindex $res 0]
110 set num_ran [lindex $res 1]
113 if { $self_tests_enabled && ![is_remote host] } {
114 # Check that we have the same amount of selftests whatever the
115 # initialization order of GDB.
116 with_test_prefix "reversed initialization" {
117 save_vars { env(GDB_REVERSE_INIT_FUNCTIONS) } {
118 if [info exists env(GDB_REVERSE_INIT_FUNCTIONS)] {
119 unset env(GDB_REVERSE_INIT_FUNCTIONS)
120 } else {
121 set env(GDB_REVERSE_INIT_FUNCTIONS) 1
124 set res [run_selftests ""]
125 gdb_assert "$num_ran == [lindex $res 1]" \
126 "selftest not dependent on initialization order"
131 with_test_prefix "executable loaded" {
132 run_selftests ${binfile}
135 test_completion
137 if { ![is_remote host] && $do_xml_test } {
138 gdb_test "maintenance check xml-descriptions ${srcdir}/../features" \
139 "Tested $decimal XML files, 0 failed" \
140 "maintenance check xml-descriptions \${srcdir}/../features"