diff --git a/test/unit/1.sh b/test/unit/1.sh index 4ec281120da..50a1c90f874 100755 --- a/test/unit/1.sh +++ b/test/unit/1.sh @@ -19,7 +19,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common +. include/common CFG=1.cfg diff --git a/test/unit/10.sh b/test/unit/10.sh index 47bbc9d4a22..fe50552aa63 100755 --- a/test/unit/10.sh +++ b/test/unit/10.sh @@ -19,7 +19,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common +. include/common cd $CTL_DIR diff --git a/test/unit/11.sh b/test/unit/11.sh index 4bbb9ad0410..133b68c7f19 100755 --- a/test/unit/11.sh +++ b/test/unit/11.sh @@ -19,9 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require -source include/database +. include/common +. include/require.sh +. include/database.sh CFG=11.cfg diff --git a/test/unit/12.sh b/test/unit/12.sh index 19c16f7c080..918744eb51d 100755 --- a/test/unit/12.sh +++ b/test/unit/12.sh @@ -19,8 +19,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require +. include/common +. include/require.sh CFG=12.cfg TMPFILE=`mktemp -t kamailio-test.XXXXXXXXXX` diff --git a/test/unit/13.sh b/test/unit/13.sh index a47963b4336..bbfec25350e 100755 --- a/test/unit/13.sh +++ b/test/unit/13.sh @@ -19,9 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require -source include/database +. include/common +. include/require.sh +. include/database.sh CFG=13.cfg diff --git a/test/unit/14.sh b/test/unit/14.sh index 4114f851774..eb9fab261b1 100755 --- a/test/unit/14.sh +++ b/test/unit/14.sh @@ -19,8 +19,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require +. include/common +. include/require.sh CFG=14.cfg diff --git a/test/unit/15.sh b/test/unit/15.sh index 5cceb053578..f5f7033f457 100755 --- a/test/unit/15.sh +++ b/test/unit/15.sh @@ -19,8 +19,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require +. include/common +. include/require.sh CFG=15.cfg diff --git a/test/unit/16.sh b/test/unit/16.sh index ddcd615a9fa..701131498c3 100755 --- a/test/unit/16.sh +++ b/test/unit/16.sh @@ -19,8 +19,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require +. include/common +. include/require.sh # Needs a default kamailio database setup for postgres diff --git a/test/unit/17.sh b/test/unit/17.sh index 2bf6154ceeb..318c18da530 100755 --- a/test/unit/17.sh +++ b/test/unit/17.sh @@ -19,8 +19,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require +. include/common +. include/require.sh if ! (check_kamailio && check_module "db_berkeley" ); then exit 0 diff --git a/test/unit/18.sh b/test/unit/18.sh index 5f618e7bc64..4afaa2fcefb 100755 --- a/test/unit/18.sh +++ b/test/unit/18.sh @@ -20,8 +20,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require +. include/common +. include/require.sh if ! (check_kamailio); then exit 0 diff --git a/test/unit/19.sh b/test/unit/19.sh index 1042bc6153a..91143675a42 100755 --- a/test/unit/19.sh +++ b/test/unit/19.sh @@ -19,9 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require -source include/database +. include/common +. include/require.sh +. include/database.sh if ! (check_sipp && check_kamailio && check_module "db_mysql" && check_mysql); then exit 0 diff --git a/test/unit/2.sh b/test/unit/2.sh index b0122960f07..b803c5dd2fb 100755 --- a/test/unit/2.sh +++ b/test/unit/2.sh @@ -21,9 +21,9 @@ # Needs a default kamailio database setup for mysql -source include/common -source include/require -source include/database +. include/common +. include/require.sh +. include/database.sh CFG=2.cfg diff --git a/test/unit/20.sh b/test/unit/20.sh index 3689c7d425b..17372bb6eac 100755 --- a/test/unit/20.sh +++ b/test/unit/20.sh @@ -19,9 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require -source include/database +. include/common +. include/require.sh +. include/database.sh if ! (check_sipp && check_kamailio && check_module "db_mysql" && check_mysql); then exit 0 diff --git a/test/unit/21.sh b/test/unit/21.sh index b0fe80cc47f..0eafdd83f4b 100755 --- a/test/unit/21.sh +++ b/test/unit/21.sh @@ -19,9 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require -source include/database +. include/common +. include/require.sh +. include/database.sh if ! (check_sipp && check_kamailio && check_module "db_mysql" && check_mysql); then exit 0 diff --git a/test/unit/22.sh b/test/unit/22.sh index 0849225f086..346632136f1 100755 --- a/test/unit/22.sh +++ b/test/unit/22.sh @@ -19,9 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require -source include/database +. include/common +. include/require.sh +. include/database.sh if ! (check_sipsak && check_kamailio && check_module "db_postgres" && check_postgres); then exit 0 diff --git a/test/unit/23.sh b/test/unit/23.sh index 375cfe7d9ce..3a0371959e9 100755 --- a/test/unit/23.sh +++ b/test/unit/23.sh @@ -19,9 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require -source include/database +. include/common +. include/require.sh +. include/database.sh if ! (check_kamailio && check_module "carrierroute" && check_module "db_postgres" && check_postgres); then exit 0 diff --git a/test/unit/24.sh b/test/unit/24.sh index 325c3dfad1f..196bb9df2ae 100755 --- a/test/unit/24.sh +++ b/test/unit/24.sh @@ -22,7 +22,7 @@ # Needs a mysql database, the root user password must be given # in the file 'dbrootpw' in the test directory -source include/common +. include/common if [ ! -f ~/.pgpass ] ; then echo "no .pgpass file, not run" @@ -55,4 +55,4 @@ mv $CTLRC.bak $CTLRC mv $DBCTL.bak $DBCTL cd - -exit $ret \ No newline at end of file +exit $ret diff --git a/test/unit/25.sh b/test/unit/25.sh index 974f42eda8f..36841cac483 100755 --- a/test/unit/25.sh +++ b/test/unit/25.sh @@ -19,9 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require -source include/database +. include/common +. include/require.sh +. include/database.sh function cleanup() { killall -9 sipp > /dev/null 2>&1 diff --git a/test/unit/26.sh b/test/unit/26.sh index 589805b2201..730813935e5 100755 --- a/test/unit/26.sh +++ b/test/unit/26.sh @@ -19,9 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require -source include/database +. include/common +. include/require.sh +. include/database.sh if ! (check_kamailio && check_module "carrierroute" && check_module "db_mysql" && check_mysql); then exit 0 diff --git a/test/unit/27.sh b/test/unit/27.sh index ec3feae19dd..97a8ce5c486 100755 --- a/test/unit/27.sh +++ b/test/unit/27.sh @@ -19,9 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require -source include/database +. include/common +. include/require.sh +. include/database.sh if ! (check_sipp && check_kamailio && check_module "db_mysql" \ && check_module "presence" && check_module "presence_xml" \ diff --git a/test/unit/28.sh b/test/unit/28.sh index a9969ed3539..23d08ed11ae 100755 --- a/test/unit/28.sh +++ b/test/unit/28.sh @@ -19,9 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require -source include/database +. include/common +. include/require.sh +. include/database.sh if ! (check_sipp && check_kamailio && check_module "db_mysql" && check_module "cpl-c" && check_mysql); then exit 0 diff --git a/test/unit/29.sh b/test/unit/29.sh index f75159b5c69..b12ebfab422 100755 --- a/test/unit/29.sh +++ b/test/unit/29.sh @@ -19,8 +19,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require +. include/common +. include/require.sh if ! (check_sipp && check_kamailio && check_module "db_postgres" && check_module "cpl-c"); then exit 0 diff --git a/test/unit/3.sh b/test/unit/3.sh index 9578c01a210..03c98b04fb8 100755 --- a/test/unit/3.sh +++ b/test/unit/3.sh @@ -25,14 +25,14 @@ # If MySQL root password is empty, add in the file the line: # PWSKIP=yes -source include/common +. include/common if [ ! -f dbrootpw ] ; then echo "no root password, not run" exit 0 fi ; -source dbrootpw +. dbrootpw tmp_name=""$RANDOM"_kamailiodb_tmp" diff --git a/test/unit/30.sh b/test/unit/30.sh index 084858e2d31..a88519c1aea 100755 --- a/test/unit/30.sh +++ b/test/unit/30.sh @@ -19,8 +19,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require +. include/common +. include/require.sh if ! (check_sipp && check_kamailio && check_module "carrierroute"); then exit 0 diff --git a/test/unit/31.sh b/test/unit/31.sh index 258fefc4a09..cc15e7a02c3 100755 --- a/test/unit/31.sh +++ b/test/unit/31.sh @@ -19,9 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require -source include/database +. include/common +. include/require.sh +. include/database.sh if ! (check_kamailio && check_module "db_mysql" && check_mysql); then exit 0 diff --git a/test/unit/4.sh b/test/unit/4.sh index fb2dfff0687..f75349a1281 100755 --- a/test/unit/4.sh +++ b/test/unit/4.sh @@ -19,8 +19,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require +. include/common +. include/require.sh CFG=4.cfg diff --git a/test/unit/42.sh b/test/unit/42.sh index 8415649c43e..5b0faa08637 100755 --- a/test/unit/42.sh +++ b/test/unit/42.sh @@ -19,9 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require -source include/database +. include/common +. include/require.sh +. include/database.sh if ! (check_kamailio && check_module "carrierroute" && check_module "db_mysql" && check_mysql); then exit 0 diff --git a/test/unit/43.sh b/test/unit/43.sh index dcb8a7d6dbd..a77f7cfd6e2 100755 --- a/test/unit/43.sh +++ b/test/unit/43.sh @@ -19,9 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require -source include/database +. include/common +. include/require.sh +. include/database.sh if ! (check_kamailio && check_module "utils" && check_module "db_mysql" && check_mysql); then exit 0 diff --git a/test/unit/44.sh b/test/unit/44.sh index c585be29a0c..8ab0fdca7b3 100755 --- a/test/unit/44.sh +++ b/test/unit/44.sh @@ -19,9 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require -source include/database +. include/common +. include/require.sh +. include/database.sh if ! (check_sipsak && check_kamailio && check_module "db_unixodbc" && check_unixodbc); then exit 0 diff --git a/test/unit/45.sh b/test/unit/45.sh index b01b9aaed1f..db05ad86147 100755 --- a/test/unit/45.sh +++ b/test/unit/45.sh @@ -19,9 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require -source include/database +. include/common +. include/require.sh +. include/database.sh if ! (check_sipp && check_kamailio && check_module "db_mysql" && check_mysql && check_module "memcached"); then exit 0 diff --git a/test/unit/46.sh b/test/unit/46.sh index 1ad64febafa..a2e1ea5ee24 100755 --- a/test/unit/46.sh +++ b/test/unit/46.sh @@ -19,9 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require -source include/database +. include/common +. include/require.sh +. include/database.sh if ! (check_sipp && check_kamailio && check_module "db_mysql" && check_mysql ); then exit 0 diff --git a/test/unit/5.sh b/test/unit/5.sh index d4fe178f3da..d7d1c6255cb 100755 --- a/test/unit/5.sh +++ b/test/unit/5.sh @@ -21,8 +21,8 @@ # Needs a default kamailio database setup for mysql -source include/common -source include/require +. include/common +. include/require.sh CFG=$TOP_DIR/etc/kamailio.cfg diff --git a/test/unit/50.sh b/test/unit/50.sh index ec78074a234..14571c327f9 100755 --- a/test/unit/50.sh +++ b/test/unit/50.sh @@ -19,9 +19,9 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require -source include/database +. include/common +. include/require.sh +. include/database.sh CFG=50.cfg diff --git a/test/unit/6.sh b/test/unit/6.sh index 6ddd9681fc7..b6ed5a3b2ba 100755 --- a/test/unit/6.sh +++ b/test/unit/6.sh @@ -19,8 +19,8 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common -source include/require +. include/common +. include/require.sh CFG=2.cfg diff --git a/test/unit/7.sh b/test/unit/7.sh index 05ba291cc0e..33f419f13d8 100755 --- a/test/unit/7.sh +++ b/test/unit/7.sh @@ -23,8 +23,8 @@ # Needs a default kamailio database setup for mysql -source include/common -source include/require +. include/common +. include/require.sh CFG=7.cfg diff --git a/test/unit/8.sh b/test/unit/8.sh index 3165e2fe389..7d41c537cbd 100755 --- a/test/unit/8.sh +++ b/test/unit/8.sh @@ -19,7 +19,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common +. include/common tmp_name=""$RANDOM"_kamailiodb_tmp" diff --git a/test/unit/9.sh b/test/unit/9.sh index 8e21626f444..c34c9b29d95 100755 --- a/test/unit/9.sh +++ b/test/unit/9.sh @@ -19,7 +19,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -source include/common +. include/common cd $CTL_DIR diff --git a/test/unit/include/common b/test/unit/include/common index 86ee0dca671..1868ef76347 100644 --- a/test/unit/include/common +++ b/test/unit/include/common @@ -25,3 +25,7 @@ KILL="killall -15 $BNAME" PIDFILE="${RUN_DIR}/kamailio.pid" # test directory relative to root TEST_DIR="test/unit" + +kill_kamailio() { + kill $(cat ${PIDFILE}) +} diff --git a/test/unit/include/database.sh b/test/unit/include/database.sh new file mode 100644 index 00000000000..c78c62bd7f6 --- /dev/null +++ b/test/unit/include/database.sh @@ -0,0 +1,72 @@ +# Copyright (C) 2017 mslehto@iki.fi +# Copyright (C) 2008 1&1 Internet AG +# +# This file is part of kamailio, a free SIP server. +# +# kamailio 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 +# +# kamailio 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +. include/common +KAMUSER="kamailio" +MYSQL="mysql kamailio --show-warnings --batch --user="${KAMUSER}" --password=kamailiorw -e" + +export PGPASSWORD="kamailiorw" +PSQL="psql -A -t -n -q -h localhost -U kamailio kamailio -c" + +ISQL="isql -b -v -d0x0 kamailio kamailio kamailiorw" + +check_mysql() { + $MYSQL "select * from location;" > /dev/null + if ! [ "$?" -eq 0 ] ; then + echo "can't read from database" + return 1 + fi; + $MYSQL "insert into location (user_agent) values ('___test___');" > /dev/null + if ! [ "$?" -eq 0 ] ; then + echo "can't write to database" + return 1 + fi; + $MYSQL "delete from location where user_agent ='___test___';" > /dev/null + return 0 +} + +check_postgres() { + $PSQL "select * from location;" > /dev/null + if ! [ "$?" -eq 0 ] ; then + echo "can't read from database" + return 1 + fi; + $PSQL "insert into location (user_agent) values ('___test___');" > /dev/null + if ! [ "$?" -eq 0 ] ; then + echo "can't write to database" + return 1 + fi; + $PSQL "delete from location where user_agent ='___test___';" > /dev/null + return 0 +} + +check_unixodbc() { + echo "select * from location;" | $ISQL > /dev/null + if ! [ "$?" -eq 0 ] ; then + echo "can't read from database" + return 1 + fi; + echo "insert into location (id, user_agent) values ('$RANDOM', '___test___');" | $ISQL > /dev/null + if ! [ "$?" -eq 0 ] ; then + echo "can't write to database" + return 1 + fi; + echo "delete from location where user_agent ='___test___';" | $ISQL > /dev/null + return 0 +} diff --git a/test/unit/include/require.sh b/test/unit/include/require.sh index c7642bbbbb0..07d800c75fe 100644 --- a/test/unit/include/require.sh +++ b/test/unit/include/require.sh @@ -1,5 +1,5 @@ +# Copyright (C) 2017 Mikko Lehto # Copyright (C) 2008 1&1 Internet AG -# Copyright (C) 2016 Mikko Lehto # # This file is part of kamailio, a free SIP server. # @@ -64,6 +64,3 @@ check_sipsak() { return 0 } -kill_kamailio() { - kill $(cat ${PIDFILE}) -}