Module: sip-router Branch: master Commit: da3327522527211fcd76aba394de9f2f538d8b9d URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=da332752...
Author: Henning Westerholt henning.westerholt@1und1.de Committer: Henning Westerholt henning.westerholt@1und1.de Date: Wed Oct 7 18:35:00 2009 +0200
unit test(sr): add initial small test for memcache module
---
test/unit/45.cfg | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ test/unit/45.sh | 50 +++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+), 0 deletions(-)
diff --git a/test/unit/45.cfg b/test/unit/45.cfg new file mode 100644 index 0000000..e434654 --- /dev/null +++ b/test/unit/45.cfg @@ -0,0 +1,72 @@ +# Kamailio config for lookup / registrar testing + +#------------------------Global configuration---------------------------------- +debug=2 +fork=yes +log_stderror=no +listen=127.0.0.1 +port=5060 +dns=no +rev_dns=no + +#-----------------------Loading Modules------------------------------------- +mpath="../../modules_k/" +loadmodule "../../modules/db_mysql/db_mysql.so" +loadmodule "usrloc/usrloc.so" +loadmodule "registrar/registrar.so" +loadmodule "sl/sl.so" +loadmodule "../../modules/tm/tm.so" +loadmodule "maxfwd/maxfwd.so" +loadmodule "pv/pv.so" +loadmodule "cfgutils.so" +loadmodule "memcached.so" +#for debugging purposes only +loadmodule "mi_fifo/mi_fifo.so" +loadmodule "xlog/xlog.so" + + +#-----------------------Module parameters------------------------------------- +modparam("mi_fifo", "fifo_name", "/tmp/kamailio_fifo") +modparam("usrloc", "db_mode", 3) +modparam("usrloc", "db_url", "mysql://openser:openserrw@localhost/openser") + +#-----------------------Routing configuration---------------------------------# +route{ + if (!mf_process_maxfwd_header("10")) { + sl_send_reply("483","Too Many Hops"); + exit(); + } + + $mct(test) = "1"; + $mct(test) = 5; + xlog("stored value is $mct(test)"); +# not work at the moment? +# $mct(test) = null; +# xlog("stored value is $mct(test)"); + + $mct(cnt) = 1; + $mcinc(cnt) = 1; # increment by 1 + xlog("counter is now $mct(cnt)"); + $mcdec(cnt) = 1; # decrement by 1 + xlog("counter is now $mct(cnt)"); + + $mct(test) = 111; + xlog("stored value is $mct(test)"); + $mctex(test) = 1; +# also not work at the moment? +# sleep("2"); + xlog("stored value is now $mct(test)"); + + if (registered("location")) { + xlog("contact registered"); + } + + if(!lookup ("location")){ + sl_send_reply("404", "Not Found"); + } + + if (!t_relay()) { + sl_reply_error(); + } +} + diff --git a/test/unit/45.sh b/test/unit/45.sh new file mode 100755 index 0000000..7b28c64 --- /dev/null +++ b/test/unit/45.sh @@ -0,0 +1,50 @@ +#!/bin/bash +# check memcached module with a basic usrloc scenario + +# Copyright (C) 2007 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. + +source include/common +source include/require +source include/database + +if ! (check_sipp && check_kamailio && check_module "db_mysql" && check_mysql && check_module "memcached"); then + exit 0 +fi ; + +CFG=45.cfg +SRV=5060 +UAS=5070 +UAC=5080 + + +# add an registrar entry to the db; +$MYSQL "INSERT INTO location (username,contact,socket,user_agent,cseq,q) VALUES ("foo","sip:foo@localhost:$UAS","udp:127.0.0.1:$UAS","ser_test",1,-1);" + +$BIN -w . -f $CFG &> /dev/null +sipp -sn uas -bg -i localhost -m 10 -f 2 -p $UAS &> /dev/null +sipp -sn uac -s foo 127.0.0.1:$SRV -i localhost -m 10 -f 2 -p $UAC &> /dev/null + +ret=$? + +# cleanup +killall -9 sipp > /dev/null 2>&1 +$KILL > /dev/null 2>&1 + +$MYSQL "DELETE FROM location WHERE ((contact = "sip:foo@localhost:$UAS") and (user_agent = "ser_test"));" +exit $ret;