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