Tests: take multiple snapshots in streaming mode
[lttng-tools.git] / tests / regression / tools / snapshots / test_kernel_streaming
CommitLineData
26402e0c
DG
1#!/bin/bash
2#
3# Copyright (C) - 2013 David Goulet <dgoulet@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
17TEST_DESC="Streaming - Snapshot Kernel tracing"
18
19CURDIR=$(dirname $0)/
20TESTDIR=$CURDIR/../../..
21EVENT_NAME="sched_switch"
22PID_RELAYD=0
23SESSION_NAME=""
24CHANNEL_NAME="chan1"
25
26TRACE_PATH=$(mktemp -d)
27
81004a7f 28NUM_TESTS=61
26402e0c
DG
29
30source $TESTDIR/utils/utils.sh
31
32# LTTng kernel modules check
33out=`ls /lib/modules/$(uname -r)/extra | grep lttng`
34if [ -z "$out" ]; then
35 BAIL_OUT "LTTng modules not detected."
36fi
37
38function snapshot_add_output ()
39{
40 local sess_name=$1
41 local trace_path=$2
42 local name=$3
43 local extra_opt=""
44
45 if [ ! -z $name ]; then
46 extra_opt="-n $name"
47 fi
48
49 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name $extra_opt $trace_path >/dev/null 2>&1
50 ok $? "Added snapshot output $trace_path"
51}
52
53# Test a snapshot using a default name for the output destination.
54function test_kernel_default_name_with_del()
55{
56 diag "Test kernel snapshot streaming with default name with delete output"
57 create_lttng_session_no_output $SESSION_NAME
58 enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME
59 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
e563bbdb 60 start_lttng_tracing_ok $SESSION_NAME
26402e0c
DG
61 snapshot_add_output $SESSION_NAME "net://localhost"
62 lttng_snapshot_record $SESSION_NAME
63
64 # Validate test
65 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1*
66 if [ $? -ne 0 ]; then
67 return $?
68 fi
69
31580dc7 70 lttng_snapshot_del_output_ok $SESSION_NAME 1
26402e0c 71 snapshot_add_output $SESSION_NAME "net://localhost"
26402e0c
DG
72 lttng_snapshot_record $SESSION_NAME
73
74 # Validate test with the next ID since a del output was done prior.
75 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-2*
76 if [ $? -ne 0 ]; then
77 return $?
78 fi
79
96340a01 80 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 81 destroy_lttng_session_ok $SESSION_NAME
26402e0c
DG
82
83 return 0
84}
85
86# Test a snapshot using a default name for the output destination.
87function test_kernel_default_name()
88{
89 diag "Test kernel snapshot streaming with default name"
90 create_lttng_session_no_output $SESSION_NAME
91 enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME
92 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
e563bbdb 93 start_lttng_tracing_ok $SESSION_NAME
26402e0c
DG
94 snapshot_add_output $SESSION_NAME "net://localhost"
95 lttng_snapshot_record $SESSION_NAME
96340a01 96 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 97 destroy_lttng_session_ok $SESSION_NAME
26402e0c
DG
98 # Validate test
99 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1*
100 out=$?
101
102 return $out
103}
104
105# Test a snapshot using a custom name for the output destination.
106function test_kernel_custom_name()
107{
108 local out
109 local name="asnapshotname"
110
111 diag "Test kernel snapshot streaming with custom name"
112 create_lttng_session_no_output $SESSION_NAME
113 enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME
114 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
e563bbdb 115 start_lttng_tracing_ok $SESSION_NAME
26402e0c
DG
116 snapshot_add_output $SESSION_NAME "net://localhost" $name
117 lttng_snapshot_record $SESSION_NAME
96340a01 118 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 119 destroy_lttng_session_ok $SESSION_NAME
26402e0c
DG
120
121 if ls $TRACE_PATH/$HOSTNAME/$name* &> /dev/null; then
122 ok 0 "Custom name snapshot exists"
123 # Validate test
124 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$name-*
125 out=$?
126 else
127 fail "No custom name snapshot found"
128 out=1
129 fi
130
131 return $out
132}
133
81004a7f
JR
134function test_kernel_n_snapshot()
135{
136 diag "Test kernel snapshot streaming multiple consecutive snapshot"
137 create_lttng_session_no_output $SESSION_NAME
138 enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME
139 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
140 snapshot_add_output $SESSION_NAME "net://localhost"
141
142 for i in {1..5};
143 do
144 start_lttng_tracing_ok $SESSION_NAME
145 lttng_snapshot_record $SESSION_NAME
146 stop_lttng_tracing_ok $SESSION_NAME
147 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1*
148 if [ $? -ne 0 ]; then
149 return 1
150 fi
151 set -u
152 rm -rf $TRACE_PATH/$HOSTNAME
153 set +u
154 done
155
156 destroy_lttng_session_ok $SESSION_NAME
157 return 0
158}
159
26402e0c
DG
160plan_tests $NUM_TESTS
161
162print_test_banner "$TEST_DESC"
163
164if [ "$(id -u)" == "0" ]; then
165 isroot=1
166else
167 isroot=0
168fi
169
170skip $isroot "Root access is needed. Skipping all kernel streaming tests." $NUM_TESTS ||
171{
172 start_lttng_relayd "-o $TRACE_PATH"
173 start_lttng_sessiond
174
81004a7f
JR
175 tests=( test_kernel_default_name
176 test_kernel_custom_name
177 test_kernel_default_name_with_del
178 test_kernel_n_snapshot
179 )
26402e0c
DG
180
181 for fct_test in ${tests[@]};
182 do
183 SESSION_NAME=$(randstring 16 0)
184 ${fct_test}
185 if [ $? -eq 0 ]; then
186 # Only delete if successful
25d6f007 187 rm -rf $TRACE_PATH
26402e0c
DG
188 else
189 break
190 fi
191 done
192
193 stop_lttng_sessiond
194 stop_lttng_relayd
195}
This page took 0.050885 seconds and 5 git commands to generate.