Mi test: Refactoring and multiple test suites
[lttng-tools.git] / tests / regression / tools / mi / test_mi
1 #!/bin/bash
2 #
3 # Copyright (C) - 2014 Jonathan Rajotte <jonathan.r.julien@gmail.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 TEST_DESC="Machine interface testing"
19
20 CURDIR=$(dirname $0)/
21 TESTDIR=$CURDIR/../../../
22 XSD_PATH=$TESTDIR/../src/common/mi_lttng.xsd
23 SESSIOND_BIN="lttng-sessiond"
24 RELAYD_BIN="lttng-relayd"
25
26
27 #Temp file output
28 #OUTPUT_DIR=$(mktemp -d)
29 OUTPUT_DIR="/tmp/test"
30 OUTPUT_FILE="default.xml"
31
32 #Path to custom xml utilities
33 XML_VALIDATE="$CURDIR/validate_xml $XSD_PATH"
34 XML_EXTRACT="$CURDIR/extract_xml"
35
36 XPATH_COMMAND_SUCCESS="/command/success/text()"
37 XPATH_SESSION_NAME="/command/output/sessions/session/name/text()"
38 XPATH_ENABLE_CHANNEL_NAME="/command/output/channels/channel/name/text()"
39
40 DEVNULL=/dev/null 2>&1
41
42 DIR=$(readlink -f $TESTDIR)
43
44 NUM_TESTS=60
45
46 source $TESTDIR/utils/utils.sh
47
48 #Overwrite the lttng_bin to get mi output
49 LTTNG_BIN="lttng --mi xml"
50
51 #Global devlaration for simplification
52 LTTNG=$TESTDIR/../src/bin/lttng/$LTTNG_BIN
53
54 #Overwrite the default output for utils.sh command
55
56 #MUST set TESTDIR before calling those functions
57 plan_tests $NUM_TESTS
58
59 print_test_banner "$TEST_DESC"
60
61 function extract_xml ()
62 {
63 local xml=$1
64 local xpath=$2
65 local __result=$3
66 local output=$($XML_EXTRACT $xml $xpath)
67 ok $? "Extraction of xpath $xpath"
68 eval $__result="'$output'"
69 }
70
71 # Arg1 is path to xml file
72 # Arg2:
73 # is true if we expected the success element to be false
74 # else
75 # passe false
76
77 function is_command_success ()
78 {
79 local xml=$1
80 local expect_false=$2
81
82 local xpath=$XPATH_COMMAND_SUCCESS
83
84 #Extract the success element
85 #expect false
86 extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
87 if [[ $expect_false ]]; then
88 if [[ $result ]]; then
89 pass "Mi test: $xml command failed as expected"
90 else
91 fail "Mi test: $xml command did not fail as expected"
92 fi
93 else
94 if [[ $result ]]; then
95 fail "Mi test: $xml command failed"
96 else
97 pass "Mi test: $xml command success"
98 fi
99 fi
100 }
101
102 function mi_print_version ()
103 {
104 local opt=$2
105 local output_path=$1
106
107 $LTTNG version $opt > $1
108 ok $? "MI test: Lttng version"
109
110 }
111
112 function test_version ()
113 {
114 OUTPUT_FILE="version.xml"
115 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
116 mi_print_version $OUTPUT_DEST
117 $XML_VALIDATE $OUTPUT_DEST
118 ok $? "MI test: Version xsd validation"
119 }
120
121 function test_create_session ()
122 {
123 local session_name="testSession"
124
125 OUTPUT_FILE="create_session.xml"
126 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
127 create_lttng_session $session_name $OUTPUT_DIR
128 $XML_VALIDATE $OUTPUT_DEST
129 ok $? "MI test: create session xsd validation"
130
131 #try to recreate a session. Expecting it to fail
132 create_lttng_session $session_name $OUTPUT_DIR true
133 $XML_VALIDATE $OUTPUT_DEST
134 ok $? "MI test: expecting fail create session xsd validation"
135 is_command_success $OUTPUT_DEST true
136
137 OUTPUT_DEST=$DEVNULL
138 destroy_lttng_session $session_name
139 }
140
141 function test_destroy_session ()
142 {
143 local session_name=(
144 "testSession1"
145 "testSession2"
146 "testSession3")
147
148 OUTPUT_FILE="destroy_session.xml"
149
150 #Test build up
151 OUTPUT_DEST=$DEVNULL
152 for (( i = 0; i < 3; i++ )); do
153 create_lttng_session ${session_name[$i]} $OUTPUT_DIR
154 done
155
156 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
157 destroy_lttng_session ${session_name[0]}
158 $XML_VALIDATE $OUTPUT_DEST
159 ok $? "MI test: destroy session ${session_name[0]} xsd validation"
160
161 #Verify that we destroyed the good session
162 extract_xml $OUTPUT_DEST $XPATH_SESSION_NAME result
163 if [[ "$result" == "${session_name[0]}" ]]; then
164 ok 0 "Mi test: delete by name"
165 else
166 ok 1 "Mi test: we deleted the wrong session"
167 fi
168
169 #Destroy all and count:should be 2
170 destroy_lttng_sessions
171 $XML_VALIDATE $OUTPUT_DEST
172 ok $? "MI test: destroy all session xsd validation"
173
174 #Verify that we destroyed 2 sessions
175 extract_xml $OUTPUT_DEST $XPATH_SESSION_NAME result
176 num=$(echo "$result" | wc -l)
177 test "$num" -eq "2"
178 ok $? "Mi test: $num / 2 sessions discovered"
179 }
180
181 function test_list_sessions ()
182 {
183 local session_name=(
184 "testSession1"
185 "testSession2"
186 "testSession3")
187
188 OUTPUT_FILE="list_sessions.xml"
189
190 #Test buid up
191 OUTPUT_DEST=$DEVNULL
192 for (( i = 0; i < 3; i++ )); do
193 create_lttng_session ${session_name[$i]} $OUTPUT_DIR
194 done
195
196 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
197 list_lttng_with_opts
198 $XML_VALIDATE $OUTPUT_DEST
199 ok $? "Mi test: list session xsd validation"
200
201 #We should have 3 session
202 extract_xml $OUTPUT_DEST $XPATH_SESSION_NAME result
203 num=$(echo "$result" | wc -l)
204 test "$num" -eq "3"
205 ok $? "Mi test: $num / 3 sessions discovered"
206
207 #Teardown
208 OUTPUT_DEST=$DEVNULL
209 destroy_lttng_sessions
210 }
211
212 function test_ust_channel ()
213 {
214 local session_name="testsession"
215 local channel_name=("channelUst0"
216 "channelUst1"
217 "channelUst2")
218
219 OUTPUT_FILE="ust_channel.xml"
220
221 #Test buil up
222 OUTPUT_DEST=$DEVNULL
223 create_lttng_session $session_name $OUTPUT_DIR
224
225 #Test the enable_channel command
226 OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
227 enable_ust_lttng_channel $session_name ${channel_name[0]}
228 $XML_VALIDATE $OUTPUT_DEST
229 ok $? "Mi test: enable ust channel xsd validation"
230 is_command_success $OUTPUT_DIR false
231
232 #Expect the command to fail
233 enable_ust_lttng_channel $session_name ${channel_name[0]} true
234 $XML_VALIDATE $OUTPUT_DEST
235 ok $? "Mi test: fail enable ust channel xsd validation"
236 is_command_success $OUTPUT_DIR true
237
238 #Create two ust channel to test multiple disable
239 for (( i = 1; i < 3; i++ )); do
240 enable_ust_lttng_channel $session_name ${channel_name[$i]}
241 done
242
243 #Test the disable_channel command
244 disable_ust_lttng_channel $session_name ${channel_name[0]}
245 $XML_VALIDATE $OUTPUT_DEST
246 ok $? "Mi test: disable ust channel xsd validation"
247 is_command_success $OUTPUT_DIR false
248 #Check that we delete the good channel
249 extract_xml $OUTPUT_DEST $XPATH_ENABLE_CHANNEL_NAME result
250 test "$result" == "${channel_name[0]}"
251 ok $? "MI test: ${channel_name[0]} disabled"
252
253 #Test multiple disable_channel;
254 disable_ust_lttng_channel $session_name ${channel_name[1]},${channel_name[2]}
255 $XML_VALIDATE $OUTPUT_DEST
256 ok $? "Mi test: multiple disable ust channel xsd validation"
257 is_command_success $OUTPUT_DIR false
258
259 #Make sure we have two disabled channel
260 extract_xml $OUTPUT_DEST $XPATH_ENABLE_CHANNEL_NAME result
261 local num=$(echo "$result" | wc -l)
262 test "$num" == "2"
263 ok $? "Mi test: disabled ust channel $num/2"
264
265 #Teardown
266 OUTPUT_DEST=$DEVNULL
267 destroy_lttng_sessions
268
269 }
270
271 start_lttng_sessiond
272 TESTS=(
273 test_version
274 test_create_session
275 test_destroy_session
276 test_list_sessions
277 test_ust_channel
278 )
279
280 echo $OUTPUT_DIR
281 for fct_test in ${TESTS[@]};
282 do
283
284 ${fct_test}
285 if [ $? -ne 0 ]; then
286 break;
287 fi
288 # Only delete if successful
289 #TO REMOVE comment
290 #rm -rf $OUTPUT_DIR
291 done
292
293 OUTPUT_DEST=/dev/null 2>&1
294 stop_lttng_sessiond
This page took 0.052193 seconds and 4 git commands to generate.