Tests: take multiple snapshots in streaming mode
[lttng-tools.git] / tests / regression / tools / snapshots / test_kernel_streaming
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
17 TEST_DESC="Streaming - Snapshot Kernel tracing"
18
19 CURDIR=$(dirname $0)/
20 TESTDIR=$CURDIR/../../..
21 EVENT_NAME="sched_switch"
22 SESSION_NAME=""
23 CHANNEL_NAME="chan1"
24
25 TRACE_PATH=$(mktemp -d)
26
27 NUM_TESTS=61
28
29 source $TESTDIR/utils/utils.sh
30
31 function 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.
47 function 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
53 start_lttng_tracing_ok $SESSION_NAME
54 snapshot_add_output $SESSION_NAME "net://localhost"
55 lttng_snapshot_record $SESSION_NAME
56
57 # Validate test
58 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1*
59 if [ $? -ne 0 ]; then
60 return $?
61 fi
62
63 lttng_snapshot_del_output_ok $SESSION_NAME 1
64 snapshot_add_output $SESSION_NAME "net://localhost"
65 lttng_snapshot_record $SESSION_NAME
66
67 # Validate test with the next ID since a del output was done prior.
68 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-2*
69 if [ $? -ne 0 ]; then
70 return $?
71 fi
72
73 stop_lttng_tracing_ok $SESSION_NAME
74 destroy_lttng_session_ok $SESSION_NAME
75
76 return 0
77 }
78
79 # Test a snapshot using a default name for the output destination.
80 function 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
86 start_lttng_tracing_ok $SESSION_NAME
87 snapshot_add_output $SESSION_NAME "net://localhost"
88 lttng_snapshot_record $SESSION_NAME
89 stop_lttng_tracing_ok $SESSION_NAME
90 destroy_lttng_session_ok $SESSION_NAME
91 # Validate test
92 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1*
93 out=$?
94
95 return $out
96 }
97
98 # Test a snapshot using a custom name for the output destination.
99 function 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
108 start_lttng_tracing_ok $SESSION_NAME
109 snapshot_add_output $SESSION_NAME "net://localhost" $name
110 lttng_snapshot_record $SESSION_NAME
111 stop_lttng_tracing_ok $SESSION_NAME
112 destroy_lttng_session_ok $SESSION_NAME
113
114 if ls $TRACE_PATH/$HOSTNAME/$name* &> /dev/null; then
115 ok 0 "Custom name snapshot exists"
116 # Validate test
117 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$name-*
118 out=$?
119 else
120 fail "No custom name snapshot found"
121 out=1
122 fi
123
124 return $out
125 }
126
127 function 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
140 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1*
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
153 plan_tests $NUM_TESTS
154
155 print_test_banner "$TEST_DESC"
156
157 if [ "$(id -u)" == "0" ]; then
158 isroot=1
159 else
160 isroot=0
161 fi
162
163 skip $isroot "Root access is needed. Skipping all kernel streaming tests." $NUM_TESTS ||
164 {
165 validate_lttng_modules_present
166
167 start_lttng_relayd "-o $TRACE_PATH"
168 start_lttng_sessiond
169
170 tests=( test_kernel_default_name
171 test_kernel_custom_name
172 test_kernel_default_name_with_del
173 test_kernel_n_snapshot
174 )
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
182 rm -rf $TRACE_PATH
183 else
184 break
185 fi
186 done
187
188 stop_lttng_sessiond
189 stop_lttng_relayd
190 }
This page took 0.034009 seconds and 5 git commands to generate.