Add a basic structure for tests and sessiond tests
authorDavid Goulet <david.goulet@polymtl.ca>
Thu, 28 Apr 2011 17:07:23 +0000 (13:07 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Thu, 28 Apr 2011 17:08:55 +0000 (13:08 -0400)
Basic stuff for ltt-sessiond testing. Also, the runall.sh
should be used for all tests.

Signed-off-by: David Goulet <david.goulet@polymtl.ca>
configure.ac
tests/Makefile.am
tests/ltt-sessiond/Makefile.am [new file with mode: 0644]
tests/ltt-sessiond/run.sh [new file with mode: 0755]
tests/runall [deleted file]
tests/runall.sh [new file with mode: 0755]

index acf80176bb0ee27ac6b3a0b4bb35cb2eebb45247..96f1f1bd7b76eb1a9fc94ce8b2c0878cb6fb1fdc 100644 (file)
@@ -48,9 +48,10 @@ AC_CONFIG_FILES([
        include/Makefile
        liblttngctl/Makefile
        liblttsessiondcomm/Makefile
+       ltt-sessiond/Makefile
        lttng/Makefile
        tests/Makefile
-       ltt-sessiond/Makefile
+       tests/ltt-sessiond/Makefile
 ])
 
 AC_OUTPUT
index 4824e2215f4dbc77b1c6c41c5a09f4097fb6c3bb..e1c39bd3dc3c87d7dfc921fbdf6bb58339cf2b0f 100644 (file)
@@ -1,3 +1,3 @@
-SUBDIRS = .
+SUBDIRS = . ltt-sessiond
 
-dist_noinst_SCRIPTS = runall
+dist_noinst_SCRIPTS = runall.sh
diff --git a/tests/ltt-sessiond/Makefile.am b/tests/ltt-sessiond/Makefile.am
new file mode 100644 (file)
index 0000000..2614c56
--- /dev/null
@@ -0,0 +1,4 @@
+AM_CPPFLAGS = -I$(top_srcdir)/include
+
+noinst_SCRIPTS = run.sh
+EXTRA_DIST = run.sh
diff --git a/tests/ltt-sessiond/run.sh b/tests/ltt-sessiond/run.sh
new file mode 100755 (executable)
index 0000000..f8bdf7f
--- /dev/null
@@ -0,0 +1,130 @@
+#!/bin/bash
+#
+# Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+
+PWD=$(dirname $0)
+
+SESSIOND_CLIENT_SOCK_PATH="/tmp/.test-sessiond-client"
+SESSIOND_APPS_SOCK_PATH="/tmp/.test-sessiond-apps"
+SESSIOND_BIN="$PWD/../../ltt-sessiond/ltt-sessiond"
+LTTNG_BIN="$PWD/../../lttng/lttng"
+#SESSIOND_ARGS="-c $SESSIOND_CLIENT_SOCK_PATH -a $SESSIOND_APPS_SOCK_PATH"
+SESSIOND_ARGS=""
+SESSION_ID_REGEX="[[:alnum:]]{8}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{4}-[[:alnum:]]{12}"
+
+function clean_exit()
+{
+       echo "[+] Shuting down session daemon..."
+       kill -s SIGTERM $pid
+       exit $1
+}
+
+# Exec $1, check error code.
+# If 0, return output, else, stop execution
+# and return and error.
+function check_ret_code()
+{
+       if [ $1 -ne 0 ]; then
+               printf "\n!STOPPING!\n"
+               clean_exit 1
+       fi
+}
+
+# Create session with $1 and return output.
+function lttng_create_session()
+{
+       local command="$LTTNG_BIN -c $1"
+       local ret=$($command)
+       LTTNG_RET_CODE=$?
+
+       # Extract session UUID
+       if [[ "$ret" =~ $SESSION_ID_REGEX ]]; then
+               LTTNG_SESSION_ID="$BASH_REMATCH"
+       fi
+}
+
+# List sessions and return output.
+function lttng_list_session()
+{
+       local command="$LTTNG_BIN --list-sessions"
+       local ret=$(lttng_command "$command")
+
+       if [[ "$result" =~ $session_id ]]; then
+               printf "SUCCESS!\n"
+       else
+               printf "FAIL!\n"
+               printf "Missing $session_id!\n"
+               exit 1
+       fi
+       echo "$ret"
+}
+
+function test_destroy_session()
+{
+       local command="$LTTNG_BIN -d $LTTNG_SESSION_ID"
+       local ret=$($command)
+       check_ret_code $LTTNG_RET_CODE
+       echo "[+] Destroy session: PASSED!"
+}
+
+function test_one_session()
+{
+       lttng_create_session "test1"
+       check_ret_code $LTTNG_RET_CODE
+       echo "[+] Session creation: PASSED!"
+}
+
+function test_session_same_name()
+{
+       lttng_create_session "test-same"
+       lttng_create_session "test-same"
+       if [ $LTTNG_RET_CODE -ne 1 ]; then
+               echo "[-] Session with the same name: FAILED!"
+               printf "Two session having the same name NOT ALLOWED\n"
+               clean_exit 1
+       fi
+       echo "[+] Session with the same name: PASSED!"
+}
+
+if [ ! -x $SESSIOND_BIN ]; then
+       echo "Please use make before test execution"
+       exit 1
+fi
+
+# Daemonized by the -d
+./$SESSIOND_BIN $SESSIOND_ARGS -d
+echo "[+] Session daemon started"
+
+pid=$(pidof lt-ltt-sessiond)
+if [ -z "$pid" ]; then
+       echo "[-] Can't found session daemon"
+       ./$SESSIOND_BIN $SESSIOND_ARGS
+       exit 1
+fi
+echo "[+] Got the session daemon pid $pid"
+
+printf "=== Starting tests ===\n"
+
+test_one_session
+
+test_destroy_session
+
+test_session_same_name
+
+clean_exit 0
+
diff --git a/tests/runall b/tests/runall
deleted file mode 100755 (executable)
index e69de29..0000000
diff --git a/tests/runall.sh b/tests/runall.sh
new file mode 100755 (executable)
index 0000000..a1db92d
--- /dev/null
@@ -0,0 +1,55 @@
+#!/bin/bash
+#
+# Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program 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 General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+
+TEST_DIR=$(dirname $0)
+
+failed=0
+num_test=1
+
+function run() {
+       printf "%d) Running test $@\n" $num_test
+       echo "=================================="
+
+       # Running test
+       ./$@
+       if [ $? -ne 0 ]; then
+               let failed=$failed+1
+               printf "\nTest $@ FAILED\n\n"
+       else
+               printf "\nTest $@ PASSED\n\n"
+       fi
+
+       let num_test=$num_test+1
+}
+
+#### ADD TESTS HERE ####
+
+run ltt-sessiond/run.sh
+
+#### END TESTS HERE ####
+
+echo "--------------------------"
+if [ $failed -eq 0 ]; then
+       echo "All passed!"
+else
+       echo "$failed tests failed"
+fi
+echo "--------------------------"
+
+exit 0
This page took 0.029048 seconds and 4 git commands to generate.