Commit | Line | Data |
---|---|---|
07b86b52 JD |
1 | #!/bin/bash |
2 | # | |
3 | # Copyright (C) - 2013 Julien Desfossez <jdesfossez@efficios.com> | |
4 | # | |
5 | # This library is free software; you can redistribute it and/or modify it under | |
6 | # the terms of the GNU Lesser General Public License as published by the Free | |
7 | # Software Foundation; version 2.1 of the License. | |
8 | # | |
9 | # This library is distributed in the hope that it will be useful, but WITHOUT | |
10 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
11 | # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | |
12 | # details. | |
13 | # | |
14 | # You should have received a copy of the GNU Lesser General Public License | |
15 | # along with this library; if not, write to the Free Software Foundation, Inc., | |
16 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
17 | TEST_DESC="Snapshots - Kernel tracing" | |
18 | ||
19 | CURDIR=$(dirname $0)/ | |
20 | TESTDIR=$CURDIR/../../.. | |
21 | EVENT_NAME="sched_switch" | |
07b86b52 JD |
22 | SESSION_NAME="" |
23 | CHANNEL_NAME="snapchan" | |
24 | ||
25 | TRACE_PATH=$(mktemp -d) | |
26 | ||
086e6add | 27 | NUM_TESTS=2060 |
07b86b52 JD |
28 | |
29 | source $TESTDIR/utils/utils.sh | |
30 | ||
07b86b52 JD |
31 | function test_kernel_local_snapshot () |
32 | { | |
33 | diag "Test local kernel snapshots" | |
34 | create_lttng_session_no_output $SESSION_NAME | |
35 | enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME | |
36 | lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
e563bbdb | 37 | start_lttng_tracing_ok $SESSION_NAME |
b5633831 | 38 | lttng_snapshot_add_output_ok $SESSION_NAME $TRACE_PATH |
07b86b52 | 39 | lttng_snapshot_record $SESSION_NAME |
96340a01 | 40 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 41 | destroy_lttng_session_ok $SESSION_NAME |
07b86b52 JD |
42 | |
43 | # Validate test | |
78435723 | 44 | validate_trace $EVENT_NAME $TRACE_PATH/ |
07b86b52 JD |
45 | if [ $? -eq 0 ]; then |
46 | # Only delete if successful | |
47 | rm -rf $TRACE_PATH | |
48 | else | |
49 | break | |
50 | fi | |
51 | } | |
52 | ||
53 | function test_kernel_local_snapshot_after_stop () | |
54 | { | |
55 | diag "Test local kernel snapshots after stop" | |
56 | create_lttng_session_no_output $SESSION_NAME | |
57 | enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME | |
58 | lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
e563bbdb | 59 | start_lttng_tracing_ok $SESSION_NAME |
96340a01 | 60 | stop_lttng_tracing_ok $SESSION_NAME |
b5633831 | 61 | lttng_snapshot_add_output_ok $SESSION_NAME $TRACE_PATH |
07b86b52 | 62 | lttng_snapshot_record $SESSION_NAME |
67b4c664 | 63 | destroy_lttng_session_ok $SESSION_NAME |
07b86b52 JD |
64 | |
65 | # Validate test | |
78435723 | 66 | validate_trace $EVENT_NAME $TRACE_PATH/ |
07b86b52 JD |
67 | if [ $? -eq 0 ]; then |
68 | # Only delete if successful | |
69 | rm -rf $TRACE_PATH | |
70 | else | |
71 | break | |
72 | fi | |
73 | } | |
74 | ||
75 | function test_kernel_local_snapshot_append_to_metadata () | |
76 | { | |
78435723 JD |
77 | local EVENT1=sched_switch |
78 | local EVENT2=sched_process_exit | |
07b86b52 JD |
79 | |
80 | diag "Test local kernel snapshots with one event $EVENT1" | |
81 | create_lttng_session_no_output $SESSION_NAME | |
82 | enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME | |
83 | lttng_enable_kernel_event $SESSION_NAME $EVENT1 $CHANNEL_NAME | |
e563bbdb | 84 | start_lttng_tracing_ok $SESSION_NAME |
b5633831 | 85 | lttng_snapshot_add_output_ok $SESSION_NAME $TRACE_PATH |
07b86b52 JD |
86 | |
87 | # first snapshot with only 1 event | |
88 | lttng_snapshot_record $SESSION_NAME | |
78435723 | 89 | validate_trace $EVENT_NAME $TRACE_PATH/ |
07b86b52 JD |
90 | if [ $? -eq 0 ]; then |
91 | # Only delete if successful | |
92 | rm -rf $TRACE_PATH | |
93 | else | |
94 | break | |
95 | fi | |
96 | ||
97 | diag "Adding event $EVENT2" | |
98 | # second snapshot with 2 events | |
99 | lttng_enable_kernel_event $SESSION_NAME $EVENT2 $CHANNEL_NAME | |
100 | rm -rf $TRACE_PATH/snapshot/* 2>/dev/null | |
101 | lttng_snapshot_record $SESSION_NAME | |
78435723 | 102 | validate_trace "${EVENT1},${EVENT2}" $TRACE_PATH/ |
07b86b52 JD |
103 | if [ $? -eq 0 ]; then |
104 | # Only delete if successful | |
105 | rm -rf $TRACE_PATH | |
106 | else | |
107 | break | |
108 | fi | |
109 | ||
96340a01 | 110 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 111 | destroy_lttng_session_ok $SESSION_NAME |
07b86b52 JD |
112 | } |
113 | ||
086e6add MD |
114 | function true_loop_cpu0() |
115 | { | |
116 | # Generate many system call events (fill buffers) on CPU 0 | |
117 | for a in $(seq 1 $1); do | |
118 | taskset 0x00000001 /bin/true; | |
119 | done | |
120 | } | |
121 | ||
122 | function test_kernel_local_snapshot_discard () | |
123 | { | |
124 | diag "Test local kernel snapshots with small discard buffers" | |
125 | create_lttng_session_no_output $SESSION_NAME | |
126 | enable_lttng_mmap_discard_small_kernel_channel $SESSION_NAME \ | |
127 | $CHANNEL_NAME | |
128 | lttng_enable_kernel_syscall_ok $SESSION_NAME -a $CHANNEL_NAME | |
129 | start_lttng_tracing_ok $SESSION_NAME | |
130 | lttng_snapshot_add_output_ok $SESSION_NAME $TRACE_PATH | |
131 | ||
132 | true_loop_cpu0 10000 | |
133 | ||
134 | # Take first snapshot, remember first line. | |
135 | lttng_snapshot_record $SESSION_NAME | |
136 | FIRST_LINE="$(trace_first_line $TRACE_PATH/)" | |
137 | diag "First line (1st snapshot): $FIRST_LINE" | |
138 | ||
139 | rm -rf $TRACE_PATH | |
140 | ||
141 | true_loop_cpu0 10000 | |
142 | ||
143 | # Take 2nd snapshot, compare first line. In discard mode, they | |
144 | # should still be the same. | |
145 | lttng_snapshot_record $SESSION_NAME | |
146 | FIRST_LINE_2="$(trace_first_line $TRACE_PATH/)" | |
147 | diag "First line (2nd snapshot): $FIRST_LINE" | |
148 | rm -rf $TRACE_PATH | |
149 | ||
150 | if [ x"$FIRST_LINE" != x"$FIRST_LINE_2" ]; then | |
151 | fail "First snapshot event do not match." | |
152 | else | |
153 | pass "First snapshot event match." | |
154 | fi | |
155 | ||
156 | stop_lttng_tracing_ok $SESSION_NAME | |
157 | destroy_lttng_session_ok $SESSION_NAME | |
158 | } | |
159 | ||
160 | function test_kernel_local_snapshot_overwrite_small_buffers () | |
161 | { | |
162 | diag "Test local kernel snapshot with small overwrite buffers" | |
163 | create_lttng_session_no_output $SESSION_NAME | |
164 | enable_lttng_mmap_overwrite_small_kernel_channel $SESSION_NAME \ | |
165 | $CHANNEL_NAME | |
166 | lttng_enable_kernel_syscall_ok $SESSION_NAME -a $CHANNEL_NAME | |
167 | start_lttng_tracing_ok $SESSION_NAME | |
168 | lttng_snapshot_add_output_ok $SESSION_NAME $TRACE_PATH | |
169 | ||
170 | true_loop_cpu0 10000 | |
171 | ||
172 | # Take first snapshot, remember first line. | |
173 | lttng_snapshot_record $SESSION_NAME | |
174 | FIRST_LINE="$(trace_first_line $TRACE_PATH/)" | |
175 | diag "First line (1st snapshot): $FIRST_LINE" | |
176 | ||
177 | rm -rf $TRACE_PATH | |
178 | ||
179 | true_loop_cpu0 10000 | |
180 | ||
181 | # Take 2nd snapshot, compare first line. In overwrite mode, they | |
182 | # WILL be different. | |
183 | lttng_snapshot_record $SESSION_NAME | |
184 | FIRST_LINE_2="$(trace_first_line $TRACE_PATH/)" | |
185 | diag "First line (2nd snapshot): $FIRST_LINE_2" | |
186 | rm -rf $TRACE_PATH | |
187 | ||
188 | if [ x"$FIRST_LINE" != x"$FIRST_LINE_2" ]; then | |
189 | pass "First snapshot event do not match." | |
190 | else | |
191 | fail "First snapshot event match." | |
192 | fi | |
193 | ||
194 | stop_lttng_tracing_ok $SESSION_NAME | |
195 | destroy_lttng_session_ok $SESSION_NAME | |
196 | } | |
197 | ||
07b86b52 JD |
198 | function test_kernel_1000_local_snapshots () |
199 | { | |
200 | NB_SNAP=1000 | |
201 | ||
202 | diag "Test local kernel snapshots" | |
203 | create_lttng_session_no_output $SESSION_NAME | |
204 | enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME | |
205 | lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME | |
e563bbdb | 206 | start_lttng_tracing_ok $SESSION_NAME |
b5633831 | 207 | lttng_snapshot_add_output_ok $SESSION_NAME $TRACE_PATH |
07b86b52 JD |
208 | for i in $(seq 1 $NB_SNAP); do |
209 | diag "Snapshot $i/$NB_SNAP" | |
210 | rm -rf $TRACE_PATH/snapshot/* 2>/dev/null | |
211 | lttng_snapshot_record $SESSION_NAME | |
212 | # Validate test | |
78435723 | 213 | validate_trace $EVENT_NAME $TRACE_PATH/ |
07b86b52 JD |
214 | if [ $? -eq 0 ]; then |
215 | # Only delete if successful | |
216 | rm -rf $TRACE_PATH | |
217 | else | |
218 | break | |
219 | fi | |
220 | done | |
96340a01 | 221 | stop_lttng_tracing_ok $SESSION_NAME |
67b4c664 | 222 | destroy_lttng_session_ok $SESSION_NAME |
07b86b52 JD |
223 | } |
224 | ||
225 | plan_tests $NUM_TESTS | |
226 | ||
227 | print_test_banner "$TEST_DESC" | |
228 | ||
229 | if [ "$(id -u)" == "0" ]; then | |
230 | isroot=1 | |
231 | else | |
232 | isroot=0 | |
233 | fi | |
234 | ||
235 | skip $isroot "Root access is needed. Skipping all kernel snapshot tests." $NUM_TESTS || | |
236 | { | |
9c8a3964 JR |
237 | |
238 | validate_lttng_modules_present | |
239 | ||
07b86b52 JD |
240 | start_lttng_sessiond |
241 | ||
242 | #tests=( test_kernel_1000_local_snapshots ) | |
086e6add MD |
243 | tests=( test_kernel_local_snapshot |
244 | test_kernel_local_snapshot_after_stop | |
245 | test_kernel_local_snapshot_append_to_metadata | |
246 | test_kernel_local_snapshot_discard | |
247 | test_kernel_local_snapshot_overwrite_small_buffers | |
248 | test_kernel_1000_local_snapshots | |
249 | ) | |
07b86b52 JD |
250 | |
251 | for fct_test in ${tests[@]}; | |
252 | do | |
253 | SESSION_NAME=$(randstring 16 0) | |
254 | ${fct_test} | |
255 | ||
256 | done | |
257 | ||
258 | stop_lttng_sessiond | |
259 | } |