[asterisk-commits] mmichelson: testsuite/asterisk/trunk r164 - in /asterisk/trunk/tests/sip_chan...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Mar 31 10:04:40 CDT 2010


Author: mmichelson
Date: Wed Mar 31 10:04:37 2010
New Revision: 164

URL: http://svnview.digium.com/svn/testsuite?view=rev&rev=164
Log:
Add unit test for testing SIP parameters retrieved from the CHANNEL dialplan function.

Review: https://reviewboard.asterisk.org/r/589


Added:
    asterisk/trunk/tests/sip_channel_params/
    asterisk/trunk/tests/sip_channel_params/configs/
    asterisk/trunk/tests/sip_channel_params/configs/extensions.conf   (with props)
    asterisk/trunk/tests/sip_channel_params/configs/rtp.conf   (with props)
    asterisk/trunk/tests/sip_channel_params/configs/sip.conf   (with props)
    asterisk/trunk/tests/sip_channel_params/run-test   (with props)
    asterisk/trunk/tests/sip_channel_params/sipp/
    asterisk/trunk/tests/sip_channel_params/sipp/call.xml   (with props)
    asterisk/trunk/tests/sip_channel_params/sipp/register.xml   (with props)
    asterisk/trunk/tests/sip_channel_params/test.lua   (with props)

Added: asterisk/trunk/tests/sip_channel_params/configs/extensions.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/sip_channel_params/configs/extensions.conf?view=auto&rev=164
==============================================================================
--- asterisk/trunk/tests/sip_channel_params/configs/extensions.conf (added)
+++ asterisk/trunk/tests/sip_channel_params/configs/extensions.conf Wed Mar 31 10:04:37 2010
@@ -1,0 +1,5 @@
+[channel_test]
+
+exten => test,1,Answer
+exten => test,n,Playback(demo-congrats)
+exten => test,n,Hangup

Propchange: asterisk/trunk/tests/sip_channel_params/configs/extensions.conf
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/sip_channel_params/configs/extensions.conf
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/sip_channel_params/configs/extensions.conf
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/sip_channel_params/configs/rtp.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/sip_channel_params/configs/rtp.conf?view=auto&rev=164
==============================================================================
--- asterisk/trunk/tests/sip_channel_params/configs/rtp.conf (added)
+++ asterisk/trunk/tests/sip_channel_params/configs/rtp.conf Wed Mar 31 10:04:37 2010
@@ -1,0 +1,3 @@
+[general]
+rtpstart=10000
+rtpend=10003

Propchange: asterisk/trunk/tests/sip_channel_params/configs/rtp.conf
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/sip_channel_params/configs/rtp.conf
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/sip_channel_params/configs/rtp.conf
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/sip_channel_params/configs/sip.conf
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/sip_channel_params/configs/sip.conf?view=auto&rev=164
==============================================================================
--- asterisk/trunk/tests/sip_channel_params/configs/sip.conf (added)
+++ asterisk/trunk/tests/sip_channel_params/configs/sip.conf Wed Mar 31 10:04:37 2010
@@ -1,0 +1,13 @@
+[general]
+udpbindaddr=127.0.0.1:5060
+canreinvite=no
+videosupport=yes
+
+[test1]
+type=friend
+host=dynamic
+dtmf=rfc2833
+context=channel_test
+disallow=all
+allow=ulaw
+allow=h263

Propchange: asterisk/trunk/tests/sip_channel_params/configs/sip.conf
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/sip_channel_params/configs/sip.conf
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/sip_channel_params/configs/sip.conf
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/sip_channel_params/run-test
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/sip_channel_params/run-test?view=auto&rev=164
==============================================================================
--- asterisk/trunk/tests/sip_channel_params/run-test (added)
+++ asterisk/trunk/tests/sip_channel_params/run-test Wed Mar 31 10:04:37 2010
@@ -1,0 +1,3 @@
+#!/bin/bash -e
+
+asttest -a / -s tests/sip_channel_params

Propchange: asterisk/trunk/tests/sip_channel_params/run-test
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/sip_channel_params/run-test
------------------------------------------------------------------------------
    svn:executable = *

Propchange: asterisk/trunk/tests/sip_channel_params/run-test
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/sip_channel_params/run-test
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/sip_channel_params/sipp/call.xml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/sip_channel_params/sipp/call.xml?view=auto&rev=164
==============================================================================
--- asterisk/trunk/tests/sip_channel_params/sipp/call.xml (added)
+++ asterisk/trunk/tests/sip_channel_params/sipp/call.xml Wed Mar 31 10:04:37 2010
@@ -1,0 +1,95 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!DOCTYPE scenario SYSTEM "sipp.dtd">
+
+<scenario name="Channel Test">
+  <send retrans="500">
+    <![CDATA[
+
+      INVITE sip:test@[remote_ip]:[remote_port] SIP/2.0
+      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+      From: test1 <sip:wienerschnitzel@[local_ip]:[local_port]>;tag=[call_number]
+      To: test <sip:test@[remote_ip]:[remote_port]>
+      Call-ID: [call_id]
+      CSeq: 1 INVITE
+      Contact: sip:kartoffelsalat@[local_ip]:[local_port]
+      Max-Forwards: 70
+      Subject: Performance Test
+      User-Agent: Channel Param Test
+      Content-Type: application/sdp
+      Content-Length: [len]
+
+      v=0
+      o=user1 53655765 2353687637 IN IP[local_ip_type] [local_ip]
+      s=-
+      c=IN IP[media_ip_type] [media_ip]
+      t=0 0
+      m=audio 6000 RTP/AVP 0 101
+      a=rtpmap:0 PCMU/8000
+      a=rtpmap:101 telephone-event/8000
+      m=video 6002 RTP/AVP 34
+      a=rtpmap:34 H263/90000
+
+    ]]>
+  </send>
+
+  <recv response="100"
+        optional="true">
+  </recv>
+
+  <recv response="180" optional="true">
+  </recv>
+
+  <recv response="183" optional="true">
+  </recv>
+
+  <recv response="200" rtd="true">
+  </recv>
+
+  <send>
+    <![CDATA[
+
+      ACK sip:test@[remote_ip]:[remote_port] SIP/2.0
+      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+      From: test1 <sip:wienerschnitzel@[local_ip]:[local_port]>;tag=[call_number]
+      To: test <sip:test@[remote_ip]:[remote_port]>[peer_tag_param]
+      Call-ID: [call_id]
+      CSeq: 1 ACK
+      Contact: sip:kartoffelsalat@[local_ip]:[local_port]
+      Max-Forwards: 70
+      Subject: Performance Test
+      Content-Length: 0
+
+    ]]>
+  </send>
+
+  <!-- Pause long enough for our test to run -->
+  <pause milliseconds="4000" />
+
+  <send retrans="500">
+    <![CDATA[
+
+      BYE sip:test@[remote_ip]:[remote_port] SIP/2.0
+      Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+      From: test1 <sip:wienerschnitzel@[local_ip]:[local_port]>;tag=[call_number]
+      To: test <sip:test@[remote_ip]:[remote_port]>[peer_tag_param]
+      Call-ID: [call_id]
+      CSeq: 2 BYE
+      Contact: sip:kartoffelsalat@[local_ip]:[local_port]
+      Max-Forwards: 70
+      Subject: Performance Test
+      Content-Length: 0
+
+    ]]>
+  </send>
+
+  <recv response="200" crlf="true">
+  </recv>
+
+  <!-- definition of the response time repartition table (unit is ms)   -->
+  <ResponseTimeRepartition value="10, 20, 30, 40, 50, 100, 150, 200"/>
+
+  <!-- definition of the call length repartition table (unit is ms)     -->
+  <CallLengthRepartition value="10, 50, 100, 500, 1000, 5000, 10000"/>
+
+</scenario>
+

Propchange: asterisk/trunk/tests/sip_channel_params/sipp/call.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/sip_channel_params/sipp/call.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/sip_channel_params/sipp/call.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/sip_channel_params/sipp/register.xml
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/sip_channel_params/sipp/register.xml?view=auto&rev=164
==============================================================================
--- asterisk/trunk/tests/sip_channel_params/sipp/register.xml (added)
+++ asterisk/trunk/tests/sip_channel_params/sipp/register.xml Wed Mar 31 10:04:37 2010
@@ -1,0 +1,29 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+
+<!--
+This scenario will execute a sip register with the given parameters.
+-->
+
+
+<scenario name="Register">
+	<send retrans="500">
+		<![CDATA[
+
+		REGISTER sip:test1@[remote_ip]:[remote_port] SIP/2.0
+		Via: SIP/2.0/[transport] [local_ip]:[local_port];branch=[branch]
+		From: test1 <sip:test1@[local_ip]:[local_port]>;tag=[call_number]
+		To: test1 <sip:test1@[remote_ip]:[remote_port]>
+		Call-ID: [call_id]
+		CSeq: 1 REGISTER
+		Contact: sip:test1@[local_ip]:[local_port]
+		Content-Length: 0
+		Expires: 120
+
+		]]>
+	</send>
+
+	<recv response="100" optional="true" />
+	<recv response="200"/>
+
+</scenario>
+

Propchange: asterisk/trunk/tests/sip_channel_params/sipp/register.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/sip_channel_params/sipp/register.xml
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/sip_channel_params/sipp/register.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: asterisk/trunk/tests/sip_channel_params/test.lua
URL: http://svnview.digium.com/svn/testsuite/asterisk/trunk/tests/sip_channel_params/test.lua?view=auto&rev=164
==============================================================================
--- asterisk/trunk/tests/sip_channel_params/test.lua (added)
+++ asterisk/trunk/tests/sip_channel_params/test.lua Wed Mar 31 10:04:37 2010
@@ -1,0 +1,144 @@
+function sipp_exec(scenario, name, local_port)
+	return proc.exec_io("sipp",
+	"127.0.0.1",
+	"-m", "1",
+	"-sf", scenario,
+	"-i", "127.0.0.1",
+	"-p", local_port,
+	"-timeout", "30",
+	"-trace_err"
+	)
+end
+
+function sipp_exec_and_wait(scenario, name, local_port)
+	return sipp_check_error(sipp_exec(scenario, name, local_port), scenario)
+end
+
+function sipp_check_error(p, scenario)
+	local res, err = p:wait()
+
+	if not res then error(err) end
+	if res ~= 0 then
+		error("error while executing " .. scenario .. " sipp scenario (sipp exited with status " .. res .. ")\n" .. p.stderr:read("*a"))
+	end
+
+	return res, err
+end
+
+function manager_setup(a)
+	m,err = a:manager_connect()
+	if not m then
+		fail("error connecting to asterisk: " .. err)
+	end
+
+	local login = ast.manager.action:new("login")
+	login["Username"] = "asttest"
+	login["Secret"] = "asttest"
+
+	local r = m(login)
+	if not r then
+		fail("error logging in to the manager: " .. err)
+	end
+
+	if r["Response"] ~= "Success" then
+		fail("error authenticating: " .. r["Message"])
+	end
+end
+
+function findpattern(text, pattern, start)
+	return string.sub(text, string.find(text, pattern, start))
+end
+
+function check_sip_params(sip_params, chan_name)
+	for key,value in pairs(sip_params) do
+		local variable = "CHANNEL(" .. key .. ")"
+		local getvar = ast.manager.action:new("GetVar")
+		getvar["Channel"] = chan_name
+		getvar["Variable"] = variable
+		local response, err = m(getvar)
+		if not response then
+			fail("error getting variable " .. key .. ": " .. err)
+			break
+		end
+		if response["Response"] ~= "Success" then
+			fail("Response failure: " .. response["Message"])
+		end
+		if response["Variable"] ~= variable then
+			fail("Wrong variable. Expected " .. variable .. " but got " .. response["Variable"])
+		end
+		--Helpful for debugging in case this test starts failing
+		--print ("Got value " ..  response["Value"] .. " for variable " .. response["Variable"])
+		if not findpattern(response["Value"], value) then
+			fail("Expected " .. value .. " for variable " .. response["Variable"] .. " but got " .. response["Value"])
+		end
+	end
+end
+
+function get_channel_name()
+	local chan_name = nil
+	local function set_name(event)
+		chan_name = event["Channel"]
+	end
+	m:register_event("Newchannel", set_name)
+	local res, err = m:pump_messages()
+	if not res then
+		fail("Error pumping messages: " .. err)
+	end
+	m:process_events()
+	m:unregister_event("Newchannel", set_name)
+	return chan_name
+end
+
+function test_call(scenario, name, local_port, sip_params)
+	local t1 = sipp_exec(scenario, name, local_port)
+	local chan_name = nil
+
+	posix.sleep(1)
+	chan_name = get_channel_name()
+	if not chan_name then
+		fail("Failed to get the name of the channel\n");
+	else
+		print("Got channel name " .. chan_name)
+	end
+	check_sip_params(sip_params, chan_name)
+	-- We have what we want. Let the scenario conclude
+	sipp_check_error(t1, scenario)
+end
+
+function call_and_check_sip_params(name)
+	local a = ast.new()
+	local sip_params = {
+		["peerip"] = "127.0.0.1",
+		["recvip"] = "127.0.0.1",
+		["from"] = "sip:wienerschnitzel at 127.0.0.1:5061",
+		["uri"] = "sip:kartoffelsalat at 127.0.0.1:5061",
+		["useragent"] = "Channel Param Test",
+		["peername"] = "test1",
+		["t38passthrough"] = "0",
+		["rtpdest,audio"] = "127.0.0.1:6000",
+		["rtpdest,video"] = "127.0.0.1:6002",
+		["rtpdest,text"] = "",
+		--We have no way to force a specific source
+		--RTP port to be used; we can specify only a
+		--range. Thus, our rtp.conf file limits the
+		--audio and video RTP ports to a selection of
+		--either 10000 or 10002.
+		["rtpsource,audio"] = "127.0.0.1:1000[02]",
+		["rtpsource,video"] = "127.0.0.1:1000[02]",
+		["rtpsource,text"] = ""
+	}
+	
+	a:load_config("configs/sip.conf")
+	a:load_config("configs/extensions.conf")
+	a:load_config("configs/rtp.conf")
+	a:generate_manager_conf()
+	a:spawn()
+
+	manager_setup(a)
+	--register our peer
+	sipp_exec_and_wait("sipp/register.xml", name, "5061")
+
+	test_call("sipp/call.xml", name, "5061", sip_params)
+end
+
+call_and_check_sip_params("test1")

Propchange: asterisk/trunk/tests/sip_channel_params/test.lua
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: asterisk/trunk/tests/sip_channel_params/test.lua
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: asterisk/trunk/tests/sip_channel_params/test.lua
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list