浏览代码

tregxx0002: check avp_rcd fields and order with save()

Victor Seva 5 年之前
父节点
当前提交
3450409e63

+ 10 - 0
units/tregxx0002/README.md

@@ -0,0 +1,10 @@
+# Regisrar - xavp_rcd Tests #
+
+Summary: regisrar - check xavp_rcd values
+
+Following tests are done:
+
+  * run kamailio with kamailio-tregxx0002.cfg sends different REGISTER msg
+    (three contacts for the same user ) and check the xavp_rcd values after
+    save()
+

+ 47 - 0
units/tregxx0002/kamailio-tregxx0002.cfg

@@ -0,0 +1,47 @@
+#!KAMAILIO
+
+children=1
+
+loadmodule "kex.so"
+loadmodule "jsonrpcs.so"
+loadmodule "tm.so"
+loadmodule "tmx.so"
+loadmodule "sl.so"
+loadmodule "rr.so"
+loadmodule "pv.so"
+loadmodule "textops.so"
+loadmodule "usrloc.so"
+loadmodule "registrar.so"
+loadmodule "xlog.so"
+loadmodule "app_lua.so"
+
+modparam("jsonrpcs", "pretty_format", 1)
+
+modparam("app_lua", "load", "/usr/local/src/kamailio-tests/units/tregxx0002/kamailio-tregxx0002.lua")
+
+modparam("registrar", "xavp_rcd", "rcd")
+modparam("registrar", "use_path", 1)
+modparam("registrar", "path_use_received", 1)
+
+request_route {
+    route(REGISTRAR);
+    exit;
+}
+
+route[REGISTRAR] {
+    if (!is_method("REGISTER")) return;
+    xavp_rm("rcd");
+    if (!save("location")) {
+        sl_reply_error();
+    }
+    xlog("set: ruid$var(tmp) $xavp(rcd=>ruid[0])\n");
+    $var(tmp) = $var(tmp) + 1;
+    route(CHECK);
+    exit;
+}
+
+route[CHECK] {
+    pv_xavp_print();
+    lua_run("check");
+    return;
+}

+ 19 - 0
units/tregxx0002/kamailio-tregxx0002.lua

@@ -0,0 +1,19 @@
+-- luacheck: globals KSR
+function check ()
+	local fields = {'ruid', 'expires', 'contact', 'received', 'path'}
+	local str_x = '$xavp(rcd[0]=>%s[%d])'
+	local str_y = 'check: %s%d exists\n'
+	local val
+
+	for i=0,2 do
+		for _,field in ipairs(fields) do
+			local xavp = string.format(str_x, field, i)
+			val = KSR.pv.get(xavp)
+			if val then
+				local tmp = string.format('val %s%d:%s\n', field, i, tostring(val))
+				KSR.dbg(tmp)
+				KSR.err(string.format(str_y, field, i))
+			end
+		end
+	end
+end

+ 75 - 0
units/tregxx0002/tregxx0002.sh

@@ -0,0 +1,75 @@
+#!/bin/bash
+
+. ../../etc/config
+. ../../libs/utils
+
+LOG=/tmp/kamailio-tregxx0001.log
+
+function run() {
+	echo "--- start kamailio -f ./kamailio-tregxx0002.cfg"
+	${KAMBIN} -P ${KAMPID} -w ${KAMRUN} -Y ${KAMRUN} \
+		-f ./kamailio-tregxx0002.cfg -a no -ddd -E 2>&1 | tee ${LOG} &
+	sleep 1
+	sipsak -U -s sip:[email protected] -C sip:[email protected]:5066
+	sipsak -U -s sip:[email protected] -C sip:[email protected]:5066
+	sipsak -U -s sip:[email protected] -C sip:[email protected]:5066
+	sleep 1
+	kill_pidfile ${KAMPID}
+	sleep 1
+}
+
+function _check_save() {
+	local val=${1}
+	local index=${2}
+	# build_contact() has only those two for now
+	if [[ "${val}" =~ ruid|expires ]]; then
+		if ! grep -q "check: ${val}${index} exists" ${LOG} ; then
+			echo "${val}[${index}] not found"
+			exit 1
+		fi
+	else
+		if grep -q "check: ${val}${index} exists" ${LOG} ; then
+			echo "${val}[${index}] found"
+			exit 1
+		fi
+	fi
+}
+
+function _check_value() {
+	local field=${1}
+	local val=${2}
+	if ! grep -q "val ${field}:${val}" ${LOG} ; then
+		echo "${field} val not ${val}"
+		grep "val ${field}:" ${LOG}
+		exit 1
+	fi
+}
+
+function check_save() {
+	local i
+	local field
+	for i in 0 1 2; do
+		for field in ruid expires; do
+			_check_save ${field} ${i}
+		done
+	done
+}
+
+function check_order() {
+	local indx=0
+	local i
+	for i in $(awk '/set: ruid/ { print $6}' ${LOG}| sort -r | xargs); do
+		_check_value ruid${indx} ${i}
+		(( indx++ ))
+	done
+}
+
+echo
+echo "--- grep output"
+echo
+
+run
+check_save
+check_order
+
+exit 0