Fix typo: utils.sh
[lttng-tools.git] / tests / utils.sh
CommitLineData
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
18SESSIOND_BIN="lttng-sessiond"
19LTTNG_BIN="lttng"
20BABELTRACE_BIN="babeltrace"
21
fd4dfcec
DG
22# Minimal kernel version supported for session daemon tests
23KERNEL_MAJOR_VERSION=2
24KERNEL_MINOR_VERSION=6
25KERNEL_PATCHLEVEL_VERSION=27
26
27function validate_kernel_version ()
28{
29 kern_version=($(uname -r | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n'))
30 if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then
31 return 0
32 fi
33 if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then
34 return 0
35 fi
36 if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then
37 return 0
38 fi
39 return 1
40}
41
d3e8f6bb
DG
42function start_sessiond ()
43{
317eef93
DG
44 echo ""
45 echo -n "Starting session daemon... "
fd4dfcec
DG
46 validate_kernel_version
47 if [ $? -ne 0 ]; then
dcb543b0 48 echo -e "\n*** Kernel too old for session daemon tests ***\n"
fd4dfcec
DG
49 return 2
50 fi
51
317eef93
DG
52 if [ -z $(pidof lt-$SESSIOND_BIN) ]; then
53 $TESTDIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --daemonize --quiet --consumerd32-path="$(pwd)/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$(pwd)/../src/bin/lttng-consumerd/lttng-consumerd"
d3e8f6bb
DG
54 if [ $? -eq 1 ]; then
55 echo -e "\e[1;31mFAILED\e[0m"
56 return 1
57 else
58 echo -e "\e[1;32mOK\e[0m"
59 fi
60 fi
fd4dfcec
DG
61
62 return 0
d3e8f6bb
DG
63}
64
65function stop_sessiond ()
66{
67 PID_SESSIOND=`pidof lt-$SESSIOND_BIN`
68
69 echo -e -n "Killing session daemon... "
70 kill $PID_SESSIOND >/dev/null 2>&1
71 if [ $? -eq 1 ]; then
72 echo -e "\e[1;31mFAILED\e[0m"
73 return 1
74 else
cccd0e3a
DG
75 out=1
76 while [ -n "$out" ]; do
77 out=$(pidof lt-$SESSIOND_BIN)
78 sleep 0.5
79 done
d3e8f6bb
DG
80 echo -e "\e[1;32mOK\e[0m"
81 fi
82}
83
84function create_lttng_session ()
85{
86 sess_name=$1
87 trace_path=$2
88
89 echo -n "Creating lttng session $SESSION_NAME in $TRACE_PATH "
10a8a223 90 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path >/dev/null 2>&1
d3e8f6bb
DG
91 if [ $? -eq 1 ]; then
92 echo -e "\e[1;31mFAILED\e[0m"
93 return 1
94 else
95 echo -e "\e[1;32mOK\e[0m"
96 #echo $out | grep "written in" | cut -d' ' -f6
97 fi
98}
99
100function enable_ust_lttng_event ()
101{
102 sess_name=$1
103 event_name=$2
104
105 echo -n "Enabling lttng event $event_name for session $sess_name "
10a8a223 106 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $event_name -s $sess_name -u >/dev/null 2>&1
d3e8f6bb
DG
107 if [ $? -eq 1 ]; then
108 echo -e '\e[1;31mFAILED\e[0m'
109 return 1
110 else
111 echo -e "\e[1;32mOK\e[0m"
112 fi
113}
114
115function start_tracing ()
116{
117 sess_name=$1
118
119 echo -n "Start lttng tracing for session $sess_name "
10a8a223 120 $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name >/dev/null 2>&1
d3e8f6bb
DG
121 if [ $? -eq 1 ]; then
122 echo -e '\e[1;31mFAILED\e[0m'
123 return 1
124 else
125 echo -e "\e[1;32mOK\e[0m"
126 fi
127}
128
129function stop_tracing ()
130{
131 sess_name=$1
132
133 echo -n "Stop lttng tracing for session $sess_name "
10a8a223 134 $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name >/dev/null 2>&1
d3e8f6bb
DG
135 if [ $? -eq 1 ]; then
136 echo -e '\e[1;31mFAILED\e[0m'
137 return 1
138 else
139 echo -e "\e[1;32mOK\e[0m"
140 fi
141}
142
143function destroy_lttng_session ()
144{
145 sess_name=$1
146
147 echo -n "Destroy lttng session $sess_name "
10a8a223 148 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name >/dev/null 2>&1
d3e8f6bb
DG
149 if [ $? -eq 1 ]; then
150 echo -e '\e[1;31mFAILED\e[0m'
151 return 1
152 else
153 echo -e "\e[1;32mOK\e[0m"
154 fi
155}
156
157function trace_matches ()
158{
159 event_name=$1
160 nr_iter=$2
161 trace_path=$3
162
317eef93
DG
163 which $BABELTRACE_BIN >/dev/null
164 if [ $? -eq 1 ]; then
165 echo "Babeltrace binary not found. Skipping trace matches"
166 return 0
167 fi
168
d3e8f6bb
DG
169 echo -n "Looking for $nr_iter $event_name in $trace_path "
170
171 count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
172 if [ "$count" -ne "$nr_iter" ]; then
173 echo -e "$count found in trace \e[1;31mFAILED\e[0m"
174 return 1
175 else
176 echo -e "Trace is coherent \e[1;32mOK\e[0m"
177 return 0
178 fi
179}
This page took 0.030027 seconds and 4 git commands to generate.