Re #1523: use random port for PJSUA instance(s) and configurable SIPp port.
git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@4188 74dad513-b988-da41-8d7b-12977e46ad98
This commit is contained in:
parent
29e1bc7d75
commit
5a4d6ed11b
|
@ -1,4 +1,24 @@
|
|||
# $Id$
|
||||
|
||||
## Automatic test module for SIPp.
|
||||
##
|
||||
## This module will need a test driver for each SIPp scenario:
|
||||
## - For simple scenario, i.e: make/receive call (including auth), this
|
||||
## test module can auto-generate a default test driver, i.e: make call
|
||||
## or apply auto answer. Just name the SIPp scenario using "uas" or
|
||||
## "uac" prefix accordingly.
|
||||
## - Custom test driver can be defined in a python script file containing
|
||||
## a list of the PJSUA instances and another list for PJSUA expects/
|
||||
## commands. The custom test driver file must use the same filename as
|
||||
## the SIPp XML scenario. See samples of SIPp scenario + its driver
|
||||
## in tests/pjsua/scripts-sipp/ folder for detail.
|
||||
##
|
||||
## Here are defined macros that can be used in the custom driver:
|
||||
## - $SIPP_PORT : SIPp binding port
|
||||
## - $SIPP_URI : SIPp SIP URI
|
||||
## - $PJSUA_PORT[N] : binding port of PJSUA instance #N
|
||||
## - $PJSUA_URI[N] : SIP URI of PJSUA instance #N
|
||||
|
||||
import ctypes
|
||||
import time
|
||||
import imp
|
||||
|
@ -22,7 +42,8 @@ FDEVNULL = None
|
|||
# SIPp executable path and param
|
||||
#SIPP_PATH = '"C:\\Program Files (x86)\\Sipp_3.2\\sipp.exe"'
|
||||
SIPP_PATH = 'sipp'
|
||||
SIPP_PARAM = "-i 127.0.0.1 -p 6000 -m 1 127.0.0.1"
|
||||
SIPP_PORT = 6000
|
||||
SIPP_PARAM = "-m 1 -i 127.0.0.1 -p " + str(SIPP_PORT)
|
||||
SIPP_TIMEOUT = 60
|
||||
# On BG mode, SIPp doesn't require special terminal
|
||||
# On non-BG mode, on win, it needs env var: "TERMINFO=c:\cygwin\usr\share\terminfo"
|
||||
|
@ -30,11 +51,11 @@ SIPP_TIMEOUT = 60
|
|||
SIPP_BG_MODE = False
|
||||
#SIPP_BG_MODE = not G_INUNIX
|
||||
|
||||
# Will be updated based on configuration file (a .py file whose the same name as SIPp XML file)
|
||||
# Will be updated based on the test driver file (a .py file whose the same name as SIPp XML file)
|
||||
PJSUA_INST_PARAM = []
|
||||
PJSUA_EXPECTS = []
|
||||
|
||||
# Default PJSUA param if configuration file (the corresponding .py file) is not available:
|
||||
# Default PJSUA param if test driver is not available:
|
||||
# - no-tcp as SIPp is on UDP only
|
||||
# - id, username, and realm: to allow PJSUA sending re-INVITE with auth after receiving 401/407 response
|
||||
PJSUA_DEF_PARAM = "--null-audio --max-calls=1 --no-tcp --id=sip:a@localhost --username=a --realm=*"
|
||||
|
@ -47,23 +68,38 @@ else:
|
|||
exit(-99)
|
||||
|
||||
|
||||
# Init PJSUA test instance
|
||||
# Functions for resolving macros in the test driver
|
||||
def resolve_pjsua_port(mo):
|
||||
return str(PJSUA_INST_PARAM[int(mo.group(1))].sip_port)
|
||||
|
||||
def resolve_pjsua_uri(mo):
|
||||
return PJSUA_INST_PARAM[int(mo.group(1))].uri[1:-1]
|
||||
|
||||
def resolve_driver_macros(st):
|
||||
st = re.sub("\$SIPP_PORT", str(SIPP_PORT), st)
|
||||
st = re.sub("\$SIPP_URI", "sip:sipp@127.0.0.1:"+str(SIPP_PORT), st)
|
||||
st = re.sub("\$PJSUA_PORT\[(\d+)\]", resolve_pjsua_port, st)
|
||||
st = re.sub("\$PJSUA_URI\[(\d+)\]", resolve_pjsua_uri, st)
|
||||
return st
|
||||
|
||||
|
||||
# Init test driver
|
||||
if os.access(SIPP_SCEN_XML[:-4]+".py", os.R_OK):
|
||||
# Load from configuration file (the corresponding .py file), if any
|
||||
# Load test driver file (the corresponding .py file), if any
|
||||
cfg_file = imp.load_source("cfg_file", SIPP_SCEN_XML[:-4]+".py")
|
||||
for ua_idx, ua_param in enumerate(cfg_file.PJSUA):
|
||||
PJSUA_INST_PARAM.append(InstanceParam("pjsua"+str(ua_idx+1), ua_param, sip_port=5060+ua_idx*2))
|
||||
ua_param = resolve_driver_macros(ua_param)
|
||||
PJSUA_INST_PARAM.append(InstanceParam("pjsua"+str(ua_idx), ua_param))
|
||||
PJSUA_EXPECTS = cfg_file.PJSUA_EXPECTS
|
||||
else:
|
||||
# Just use the SIPp XML scenario
|
||||
# Generate default test driver
|
||||
if os.path.basename(SIPP_SCEN_XML)[0:3] == "uas":
|
||||
# auto make call when SIPp is as UAS
|
||||
ua_param = PJSUA_DEF_PARAM + " sip:127.0.0.1:6000"
|
||||
ua_param = PJSUA_DEF_PARAM + " sip:127.0.0.1:" + str(SIPP_PORT)
|
||||
else:
|
||||
# auto answer when SIPp is as UAC
|
||||
ua_param = PJSUA_DEF_PARAM + " --auto-answer=200"
|
||||
PJSUA_INST_PARAM.append(InstanceParam("pjsua", ua_param, sip_port=5060))
|
||||
|
||||
PJSUA_INST_PARAM.append(InstanceParam("pjsua", ua_param))
|
||||
|
||||
|
||||
# Start SIPp process, returning PID
|
||||
|
@ -71,12 +107,16 @@ def start_sipp():
|
|||
global SIPP_BG_MODE
|
||||
sipp_proc = None
|
||||
|
||||
# run SIPp
|
||||
sipp_param = SIPP_PARAM + " -sf " + SIPP_SCEN_XML
|
||||
if SIPP_BG_MODE:
|
||||
sipp_param = sipp_param + " -bg"
|
||||
if SIPP_TIMEOUT:
|
||||
sipp_param = sipp_param + " -timeout "+str(SIPP_TIMEOUT)+"s -timeout_error" + " -deadcall_wait "+str(SIPP_TIMEOUT)+"s"
|
||||
|
||||
# add target param
|
||||
sipp_param = sipp_param + " 127.0.0.1:" + str(PJSUA_INST_PARAM[0].sip_port)
|
||||
|
||||
# run SIPp
|
||||
fullcmd = os.path.normpath(SIPP_PATH) + " " + sipp_param
|
||||
print "Running SIPP: " + fullcmd
|
||||
if SIPP_BG_MODE:
|
||||
|
@ -161,7 +201,7 @@ def exec_pjsua_expects(t, sipp):
|
|||
expect = PJSUA_EXPECTS.pop(0)
|
||||
ua_idx = expect[0]
|
||||
expect_st = expect[1]
|
||||
send_cmd = expect[2]
|
||||
send_cmd = resolve_driver_macros(expect[2])
|
||||
# Handle exception in pjsua flow, to avoid zombie SIPp process
|
||||
try:
|
||||
if expect_st != "":
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#
|
||||
import inc_const as const
|
||||
|
||||
PJSUA = ["--null-audio --max-calls=1 --id=sip:pjsua@localhost --username=pjsua --realm=* sip:sipp@localhost:6000"]
|
||||
PJSUA = ["--null-audio --max-calls=1 --id=sip:pjsua@localhost --username=pjsua --realm=* $SIPP_URI"]
|
||||
|
||||
PJSUA_EXPECTS = [[0, "ACK sip:proxy@.* SIP/2\.0", ""],
|
||||
[0, const.STATE_CONFIRMED, "h"]
|
||||
|
|
|
@ -2,15 +2,15 @@
|
|||
#
|
||||
import inc_const as const
|
||||
|
||||
PJSUA = ["--null-audio", # UA0 @ port 5060
|
||||
"--null-audio", # UA1 @ port 5062
|
||||
"--null-audio" # UA2 @ port 5064
|
||||
PJSUA = ["--null-audio", # UA0
|
||||
"--null-audio", # UA1
|
||||
"--null-audio" # UA2
|
||||
]
|
||||
|
||||
PJSUA_EXPECTS = [
|
||||
# A calls B
|
||||
[0, "", "m"],
|
||||
[0, "", "sip:localhost:5062"],
|
||||
[0, "", "$PJSUA_URI[1]"],
|
||||
[0, const.STATE_CALLING, ""],
|
||||
[1, const.EVENT_INCOMING_CALL, "a"],
|
||||
[1, "", "200"],
|
||||
|
@ -24,7 +24,7 @@ PJSUA_EXPECTS = [
|
|||
|
||||
# B calls C
|
||||
[1, "", "m"],
|
||||
[1, "", "sip:localhost:5064"],
|
||||
[1, "", "$PJSUA_URI[2]"],
|
||||
[1, const.STATE_CALLING, ""],
|
||||
[2, const.EVENT_INCOMING_CALL, "a"],
|
||||
[2, "", "200"],
|
||||
|
|
|
@ -2,15 +2,15 @@
|
|||
#
|
||||
import inc_const as const
|
||||
|
||||
PJSUA = ["--null-audio", # UA0 @ port 5060
|
||||
"--null-audio", # UA1 @ port 5062
|
||||
"--null-audio" # UA2 @ port 5064
|
||||
PJSUA = ["--null-audio", # UA0
|
||||
"--null-audio", # UA1
|
||||
"--null-audio" # UA2
|
||||
]
|
||||
|
||||
PJSUA_EXPECTS = [
|
||||
# A calls B
|
||||
[0, "", "m"],
|
||||
[0, "", "sip:localhost:5062"],
|
||||
[0, "", "$PJSUA_URI[1]"],
|
||||
[0, const.STATE_CALLING, ""],
|
||||
[1, const.EVENT_INCOMING_CALL, "a"],
|
||||
[1, "", "200"],
|
||||
|
@ -19,7 +19,7 @@ PJSUA_EXPECTS = [
|
|||
|
||||
# B transfer A to C
|
||||
[1, "", "x"],
|
||||
[1, "", "sip:localhost:5064"],
|
||||
[1, "", "$PJSUA_URI[2]"],
|
||||
[0, const.STATE_CALLING, ""],
|
||||
[2, const.EVENT_INCOMING_CALL, "a"],
|
||||
[2, "", "200"],
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
#
|
||||
import inc_const as const
|
||||
|
||||
PJSUA = ["--null-audio --max-calls=1 sip:localhost:6000"]
|
||||
PJSUA = ["--null-audio --max-calls=1 $SIPP_URI"]
|
||||
|
||||
PJSUA_EXPECTS = [[0, const.STATE_CONFIRMED, "v"]]
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
#
|
||||
import inc_const as const
|
||||
|
||||
PJSUA = ["--null-audio --max-calls=1 sip:localhost:6000"]
|
||||
PJSUA = ["--null-audio --max-calls=1 $SIPP_URI"]
|
||||
|
||||
PJSUA_EXPECTS = [[0, const.STATE_CONFIRMED, "U"]]
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
#
|
||||
import inc_const as const
|
||||
|
||||
PJSUA = ["--null-audio --max-calls=1 --id=sip:a@localhost --username=a --realm=* --registrar=sip:localhost:6000"]
|
||||
PJSUA = ["--null-audio --max-calls=1 --id=sip:a@localhost --username=a --realm=* --registrar=$SIPP_URI"]
|
||||
|
||||
PJSUA_EXPECTS = []
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
#
|
||||
import inc_const as const
|
||||
|
||||
PJSUA = ["--null-audio --max-calls=1 sip:localhost:6000"]
|
||||
PJSUA = ["--null-audio --max-calls=1 $SIPP_URI"]
|
||||
|
||||
PJSUA_EXPECTS = [[0, const.STATE_EARLY, "h"]]
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
#
|
||||
import inc_const as const
|
||||
|
||||
PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost:6000 --mwi"]
|
||||
PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost:$SIPP_PORT --mwi"]
|
||||
|
||||
PJSUA_EXPECTS = []
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
#
|
||||
import inc_const as const
|
||||
|
||||
PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost:6000 --mwi"]
|
||||
PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost:$SIPP_PORT --mwi"]
|
||||
|
||||
PJSUA_EXPECTS = []
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
#
|
||||
import inc_const as const
|
||||
|
||||
PJSUA = ["--null-audio --max-calls=1 sip:localhost:6000"]
|
||||
PJSUA = ["--null-audio --max-calls=1 $SIPP_URI"]
|
||||
|
||||
PJSUA_EXPECTS = [[0, const.STATE_CONFIRMED, "U"]]
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#
|
||||
import inc_const as const
|
||||
|
||||
PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost:6000 --add-buddy sip:sipp@localhost:6000"]
|
||||
PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost --add-buddy $SIPP_URI"]
|
||||
|
||||
PJSUA_EXPECTS = [[0, "", "s"],
|
||||
[0, "Subscribe presence of:", "1"],
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
#
|
||||
import inc_const as const
|
||||
|
||||
PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost:6000 --add-buddy sip:sipp@localhost:6000"]
|
||||
PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost --add-buddy $SIPP_URI"]
|
||||
|
||||
PJSUA_EXPECTS = [[0, "", "s"],
|
||||
[0, "Subscribe presence of:", "1"],
|
||||
[0, "sip:sipp@localhost:6000 .* Online", ""],
|
||||
[0, "status is Online", ""],
|
||||
[0, "subscription state is TERMINATED", ""]
|
||||
]
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#
|
||||
import inc_const as const
|
||||
|
||||
PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost:6000 --add-buddy sip:sipp@localhost:6000"]
|
||||
PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost --add-buddy $SIPP_URI"]
|
||||
|
||||
PJSUA_EXPECTS = [[0, "", "s"],
|
||||
[0, "Subscribe presence of:", "1"],
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
#
|
||||
import inc_const as const
|
||||
|
||||
PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost:6000 --add-buddy sip:sipp@localhost:6000"]
|
||||
PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost --add-buddy $SIPP_URI"]
|
||||
|
||||
PJSUA_EXPECTS = [[0, "", "s"],
|
||||
[0, "Subscribe presence of:", "1"],
|
||||
[0, "sip:sipp@localhost:6000 .* Online", ""],
|
||||
[0, "status is Online", ""],
|
||||
[0, "subscription state is TERMINATED", ""]
|
||||
]
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#
|
||||
import inc_const as const
|
||||
|
||||
PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost:6000 --add-buddy sip:sipp@localhost:6000"]
|
||||
PJSUA = ["--null-audio --max-calls=1 --id sip:pjsua@localhost --add-buddy $SIPP_URI"]
|
||||
|
||||
PJSUA_EXPECTS = [[0, "", "s"],
|
||||
[0, "Subscribe presence of:", "1"],
|
||||
|
|
Loading…
Reference in New Issue