3 # Copyright (C) - 2013 Julien Desfossez <jdesfossez@efficios.com>
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.
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
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"
20 TESTDIR
=$CURDIR/..
/..
/..
21 EVENT_NAME
="sched_switch"
24 CHANNEL_NAME
="snapchan"
26 TRACE_PATH
=$
(mktemp
-d)
30 source $TESTDIR/utils
/utils.sh
32 # LTTng kernel modules check
33 out
=`ls /lib/modules/$(uname -r)/extra | grep lttng`
34 if [ -z "$out" ]; then
35 BAIL_OUT
"LTTng modules not detected."
38 function test_kernel_local_snapshot
()
40 diag
"Test local kernel snapshots"
41 create_lttng_session_no_output
$SESSION_NAME
42 enable_lttng_mmap_overwrite_kernel_channel
$SESSION_NAME $CHANNEL_NAME
43 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
44 start_lttng_tracing_ok
$SESSION_NAME
45 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
46 lttng_snapshot_record
$SESSION_NAME
47 stop_lttng_tracing_ok
$SESSION_NAME
48 destroy_lttng_session_ok
$SESSION_NAME
51 validate_trace
$EVENT_NAME $TRACE_PATH/
53 # Only delete if successful
60 function test_kernel_local_snapshot_after_stop
()
62 diag
"Test local kernel snapshots after stop"
63 create_lttng_session_no_output
$SESSION_NAME
64 enable_lttng_mmap_overwrite_kernel_channel
$SESSION_NAME $CHANNEL_NAME
65 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
66 start_lttng_tracing_ok
$SESSION_NAME
67 stop_lttng_tracing_ok
$SESSION_NAME
68 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
69 lttng_snapshot_record
$SESSION_NAME
70 destroy_lttng_session_ok
$SESSION_NAME
73 validate_trace
$EVENT_NAME $TRACE_PATH/
75 # Only delete if successful
82 function test_kernel_local_snapshot_append_to_metadata
()
84 local EVENT1
=sched_switch
85 local EVENT2
=sched_process_exit
87 diag
"Test local kernel snapshots with one event $EVENT1"
88 create_lttng_session_no_output
$SESSION_NAME
89 enable_lttng_mmap_overwrite_kernel_channel
$SESSION_NAME $CHANNEL_NAME
90 lttng_enable_kernel_event
$SESSION_NAME $EVENT1 $CHANNEL_NAME
91 start_lttng_tracing_ok
$SESSION_NAME
92 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
94 # first snapshot with only 1 event
95 lttng_snapshot_record
$SESSION_NAME
96 validate_trace
$EVENT_NAME $TRACE_PATH/
98 # Only delete if successful
104 diag
"Adding event $EVENT2"
105 # second snapshot with 2 events
106 lttng_enable_kernel_event
$SESSION_NAME $EVENT2 $CHANNEL_NAME
107 rm -rf $TRACE_PATH/snapshot
/* 2>/dev
/null
108 lttng_snapshot_record
$SESSION_NAME
109 validate_trace
"${EVENT1},${EVENT2}" $TRACE_PATH/
110 if [ $?
-eq 0 ]; then
111 # Only delete if successful
117 stop_lttng_tracing_ok
$SESSION_NAME
118 destroy_lttng_session_ok
$SESSION_NAME
121 function test_kernel_1000_local_snapshots
()
125 diag
"Test local kernel snapshots"
126 create_lttng_session_no_output
$SESSION_NAME
127 enable_lttng_mmap_overwrite_kernel_channel
$SESSION_NAME $CHANNEL_NAME
128 lttng_enable_kernel_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
129 start_lttng_tracing_ok
$SESSION_NAME
130 lttng_snapshot_add_output_ok
$SESSION_NAME $TRACE_PATH
131 for i
in $
(seq 1 $NB_SNAP); do
132 diag
"Snapshot $i/$NB_SNAP"
133 rm -rf $TRACE_PATH/snapshot
/* 2>/dev
/null
134 lttng_snapshot_record
$SESSION_NAME
136 validate_trace
$EVENT_NAME $TRACE_PATH/
137 if [ $?
-eq 0 ]; then
138 # Only delete if successful
144 stop_lttng_tracing_ok
$SESSION_NAME
145 destroy_lttng_session_ok
$SESSION_NAME
148 plan_tests
$NUM_TESTS
150 print_test_banner
"$TEST_DESC"
152 if [ "$(id -u)" == "0" ]; then
158 skip
$isroot "Root access is needed. Skipping all kernel snapshot tests." $NUM_TESTS ||
162 #tests=( test_kernel_1000_local_snapshots )
163 tests
=( test_kernel_local_snapshot test_kernel_local_snapshot_after_stop test_kernel_local_snapshot_append_to_metadata test_kernel_1000_local_snapshots
)
165 for fct_test
in ${tests[@]};
167 SESSION_NAME
=$
(randstring
16 0)