Procházet zdrojové kódy

- add some small functions to check for an compiled openser, modules
and some helper programs
- add also a variable for a "all module" statement for inclusion in the cfg
- convert existing tests to use the functions


git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@4349 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt před 17 roky
rodič
revize
0ed71b08f9

+ 2 - 6
test/unit/11.sh

@@ -19,15 +19,11 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-# needs the netcat utility to run
+source include/require
 
 CFG=11.cfg
 
-which nc > /dev/null
-ret=$?
-
-if [ ! $ret -eq 0 ] ; then
-	echo "netcat not found, not run"
+if ! (check_netcat && check_openser && check_module "db_mysql"); then
 	exit 0
 fi ;
 

+ 2 - 6
test/unit/12.sh

@@ -19,16 +19,12 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-# needs the netcat utility to run
+source include/require
 
 CFG=12.cfg
 TMPFILE=`mktemp -t openser-test.XXXXXXXXXX`
 
-which nc > /dev/null
-ret=$?
-
-if [ ! $? -eq 0 ] ; then
-	echo "netcat not found, not run"
+if ! (check_netcat && check_openser); then
 	exit 0
 fi ;
 

+ 3 - 2
test/unit/13.sh

@@ -19,10 +19,11 @@
 # 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/require
+
 CFG=13.cfg
 
-if [ ! -e ../modules/carrierroute/carrierroute.so ] ; then
-	echo "carrierroute not found, not run"
+if ! (check_openser && check_module "carrierroute" ); then
 	exit 0
 fi ;
 

+ 3 - 2
test/unit/14.sh

@@ -19,10 +19,11 @@
 # 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/require
+
 CFG=14.cfg
 
-if [ ! -e ../modules/carrierroute/carrierroute.so ] ; then
-	echo "carrierroute not found, not run"
+if ! (check_openser && check_module "carrierroute" ); then
 	exit 0
 fi ;
 

+ 8 - 1
test/unit/15.sh

@@ -19,11 +19,18 @@
 # 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
+
 CFG=15.cfg
 
+if ! (check_openser); then
+	exit 0
+fi ;
+
 echo "loadmodule \"../modules/db_text/db_text.so\"" >> $CFG
 cat 2.cfg >> $CFG
-echo "modparam(\"acc|alias_db|auth_db|dialog|dialplan|dispatcher|domain|domainpolicy|group|imc|lcr|msilo|siptrace|speeddial|uri_db|usrloc|permissions|pdt|userblacklist\", \"db_url\", \"text://`pwd`/../scripts/dbtext/openser\")" >> $CFG
+echo "modparam(\"$DB_ALL_MOD\", \"db_url\", \"text://`pwd`/../scripts/dbtext/openser\")" >> $CFG
 
 ../openser -w . -f $CFG > /dev/null
 ret=$?

+ 5 - 4
test/unit/16.sh

@@ -19,10 +19,12 @@
 # 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
+
 # Needs a default openser database setup for postgres
 
-if [ ! -e ../modules/db_postgres/db_postgres.so ] ; then
-	echo "postgres driver not found, not run"
+if ! (check_openser && check_module "db_postgres" ); then
 	exit 0
 fi ;
 
@@ -30,8 +32,7 @@ CFG=2.cfg
 cp $CFG $CFG.bak
 
 echo "loadmodule \"db_postgres/db_postgres.so\"" >> $CFG
-echo "modparam(\"acc|alias_db|auth_db|dialog|dispatcher|domain|domainpolicy|group|imc|lcr|msilo|siptrace|speeddial|uri_db|usrloc|permissions|pdt|userblacklist\", \"db_url\", \"postgres://openserro:openserro@localhost/openser\")" >> $CFG
-
+echo "modparam(\"$DB_ALL_MOD\", \"db_url\", \"postgres://openserro:openserro@localhost/openser\")" >> $CFG
 
 # start
 ../openser -w . -f $CFG > /dev/null

+ 5 - 3
test/unit/17.sh

@@ -19,8 +19,10 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-if [ ! -e ../modules/db_berkeley/db_berkeley.so ] ; then
-	echo "db_berkeley driver not found, not run"
+source include/common
+source include/require
+
+if ! (check_openser && check_module "db_berkeley" ); then
 	exit 0
 fi ;
 
@@ -30,7 +32,7 @@ tmp_name=""$RANDOM"_openserdb_tmp"
 
 echo "loadmodule \"../modules/db_berkeley/db_berkeley.so\"" >> $CFG
 cat 2.cfg >> $CFG
-echo "modparam(\"acc|alias_db|auth_db|dialog|dispatcher|domain|domainpolicy|group|imc|lcr|msilo|siptrace|speeddial|uri_db|usrloc|permissions|pdt|userblacklist\", \"db_url\", \"berkeley://`pwd`/../scripts/$tmp_name\")" >> $CFG
+echo "modparam(\"$DB_ALL_MOD\", \"db_url\", \"berkeley://`pwd`/../scripts/$tmp_name\")" >> $CFG
 
 cd ../scripts
 

+ 6 - 0
test/unit/18.sh

@@ -20,6 +20,12 @@
 # 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/require
+
+if ! (check_openser); then
+	exit 0
+fi ;
+
 # the config file
 CFG=18.cfg
 

+ 5 - 8
test/unit/19.sh

@@ -19,17 +19,14 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-CFG=19.cfg
-
-# needs the sipp utility to run
-which sipp > /dev/null
-ret=$?
+source include/require
 
-if [ ! $? -eq 0 ] ; then
-	echo "sipp not found, not run"
+if ! (check_sipp && check_openser); then
 	exit 0
 fi ;
 
+CFG=19.cfg
+
 # add an registrar entry to the db;
 mysql --show-warnings -B -u openser --password=openserrw -D openser -e "INSERT INTO location (username,contact,socket,user_agent,cseq,q) VALUES (\"foo\",\"sip:foo@localhost\",\"udp:127.0.0.1:5060\",\"ser_test\",1,-1);"
 
@@ -39,7 +36,7 @@ sipp -sn uac -s foo 127.0.0.1:5059 -i 127.0.0.1 -m 10 -f 2 -p 5061 &> /dev/null
 
 ret=$?
 
-# cleanup:
+# cleanup
 killall -9 sipp > /dev/null 2>&1
 killall -9 openser > /dev/null 2>&1
 

+ 3 - 6
test/unit/20.sh

@@ -19,12 +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.
 
-# needs the sipp utility to run
-which sipp > /dev/null
-ret=$?
+source include/require
 
-if [ ! $? -eq 0 ] ; then
-	echo "sipp not found, not run"
+if ! (check_sipp && check_openser); then
 	exit 0
 fi ;
 
@@ -43,7 +40,7 @@ sipp -sn uac -s foo 127.0.0.1:5059 -i 127.0.0.1 -m 1 -f 10 -p 5061 &> /dev/null
 egrep '^ACC:[[:space:]]+transaction[[:space:]]+answered:[[:print:]]*code=200;reason=OK$' $TMPFILE > /dev/null
 ret=$?
 
-# cleanup:
+# cleanup
 killall -9 sipp &> /dev/null
 killall -9 openser &> /dev/null
 rm $TMPFILE

+ 4 - 7
test/unit/21.sh

@@ -19,15 +19,13 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-# needs the sipp utility to run
-which sipp > /dev/null
-ret=$?
+source include/require
 
-if [ ! $? -eq 0 ] ; then
-	echo "sipp not found, not run"
+if ! (check_sipp && check_openser); then
 	exit 0
 fi ;
 
+
 CFG=21.cfg
 
 MYSQL="mysql openser -u openser --password=openserrw -e"
@@ -49,8 +47,7 @@ if [ "$ret" -eq 0 ] ; then
 	ret=$?
 fi;
 
-
-#cleanup:
+#cleanup
 killall -9 openser &> /dev/null;
 killall -9 sipp &> /dev/null;
 $MYSQL "DELETE FROM subscriber WHERE((username = \"alice\") and (domain = \"localhost\"));"

+ 4 - 8
test/unit/22.sh

@@ -19,18 +19,14 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-# needs the netcat utility to run
+source include/require
 
-CFG=11.cfg
-
-which nc > /dev/null
-ret=$?
-
-if [ ! $ret -eq 0 ] ; then
-	echo "netcat not found, not run"
+if ! (check_netcat && check_openser && check_module "db_postgres"); then
 	exit 0
 fi ;
 
+CFG=11.cfg
+
 cp $CFG $CFG.tmp
 echo "loadmodule \"db_postgres/db_postgres.so\"" >> $CFG
 echo "modparam(\"usrloc\", \"db_url\", \"postgres://openser:openserrw@localhost/openser\")" >> $CFG

+ 4 - 3
test/unit/23.sh

@@ -19,13 +19,14 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-CFG=13.cfg
+source include/require
 
-if [ ! -e ../modules/carrierroute/carrierroute.so ] ; then
-	echo "carrierroute not found, not run"
+if ! (check_openser && check_module "carrierroute" && check_module "db_postgres"); then
 	exit 0
 fi ;
 
+CFG=13.cfg
+
 cp $CFG $CFG.bak
 
 # setup config

+ 2 - 5
test/unit/25.sh

@@ -19,12 +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.
 
-# needs the sipp utility to run
-which sipp > /dev/null
-ret=$?
+source include/require
 
-if [ ! $? -eq 0 ] ; then
-	echo "sipp not found, not run"
+if ! (check_sipp && check_openser); then
 	exit 0
 fi ;
 

+ 4 - 3
test/unit/26.sh

@@ -19,13 +19,14 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-CFG=26.cfg
+source include/require
 
-if [ ! -e ../modules/carrierroute/carrierroute.so ] ; then
-	echo "carrierroute not found, not run"
+if ! (check_openser && check_module "carrierroute" ); then
 	exit 0
 fi ;
 
+CFG=26.cfg
+
 cp $CFG $CFG.bak
 
 # setup config

+ 2 - 5
test/unit/27.sh

@@ -19,12 +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.
 
-# needs the sipp utility to run
-which sipp > /dev/null
-ret=$?
+source include/require
 
-if [ ! $? -eq 0 ] ; then
-	echo "sipp not found, not run"
+if ! (check_sipp && check_openser && check_module "db_mysql" && check_module "presence" && check_module "presence_xml"); then
 	exit 0
 fi ;
 

+ 2 - 5
test/unit/28.sh

@@ -19,12 +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.
 
-# needs the sipp utility to run
-which sipp > /dev/null
-ret=$?
+source include/require
 
-if [ ! $? -eq 0 ] ; then
-	echo "sipp not found, not run"
+if ! (check_sipp && check_openser && check_module "db_mysql" && check_module "cpl-c"); then
 	exit 0
 fi ;
 

+ 2 - 5
test/unit/29.sh

@@ -19,12 +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.
 
-# needs the sipp utility to run
-which sipp > /dev/null
-ret=$?
+source include/require
 
-if [ ! $? -eq 0 ] ; then
-	echo "sipp not found, not run"
+if ! (check_sipp && check_openser && check_module "db_postgres" && check_module "cpl-c"); then
 	exit 0
 fi ;
 

+ 5 - 3
test/unit/30.sh

@@ -19,13 +19,15 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-CFG=30.cfg
+source include/require
 
-if [ ! -e ../modules/carrierroute/carrierroute.so ] ; then
-	echo "carrierroute not found, not run"
+if ! (check_sipp && check_openser && check_module "carrierroute"); then
 	exit 0
 fi ;
 
+CFG=30.cfg
+
+
 cp $CFG $CFG.bak
 
 # setup config

+ 4 - 5
test/unit/31.sh

@@ -19,15 +19,14 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-CFG=11.cfg
-
-# Needs a default openser database setup for mysql
+source include/require
 
-if [ ! -e ../modules/db_mysql/db_mysql.so ] ; then
-	echo "mysql driver not found, not run"
+if ! (check_openser && check_module "db_mysql"); then
 	exit 0
 fi ;
 
+CFG=11.cfg
+
 DOMAIN="local"
 MYSQL="mysql openser -u openser --password=openserrw -e"
 

+ 4 - 5
test/unit/32.sh

@@ -19,15 +19,14 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-CFG=11.cfg
-
-# Needs a default openser database setup for mysql
+source include/require
 
-if [ ! -e ../modules/db_postgres/db_postgres.so ] ; then
-	echo "postgres driver not found, not run"
+if ! (check_sipp && check_openser && check_module "db_postgres"); then
 	exit 0
 fi ;
 
+CFG=11.cfg
+
 cp $CFG $CFG.bak
 
 echo "loadmodule \"db_postgres/db_postgres.so\"" >> $CFG

+ 5 - 9
test/unit/33.sh

@@ -19,15 +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.
 
-# needs the netcat utility to run
+source include/require
 
-CFG=33.cfg
-
-which nc > /dev/null
-ret=$?
-
-if [ ! $ret -eq 0 ] ; then
-	echo "netcat not found, not run"
+if ! (check_netcat && check_openser); then
 	exit 0
 fi;
 
@@ -36,7 +30,9 @@ if [ -e core ] ; then
 	exit 0
 fi;
 
-cp $CFG $CFG.bak                
+CFG=33.cfg
+
+cp $CFG $CFG.bak
 
 ../openser -w . -f $CFG > /dev/null
 ret=$?

+ 1 - 0
test/unit/include/common

@@ -0,0 +1 @@
+DB_ALL_MOD="acc|alias_db|auth_db|dialog|dialplan|dispatcher|domain|domainpolicy|group|imc|lcr|msilo|siptrace|speeddial|uri_db|usrloc|permissions|pdt|userblacklist"

+ 54 - 0
test/unit/include/require

@@ -0,0 +1,54 @@
+# Copyright (C) 2008 1&1 Internet AG
+#
+# This file is part of openser, a free SIP server.
+#
+# openser 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
+#
+# openser 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.
+
+function check_openser() {
+	if ! (test -e ../openser) ; then
+		echo "openser not found, not run"
+		return -1
+	fi;
+	return 0
+}
+
+function check_module() {
+	if [ $# -ne 1 ]; then
+		echo "wrong number of params in check_module()"
+		return -1
+	fi
+
+	if ! (test -e ../modules/$1/$1.so) ; then
+		echo "modules/$1/$1.so not found, not run"
+		return -1
+	fi;
+	return 0
+}
+
+function check_netcat() {
+	if ! ( which nc > /dev/null ); then
+		echo "netcat not found, not run"
+		return -1
+	fi;
+	return 0
+}
+
+function check_sipp() {
+	if ! ( which sipp > /dev/null ); then
+		echo "sipp not found, not run"
+		return -1
+	fi;
+	return 0
+}