1 # Copyright 2016-2023 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 if [gdb_debug_enabled] {
19 untested "debug is enabled"
23 load_lib completion-support.exp
25 set do_xml_test [expr ![gdb_skip_xml_test]]
29 if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
33 proc run_selftests { binfile } {
34 global decimal gdb_prompt
36 if { $binfile == "" } {
40 clean_restart ${binfile}
43 # Some of the selftests create temporary files in GDB's current
44 # directory. So, while running the selftests, switch to the
45 # test's output directory to avoid leaving clutter in the
46 # gdb/testsuite root directory.
47 set dir [standard_output_file ""]
51 set test "maintenance selftest"
52 gdb_test_multiple $test $test {
53 -re ".*Running selftest \[^\n\r\]+\." {
54 # The selftests can take some time to complete. To prevent
55 # timeout spot the 'Running ...' lines going past, so long as
56 # these are produced quickly enough then the overall test will
60 -re "Ran ($decimal) unit tests, ($decimal) failed\r\n$gdb_prompt $" {
61 set num_ran $expect_out(1,string)
62 set num_failed $expect_out(2,string)
63 gdb_assert "$num_ran > 0" "$test, ran some tests"
64 gdb_assert "$num_failed == 0" "$test, failed none"
66 -re "Selftests have been disabled for this build.\r\n$gdb_prompt $" {
74 return [list $enabled $num_ran]
77 # Test completion of command "maintenance selftest".
79 proc_with_prefix test_completion {} {
80 global self_tests_enabled
84 if { $self_tests_enabled } {
85 test_gdb_complete_tab_multiple "maintenance selftest copy" "_" \
86 {copy_bitwise copy_integer_to_size}
87 test_gdb_complete_tab_unique "maintenance selftest copy_bit" \
88 "maintenance selftest copy_bitwise" " "
90 test_gdb_complete_tab_none "maintenance selftest copy_"
91 test_gdb_complete_tab_none "maintenance selftest copy_bit"
93 test_gdb_complete_tab_unique "maintenance selftest -ver" "maintenance selftest -verbose" " "
94 test_gdb_complete_tab_none "maintenance selftest name_that_does_not_exist"
97 with_test_prefix "no executable loaded" {
98 set res [run_selftests ""]
99 set self_tests_enabled [lindex $res 0]
100 set num_ran [lindex $res 1]
103 if { $self_tests_enabled && ![is_remote host] } {
104 # Check that we have the same amount of selftests whatever the
105 # initialization order of GDB.
106 with_test_prefix "reversed initialization" {
107 save_vars { env(GDB_REVERSE_INIT_FUNCTIONS) } {
108 if [info exists env(GDB_REVERSE_INIT_FUNCTIONS)] {
109 unset env(GDB_REVERSE_INIT_FUNCTIONS)
111 set env(GDB_REVERSE_INIT_FUNCTIONS) 1
114 set res [run_selftests ""]
115 gdb_assert "$num_ran == [lindex $res 1]" \
116 "selftest not dependent on initialization order"
121 with_test_prefix "executable loaded" {
122 run_selftests ${binfile}
127 if { ![is_remote host] && $do_xml_test } {
128 gdb_test "maintenance check xml-descriptions ${srcdir}/../features" \
129 "Tested $decimal XML files, 0 failed" \
130 "maintenance check xml-descriptions \${srcdir}/../features"