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