Fix typo: utils.sh
[lttng-tools.git] / tests / utils.sh
1 #!/src/bin/bash
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"
19 LTTNG_BIN="lttng"
20 BABELTRACE_BIN="babeltrace"
21
22 # Minimal kernel version supported for session daemon tests
23 KERNEL_MAJOR_VERSION=2
24 KERNEL_MINOR_VERSION=6
25 KERNEL_PATCHLEVEL_VERSION=27
26
27 function 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
42 function spawn_sessiond ()
43 {
44 echo ""
45 echo -n "Starting session daemon... "
46 validate_kernel_version
47 if [ $? -ne 0 ]; then
48 echo -e "\n*** Kernel too old for session daemon tests ***\n"
49 return 2
50 fi
51
52 DIR=$(readlink -f $TESTDIR)
53
54 if [ -z $(pidof lt-$SESSIOND_BIN) ]; then
55 $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"
56 if [ $? -eq 1 ]; then
57 echo -e "\e[1;31mFAILED\e[0m"
58 return 1
59 else
60 echo -e "\e[1;32mOK\e[0m"
61 fi
62 fi
63
64 return 0
65 }
66
67 function start_sessiond()
68 {
69 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
70 # Env variable requested no session daemon
71 return
72 fi
73
74 spawn_sessiond
75 out=$?
76 if [ $out -eq 2 ]; then
77 # Kernel version is not compatible.
78 exit 0
79 elif [ $out -ne 0 ]; then
80 echo "NOT bad $?"
81 exit 1
82 fi
83
84 # Simply wait for the session daemon bootstrap
85 echo "Waiting for the session daemon to bootstrap (2 secs)"
86 sleep 2
87 }
88
89 function stop_sessiond ()
90 {
91 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
92 # Env variable requested no session daemon
93 return
94 fi
95
96 PID_SESSIOND=`pidof lt-$SESSIOND_BIN`
97
98 echo -e -n "Killing session daemon... "
99 kill $PID_SESSIOND >/dev/null 2>&1
100 if [ $? -eq 1 ]; then
101 echo -e "\e[1;31mFAILED\e[0m"
102 return 1
103 else
104 out=1
105 while [ -n "$out" ]; do
106 out=$(pidof lt-$SESSIOND_BIN)
107 sleep 0.5
108 done
109 echo -e "\e[1;32mOK\e[0m"
110 fi
111 }
112
113 function create_lttng_session ()
114 {
115 sess_name=$1
116 trace_path=$2
117
118 echo -n "Creating lttng session $sess_name in $trace_path "
119 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path >/dev/null 2>&1
120 if [ $? -eq 1 ]; then
121 echo -e "\e[1;31mFAILED\e[0m"
122 return 1
123 else
124 echo -e "\e[1;32mOK\e[0m"
125 fi
126 }
127
128 function enable_lttng_channel()
129 {
130 sess_name=$1
131 channel_name=$2
132
133 echo -n "Enabling lttng channel $channel_name for session $sess_name"
134 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel $channel_name -s $sess_name >/dev/null 2>&1
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
143 function disable_lttng_channel()
144 {
145 sess_name=$1
146 channel_name=$2
147
148 echo -n "Disabling lttng channel $channel_name for session $sess_name"
149 $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel $channel_name -s $sess_name >/dev/null 2>&1
150 if [ $? -eq 1 ]; then
151 echo -e "\e[1;31mFAILED\e[0m"
152 return 1
153 else
154 echo -e "\e[1;32mOK\e[0m"
155 fi
156 }
157
158 function enable_ust_lttng_event ()
159 {
160 sess_name=$1
161 event_name=$2
162
163 echo -n "Enabling lttng event $event_name for session $sess_name "
164 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $event_name -s $sess_name -u >/dev/null 2>&1
165 if [ $? -eq 1 ]; then
166 echo -e '\e[1;31mFAILED\e[0m'
167 return 1
168 else
169 echo -e "\e[1;32mOK\e[0m"
170 fi
171 }
172
173 function start_tracing ()
174 {
175 sess_name=$1
176
177 echo -n "Start lttng tracing for session $sess_name "
178 $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name >/dev/null 2>&1
179 if [ $? -eq 1 ]; then
180 echo -e '\e[1;31mFAILED\e[0m'
181 return 1
182 else
183 echo -e "\e[1;32mOK\e[0m"
184 fi
185 }
186
187 function stop_tracing ()
188 {
189 sess_name=$1
190
191 echo -n "Stop lttng tracing for session $sess_name "
192 $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name >/dev/null 2>&1
193 if [ $? -eq 1 ]; then
194 echo -e '\e[1;31mFAILED\e[0m'
195 return 1
196 else
197 echo -e "\e[1;32mOK\e[0m"
198 fi
199 }
200
201 function destroy_lttng_session ()
202 {
203 sess_name=$1
204
205 echo -n "Destroy lttng session $sess_name "
206 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $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 trace_matches ()
216 {
217 event_name=$1
218 nr_iter=$2
219 trace_path=$3
220
221 which $BABELTRACE_BIN >/dev/null
222 if [ $? -eq 1 ]; then
223 echo "Babeltrace binary not found. Skipping trace matches"
224 return 0
225 fi
226
227 echo -n "Looking for $nr_iter $event_name in $trace_path "
228
229 count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
230 if [ "$count" -ne "$nr_iter" ]; then
231 echo -e "$count found in trace \e[1;31mFAILED\e[0m"
232 return 1
233 else
234 echo -e "Trace is coherent \e[1;32mOK\e[0m"
235 return 0
236 fi
237 }
This page took 0.034137 seconds and 5 git commands to generate.