From 3724400d6eb0c9f67ce2c69200b9f5eae62b7385 Mon Sep 17 00:00:00 2001 From: "Olle E. Johansson" Date: Fri, 3 Jun 2016 21:50:52 +0200 Subject: [PATCH] test Adding test configuration starting point --- test/README.md | 16 +++--- test/mkinclude/findkampath.sh | 12 +++++ test/mkinclude/ipaddr.mak | 20 ++++++++ test/mkinclude/kambin.mak | 1 + test/mkinclude/kamdefault.mak | 11 +++++ test/mkinclude/kamversion.mak | 6 +++ test/mod_httpapitest/test/Makefile | 18 +++++++ test/mod_httpapitest/test/curlapi.cfg | 71 +++++++++++++++++++++++++++ test/mod_httpapitest/test/test.log | 1 + 9 files changed, 150 insertions(+), 6 deletions(-) create mode 100755 test/mkinclude/findkampath.sh create mode 100644 test/mkinclude/ipaddr.mak create mode 100644 test/mkinclude/kambin.mak create mode 100644 test/mkinclude/kamdefault.mak create mode 100644 test/mkinclude/kamversion.mak create mode 100644 test/mod_httpapitest/test/Makefile create mode 100644 test/mod_httpapitest/test/curlapi.cfg create mode 100644 test/mod_httpapitest/test/test.log diff --git a/test/README.md b/test/README.md index 0547475bad..f2a20373dc 100644 --- a/test/README.md +++ b/test/README.md @@ -9,18 +9,22 @@ Modules found here test APIs in other modules or are just created for testing, n use. In order to use the existing build system, each module needs a directory named mod_something in test. +Module testing +-------------- Each module needs a subdirectory called "test" with a test configuration and a Makefile. A typical test script load the htable module and execute tests in the [event:htable_init] event route when starting. Typically, if a test fails, it runs abort() from the cfg_utils module to abort the process. +Targets of the test makefile: + - "test": Test syntax with "kamailio -c" + - "all": Run full test + Ideas: We may need a way to exit kamailio from inside without dumping a core file, but simply -stopping execution and returning different return values to the shell. That way a test -config can run for a limited amount of time or until a test fails. We can also -stop on an external action, like a RPC request calling the same function. + stopping execution and returning different return values to the shell. That way a test + config can run for a limited amount of time or until a test fails. We can also + stop on an external action, like a RPC request calling the same function. + -Targets: - - "test": Test syntax with "kamailio -c" - - "all": Run full test diff --git a/test/mkinclude/findkampath.sh b/test/mkinclude/findkampath.sh new file mode 100755 index 0000000000..2f27900304 --- /dev/null +++ b/test/mkinclude/findkampath.sh @@ -0,0 +1,12 @@ +#!/bin/sh +if test -x /usr/sbin/kamailio +then + echo "/usr/sbin" + exit 0 +fi +if test -x /usr/local/sbin/kamailio +then + echo "/usr/local/sbin" + exit 0 +fi +exit 1 diff --git a/test/mkinclude/ipaddr.mak b/test/mkinclude/ipaddr.mak new file mode 100644 index 0000000000..f2c60a4d6e --- /dev/null +++ b/test/mkinclude/ipaddr.mak @@ -0,0 +1,20 @@ +# +# Find IP address of local system +# Currently it's either Linux or (default) os/x + +UNAME_S:=$(shell uname) +ifeq ($(UNAME_S),Linux) +osystem=LINUX +interface:=eth0 +# Needs to be changed to "ip" instead of "ifconfig" +ipaddr:=$(shell /sbin/ifconfig $(interface) | grep 'inet '|cut -d':' -f2|cut -d' ' -f1) +else +# Assume Darwin OS/X +osystem=DARWIN +interface:=en0 +ipaddr:=$(shell /sbin/ifconfig $(interface) | grep 'inet '|cut -d' ' -f2) +endif + +ifeq ($(ipaddr),) +$(error Can not find IP address?) +endif diff --git a/test/mkinclude/kambin.mak b/test/mkinclude/kambin.mak new file mode 100644 index 0000000000..b30baac883 --- /dev/null +++ b/test/mkinclude/kambin.mak @@ -0,0 +1 @@ +KAMBIN=$(shell ../include/findkampath.sh) diff --git a/test/mkinclude/kamdefault.mak b/test/mkinclude/kamdefault.mak new file mode 100644 index 0000000000..39674b819e --- /dev/null +++ b/test/mkinclude/kamdefault.mak @@ -0,0 +1,11 @@ +# Default include file + +# Test version +testver=1.0 +ifeq ($(config),) + $error("??? No config set=") +endif +pidfile:=/tmp/${config}.pid + +include ../../mkinclude/kambin.mak +include ../../mkinclude/ipaddr.mak diff --git a/test/mkinclude/kamversion.mak b/test/mkinclude/kamversion.mak new file mode 100644 index 0000000000..e2d05280fb --- /dev/null +++ b/test/mkinclude/kamversion.mak @@ -0,0 +1,6 @@ +# Log the latest test version +ifeq ($(KAMBIN),) + $(error NO KAMBIN??? ) +endif +KAMVER=$(shell $(KAMBIN)/kamailio -v|head -n1) +$(shell echo "$(KAMVER)" > test.log) diff --git a/test/mod_httpapitest/test/Makefile b/test/mod_httpapitest/test/Makefile new file mode 100644 index 0000000000..510e9f96a2 --- /dev/null +++ b/test/mod_httpapitest/test/Makefile @@ -0,0 +1,18 @@ +config:=curlapi.cfg +KAMBIN:=/usr/local/sbin + +# Find the IP address +include ../../mkinclude/ipaddr.mak + + +# Log the version +include ../../mkinclude/kamversion.mak + +all: + @echo Our IP address $(ipaddr) on interface $(interface) - Redo to fly Kamailio? + @/usr/local/sbin/kamailio -f $(config) -l udp:$(ipaddr):5060 -D 1 -E -M 2000 + +debug: + @/usr/local/sbin/kamailio -f $(config) -l udp:$(ipaddr):5060 -D 1 -E > /tmp/kamcurl.$$$$ 2>&1 + grep curl /tmp/kamcurl.$$$$ + diff --git a/test/mod_httpapitest/test/curlapi.cfg b/test/mod_httpapitest/test/curlapi.cfg new file mode 100644 index 0000000000..6082c707dd --- /dev/null +++ b/test/mod_httpapitest/test/curlapi.cfg @@ -0,0 +1,71 @@ + +# Test of the new http_client API module +# +# (C) 2016 Edvina AB, Sollentuna, Sweden. All rights reserved. +# +# + +debug=3 +log_stderror=yes +fork=no + +# ------------------ module loading ---------------------------------- +# Set a path to known locations for modules +# +mpath="/usr/local/lib64/kamailio/modules:/usr/local/lib/kamailio/modules:/usr/lib64/kamailio/modules:/usr/lib/kamailio/modules" +loadmodule "pv.so" # For pseudo-variable support in log messages etc +loadmodule "xlog.so" # For extended logging with pseudovariables +loadmodule "kex.so" # Kamailio extensions: + # Script flags and basic mi commands (version, pwd, get_statistics) +# +loadmodule "tm.so" # Transactions are needed in order to fork +loadmodule "tmx.so" # Kamailio extras to TM +# +loadmodule "sl.so" # Stateless replies - needed by registrar.so +loadmodule "rtimer.so" # For ticks +loadmodule "htable.so" # For init event route +loadmodule "http_client.so" # THe CURL module +loadmodule "httpapitest.so" # THe CURL module +loadmodule "cfgutils.so" # Memory debugging + +# main routing logic + +modparam("http_client", "connection_timeout", 42); +modparam("http_client", "keep_connections", 1); +modparam("http_client", "maxdatasize", 1000); +modparam("http_client", "useragent", "Olle's Peace and Restful little HTTP grabber 42.3"); +#user and password +modparam("http_client", "httpcon", "lisa=>https://www.kamailio.org/w/"); + + +# ------------------------- request routing logic ------------------- +route { + sl_send_reply(400, "Do not wake me up"); + exit; +} + +onreply_route { + xlog("L_INFO", "<-- Incoming response: $rs $rr - from $si\n"); +} + +branch_route[BRANCH_ROUTE] +{ + xlog("L_INFO", " --> Outgoing branch $T_branch_idx : $rm from $si to $ru \n"); +} + +onsend_route +{ + xlog("ONSEND --> Sending from $sndfrom(proto):$sndfrom(ip):$sndfrom(port) to $sndto(proto):$sndto(ip):$sndto(port) \n"); +} + +# This route is executed at Kamailio start +event_route[htable:mod-init] +{ + xlog("L_ERR", "### Kamailio starting $timef(HH:mm) \n"); + $avp(gurka) = ""; + $var(res) = http_connect("lisa", "", "$avp(gurka)"); + xlog("L_ERR", "-- Lisa http_client connection: $avp(gurka) Result $var(res)\n"); + + +} + diff --git a/test/mod_httpapitest/test/test.log b/test/mod_httpapitest/test/test.log new file mode 100644 index 0000000000..114f6a68f0 --- /dev/null +++ b/test/mod_httpapitest/test/test.log @@ -0,0 +1 @@ +version: kamailio 5.0.0-dev4 (x86_64/darwin) 6dd4b1-dirty -- 2.20.1