xref: /netbsd-src/external/gpl3/gdb.old/dist/gdb/testsuite/gdb.trace/trace-enable-disable.exp (revision 6881a4007f077b54e5f51159c52b9b25f57deb0d)
1# Copyright 2015-2023 Free Software Foundation, Inc.
2# This program is free software; you can redistribute it and/or modify
3# it under the terms of the GNU General Public License as published by
4# the Free Software Foundation; either version 3 of the License, or
5# (at your option) any later version.
6#
7# This program is distributed in the hope that it will be useful,
8# but WITHOUT ANY WARRANTY; without even the implied warranty of
9# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10# GNU General Public License for more details.
11#
12# You should have received a copy of the GNU General Public License
13# along with this program.  If not, see <http://www.gnu.org/licenses/>.
14
15load_lib "trace-support.exp"
16
17if {[skip_shlib_tests]} {
18    return 0
19}
20
21standard_testfile
22set executable $testfile
23set expfile $testfile.exp
24
25# Some targets have leading underscores on assembly symbols.
26set options [list debug [gdb_target_symbol_prefix_flags]]
27
28# Check that the target supports trace.
29if ![gdb_trace_common_supports_arch] {
30    unsupported "no trace-common.h support for arch"
31    return -1
32}
33if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable $options] != "" } {
34    untested "failed to compile"
35    return -1
36}
37
38clean_restart ${testfile}
39
40if ![runto_main] {
41    return -1
42}
43
44if ![gdb_target_supports_trace] {
45    unsupported "target does not support trace"
46    return -1
47}
48
49# Compile the test case with the in-process agent library.
50set libipa [get_in_proc_agent]
51gdb_load_shlib $libipa
52
53lappend options shlib=$libipa
54
55if { [gdb_compile "$srcdir/$subdir/$srcfile" $binfile executable $options] != "" } {
56    untested "failed to compile with in-process agent library"
57    return -1
58}
59
60# This test makes sure that disabling and enabling tracepoints works
61# correctly.  TRACEPOINT_CMD is the command used to set tracepoints
62# (e.g. trace or ftrace).
63
64proc test_tracepoint_enable_disable { tracepoint_cmd } {
65    with_test_prefix "test_tracepoint_enable_disable $tracepoint_cmd" {
66	global executable
67	clean_restart ${executable}
68
69	set expected 0
70
71	if ![runto_main] {
72	    return -1
73	}
74
75	gdb_test "$tracepoint_cmd point_a" "(Tracepoint|Fast tracepoint) 2.*"
76	gdb_test "$tracepoint_cmd point_b" "(Tracepoint|Fast tracepoint) 3.*"
77	gdb_breakpoint "break_here"
78	gdb_test_no_output "tstart"
79
80	# Test that tracepoints start enabled
81	with_test_prefix "start" {
82	    gdb_continue "break_here"
83	    incr expected 2
84	    gdb_test "tstatus" "Collected $expected trace frames.*"
85	}
86
87	# Test that disabling works
88	with_test_prefix "disable #1" {
89	    gdb_test_no_output "disable 2"
90	    gdb_continue "break_here"
91	    incr expected 1
92	    gdb_test "tstatus" "Collected $expected trace frames.*"
93	}
94
95	with_test_prefix "disable #2" {
96	    gdb_test_no_output "disable 3"
97	    gdb_continue "break_here"
98	    gdb_test "tstatus" "Collected $expected trace frames.*"
99	}
100
101	# Test that disabling an already disabled tracepoint works
102	with_test_prefix "disable #3" {
103	    gdb_test_no_output "disable 2"
104	    gdb_continue "break_here"
105	    gdb_test "tstatus" "Collected $expected trace frames.*"
106	}
107
108	# Test that enabling works
109	with_test_prefix "enable #1" {
110	    gdb_test_no_output "enable 2"
111	    gdb_continue "break_here"
112	    incr expected 1
113	    gdb_test "tstatus" "Collected $expected trace frames.*"
114	}
115
116	with_test_prefix "enable #2" {
117	    gdb_test_no_output "enable 3"
118	    gdb_continue "break_here"
119	    incr expected 2
120	    gdb_test "tstatus" "Collected $expected trace frames.*"
121	}
122
123	# Test that enabling an already enabled tracepoint works
124	with_test_prefix "enable #3" {
125	    gdb_test_no_output "enable 3"
126	    gdb_continue "break_here"
127	    incr expected 2
128	    gdb_test "tstatus" "Collected $expected trace frames.*"
129	}
130    }
131}
132
133test_tracepoint_enable_disable trace
134test_tracepoint_enable_disable ftrace
135