Update version to 2.0.0 stable
[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
48 echo -e "\n*** Kernel to old for session daemon tests ***\n"
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
75 echo -e "\e[1;32mOK\e[0m"
76 fi
77}
78
79function create_lttng_session ()
80{
81 sess_name=$1
82 trace_path=$2
83
84 echo -n "Creating lttng session $SESSION_NAME in $TRACE_PATH "
10a8a223 85 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path >/dev/null 2>&1
d3e8f6bb
DG
86 if [ $? -eq 1 ]; then
87 echo -e "\e[1;31mFAILED\e[0m"
88 return 1
89 else
90 echo -e "\e[1;32mOK\e[0m"
91 #echo $out | grep "written in" | cut -d' ' -f6
92 fi
93}
94
95function enable_ust_lttng_event ()
96{
97 sess_name=$1
98 event_name=$2
99
100 echo -n "Enabling lttng event $event_name for session $sess_name "
10a8a223 101 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $event_name -s $sess_name -u >/dev/null 2>&1
d3e8f6bb
DG
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
110function start_tracing ()
111{
112 sess_name=$1
113
114 echo -n "Start lttng tracing for session $sess_name "
10a8a223 115 $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name >/dev/null 2>&1
d3e8f6bb
DG
116 if [ $? -eq 1 ]; then
117 echo -e '\e[1;31mFAILED\e[0m'
118 return 1
119 else
120 echo -e "\e[1;32mOK\e[0m"
121 fi
122}
123
124function stop_tracing ()
125{
126 sess_name=$1
127
128 echo -n "Stop lttng tracing for session $sess_name "
10a8a223 129 $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name >/dev/null 2>&1
d3e8f6bb
DG
130 if [ $? -eq 1 ]; then
131 echo -e '\e[1;31mFAILED\e[0m'
132 return 1
133 else
134 echo -e "\e[1;32mOK\e[0m"
135 fi
136}
137
138function destroy_lttng_session ()
139{
140 sess_name=$1
141
142 echo -n "Destroy lttng session $sess_name "
10a8a223 143 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name >/dev/null 2>&1
d3e8f6bb
DG
144 if [ $? -eq 1 ]; then
145 echo -e '\e[1;31mFAILED\e[0m'
146 return 1
147 else
148 echo -e "\e[1;32mOK\e[0m"
149 fi
150}
151
152function trace_matches ()
153{
154 event_name=$1
155 nr_iter=$2
156 trace_path=$3
157
317eef93
DG
158 which $BABELTRACE_BIN >/dev/null
159 if [ $? -eq 1 ]; then
160 echo "Babeltrace binary not found. Skipping trace matches"
161 return 0
162 fi
163
d3e8f6bb
DG
164 echo -n "Looking for $nr_iter $event_name in $trace_path "
165
166 count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
167 if [ "$count" -ne "$nr_iter" ]; then
168 echo -e "$count found in trace \e[1;31mFAILED\e[0m"
169 return 1
170 else
171 echo -e "Trace is coherent \e[1;32mOK\e[0m"
172 return 0
173 fi
174}
This page took 0.054686 seconds and 4 git commands to generate.