xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.trace/tspeed.exp (revision 8b657b0747480f8989760d71343d6dd33f8d4cf9)
1# Copyright 2011-2023 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
16load_lib "trace-support.exp"
17
18if {[skip_shlib_tests]} {
19    return 0
20}
21
22# Do not run if gdbsever debug is enabled - the output file is many Gb.
23if [gdbserver_debug_enabled] {
24    return 0
25}
26
27standard_testfile
28set executable $testfile
29
30# Check that the target supports trace.
31if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable $options] != "" } {
32    untested "failed to compile"
33    return -1
34}
35
36clean_restart ${testfile}
37
38if ![runto_main] {
39    return -1
40}
41
42if ![gdb_target_supports_trace] {
43    unsupported "target does not support trace"
44    return -1
45}
46
47# Compile the test case with the in-process agent library.
48set ipalib [get_in_proc_agent]
49
50if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile \
51	  executable [concat {debug c} shlib=$ipalib]] != "" } {
52    untested "failed to compile"
53    return -1
54}
55
56# Typically we need a little extra time for this test.
57set timeout 180
58
59set ws "\[\r\n\t \]+"
60set cr "\[\r\n\]+"
61
62#
63# Utility procs
64#
65
66proc prepare_for_trace_test {} {
67    global executable
68    global ipalib
69
70    clean_restart $executable
71    gdb_load_shlib $ipalib
72
73    runto_main
74
75    set testline [gdb_get_line_number "set pre-run breakpoint here"]
76
77    gdb_test "break $testline" ".*" \
78	"break at pre-run"
79
80    set testline [gdb_get_line_number "set post-run breakpoint here"]
81
82    gdb_test "break $testline" ".*" \
83	"break at post-run"
84}
85
86proc run_trace_experiment {} {
87
88    gdb_test "continue" \
89	".*Breakpoint \[0-9\]+, main .*" \
90	"advance to trace begin"
91
92    gdb_test_no_output "tstart" "start trace experiment"
93
94    gdb_test "continue" \
95	".*Breakpoint \[0-9\]+, main .*" \
96	"advance through tracing"
97
98    gdb_test "tstatus" ".*Trace .*" "check on trace status"
99
100    gdb_test "tstop" "" ""
101}
102
103proc_with_prefix gdb_slow_trace_speed_test { } {
104
105    gdb_delete_tracepoints
106
107    gdb_test "print iters = init_iters" ".* = .*"
108
109    set testline [gdb_get_line_number "set tracepoint here"]
110
111    gdb_test "trace $testline if (globfoo != 12 && globfoo2 == 45)" \
112	"Tracepoint \[0-9\]+ at .*" \
113	"set slow tracepoint"
114
115    # Begin the test.
116    run_trace_experiment
117}
118
119proc_with_prefix gdb_fast_trace_speed_test { } {
120    global gdb_prompt
121
122    gdb_delete_tracepoints
123
124    gdb_test "print iters = init_iters" ".* = .*"
125
126    set run_ftrace 0
127
128    set testline [gdb_get_line_number "set tracepoint here"]
129
130    gdb_test_multiple "ftrace $testline if (globfoo != 12 && globfoo2 == 45)" \
131	"set conditional fast tracepoint" {
132	    -re "Fast tracepoint \[0-9\]+ at .*\r\n$gdb_prompt $" {
133		pass "set conditional fast tracepoint, done"
134		set run_ftrace 1
135	    }
136	    -re "May not have a fast tracepoint at .*\r\n$gdb_prompt $" {
137		pass "set conditional fast tracepoint, not allowed at line"
138	    }
139	}
140
141    # If the fast tracepoint couldn't be set, don't bother with the run.
142    if {$run_ftrace == 1} {
143
144	# Begin the test.
145	run_trace_experiment
146    }
147}
148
149proc gdb_trace_collection_test {} {
150
151    prepare_for_trace_test
152
153    gdb_slow_trace_speed_test
154
155    gdb_fast_trace_speed_test
156}
157
158clean_restart $executable
159gdb_load_shlib $ipalib
160
161runto_main
162
163if {![gdb_target_supports_trace]} {
164    unsupported "current target does not support trace"
165    return 1
166}
167
168# Body of test encased in a proc so we can return prematurely.
169gdb_trace_collection_test
170