tests: add check_skip_kernel_test to check root user and lttng kernel modules
[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 -d -t 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 fi
60 }
61
62 function test_kernel_local_snapshot_append_to_metadata ()
63 {
64 local EVENT1=sched_switch
65 local EVENT2=sched_process_exit
66
67 diag "Test local kernel snapshots with one event $EVENT1"
68 create_lttng_session_no_output $SESSION_NAME
69 enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME
70 lttng_enable_kernel_event $SESSION_NAME $EVENT1 $CHANNEL_NAME
71 start_lttng_tracing_ok $SESSION_NAME
72 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
73
74 # first snapshot with only 1 event
75 lttng_snapshot_record $SESSION_NAME
76 validate_trace $EVENT_NAME $TRACE_PATH/
77 if [ $? -eq 0 ]; then
78 # Only delete if successful
79 rm -rf $TRACE_PATH
80 fi
81
82 diag "Adding event $EVENT2"
83 # second snapshot with 2 events
84 lttng_enable_kernel_event $SESSION_NAME $EVENT2 $CHANNEL_NAME
85 rm -rf $TRACE_PATH/snapshot/* 2>/dev/null
86 lttng_snapshot_record $SESSION_NAME
87 validate_trace "${EVENT1},${EVENT2}" $TRACE_PATH/
88 if [ $? -eq 0 ]; then
89 # Only delete if successful
90 rm -rf $TRACE_PATH
91 fi
92
93 stop_lttng_tracing_ok $SESSION_NAME
94 destroy_lttng_session_ok $SESSION_NAME
95 }
96
97 function generate_filter_events_cpu0()
98 {
99 # Generate many events (fill buffers) on a single CPU
100 taskset --cpu-list "$(get_any_available_cpu)" /bin/echo -n "$1" > /proc/lttng-test-filter-event 2> /dev/null
101 }
102
103 function test_kernel_local_snapshot_discard ()
104 {
105 diag "Test local kernel snapshots with small discard buffers"
106
107 local event_name="lttng_test_filter_event"
108
109 modprobe lttng-test
110 create_lttng_session_no_output $SESSION_NAME
111 enable_lttng_mmap_discard_small_kernel_channel $SESSION_NAME \
112 $CHANNEL_NAME
113 enable_kernel_lttng_event_ok $SESSION_NAME $event_name $CHANNEL_NAME
114 start_lttng_tracing_ok $SESSION_NAME
115 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
116
117 generate_filter_events_cpu0 10000
118
119 # Take first snapshot, remember first line.
120 lttng_snapshot_record $SESSION_NAME
121 FIRST_LINE="$(trace_first_line $TRACE_PATH/)"
122 diag "First line (1st snapshot): $FIRST_LINE"
123
124 rm -rf $TRACE_PATH
125
126 # Fill CPU 0's buffer and overwrite previous contents
127 generate_filter_events_cpu0 10000
128
129 # Take 2nd snapshot, compare first line. In discard mode, they
130 # should still be the same.
131 lttng_snapshot_record $SESSION_NAME
132 FIRST_LINE_2="$(trace_first_line $TRACE_PATH/)"
133 diag "First line (2nd snapshot): $FIRST_LINE"
134 rm -rf $TRACE_PATH
135
136 if [ x"$FIRST_LINE" != x"$FIRST_LINE_2" ]; then
137 fail "First snapshot event do not match"
138 else
139 pass "First snapshot event match"
140 fi
141
142 stop_lttng_tracing_ok $SESSION_NAME
143 destroy_lttng_session_ok $SESSION_NAME
144 modprobe --remove lttng-test
145 }
146
147 function test_kernel_local_snapshot_overwrite_small_buffers ()
148 {
149 diag "Test local kernel snapshot with small overwrite buffers"
150
151 local event_name="lttng_test_filter_event"
152
153 modprobe lttng-test
154 create_lttng_session_no_output $SESSION_NAME
155 enable_lttng_mmap_overwrite_small_kernel_channel $SESSION_NAME \
156 $CHANNEL_NAME
157 enable_kernel_lttng_event_ok $SESSION_NAME $event_name $CHANNEL_NAME
158 start_lttng_tracing_ok $SESSION_NAME
159 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
160
161 generate_filter_events_cpu0 10000
162
163 # Take first snapshot, remember first line.
164 lttng_snapshot_record $SESSION_NAME
165 FIRST_LINE="$(trace_first_line $TRACE_PATH/)"
166 diag "First line (1st snapshot): $FIRST_LINE"
167
168 rm -rf $TRACE_PATH
169
170 # Fill CPU 0's buffer and overwrite previous contents
171 generate_filter_events_cpu0 10000
172
173 # Take 2nd snapshot, compare first line. In overwrite mode, they
174 # WILL be different.
175 lttng_snapshot_record $SESSION_NAME
176 FIRST_LINE_2="$(trace_first_line $TRACE_PATH/)"
177 diag "First line (2nd snapshot): $FIRST_LINE_2"
178 rm -rf $TRACE_PATH
179
180 if [ x"$FIRST_LINE" != x"$FIRST_LINE_2" ]; then
181 pass "First snapshot event do not match"
182 else
183 fail "First snapshot event match"
184 fi
185
186 stop_lttng_tracing_ok $SESSION_NAME
187 destroy_lttng_session_ok $SESSION_NAME
188 modprobe --remove lttng-test
189 }
190
191 function test_kernel_1000_local_snapshots ()
192 {
193 NB_SNAP=1000
194
195 diag "Test local kernel snapshots"
196 create_lttng_session_no_output $SESSION_NAME
197 enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME
198 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
199 start_lttng_tracing_ok $SESSION_NAME
200 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
201 for i in $(seq 1 $NB_SNAP); do
202 diag "Snapshot $i/$NB_SNAP"
203 rm -rf $TRACE_PATH/snapshot/* 2>/dev/null
204 lttng_snapshot_record $SESSION_NAME
205 # Validate test
206 validate_trace $EVENT_NAME $TRACE_PATH/
207 if [ $? -eq 0 ]; then
208 # Only delete if successful
209 rm -rf $TRACE_PATH
210 else
211 break
212 fi
213 done
214 stop_lttng_tracing_ok $SESSION_NAME
215 destroy_lttng_session_ok $SESSION_NAME
216 }
217
218 plan_tests $NUM_TESTS
219
220 print_test_banner "$TEST_DESC"
221
222 bail_out_if_no_babeltrace
223
224 check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." ||
225 {
226
227 validate_lttng_modules_present
228
229 start_lttng_sessiond
230
231 #tests=( test_kernel_1000_local_snapshots )
232 tests=( test_kernel_local_snapshot
233 test_kernel_local_snapshot_after_stop
234 test_kernel_local_snapshot_append_to_metadata
235 test_kernel_local_snapshot_discard
236 test_kernel_local_snapshot_overwrite_small_buffers
237 test_kernel_1000_local_snapshots
238 )
239
240 for fct_test in ${tests[@]};
241 do
242 SESSION_NAME=$(randstring 16 0)
243 ${fct_test}
244
245 done
246
247 stop_lttng_sessiond
248 }
This page took 0.037143 seconds and 5 git commands to generate.