Tests: Add kernel snapshot streaming
[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 PID_RELAYD=0
23 SESSION_NAME=""
24 CHANNEL_NAME="chan1"
25
26 TRACE_PATH=$(mktemp -d)
27
28 NUM_TESTS=13
29
30 source $TESTDIR/utils/utils.sh
31
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."
36 fi
37
38 function 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.
54 function 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
60 start_lttng_tracing $SESSION_NAME
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
70 lttng_snapshot_del_output $SESSION_NAME 1
71 snapshot_add_output $SESSION_NAME "net://localhost"
72 lttng snapshot list-output
73 lttng_snapshot_record $SESSION_NAME
74
75 # Validate test with the next ID since a del output was done prior.
76 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-2*
77 if [ $? -ne 0 ]; then
78 return $?
79 fi
80
81 stop_lttng_tracing $SESSION_NAME
82 destroy_lttng_session $SESSION_NAME
83
84 return 0
85 }
86
87 # Test a snapshot using a default name for the output destination.
88 function test_kernel_default_name()
89 {
90 diag "Test kernel snapshot streaming with default name"
91 create_lttng_session_no_output $SESSION_NAME
92 enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME
93 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
94 start_lttng_tracing $SESSION_NAME
95 snapshot_add_output $SESSION_NAME "net://localhost"
96 lttng_snapshot_record $SESSION_NAME
97 stop_lttng_tracing $SESSION_NAME
98 destroy_lttng_session $SESSION_NAME
99 # Validate test
100 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/snapshot-1*
101 out=$?
102
103 return $out
104 }
105
106 # Test a snapshot using a custom name for the output destination.
107 function test_kernel_custom_name()
108 {
109 local out
110 local name="asnapshotname"
111
112 diag "Test kernel snapshot streaming with custom name"
113 create_lttng_session_no_output $SESSION_NAME
114 enable_lttng_mmap_overwrite_kernel_channel $SESSION_NAME $CHANNEL_NAME
115 lttng_enable_kernel_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
116 start_lttng_tracing $SESSION_NAME
117 snapshot_add_output $SESSION_NAME "net://localhost" $name
118 lttng_snapshot_record $SESSION_NAME
119 stop_lttng_tracing $SESSION_NAME
120 destroy_lttng_session $SESSION_NAME
121
122 if ls $TRACE_PATH/$HOSTNAME/$name* &> /dev/null; then
123 ok 0 "Custom name snapshot exists"
124 # Validate test
125 validate_trace $EVENT_NAME $TRACE_PATH/$HOSTNAME/$name-*
126 out=$?
127 else
128 fail "No custom name snapshot found"
129 out=1
130 fi
131
132 return $out
133 }
134
135 plan_tests $NUM_TESTS
136
137 print_test_banner "$TEST_DESC"
138
139 if [ "$(id -u)" == "0" ]; then
140 isroot=1
141 else
142 isroot=0
143 fi
144
145 skip $isroot "Root access is needed. Skipping all kernel streaming tests." $NUM_TESTS ||
146 {
147 start_lttng_relayd "-o $TRACE_PATH"
148 start_lttng_sessiond
149
150 tests=( test_kernel_default_name test_kernel_custom_name \
151 test_kernel_default_name_with_del )
152
153 for fct_test in ${tests[@]};
154 do
155 SESSION_NAME=$(randstring 16 0)
156 ${fct_test}
157 if [ $? -eq 0 ]; then
158 # Only delete if successful
159 echo allo
160 #rm -rf $TRACE_PATH
161 else
162 break
163 fi
164 done
165
166 stop_lttng_sessiond
167 stop_lttng_relayd
168 }
This page took 0.032862 seconds and 4 git commands to generate.