Browse Source

test Adding test configuration starting point

Olle E. Johansson 9 years ago
parent
commit
3724400d6e

+ 10 - 6
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

+ 12 - 0
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

+ 20 - 0
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

+ 1 - 0
test/mkinclude/kambin.mak

@@ -0,0 +1 @@
+KAMBIN=$(shell ../include/findkampath.sh)

+ 11 - 0
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

+ 6 - 0
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)

+ 18 - 0
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.$$$$
+

+ 71 - 0
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");
+
+
+}
+

+ 1 - 0
test/mod_httpapitest/test/test.log

@@ -0,0 +1 @@
+version: kamailio 5.0.0-dev4 (x86_64/darwin) 6dd4b1-dirty