]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.perf/skip-command.exp
Update copyright year range in all GDB files
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.perf / skip-command.exp
1 # Copyright (C) 2016-2021 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 # This test case is to test the speed of GDB when it is single-stepping
17 # with skip directives active. There's no need to test skip directives that
18 # match functions we're stepping through. That's not the interesting case.
19 # The interesting case is where there are 100s or more classes or libraries,
20 # each providing their own set of skip directives.
21 #
22 # Parameters:
23 # SKIP_STEP_COUNT: the number of single steps GDB performs
24 # SKIP_DIRECTIVE_COUNT: the number of skip directives to create
25
26 load_lib perftest.exp
27
28 if [skip_perf_tests] {
29 return 0
30 }
31
32 standard_testfile .cc skip-funcs.cc
33 set executable $testfile
34 set skip_func_file [standard_output_file $srcfile2]
35 set expfile $testfile.exp
36
37 # make check-perf RUNTESTFLAGS='skip-command.exp SKIP_STEP_COUNT=1000 ...'
38 if ![info exists SKIP_STEP_COUNT] {
39 set SKIP_STEP_COUNT 1000
40 }
41 if ![info exists SKIP_DIRECTIVE_COUNT] {
42 set SKIP_DIRECTIVE_COUNT 1000
43 }
44
45 proc delete_all_skips { } {
46 # FIXME: skip currently doesn't ask for confirmation
47 # FIXME: "skip delete" with no skips ->
48 # "No skiplist entries found with number (null)."
49 gdb_test_no_output "set confirm off"
50 gdb_test "skip delete" ""
51 gdb_test_no_output "set confirm on"
52 }
53
54 proc install_skips { kind text nr_skips } {
55 global gdb_prompt
56 set test "install_skips"
57 delete_all_skips
58 switch $kind {
59 "function" { set skip_arg "-function" }
60 "regexp" { set skip_arg "-rfunction" }
61 default {
62 perror "bad skip kind: $kind"
63 return
64 }
65 }
66 for { set i 0 } { $i < $nr_skips } { incr i } {
67 gdb_test "skip $skip_arg [format $text $i]" ""
68 }
69 # There could be 1000's of these, which can overflow the buffer.
70 # However, it's good to have this in the log, so we go to the effort
71 # to read it all in.
72 gdb_test_multiple "info skip" $test {
73 -re "\[^\r\n\]*\r\n" { exp_continue }
74 -re "\[\r\n\]*$gdb_prompt $" {
75 pass $test
76 }
77 timeout {
78 fail "$test (timeout)"
79 }
80 }
81 }
82
83 proc write_skip_func_source { file_name func_name_prefix nr_funcs } {
84 set f [open $file_name "w"]
85 puts $f "// DO NOT EDIT, machine generated file. See skip-command.exp."
86 for { set i 0 } { $i < $nr_funcs } { incr i } {
87 set func_name [format "${func_name_prefix}_%02d" $i]
88 puts $f "int $func_name () { return 0; }"
89 }
90 close $f
91 }
92
93 proc run_skip_bench { kind text } {
94 global SKIP_STEP_COUNT SKIP_DIRECTIVE_COUNT
95
96 if ![runto_main] {
97 fail "can't run to main"
98 return -1
99 }
100
101 gdb_test_no_output "set variable flag = 1"
102
103 for { set i 0 } { $i < 5 } { incr i } {
104 set nr_skips [expr $i * $SKIP_DIRECTIVE_COUNT]
105 install_skips $kind $text $nr_skips
106 gdb_test_no_output "python SkipCommand\(\"skip-$kind-$nr_skips\", ${SKIP_STEP_COUNT}\).run()"
107 }
108
109 gdb_test "set variable flag = 0"
110 }
111
112 PerfTest::assemble {
113 global srcdir subdir srcfile binfile skip_func_file
114 global SKIP_DIRECTIVE_COUNT
115
116 write_skip_func_source $skip_func_file "skip_func" [expr 4 * $SKIP_DIRECTIVE_COUNT]
117 if { [gdb_compile [list "$srcdir/$subdir/$srcfile" $skip_func_file] ${binfile} executable {c++ debug}] != "" } {
118 return -1
119 }
120 return 0
121 } {
122 global binfile
123 clean_restart $binfile
124 return 0
125 } {
126 global SKIP_STEP_COUNT SKIP_DIRECTIVE_COUNT
127
128 with_test_prefix "time_skip_func" {
129 # N.B. The function name must match the ones in skip-command.cc.
130 run_skip_bench "function" "skip_func_%02d"
131 }
132
133 with_test_prefix "time_skip_constructor" {
134 run_skip_bench "regexp" "^(skip_class_%02d)::\\1 *\\("
135 }
136
137 return 0
138 }