Mi test: Refactoring and multiple test suites
authorJonathan Rajotte Julien <jonathan.r.julien@gmail.com>
Wed, 2 Jul 2014 14:12:02 +0000 (10:12 -0400)
committerJonathan Rajotte Julien <jonathan.r.julien@gmail.com>
Tue, 22 Jul 2014 20:14:58 +0000 (16:14 -0400)
Test for: destroy command
          basic list command
          enable_channel
          disable_channel

tests/fast_regression
tests/regression/tools/mi/Makefile.am
tests/regression/tools/mi/test_mi [new file with mode: 0755]
tests/regression/tools/mi/test_mi_version [deleted file]
tests/utils/utils.sh

index 6fae89d039f003c4adb80f315d3292dc6f64d151..638c82f0e80dcadfa8042f7f3ef1e21e81f6b0aa 100644 (file)
@@ -13,7 +13,7 @@ regression/tools/snapshots/test_ust_fast
 regression/tools/snapshots/test_ust_streaming
 regression/tools/save-load/test_save
 regression/tools/save-load/test_load
 regression/tools/snapshots/test_ust_streaming
 regression/tools/save-load/test_save
 regression/tools/save-load/test_load
-regression/tools/mi/test_mi_version
+regression/tools/mi/test_mi
 regression/ust/before-after/test_before_after
 regression/ust/buffers-pid/test_buffers_pid
 regression/ust/multi-session/test_multi_session
 regression/ust/before-after/test_before_after
 regression/ust/buffers-pid/test_buffers_pid
 regression/ust/multi-session/test_multi_session
index 7a54c3487a4d5768d1bd8680277da44b78ec92fa..5586461a0f101f90bff481b5e5ce9d48e3740d79 100644 (file)
@@ -9,7 +9,7 @@ extract_xml_SOURCES = extract_xml.c
 extract_xml_CPPFLAGS = $(XML_CPPFLAGS) $(AM_CPPFLAGS)
 extract_xml_LDADD = $(XML_LIBS)
 
 extract_xml_CPPFLAGS = $(XML_CPPFLAGS) $(AM_CPPFLAGS)
 extract_xml_LDADD = $(XML_LIBS)
 
-noinst_SCRIPTS = test_mi_version
+noinst_SCRIPTS = test_mi
 EXTRA_DIST =
 
 all-local:
 EXTRA_DIST =
 
 all-local:
diff --git a/tests/regression/tools/mi/test_mi b/tests/regression/tools/mi/test_mi
new file mode 100755 (executable)
index 0000000..dc0990e
--- /dev/null
@@ -0,0 +1,294 @@
+#!/bin/bash
+#
+# Copyright (C) - 2014 Jonathan Rajotte <jonathan.r.julien@gmail.com>
+#
+# This library is free software; you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation; version 2.1 of the License.
+#
+# This library is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this library; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+
+TEST_DESC="Machine interface testing"
+
+CURDIR=$(dirname $0)/
+TESTDIR=$CURDIR/../../../
+XSD_PATH=$TESTDIR/../src/common/mi_lttng.xsd
+SESSIOND_BIN="lttng-sessiond"
+RELAYD_BIN="lttng-relayd"
+
+
+#Temp file output
+#OUTPUT_DIR=$(mktemp -d)
+OUTPUT_DIR="/tmp/test"
+OUTPUT_FILE="default.xml"
+
+#Path to custom xml utilities
+XML_VALIDATE="$CURDIR/validate_xml $XSD_PATH"
+XML_EXTRACT="$CURDIR/extract_xml"
+
+XPATH_COMMAND_SUCCESS="/command/success/text()"
+XPATH_SESSION_NAME="/command/output/sessions/session/name/text()"
+XPATH_ENABLE_CHANNEL_NAME="/command/output/channels/channel/name/text()"
+
+DEVNULL=/dev/null 2>&1
+
+DIR=$(readlink -f $TESTDIR)
+
+NUM_TESTS=60
+
+source $TESTDIR/utils/utils.sh
+
+#Overwrite the lttng_bin to get mi output
+LTTNG_BIN="lttng --mi xml"
+
+#Global devlaration for simplification
+LTTNG=$TESTDIR/../src/bin/lttng/$LTTNG_BIN
+
+#Overwrite the default output for utils.sh command
+
+#MUST set TESTDIR before calling those functions
+plan_tests $NUM_TESTS
+
+print_test_banner "$TEST_DESC"
+
+function extract_xml ()
+{
+       local xml=$1
+       local xpath=$2
+       local __result=$3
+       local output=$($XML_EXTRACT $xml $xpath)
+       ok $? "Extraction of xpath $xpath"
+       eval $__result="'$output'"
+}
+
+# Arg1 is path to xml file
+# Arg2:
+#     is true if we expected the success element to be false
+#     else
+#     passe false
+
+function is_command_success ()
+{
+       local xml=$1
+       local expect_false=$2
+
+       local xpath=$XPATH_COMMAND_SUCCESS
+
+       #Extract the success element
+       #expect false
+       extract_xml $OUTPUT_DEST $XPATH_COMMAND_SUCCESS result
+       if [[ $expect_false ]]; then
+               if [[ $result ]]; then
+                       pass "Mi test: $xml command failed as expected"
+               else
+                       fail "Mi test: $xml command did not fail as expected"
+               fi
+       else
+               if [[ $result ]]; then
+                       fail "Mi test: $xml command failed"
+               else
+                       pass "Mi test: $xml command success"
+               fi
+       fi
+}
+
+function mi_print_version ()
+{
+       local opt=$2
+       local output_path=$1
+
+       $LTTNG version $opt > $1
+       ok $? "MI test: Lttng version"
+
+}
+
+function test_version ()
+{
+       OUTPUT_FILE="version.xml"
+       OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
+       mi_print_version $OUTPUT_DEST
+       $XML_VALIDATE $OUTPUT_DEST
+       ok $? "MI test: Version xsd validation"
+}
+
+function test_create_session ()
+{
+       local session_name="testSession"
+
+       OUTPUT_FILE="create_session.xml"
+       OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
+       create_lttng_session $session_name $OUTPUT_DIR
+       $XML_VALIDATE $OUTPUT_DEST
+       ok $? "MI test: create session xsd validation"
+
+       #try to recreate a session. Expecting it to fail
+       create_lttng_session $session_name $OUTPUT_DIR true
+       $XML_VALIDATE $OUTPUT_DEST
+       ok $? "MI test: expecting fail create session xsd validation"
+       is_command_success $OUTPUT_DEST true
+
+       OUTPUT_DEST=$DEVNULL
+       destroy_lttng_session $session_name
+}
+
+function test_destroy_session ()
+{
+       local session_name=(
+                       "testSession1"
+                       "testSession2"
+                       "testSession3")
+
+       OUTPUT_FILE="destroy_session.xml"
+
+       #Test build up
+       OUTPUT_DEST=$DEVNULL
+       for (( i = 0; i < 3; i++ )); do
+               create_lttng_session ${session_name[$i]} $OUTPUT_DIR
+       done
+
+       OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
+       destroy_lttng_session ${session_name[0]}
+       $XML_VALIDATE $OUTPUT_DEST
+       ok $? "MI test: destroy session ${session_name[0]} xsd validation"
+
+       #Verify that we destroyed the good session
+       extract_xml $OUTPUT_DEST $XPATH_SESSION_NAME result
+       if [[ "$result" == "${session_name[0]}" ]]; then
+               ok 0 "Mi test: delete by name"
+       else
+               ok 1 "Mi test: we deleted the wrong session"
+       fi
+
+       #Destroy all and count:should be 2
+       destroy_lttng_sessions
+       $XML_VALIDATE $OUTPUT_DEST
+       ok $? "MI test: destroy all session xsd validation"
+
+       #Verify that we destroyed 2 sessions
+       extract_xml $OUTPUT_DEST $XPATH_SESSION_NAME result
+       num=$(echo "$result" | wc -l)
+       test "$num" -eq "2"
+       ok $? "Mi test: $num / 2 sessions discovered"
+}
+
+function test_list_sessions ()
+{
+       local session_name=(
+                       "testSession1"
+                       "testSession2"
+                       "testSession3")
+
+       OUTPUT_FILE="list_sessions.xml"
+
+       #Test buid up
+       OUTPUT_DEST=$DEVNULL
+       for (( i = 0; i < 3; i++ )); do
+               create_lttng_session ${session_name[$i]} $OUTPUT_DIR
+       done
+
+       OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
+       list_lttng_with_opts
+       $XML_VALIDATE $OUTPUT_DEST
+       ok $? "Mi test: list session xsd validation"
+
+       #We should have 3 session
+       extract_xml $OUTPUT_DEST $XPATH_SESSION_NAME result
+       num=$(echo "$result" | wc -l)
+       test "$num" -eq "3"
+       ok $? "Mi test: $num / 3 sessions discovered"
+
+       #Teardown
+       OUTPUT_DEST=$DEVNULL
+       destroy_lttng_sessions
+}
+
+function test_ust_channel ()
+{
+       local session_name="testsession"
+       local channel_name=("channelUst0"
+                                               "channelUst1"
+                                               "channelUst2")
+
+       OUTPUT_FILE="ust_channel.xml"
+
+       #Test buil up
+       OUTPUT_DEST=$DEVNULL
+       create_lttng_session $session_name $OUTPUT_DIR
+
+       #Test the enable_channel command
+       OUTPUT_DEST=$OUTPUT_DIR/$OUTPUT_FILE
+       enable_ust_lttng_channel $session_name ${channel_name[0]}
+       $XML_VALIDATE $OUTPUT_DEST
+       ok $? "Mi test: enable ust channel xsd validation"
+       is_command_success $OUTPUT_DIR false
+
+       #Expect the command to fail
+       enable_ust_lttng_channel $session_name ${channel_name[0]} true
+       $XML_VALIDATE $OUTPUT_DEST
+       ok $? "Mi test: fail enable ust channel xsd validation"
+       is_command_success $OUTPUT_DIR true
+
+       #Create two ust channel to test multiple disable
+       for (( i = 1; i < 3; i++ )); do
+               enable_ust_lttng_channel $session_name ${channel_name[$i]}
+       done
+
+       #Test the disable_channel command
+       disable_ust_lttng_channel $session_name ${channel_name[0]}
+       $XML_VALIDATE $OUTPUT_DEST
+       ok $? "Mi test: disable ust channel xsd validation"
+       is_command_success $OUTPUT_DIR false
+       #Check that we delete the good channel
+       extract_xml $OUTPUT_DEST $XPATH_ENABLE_CHANNEL_NAME result
+       test "$result" == "${channel_name[0]}"
+       ok $? "MI test: ${channel_name[0]} disabled"
+
+       #Test multiple disable_channel;
+       disable_ust_lttng_channel $session_name ${channel_name[1]},${channel_name[2]}
+       $XML_VALIDATE $OUTPUT_DEST
+       ok $? "Mi test: multiple disable ust channel xsd validation"
+       is_command_success $OUTPUT_DIR false
+
+       #Make sure we have two disabled channel
+       extract_xml $OUTPUT_DEST $XPATH_ENABLE_CHANNEL_NAME result
+       local num=$(echo "$result" | wc -l)
+       test "$num" == "2"
+       ok $? "Mi test: disabled ust channel $num/2"
+
+       #Teardown
+       OUTPUT_DEST=$DEVNULL
+       destroy_lttng_sessions
+
+}
+
+start_lttng_sessiond
+TESTS=(
+       test_version
+       test_create_session
+       test_destroy_session
+       test_list_sessions
+       test_ust_channel
+)
+
+echo $OUTPUT_DIR
+for fct_test in ${TESTS[@]};
+do
+
+       ${fct_test}
+       if [ $? -ne 0 ]; then
+               break;
+       fi
+       # Only delete if successful
+       #TO REMOVE comment
+       #rm -rf $OUTPUT_DIR
+done
+
+OUTPUT_DEST=/dev/null 2>&1
+stop_lttng_sessiond
diff --git a/tests/regression/tools/mi/test_mi_version b/tests/regression/tools/mi/test_mi_version
deleted file mode 100755 (executable)
index 1d89453..0000000
+++ /dev/null
@@ -1,78 +0,0 @@
-#!/bin/bash
-#
-# Copyright (C) - 2014 Jonathan Rajotte <jonathan.r.julien@gmail.com>
-#
-# This library is free software; you can redistribute it and/or modify it under
-# the terms of the GNU Lesser General Public License as published by the Free
-# Software Foundation; version 2.1 of the License.
-#
-# This library is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Lesser General Public License
-# along with this library; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
-
-TEST_DESC="Mi test command version"
-
-CURDIR=$(dirname $0)/
-TESTDIR=$CURDIR/../../../
-XSD_PATH=$TESTDIR/../src/common/mi_lttng.xsd
-SESSIOND_BIN="lttng-sessiond"
-RELAYD_BIN="lttng-relayd"
-LTTNG_BIN="lttng --mi xml"
-
-XML_VALIDATE="$CURDIR/validate_xml $XSD_PATH"
-
-LTTNG=$TESTDIR/../src/bin/lttng/$LTTNG_BIN
-
-
-DIR=$(readlink -f $TESTDIR)
-
-NUM_TESTS=4
-
-source $TESTDIR/utils/utils.sh
-
-# MUST set TESTDIR before calling those functions
-plan_tests $NUM_TESTS
-
-print_test_banner "$TEST_DESC"
-
-function mi_print_version()
-{
-       local opt=$2
-       local output_path=$1
-
-       $LTTNG version $opt > $output_path
-       ok $? "Machine Interface Lttng version"
-
-}
-
-function test_version_validation()
-{
-       mi_print_version version.xml
-       $XML_VALIDATE version.xml
-       ok $? "Machine Interface Version xsd validation"
-}
-
-start_lttng_sessiond
-
-TESTS=(
-       test_version_validation
-)
-
-for fct_test in ${TESTS[@]};
-do
-       TRACE_PATH=$(mktemp -d)
-
-       ${fct_test}
-       if [ $? -ne 0 ]; then
-               break;
-       fi
-       # Only delete if successful
-       rm -rf $TRACE_PATH
-done
-
-stop_lttng_sessiond
index 32f5bd19335432cdddf8cae52f7ae4cb97c1d87d..21212bc8a010505a17528e45dde7a3584cc2c8ab 100644 (file)
@@ -210,7 +210,7 @@ function stop_lttng_sessiond ()
 function list_lttng_with_opts ()
 {
        opts=$1
 function list_lttng_with_opts ()
 {
        opts=$1
-       $TESTDIR/../src/bin/lttng/$LTTNG_BIN $opts >$OUTPUT_DEST
+       $TESTDIR/../src/bin/lttng/$LTTNG_BIN list $opts >$OUTPUT_DEST
        ok $? "Lttng-tool list command with option $opts"
 }
 
        ok $? "Lttng-tool list command with option $opts"
 }
 
@@ -230,8 +230,12 @@ function create_lttng_session ()
 
        $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path > $OUTPUT_DEST
        ret=$?
 
        $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path > $OUTPUT_DEST
        ret=$?
-       if [[ $expected_to_fail && $ret ]]; then
-               ok 0 "Expected fail on session creation $sess_name in $trace_path"
+       if [[ $expected_to_fail ]]; then
+               if [[ $ret ]]; then
+                       pass "Expected fail on session creation $sess_name in $trace_path"
+               else
+                       fail "Session $sess_name creation in $trace_path was expected to fail"
+               fi
        else
                ok $ret "Create session $sess_name in $trace_path"
        fi
        else
                ok $ret "Create session $sess_name in $trace_path"
        fi
@@ -241,9 +245,19 @@ function enable_ust_lttng_channel()
 {
        sess_name=$1
        channel_name=$2
 {
        sess_name=$1
        channel_name=$2
+       expect_fail=$3
 
        $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -u $channel_name -s $sess_name >$OUTPUT_DEST
 
        $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -u $channel_name -s $sess_name >$OUTPUT_DEST
-       ok $? "Enable channel $channel_name for session $sess_name"
+       ret=$?
+       if [[ $expect_fail ]]; then
+               if [[ $ret ]]; then
+                       pass "Enable channel $channel_name for session $sess_name expected fail"
+               else
+                       fail "Enable channel $channel_name for session $sess_name did not fail as expected"
+               fi
+       else
+               ok $ret "Enable channel $channel_name for session $sess_name"
+       fi
 }
 
 function disable_ust_lttng_channel()
 }
 
 function disable_ust_lttng_channel()
This page took 0.043979 seconds and 4 git commands to generate.