test Adding test configuration starting point
authorOlle E. Johansson <oej@edvina.net>
Fri, 3 Jun 2016 19:50:52 +0000 (21:50 +0200)
committerOlle E. Johansson <oej@edvina.net>
Fri, 3 Jun 2016 19:50:52 +0000 (21:50 +0200)
test/README.md
test/mkinclude/findkampath.sh [new file with mode: 0755]
test/mkinclude/ipaddr.mak [new file with mode: 0644]
test/mkinclude/kambin.mak [new file with mode: 0644]
test/mkinclude/kamdefault.mak [new file with mode: 0644]
test/mkinclude/kamversion.mak [new file with mode: 0644]
test/mod_httpapitest/test/Makefile [new file with mode: 0644]
test/mod_httpapitest/test/curlapi.cfg [new file with mode: 0644]
test/mod_httpapitest/test/test.log [new file with mode: 0644]

index 0547475..f2a2037 100644 (file)
@@ -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 (executable)
index 0000000..2f27900
--- /dev/null
@@ -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 (file)
index 0000000..f2c60a4
--- /dev/null
@@ -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 (file)
index 0000000..b30baac
--- /dev/null
@@ -0,0 +1 @@
+KAMBIN=$(shell ../include/findkampath.sh)
diff --git a/test/mkinclude/kamdefault.mak b/test/mkinclude/kamdefault.mak
new file mode 100644 (file)
index 0000000..39674b8
--- /dev/null
@@ -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 (file)
index 0000000..e2d0528
--- /dev/null
@@ -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 (file)
index 0000000..510e9f9
--- /dev/null
@@ -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 (file)
index 0000000..6082c70
--- /dev/null
@@ -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 (file)
index 0000000..114f6a6
--- /dev/null
@@ -0,0 +1 @@
+version: kamailio 5.0.0-dev4 (x86_64/darwin) 6dd4b1-dirty