Commit | Line | Data |
---|---|---|
10a8a223 | 1 | #!/src/bin/bash |
d3e8f6bb DG |
2 | # |
3 | # Copyright (C) - 2012 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 | ||
18 | SESSIOND_BIN="lttng-sessiond" | |
f4e40ab6 | 19 | RELAYD_BIN="lttng-relayd" |
d3e8f6bb DG |
20 | LTTNG_BIN="lttng" |
21 | BABELTRACE_BIN="babeltrace" | |
22 | ||
fd4dfcec DG |
23 | # Minimal kernel version supported for session daemon tests |
24 | KERNEL_MAJOR_VERSION=2 | |
25 | KERNEL_MINOR_VERSION=6 | |
26 | KERNEL_PATCHLEVEL_VERSION=27 | |
27 | ||
28 | function validate_kernel_version () | |
29 | { | |
30 | kern_version=($(uname -r | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n')) | |
31 | if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then | |
32 | return 0 | |
33 | fi | |
34 | if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then | |
35 | return 0 | |
36 | fi | |
37 | if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then | |
38 | return 0 | |
39 | fi | |
40 | return 1 | |
41 | } | |
42 | ||
f4e40ab6 DG |
43 | # Generate a random string |
44 | # $1 = number of characters; defaults to 16 | |
45 | # $2 = include special characters; 1 = yes, 0 = no; defaults to yes | |
46 | function randstring() | |
47 | { | |
48 | [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]" | |
49 | cat /dev/urandom | tr -cd "$CHAR" | head -c ${1:-16} | |
50 | echo | |
51 | } | |
52 | ||
355f483d | 53 | function spawn_sessiond () |
d3e8f6bb | 54 | { |
317eef93 DG |
55 | echo "" |
56 | echo -n "Starting session daemon... " | |
fd4dfcec DG |
57 | validate_kernel_version |
58 | if [ $? -ne 0 ]; then | |
fbb28ea9 | 59 | echo -e "\n*** Kernel too old for session daemon tests ***\n" |
fd4dfcec DG |
60 | return 2 |
61 | fi | |
62 | ||
2e6a03f6 | 63 | DIR=$(readlink -f $TESTDIR) |
355f483d | 64 | |
317eef93 | 65 | if [ -z $(pidof lt-$SESSIOND_BIN) ]; then |
355f483d | 66 | $DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --daemonize --quiet --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" |
d3e8f6bb DG |
67 | if [ $? -eq 1 ]; then |
68 | echo -e "\e[1;31mFAILED\e[0m" | |
69 | return 1 | |
70 | else | |
71 | echo -e "\e[1;32mOK\e[0m" | |
72 | fi | |
73 | fi | |
fd4dfcec DG |
74 | |
75 | return 0 | |
d3e8f6bb DG |
76 | } |
77 | ||
f4e40ab6 DG |
78 | function lttng_enable_kernel_event |
79 | { | |
80 | sess_name=$1 | |
81 | event_name=$2 | |
82 | ||
83 | if [ -z $event_name ]; then | |
84 | # Enable all event if no event name specified | |
85 | $event_name="-a" | |
86 | fi | |
87 | ||
88 | echo -n "Enabling kernel event $event_name for session $sess_name" | |
89 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $event_name -s $sess_name -k >/dev/null 2>&1 | |
90 | if [ $? -eq 1 ]; then | |
91 | echo -e '\e[1;31mFAILED\e[0m' | |
92 | return 1 | |
93 | else | |
94 | echo -e "\e[1;32mOK\e[0m" | |
95 | fi | |
96 | } | |
97 | ||
98 | function lttng_start_relayd | |
99 | { | |
173af62f DG |
100 | local opt="$1" |
101 | ||
102 | echo -e -n "Starting lttng-relayd (opt: $opt)... " | |
103 | ||
f4e40ab6 DG |
104 | DIR=$(readlink -f $TESTDIR) |
105 | ||
106 | if [ -z $(pidof lt-$RELAYD_BIN) ]; then | |
173af62f | 107 | $DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt >/dev/null 2>&1 & |
f4e40ab6 DG |
108 | if [ $? -eq 1 ]; then |
109 | echo -e "\e[1;31mFAILED\e[0m" | |
110 | return 1 | |
111 | else | |
112 | echo -e "\e[1;32mOK\e[0m" | |
113 | fi | |
114 | else | |
115 | echo -e "\e[1;32mOK\e[0m" | |
116 | fi | |
117 | } | |
118 | ||
119 | function lttng_stop_relayd | |
120 | { | |
121 | PID_RELAYD=`pidof lt-$RELAYD_BIN` | |
122 | ||
123 | echo -e -n "Killing lttng-relayd (pid: $PID_RELAYD)... " | |
124 | kill $PID_RELAYD >/dev/null 2>&1 | |
125 | if [ $? -eq 1 ]; then | |
126 | echo -e "\e[1;31mFAILED\e[0m" | |
127 | return 1 | |
128 | else | |
129 | out=1 | |
130 | while [ -n "$out" ]; do | |
131 | out=$(pidof lt-$RELAYD_BIN) | |
132 | sleep 0.5 | |
133 | done | |
134 | echo -e "\e[1;32mOK\e[0m" | |
135 | return 0 | |
136 | fi | |
137 | } | |
138 | ||
355f483d DG |
139 | function start_sessiond() |
140 | { | |
141 | if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then | |
142 | # Env variable requested no session daemon | |
143 | return | |
144 | fi | |
145 | ||
146 | spawn_sessiond | |
147 | out=$? | |
148 | if [ $out -eq 2 ]; then | |
149 | # Kernel version is not compatible. | |
150 | exit 0 | |
151 | elif [ $out -ne 0 ]; then | |
152 | echo "NOT bad $?" | |
153 | exit 1 | |
154 | fi | |
155 | ||
156 | # Simply wait for the session daemon bootstrap | |
157 | echo "Waiting for the session daemon to bootstrap (2 secs)" | |
158 | sleep 2 | |
159 | } | |
160 | ||
d3e8f6bb DG |
161 | function stop_sessiond () |
162 | { | |
355f483d DG |
163 | if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then |
164 | # Env variable requested no session daemon | |
165 | return | |
166 | fi | |
167 | ||
d3e8f6bb DG |
168 | PID_SESSIOND=`pidof lt-$SESSIOND_BIN` |
169 | ||
170 | echo -e -n "Killing session daemon... " | |
171 | kill $PID_SESSIOND >/dev/null 2>&1 | |
172 | if [ $? -eq 1 ]; then | |
173 | echo -e "\e[1;31mFAILED\e[0m" | |
174 | return 1 | |
175 | else | |
5fa32580 DG |
176 | out=1 |
177 | while [ -n "$out" ]; do | |
178 | out=$(pidof lt-$SESSIOND_BIN) | |
179 | sleep 0.5 | |
180 | done | |
d3e8f6bb DG |
181 | echo -e "\e[1;32mOK\e[0m" |
182 | fi | |
183 | } | |
184 | ||
185 | function create_lttng_session () | |
186 | { | |
187 | sess_name=$1 | |
188 | trace_path=$2 | |
189 | ||
908ee7bd | 190 | echo -n "Creating lttng session $sess_name in $trace_path " |
10a8a223 | 191 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path >/dev/null 2>&1 |
d3e8f6bb DG |
192 | if [ $? -eq 1 ]; then |
193 | echo -e "\e[1;31mFAILED\e[0m" | |
194 | return 1 | |
195 | else | |
196 | echo -e "\e[1;32mOK\e[0m" | |
d4018451 DG |
197 | fi |
198 | } | |
199 | ||
200 | function enable_lttng_channel() | |
201 | { | |
202 | sess_name=$1 | |
203 | channel_name=$2 | |
204 | ||
205 | echo -n "Enabling lttng channel $channel_name for session $sess_name" | |
206 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel $channel_name -s $sess_name >/dev/null 2>&1 | |
207 | if [ $? -eq 1 ]; then | |
208 | echo -e "\e[1;31mFAILED\e[0m" | |
209 | return 1 | |
210 | else | |
211 | echo -e "\e[1;32mOK\e[0m" | |
212 | fi | |
213 | } | |
214 | ||
215 | function disable_lttng_channel() | |
216 | { | |
217 | sess_name=$1 | |
218 | channel_name=$2 | |
219 | ||
220 | echo -n "Disabling lttng channel $channel_name for session $sess_name" | |
221 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel $channel_name -s $sess_name >/dev/null 2>&1 | |
222 | if [ $? -eq 1 ]; then | |
223 | echo -e "\e[1;31mFAILED\e[0m" | |
224 | return 1 | |
225 | else | |
226 | echo -e "\e[1;32mOK\e[0m" | |
d3e8f6bb DG |
227 | fi |
228 | } | |
229 | ||
230 | function enable_ust_lttng_event () | |
231 | { | |
232 | sess_name=$1 | |
233 | event_name=$2 | |
234 | ||
235 | echo -n "Enabling lttng event $event_name for session $sess_name " | |
10a8a223 | 236 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $event_name -s $sess_name -u >/dev/null 2>&1 |
d3e8f6bb DG |
237 | if [ $? -eq 1 ]; then |
238 | echo -e '\e[1;31mFAILED\e[0m' | |
239 | return 1 | |
240 | else | |
241 | echo -e "\e[1;32mOK\e[0m" | |
242 | fi | |
243 | } | |
244 | ||
245 | function start_tracing () | |
246 | { | |
247 | sess_name=$1 | |
248 | ||
249 | echo -n "Start lttng tracing for session $sess_name " | |
10a8a223 | 250 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name >/dev/null 2>&1 |
d3e8f6bb DG |
251 | if [ $? -eq 1 ]; then |
252 | echo -e '\e[1;31mFAILED\e[0m' | |
253 | return 1 | |
254 | else | |
255 | echo -e "\e[1;32mOK\e[0m" | |
256 | fi | |
257 | } | |
258 | ||
259 | function stop_tracing () | |
260 | { | |
261 | sess_name=$1 | |
262 | ||
263 | echo -n "Stop lttng tracing for session $sess_name " | |
10a8a223 | 264 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name >/dev/null 2>&1 |
d3e8f6bb DG |
265 | if [ $? -eq 1 ]; then |
266 | echo -e '\e[1;31mFAILED\e[0m' | |
267 | return 1 | |
268 | else | |
269 | echo -e "\e[1;32mOK\e[0m" | |
270 | fi | |
271 | } | |
272 | ||
273 | function destroy_lttng_session () | |
274 | { | |
275 | sess_name=$1 | |
276 | ||
277 | echo -n "Destroy lttng session $sess_name " | |
10a8a223 | 278 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name >/dev/null 2>&1 |
d3e8f6bb DG |
279 | if [ $? -eq 1 ]; then |
280 | echo -e '\e[1;31mFAILED\e[0m' | |
281 | return 1 | |
282 | else | |
283 | echo -e "\e[1;32mOK\e[0m" | |
284 | fi | |
285 | } | |
286 | ||
287 | function trace_matches () | |
288 | { | |
289 | event_name=$1 | |
290 | nr_iter=$2 | |
291 | trace_path=$3 | |
292 | ||
317eef93 DG |
293 | which $BABELTRACE_BIN >/dev/null |
294 | if [ $? -eq 1 ]; then | |
295 | echo "Babeltrace binary not found. Skipping trace matches" | |
296 | return 0 | |
297 | fi | |
298 | ||
d3e8f6bb DG |
299 | echo -n "Looking for $nr_iter $event_name in $trace_path " |
300 | ||
301 | count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l) | |
302 | if [ "$count" -ne "$nr_iter" ]; then | |
303 | echo -e "$count found in trace \e[1;31mFAILED\e[0m" | |
304 | return 1 | |
305 | else | |
306 | echo -e "Trace is coherent \e[1;32mOK\e[0m" | |
307 | return 0 | |
308 | fi | |
309 | } | |
f4e40ab6 DG |
310 | |
311 | function validate_trace | |
312 | { | |
313 | event_name=$1 | |
314 | trace_path=$2 | |
315 | ||
316 | which $BABELTRACE_BIN >/dev/null | |
317 | if [ $? -eq 1 ]; then | |
318 | echo "Babeltrace binary not found. Skipping trace matches" | |
319 | return 0 | |
320 | fi | |
321 | ||
322 | echo -n "Validating trace for event $event_name... " | |
323 | traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $event_name | wc -l) | |
324 | if [ $traced -eq 0 ]; then | |
325 | echo -e "\e[1;31mFAILED\e[0m" | |
326 | return 1 | |
327 | else | |
328 | echo -e "\e[1;32mOK\e[0m" | |
329 | return 0 | |
330 | fi | |
331 | } |