Browse code

test Adding test configuration starting point

Olle E. Johansson authored on 03/06/2016 19:50:52
Showing 9 changed files
... ...
@@ -9,18 +9,22 @@ Modules found here test APIs in other modules or are just created for testing, n
9 9
 use. In order to use the existing build system, each module needs a directory named mod_something
10 10
 in test. 
11 11
 
12
+Module testing
13
+--------------
12 14
 Each module needs a subdirectory called "test" with a test configuration and a Makefile.
13 15
 
14 16
 A typical test script load the htable module and execute tests in the [event:htable_init]
15 17
 event route when starting. Typically, if a test fails, it runs abort() from the cfg_utils
16 18
 module to abort the process. 
17 19
 
20
+Targets of the test makefile:
21
+	- "test":	Test syntax with "kamailio -c"
22
+	- "all":	Run full test
23
+
18 24
 
19 25
 Ideas: We may need a way to exit kamailio from inside without dumping a core file, but simply
20
-stopping execution and returning different return values to the shell. That way a test
21
-config can run for a limited amount of time or until a test fails. We can also
22
-stop on an external action, like a RPC request calling the same function.
26
+  stopping execution and returning different return values to the shell. That way a test
27
+  config can run for a limited amount of time or until a test fails. We can also
28
+  stop on an external action, like a RPC request calling the same function.
29
+
23 30
 
24
-Targets:
25
-	- "test":	Test syntax with "kamailio -c"
26
-	- "all":	Run full test
27 31
new file mode 100755
... ...
@@ -0,0 +1,12 @@
1
+#!/bin/sh
2
+if test -x /usr/sbin/kamailio
3
+then
4
+	echo "/usr/sbin"
5
+	exit 0
6
+fi
7
+if test -x /usr/local/sbin/kamailio
8
+then
9
+	echo "/usr/local/sbin"
10
+	exit 0
11
+fi
12
+exit 1
0 13
new file mode 100644
... ...
@@ -0,0 +1,20 @@
1
+#
2
+#  Find IP address of local system
3
+#  Currently it's either Linux or (default) os/x
4
+
5
+UNAME_S:=$(shell uname)
6
+ifeq ($(UNAME_S),Linux)
7
+osystem=LINUX
8
+interface:=eth0
9
+# Needs to be changed to "ip" instead of "ifconfig"
10
+ipaddr:=$(shell  /sbin/ifconfig $(interface) | grep 'inet '|cut -d':' -f2|cut -d' ' -f1)
11
+else
12
+# Assume Darwin OS/X
13
+osystem=DARWIN
14
+interface:=en0
15
+ipaddr:=$(shell /sbin/ifconfig $(interface) | grep 'inet '|cut -d' ' -f2)
16
+endif
17
+
18
+ifeq ($(ipaddr),)
19
+$(error Can not find IP address?)
20
+endif
0 21
new file mode 100644
... ...
@@ -0,0 +1 @@
1
+KAMBIN=$(shell ../include/findkampath.sh)
0 2
new file mode 100644
... ...
@@ -0,0 +1,11 @@
1
+# Default include file
2
+
3
+# Test version
4
+testver=1.0
5
+ifeq ($(config),)
6
+	$error("??? No config set=")
7
+endif
8
+pidfile:=/tmp/${config}.pid
9
+
10
+include ../../mkinclude/kambin.mak
11
+include ../../mkinclude/ipaddr.mak
0 12
new file mode 100644
... ...
@@ -0,0 +1,6 @@
1
+# Log the latest test version
2
+ifeq ($(KAMBIN),)
3
+	$(error NO KAMBIN??? )
4
+endif
5
+KAMVER=$(shell $(KAMBIN)/kamailio -v|head -n1)
6
+$(shell echo "$(KAMVER)" > test.log)
0 7
new file mode 100644
... ...
@@ -0,0 +1,18 @@
1
+config:=curlapi.cfg
2
+KAMBIN:=/usr/local/sbin
3
+
4
+# Find the IP address
5
+include ../../mkinclude/ipaddr.mak
6
+
7
+
8
+# Log the version
9
+include ../../mkinclude/kamversion.mak
10
+
11
+all:
12
+	@echo Our IP address $(ipaddr) on interface $(interface)  - Redo to fly Kamailio?
13
+	@/usr/local/sbin/kamailio -f $(config)  -l udp:$(ipaddr):5060 -D 1 -E -M 2000
14
+
15
+debug:
16
+	@/usr/local/sbin/kamailio -f $(config)  -l udp:$(ipaddr):5060 -D 1 -E > /tmp/kamcurl.$$$$ 2>&1
17
+	grep curl /tmp/kamcurl.$$$$
18
+
0 19
new file mode 100644
... ...
@@ -0,0 +1,71 @@
1
+
2
+# Test of the new http_client API module
3
+# 
4
+# (C) 2016 Edvina AB, Sollentuna, Sweden. All rights reserved.
5
+#
6
+#
7
+
8
+debug=3
9
+log_stderror=yes
10
+fork=no
11
+
12
+# ------------------ module loading ----------------------------------
13
+# Set a path to known locations for modules
14
+#
15
+mpath="/usr/local/lib64/kamailio/modules:/usr/local/lib/kamailio/modules:/usr/lib64/kamailio/modules:/usr/lib/kamailio/modules"
16
+loadmodule "pv.so"	# For pseudo-variable support in log messages etc
17
+loadmodule "xlog.so"	# For extended logging with pseudovariables
18
+loadmodule "kex.so" 	# Kamailio extensions: 
19
+			# Script flags and basic mi commands (version, pwd, get_statistics)
20
+#
21
+loadmodule "tm.so"	# Transactions are needed in order to fork
22
+loadmodule "tmx.so"	# Kamailio extras to TM
23
+#
24
+loadmodule "sl.so" 	# Stateless replies - needed by registrar.so
25
+loadmodule "rtimer.so" 	# For ticks
26
+loadmodule "htable.so" 	# For init event route
27
+loadmodule "http_client.so" 	# THe CURL module
28
+loadmodule "httpapitest.so" 	# THe CURL module
29
+loadmodule "cfgutils.so" 	# Memory debugging
30
+
31
+# main routing logic
32
+
33
+modparam("http_client", "connection_timeout", 42);
34
+modparam("http_client", "keep_connections", 1);
35
+modparam("http_client", "maxdatasize", 1000);
36
+modparam("http_client", "useragent", "Olle's Peace and Restful little HTTP grabber 42.3");
37
+#user and password
38
+modparam("http_client", "httpcon", "lisa=>https://www.kamailio.org/w/");
39
+
40
+
41
+# -------------------------  request routing logic -------------------
42
+route {
43
+	sl_send_reply(400, "Do not wake me up");
44
+	exit;
45
+}
46
+
47
+onreply_route {
48
+	xlog("L_INFO", "<-- Incoming response: $rs $rr - from $si\n");
49
+}
50
+
51
+branch_route[BRANCH_ROUTE]
52
+{
53
+	xlog("L_INFO", "    --> Outgoing branch $T_branch_idx : $rm from $si to $ru \n");
54
+}
55
+
56
+onsend_route
57
+{
58
+	xlog("ONSEND --> Sending from $sndfrom(proto):$sndfrom(ip):$sndfrom(port) to $sndto(proto):$sndto(ip):$sndto(port) \n");
59
+}
60
+
61
+# This route is executed at Kamailio start
62
+event_route[htable:mod-init]
63
+{
64
+	xlog("L_ERR", "### Kamailio starting $timef(HH:mm) \n");
65
+	$avp(gurka) = "";
66
+	$var(res) = http_connect("lisa", "", "$avp(gurka)");
67
+	xlog("L_ERR", "-- Lisa http_client connection: $avp(gurka) Result $var(res)\n");
68
+
69
+
70
+}
71
+
0 72
new file mode 100644
... ...
@@ -0,0 +1 @@
1
+version: kamailio 5.0.0-dev4 (x86_64/darwin) 6dd4b1-dirty