From: David Goulet Date: Thu, 28 Apr 2011 17:07:23 +0000 (-0400) Subject: Add a basic structure for tests and sessiond tests X-Git-Tag: v2.0-pre1~172 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=6e0ca3c2c2afedf4a944cec63a6a566f7014c93f;p=lttng-tools.git Add a basic structure for tests and sessiond tests Basic stuff for ltt-sessiond testing. Also, the runall.sh should be used for all tests. Signed-off-by: David Goulet --- diff --git a/configure.ac b/configure.ac index acf80176b..96f1f1bd7 100644 --- a/configure.ac +++ b/configure.ac @@ -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 diff --git a/tests/Makefile.am b/tests/Makefile.am index 4824e2215..e1c39bd3d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 000000000..2614c56c9 --- /dev/null +++ b/tests/ltt-sessiond/Makefile.am @@ -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 index 000000000..f8bdf7fef --- /dev/null +++ b/tests/ltt-sessiond/run.sh @@ -0,0 +1,130 @@ +#!/bin/bash +# +# Copyright (C) 2011 - David Goulet +# +# 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 index e69de29bb..000000000 diff --git a/tests/runall.sh b/tests/runall.sh new file mode 100755 index 000000000..a1db92d70 --- /dev/null +++ b/tests/runall.sh @@ -0,0 +1,55 @@ +#!/bin/bash +# +# Copyright (C) 2011 - David Goulet +# +# 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