Update copyright year range in header of all files managed by GDB
[binutils-gdb.git] / gdb / testsuite / gdb.gdb / unittest.exp
blobc8a68469767c19dcf31ad7067b910203d4ed5a67
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"
20     return 0
23 load_lib completion-support.exp
25 set do_xml_test [expr ![gdb_skip_xml_test]]
27 standard_testfile
29 if {[build_executable "failed to prepare" $testfile $srcfile debug]} {
30     return -1
33 proc run_selftests { binfile } {
34     global decimal gdb_prompt
36     if { $binfile == "" } {
37         gdb_exit
38         gdb_start
39     } else {
40         clean_restart ${binfile}
41     }
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 ""]
48     set enabled 1
49     set num_ran 0
50     with_gdb_cwd $dir {
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
57                 # not timeout.
58                 exp_continue
59             }
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"
65             }
66             -re "Selftests have been disabled for this build.\r\n$gdb_prompt $" {
67                 unsupported $test
68                 set num_ran 0
69                 set enabled 0
70             }
71         }
72     }
74     return [list $enabled $num_ran]
77 # Test completion of command "maintenance selftest".
79 proc_with_prefix test_completion {} {
80     global self_tests_enabled
82     clean_restart
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" " "
89     } else {
90         test_gdb_complete_tab_none "maintenance selftest copy_"
91         test_gdb_complete_tab_none "maintenance selftest copy_bit"
92     }
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)
110             } else {
111                 set env(GDB_REVERSE_INIT_FUNCTIONS) 1
112             }
114             set res [run_selftests ""]
115             gdb_assert "$num_ran == [lindex $res 1]" \
116                 "selftest not dependent on initialization order"
117         }
118     }
121 with_test_prefix "executable loaded" {
122     run_selftests ${binfile}
125 test_completion
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"