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