Tests: test_kernel: add comments regarding the filling of buffers
[lttng-tools.git] / tests / regression / tools / snapshots / test_kernel
1 #!/bin/bash
2 #
3 # Copyright (C) 2013 Julien Desfossez <jdesfossez@efficios.com>
4 #
5 # SPDX-License-Identifier: LGPL-2.1-only
6
7 TEST_DESC="Snapshots - Kernel tracing"
8
9 CURDIR=$(dirname $0)/
10 TESTDIR=$CURDIR/../../..
11 EVENT_NAME="sched_switch"
12 SESSION_NAME=""
13 CHANNEL_NAME="snapchan"
14
15 TRACE_PATH=$(mktemp --tmpdir -d tmp.test_snapshots_kernel_trace_path.XXXXXX)
16
17 NUM_TESTS=2061
18
19 source $TESTDIR/utils/utils.sh
20
21 function test_kernel_local_snapshot ()
22 {
23 diag "Test local kernel snapshots"
24 create_lttng_session_no_output $SESSION_NAME
25 enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME
26 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
27 start_lttng_tracing_ok $SESSION_NAME
28 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
29 lttng_snapshot_record $SESSION_NAME
30 stop_lttng_tracing_ok $SESSION_NAME
31 destroy_lttng_session_ok $SESSION_NAME
32
33 # Validate test
34 validate_trace_path_kernel_snapshot "$TRACE_PATH" "" "snapshot-1" 0 ""
35 validate_trace $EVENT_NAME $TRACE_PATH/
36 if [ $? -eq 0 ]; then
37 # Only delete if successful
38 rm -rf $TRACE_PATH
39 fi
40 }
41
42 function test_kernel_local_snapshot_after_stop ()
43 {
44 diag "Test local kernel snapshots after stop"
45 create_lttng_session_no_output $SESSION_NAME
46 enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME
47 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
48 start_lttng_tracing_ok $SESSION_NAME
49 stop_lttng_tracing_ok $SESSION_NAME
50 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
51 lttng_snapshot_record $SESSION_NAME
52 destroy_lttng_session_ok $SESSION_NAME
53
54 # Validate test
55 validate_trace $EVENT_NAME $TRACE_PATH/
56 if [ $? -eq 0 ]; then
57 # Only delete if successful
58 rm -rf $TRACE_PATH
59 else
60 break
61 fi
62 }
63
64 function test_kernel_local_snapshot_append_to_metadata ()
65 {
66 local EVENT1=sched_switch
67 local EVENT2=sched_process_exit
68
69 diag "Test local kernel snapshots with one event $EVENT1"
70 create_lttng_session_no_output $SESSION_NAME
71 enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME
72 lttng_enable_kernel_event $SESSION_NAME $EVENT1 $CHANNEL_NAME
73 start_lttng_tracing_ok $SESSION_NAME
74 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
75
76 # first snapshot with only 1 event
77 lttng_snapshot_record $SESSION_NAME
78 validate_trace $EVENT_NAME $TRACE_PATH/
79 if [ $? -eq 0 ]; then
80 # Only delete if successful
81 rm -rf $TRACE_PATH
82 else
83 break
84 fi
85
86 diag "Adding event $EVENT2"
87 # second snapshot with 2 events
88 lttng_enable_kernel_event $SESSION_NAME $EVENT2 $CHANNEL_NAME
89 rm -rf $TRACE_PATH/snapshot/* 2>/dev/null
90 lttng_snapshot_record $SESSION_NAME
91 validate_trace "${EVENT1},${EVENT2}" $TRACE_PATH/
92 if [ $? -eq 0 ]; then
93 # Only delete if successful
94 rm -rf $TRACE_PATH
95 else
96 break
97 fi
98
99 stop_lttng_tracing_ok $SESSION_NAME
100 destroy_lttng_session_ok $SESSION_NAME
101 }
102
103 function generate_filter_events_cpu0()
104 {
105 # Generate many events (fill buffers) on CPU 0
106 taskset 0x00000001 /bin/echo -n "$1" > /proc/lttng-test-filter-event 2> /dev/null
107 }
108
109 function test_kernel_local_snapshot_discard ()
110 {
111 diag "Test local kernel snapshots with small discard buffers"
112
113 local event_name="lttng_test_filter_event"
114
115 modprobe lttng-test
116 create_lttng_session_no_output $SESSION_NAME
117 enable_lttng_mmap_discard_small_kernel_channel $SESSION_NAME \
118 $CHANNEL_NAME
119 enable_kernel_lttng_event_ok $SESSION_NAME $event_name $CHANNEL_NAME
120 start_lttng_tracing_ok $SESSION_NAME
121 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
122
123 generate_filter_events_cpu0 10000
124
125 # Take first snapshot, remember first line.
126 lttng_snapshot_record $SESSION_NAME
127 FIRST_LINE="$(trace_first_line $TRACE_PATH/)"
128 diag "First line (1st snapshot): $FIRST_LINE"
129
130 rm -rf $TRACE_PATH
131
132 # Fill CPU 0's buffer and overwrite previous contents
133 generate_filter_events_cpu0 10000
134
135 # Take 2nd snapshot, compare first line. In discard mode, they
136 # should still be the same.
137 lttng_snapshot_record $SESSION_NAME
138 FIRST_LINE_2="$(trace_first_line $TRACE_PATH/)"
139 diag "First line (2nd snapshot): $FIRST_LINE"
140 rm -rf $TRACE_PATH
141
142 if [ x"$FIRST_LINE" != x"$FIRST_LINE_2" ]; then
143 fail "First snapshot event do not match"
144 else
145 pass "First snapshot event match"
146 fi
147
148 stop_lttng_tracing_ok $SESSION_NAME
149 destroy_lttng_session_ok $SESSION_NAME
150 modprobe --remove lttng-test
151 }
152
153 function test_kernel_local_snapshot_overwrite_small_buffers ()
154 {
155 diag "Test local kernel snapshot with small overwrite buffers"
156
157 local event_name="lttng_test_filter_event"
158
159 modprobe lttng-test
160 create_lttng_session_no_output $SESSION_NAME
161 enable_lttng_mmap_overwrite_small_kernel_channel $SESSION_NAME \
162 $CHANNEL_NAME
163 enable_kernel_lttng_event_ok $SESSION_NAME $event_name $CHANNEL_NAME
164 start_lttng_tracing_ok $SESSION_NAME
165 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
166
167 generate_filter_events_cpu0 10000
168
169 # Take first snapshot, remember first line.
170 lttng_snapshot_record $SESSION_NAME
171 FIRST_LINE="$(trace_first_line $TRACE_PATH/)"
172 diag "First line (1st snapshot): $FIRST_LINE"
173
174 rm -rf $TRACE_PATH
175
176 # Fill CPU 0's buffer and overwrite previous contents
177 generate_filter_events_cpu0 10000
178
179 # Take 2nd snapshot, compare first line. In overwrite mode, they
180 # WILL be different.
181 lttng_snapshot_record $SESSION_NAME
182 FIRST_LINE_2="$(trace_first_line $TRACE_PATH/)"
183 diag "First line (2nd snapshot): $FIRST_LINE_2"
184 rm -rf $TRACE_PATH
185
186 if [ x"$FIRST_LINE" != x"$FIRST_LINE_2" ]; then
187 pass "First snapshot event do not match"
188 else
189 fail "First snapshot event match"
190 fi
191
192 stop_lttng_tracing_ok $SESSION_NAME
193 destroy_lttng_session_ok $SESSION_NAME
194 modprobe --remove lttng-test
195 }
196
197 function test_kernel_1000_local_snapshots ()
198 {
199 NB_SNAP=1000
200
201 diag "Test local kernel snapshots"
202 create_lttng_session_no_output $SESSION_NAME
203 enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME
204 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
205 start_lttng_tracing_ok $SESSION_NAME
206 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
207 for i in $(seq 1 $NB_SNAP); do
208 diag "Snapshot $i/$NB_SNAP"
209 rm -rf $TRACE_PATH/snapshot/* 2>/dev/null
210 lttng_snapshot_record $SESSION_NAME
211 # Validate test
212 validate_trace $EVENT_NAME $TRACE_PATH/
213 if [ $? -eq 0 ]; then
214 # Only delete if successful
215 rm -rf $TRACE_PATH
216 else
217 break
218 fi
219 done
220 stop_lttng_tracing_ok $SESSION_NAME
221 destroy_lttng_session_ok $SESSION_NAME
222 }
223
224 plan_tests $NUM_TESTS
225
226 print_test_banner "$TEST_DESC"
227
228 bail_out_if_no_babeltrace
229
230
231 if [ "$(id -u)" == "0" ]; then
232 isroot=1
233 else
234 isroot=0
235 fi
236
237 skip $isroot "Root access is needed. Skipping all kernel snapshot tests" $NUM_TESTS ||
238 {
239
240 validate_lttng_modules_present
241
242 start_lttng_sessiond
243
244 #tests=( test_kernel_1000_local_snapshots )
245 tests=( test_kernel_local_snapshot
246 test_kernel_local_snapshot_after_stop
247 test_kernel_local_snapshot_append_to_metadata
248 test_kernel_local_snapshot_discard
249 test_kernel_local_snapshot_overwrite_small_buffers
250 test_kernel_1000_local_snapshots
251 )
252
253 for fct_test in ${tests[@]};
254 do
255 SESSION_NAME=$(randstring 16 0)
256 ${fct_test}
257
258 done
259
260 stop_lttng_sessiond
261 }
This page took 0.034517 seconds and 4 git commands to generate.