Commit | Line | Data |
---|---|---|
07b86b52 JD |
1 | #!/bin/bash |
2 | # | |
9d16b343 | 3 | # Copyright (C) 2013 Julien Desfossez <jdesfossez@efficios.com> |
07b86b52 | 4 | # |
9d16b343 MJ |
5 | # SPDX-License-Identifier: LGPL-2.1-only |
6 | ||
07b86b52 JD |
7 | TEST_DESC="Snapshots - Kernel tracing" |
8 | ||
9 | CURDIR=$(dirname $0)/ | |
10 | TESTDIR=$CURDIR/../../.. | |
11 | EVENT_NAME="sched_switch" | |
07b86b52 JD |
12 | SESSION_NAME="" |
13 | CHANNEL_NAME="snapchan" | |
14 | ||
15 | TRACE_PATH=$(mktemp -d) | |
16 | ||
bd666153 | 17 | NUM_TESTS=2061 |
07b86b52 JD |
18 | |
19 | source $TESTDIR/utils/utils.sh | |
20 | ||
07b86b52 JD |
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 | |
e563bbdb | 27 | start_lttng_tracing_ok $SESSION_NAME |
9f0e230a | 28 | lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH |
07b86b52 | 29 | lttng_snapshot_record $SESSION_NAME |
96340a01 | 30 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 31 | destroy_lttng_session_ok $SESSION_NAME |
07b86b52 JD |
32 | |
33 | # Validate test | |
bd666153 | 34 | validate_trace_path_kernel_snapshot "$TRACE_PATH" "" "snapshot-1" 0 "" |
78435723 | 35 | validate_trace $EVENT_NAME $TRACE_PATH/ |
07b86b52 JD |
36 | if [ $? -eq 0 ]; then |
37 | # Only delete if successful | |
38 | rm -rf $TRACE_PATH | |
07b86b52 JD |
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 | |
e563bbdb | 48 | start_lttng_tracing_ok $SESSION_NAME |
96340a01 | 49 | stop_lttng_tracing_ok $SESSION_NAME |
9f0e230a | 50 | lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH |
07b86b52 | 51 | lttng_snapshot_record $SESSION_NAME |
67b4c664 | 52 | destroy_lttng_session_ok $SESSION_NAME |
07b86b52 JD |
53 | |
54 | # Validate test | |
78435723 | 55 | validate_trace $EVENT_NAME $TRACE_PATH/ |
07b86b52 JD |
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 | { | |
78435723 JD |
66 | local EVENT1=sched_switch |
67 | local EVENT2=sched_process_exit | |
07b86b52 JD |
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 | |
e563bbdb | 73 | start_lttng_tracing_ok $SESSION_NAME |
9f0e230a | 74 | lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH |
07b86b52 JD |
75 | |
76 | # first snapshot with only 1 event | |
77 | lttng_snapshot_record $SESSION_NAME | |
78435723 | 78 | validate_trace $EVENT_NAME $TRACE_PATH/ |
07b86b52 JD |
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 | |
78435723 | 91 | validate_trace "${EVENT1},${EVENT2}" $TRACE_PATH/ |
07b86b52 JD |
92 | if [ $? -eq 0 ]; then |
93 | # Only delete if successful | |
94 | rm -rf $TRACE_PATH | |
95 | else | |
96 | break | |
97 | fi | |
98 | ||
96340a01 | 99 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 100 | destroy_lttng_session_ok $SESSION_NAME |
07b86b52 JD |
101 | } |
102 | ||
086e6add MD |
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 | |
9f0e230a | 119 | lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH |
086e6add MD |
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 | |
ce83431d | 140 | fail "First snapshot event do not match" |
086e6add | 141 | else |
ce83431d | 142 | pass "First snapshot event match" |
086e6add MD |
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 | |
9f0e230a | 157 | lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH |
086e6add MD |
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 | |
ce83431d | 178 | pass "First snapshot event do not match" |
086e6add | 179 | else |
ce83431d | 180 | fail "First snapshot event match" |
086e6add MD |
181 | fi |
182 | ||
183 | stop_lttng_tracing_ok $SESSION_NAME | |
184 | destroy_lttng_session_ok $SESSION_NAME | |
185 | } | |
186 | ||
07b86b52 JD |
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 | |
e563bbdb | 195 | start_lttng_tracing_ok $SESSION_NAME |
9f0e230a | 196 | lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH |
07b86b52 JD |
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 | |
78435723 | 202 | validate_trace $EVENT_NAME $TRACE_PATH/ |
07b86b52 JD |
203 | if [ $? -eq 0 ]; then |
204 | # Only delete if successful | |
205 | rm -rf $TRACE_PATH | |
206 | else | |
207 | break | |
208 | fi | |
209 | done | |
96340a01 | 210 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 211 | destroy_lttng_session_ok $SESSION_NAME |
07b86b52 JD |
212 | } |
213 | ||
214 | plan_tests $NUM_TESTS | |
215 | ||
216 | print_test_banner "$TEST_DESC" | |
217 | ||
218 | if [ "$(id -u)" == "0" ]; then | |
219 | isroot=1 | |
220 | else | |
221 | isroot=0 | |
222 | fi | |
223 | ||
ce83431d | 224 | skip $isroot "Root access is needed. Skipping all kernel snapshot tests" $NUM_TESTS || |
07b86b52 | 225 | { |
9c8a3964 JR |
226 | |
227 | validate_lttng_modules_present | |
228 | ||
07b86b52 JD |
229 | start_lttng_sessiond |
230 | ||
231 | #tests=( test_kernel_1000_local_snapshots ) | |
086e6add MD |
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 | ) | |
07b86b52 JD |
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 | } |