Improve tests and change tests/ directory layout
[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 alias realpath='readlink -f'
28
29 function validate_kernel_version ()
30 {
31 kern_version=($(uname -r | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n'))
32 if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then
33 return 0
34 fi
35 if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then
36 return 0
37 fi
38 if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then
39 return 0
40 fi
41 return 1
42 }
43
44 function spawn_sessiond ()
45 {
46 echo ""
47 echo -n "Starting session daemon... "
48 validate_kernel_version
49 if [ $? -ne 0 ]; then
50 echo -e "\n*** Kernel to old for session daemon tests ***\n"
51 return 2
52 fi
53
54 DIR=$(realpath $TESTDIR)
55
56 if [ -z $(pidof lt-$SESSIOND_BIN) ]; then
57 $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"
58 if [ $? -eq 1 ]; then
59 echo -e "\e[1;31mFAILED\e[0m"
60 return 1
61 else
62 echo -e "\e[1;32mOK\e[0m"
63 fi
64 fi
65
66 return 0
67 }
68
69 function start_sessiond()
70 {
71 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
72 # Env variable requested no session daemon
73 return
74 fi
75
76 spawn_sessiond
77 out=$?
78 if [ $out -eq 2 ]; then
79 # Kernel version is not compatible.
80 exit 0
81 elif [ $out -ne 0 ]; then
82 echo "NOT bad $?"
83 exit 1
84 fi
85
86 # Simply wait for the session daemon bootstrap
87 echo "Waiting for the session daemon to bootstrap (2 secs)"
88 sleep 2
89 }
90
91 function stop_sessiond ()
92 {
93 if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
94 # Env variable requested no session daemon
95 return
96 fi
97
98 PID_SESSIOND=`pidof lt-$SESSIOND_BIN`
99
100 echo -e -n "Killing session daemon... "
101 kill $PID_SESSIOND >/dev/null 2>&1
102 if [ $? -eq 1 ]; then
103 echo -e "\e[1;31mFAILED\e[0m"
104 return 1
105 else
106 echo -e "\e[1;32mOK\e[0m"
107 fi
108 }
109
110 function create_lttng_session ()
111 {
112 sess_name=$1
113 trace_path=$2
114
115 echo -n "Creating lttng session $SESSION_NAME in $TRACE_PATH "
116 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path >/dev/null 2>&1
117 if [ $? -eq 1 ]; then
118 echo -e "\e[1;31mFAILED\e[0m"
119 return 1
120 else
121 echo -e "\e[1;32mOK\e[0m"
122 #echo $out | grep "written in" | cut -d' ' -f6
123 fi
124 }
125
126 function enable_ust_lttng_event ()
127 {
128 sess_name=$1
129 event_name=$2
130
131 echo -n "Enabling lttng event $event_name for session $sess_name "
132 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $event_name -s $sess_name -u >/dev/null 2>&1
133 if [ $? -eq 1 ]; then
134 echo -e '\e[1;31mFAILED\e[0m'
135 return 1
136 else
137 echo -e "\e[1;32mOK\e[0m"
138 fi
139 }
140
141 function start_tracing ()
142 {
143 sess_name=$1
144
145 echo -n "Start lttng tracing for session $sess_name "
146 $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name >/dev/null 2>&1
147 if [ $? -eq 1 ]; then
148 echo -e '\e[1;31mFAILED\e[0m'
149 return 1
150 else
151 echo -e "\e[1;32mOK\e[0m"
152 fi
153 }
154
155 function stop_tracing ()
156 {
157 sess_name=$1
158
159 echo -n "Stop lttng tracing for session $sess_name "
160 $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name >/dev/null 2>&1
161 if [ $? -eq 1 ]; then
162 echo -e '\e[1;31mFAILED\e[0m'
163 return 1
164 else
165 echo -e "\e[1;32mOK\e[0m"
166 fi
167 }
168
169 function destroy_lttng_session ()
170 {
171 sess_name=$1
172
173 echo -n "Destroy lttng session $sess_name "
174 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name >/dev/null 2>&1
175 if [ $? -eq 1 ]; then
176 echo -e '\e[1;31mFAILED\e[0m'
177 return 1
178 else
179 echo -e "\e[1;32mOK\e[0m"
180 fi
181 }
182
183 function trace_matches ()
184 {
185 event_name=$1
186 nr_iter=$2
187 trace_path=$3
188
189 which $BABELTRACE_BIN >/dev/null
190 if [ $? -eq 1 ]; then
191 echo "Babeltrace binary not found. Skipping trace matches"
192 return 0
193 fi
194
195 echo -n "Looking for $nr_iter $event_name in $trace_path "
196
197 count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
198 if [ "$count" -ne "$nr_iter" ]; then
199 echo -e "$count found in trace \e[1;31mFAILED\e[0m"
200 return 1
201 else
202 echo -e "Trace is coherent \e[1;32mOK\e[0m"
203 return 0
204 fi
205 }
This page took 0.034432 seconds and 5 git commands to generate.