Tests: use babeltrace2 for all tests
[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 true_loop_cpu0()
104 {
105 # Generate many system call events (fill buffers) on CPU 0
106 for a in $(seq 1 $1); do
107 taskset 0x00000001 /bin/true;
108 done
109 }
110
111 function test_kernel_local_snapshot_discard ()
112 {
113 diag "Test local kernel snapshots with small discard buffers"
114 create_lttng_session_no_output $SESSION_NAME
115 enable_lttng_mmap_discard_small_kernel_channel $SESSION_NAME \
116 $CHANNEL_NAME
117 lttng_enable_kernel_syscall_ok $SESSION_NAME -a $CHANNEL_NAME
118 start_lttng_tracing_ok $SESSION_NAME
119 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
120
121 true_loop_cpu0 10000
122
123 # Take first snapshot, remember first line.
124 lttng_snapshot_record $SESSION_NAME
125 FIRST_LINE="$(trace_first_line $TRACE_PATH/)"
126 diag "First line (1st snapshot): $FIRST_LINE"
127
128 rm -rf $TRACE_PATH
129
130 true_loop_cpu0 10000
131
132 # Take 2nd snapshot, compare first line. In discard mode, they
133 # should still be the same.
134 lttng_snapshot_record $SESSION_NAME
135 FIRST_LINE_2="$(trace_first_line $TRACE_PATH/)"
136 diag "First line (2nd snapshot): $FIRST_LINE"
137 rm -rf $TRACE_PATH
138
139 if [ x"$FIRST_LINE" != x"$FIRST_LINE_2" ]; then
140 fail "First snapshot event do not match"
141 else
142 pass "First snapshot event match"
143 fi
144
145 stop_lttng_tracing_ok $SESSION_NAME
146 destroy_lttng_session_ok $SESSION_NAME
147 }
148
149 function test_kernel_local_snapshot_overwrite_small_buffers ()
150 {
151 diag "Test local kernel snapshot with small overwrite buffers"
152 create_lttng_session_no_output $SESSION_NAME
153 enable_lttng_mmap_overwrite_small_kernel_channel $SESSION_NAME \
154 $CHANNEL_NAME
155 lttng_enable_kernel_syscall_ok $SESSION_NAME -a $CHANNEL_NAME
156 start_lttng_tracing_ok $SESSION_NAME
157 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
158
159 true_loop_cpu0 10000
160
161 # Take first snapshot, remember first line.
162 lttng_snapshot_record $SESSION_NAME
163 FIRST_LINE="$(trace_first_line $TRACE_PATH/)"
164 diag "First line (1st snapshot): $FIRST_LINE"
165
166 rm -rf $TRACE_PATH
167
168 true_loop_cpu0 10000
169
170 # Take 2nd snapshot, compare first line. In overwrite mode, they
171 # WILL be different.
172 lttng_snapshot_record $SESSION_NAME
173 FIRST_LINE_2="$(trace_first_line $TRACE_PATH/)"
174 diag "First line (2nd snapshot): $FIRST_LINE_2"
175 rm -rf $TRACE_PATH
176
177 if [ x"$FIRST_LINE" != x"$FIRST_LINE_2" ]; then
178 pass "First snapshot event do not match"
179 else
180 fail "First snapshot event match"
181 fi
182
183 stop_lttng_tracing_ok $SESSION_NAME
184 destroy_lttng_session_ok $SESSION_NAME
185 }
186
187 function test_kernel_1000_local_snapshots ()
188 {
189 NB_SNAP=1000
190
191 diag "Test local kernel snapshots"
192 create_lttng_session_no_output $SESSION_NAME
193 enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME
194 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
195 start_lttng_tracing_ok $SESSION_NAME
196 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
197 for i in $(seq 1 $NB_SNAP); do
198 diag "Snapshot $i/$NB_SNAP"
199 rm -rf $TRACE_PATH/snapshot/* 2>/dev/null
200 lttng_snapshot_record $SESSION_NAME
201 # Validate test
202 validate_trace $EVENT_NAME $TRACE_PATH/
203 if [ $? -eq 0 ]; then
204 # Only delete if successful
205 rm -rf $TRACE_PATH
206 else
207 break
208 fi
209 done
210 stop_lttng_tracing_ok $SESSION_NAME
211 destroy_lttng_session_ok $SESSION_NAME
212 }
213
214 plan_tests $NUM_TESTS
215
216 print_test_banner "$TEST_DESC"
217
218 bail_out_if_no_babeltrace
219
220
221 if [ "$(id -u)" == "0" ]; then
222 isroot=1
223 else
224 isroot=0
225 fi
226
227 skip $isroot "Root access is needed. Skipping all kernel snapshot tests" $NUM_TESTS ||
228 {
229
230 validate_lttng_modules_present
231
232 start_lttng_sessiond
233
234 #tests=( test_kernel_1000_local_snapshots )
235 tests=( test_kernel_local_snapshot
236 test_kernel_local_snapshot_after_stop
237 test_kernel_local_snapshot_append_to_metadata
238 test_kernel_local_snapshot_discard
239 test_kernel_local_snapshot_overwrite_small_buffers
240 test_kernel_1000_local_snapshots
241 )
242
243 for fct_test in ${tests[@]};
244 do
245 SESSION_NAME=$(randstring 16 0)
246 ${fct_test}
247
248 done
249
250 stop_lttng_sessiond
251 }
This page took 0.066463 seconds and 5 git commands to generate.