Fixing memory leaks in add-context command
[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{
fd4dfcec
DG
44 validate_kernel_version
45 if [ $? -ne 0 ]; then
46 echo -e "\n*** Kernel to old for session daemon tests ***\n"
47 return 2
48 fi
49
d3e8f6bb
DG
50 if [ -z $(pidof $SESSIOND_BIN) ]; then
51 echo -n "Starting session daemon... "
10a8a223 52 $TESTDIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --daemonize --quiet
d3e8f6bb
DG
53 if [ $? -eq 1 ]; then
54 echo -e "\e[1;31mFAILED\e[0m"
55 return 1
56 else
57 echo -e "\e[1;32mOK\e[0m"
58 fi
59 fi
fd4dfcec
DG
60
61 return 0
d3e8f6bb
DG
62}
63
64function stop_sessiond ()
65{
66 PID_SESSIOND=`pidof lt-$SESSIOND_BIN`
67
68 echo -e -n "Killing session daemon... "
69 kill $PID_SESSIOND >/dev/null 2>&1
70 if [ $? -eq 1 ]; then
71 echo -e "\e[1;31mFAILED\e[0m"
72 return 1
73 else
74 echo -e "\e[1;32mOK\e[0m"
75 fi
76}
77
78function create_lttng_session ()
79{
80 sess_name=$1
81 trace_path=$2
82
83 echo -n "Creating lttng session $SESSION_NAME in $TRACE_PATH "
10a8a223 84 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path >/dev/null 2>&1
d3e8f6bb
DG
85 if [ $? -eq 1 ]; then
86 echo -e "\e[1;31mFAILED\e[0m"
87 return 1
88 else
89 echo -e "\e[1;32mOK\e[0m"
90 #echo $out | grep "written in" | cut -d' ' -f6
91 fi
92}
93
94function enable_ust_lttng_event ()
95{
96 sess_name=$1
97 event_name=$2
98
99 echo -n "Enabling lttng event $event_name for session $sess_name "
10a8a223 100 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $event_name -s $sess_name -u >/dev/null 2>&1
d3e8f6bb
DG
101 if [ $? -eq 1 ]; then
102 echo -e '\e[1;31mFAILED\e[0m'
103 return 1
104 else
105 echo -e "\e[1;32mOK\e[0m"
106 fi
107}
108
109function start_tracing ()
110{
111 sess_name=$1
112
113 echo -n "Start lttng tracing for session $sess_name "
10a8a223 114 $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name >/dev/null 2>&1
d3e8f6bb
DG
115 if [ $? -eq 1 ]; then
116 echo -e '\e[1;31mFAILED\e[0m'
117 return 1
118 else
119 echo -e "\e[1;32mOK\e[0m"
120 fi
121}
122
123function stop_tracing ()
124{
125 sess_name=$1
126
127 echo -n "Stop lttng tracing for session $sess_name "
10a8a223 128 $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name >/dev/null 2>&1
d3e8f6bb
DG
129 if [ $? -eq 1 ]; then
130 echo -e '\e[1;31mFAILED\e[0m'
131 return 1
132 else
133 echo -e "\e[1;32mOK\e[0m"
134 fi
135}
136
137function destroy_lttng_session ()
138{
139 sess_name=$1
140
141 echo -n "Destroy lttng session $sess_name "
10a8a223 142 $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name >/dev/null 2>&1
d3e8f6bb
DG
143 if [ $? -eq 1 ]; then
144 echo -e '\e[1;31mFAILED\e[0m'
145 return 1
146 else
147 echo -e "\e[1;32mOK\e[0m"
148 fi
149}
150
151function trace_matches ()
152{
153 event_name=$1
154 nr_iter=$2
155 trace_path=$3
156
157 echo -n "Looking for $nr_iter $event_name in $trace_path "
158
159 count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l)
160 if [ "$count" -ne "$nr_iter" ]; then
161 echo -e "$count found in trace \e[1;31mFAILED\e[0m"
162 return 1
163 else
164 echo -e "Trace is coherent \e[1;32mOK\e[0m"
165 return 0
166 fi
167}
This page took 0.031425 seconds and 5 git commands to generate.