blob: d75c17f3519ac0509d0df99f5390dae4392b042d [file] [log] [blame]
Nanang Izzuddinf810f952008-06-18 21:04:14 +00001# $Id$
Benny Prijonocc1ada52008-06-15 19:43:43 +00002import random
Benny Prijonoc366aa92008-08-26 12:13:25 +00003import config_site
Benny Prijonocc1ada52008-06-15 19:43:43 +00004
5DEFAULT_ECHO = True
6DEFAULT_TRACE = True
7DEFAULT_START_SIP_PORT = 50000
8
Nanang Izzuddina680bd62008-06-27 21:12:12 +00009# Shared vars
10ARGS = [] # arguments containing script module & config
Benny Prijonoc366aa92008-08-26 12:13:25 +000011HAS_SND_DEV = config_site.HAS_SND_DEV
Nanang Izzuddina680bd62008-06-27 21:12:12 +000012
Benny Prijonocc1ada52008-06-15 19:43:43 +000013# Individual pjsua instance configuration class
14class InstanceParam:
15 # Name to identify this pjsua instance (e.g. "caller", "callee", etc.)
16 name = ""
17 # pjsua command line arguments, concatenated in string
18 arg = ""
19 # Specify whether pjsua output should be echoed to stdout
20 echo_enabled = DEFAULT_ECHO
21 # Enable/disable test tracing
22 trace_enabled = DEFAULT_TRACE
23 # SIP URI to send request to this instance
24 uri = ""
25 # SIP port number, zero to automatically assign
26 sip_port = 0
27 # Does this have registration? If yes then the test function will
28 # wait until the UA is registered before doing anything else
29 have_reg = False
30 # Does this have PUBLISH?
31 have_publish = False
Benny Prijono1e65e9a2008-06-27 23:53:00 +000032 # Enable stdout buffer?
33 enable_buffer = False
Benny Prijonocc1ada52008-06-15 19:43:43 +000034 def __init__( self,
35 name, # Instance name
36 arg, # Cmd-line arguments
37 uri="", # URI
38 uri_param="", # Additional URI param
39 sip_port=0, # SIP port
40 have_reg=False, # Have registration?
41 have_publish=False, # Have publish?
42 echo_enabled=DEFAULT_ECHO,
Benny Prijono1e65e9a2008-06-27 23:53:00 +000043 trace_enabled=DEFAULT_TRACE,
44 enable_buffer = False):
Benny Prijonocc1ada52008-06-15 19:43:43 +000045 # Instance name
46 self.name = name
47 # Give random sip_port if it's not specified
48 if sip_port==0:
49 self.sip_port = random.randint(DEFAULT_START_SIP_PORT, 65534)
50 else:
51 self.sip_port = sip_port
52 # Autogenerate URI if it's empty.
53 self.uri = uri
54 if self.uri=="":
55 self.uri = "sip:pjsip@127.0.0.1:" + str(self.sip_port)
56 # Add uri_param to the URI
57 self.uri = self.uri + uri_param
58 # Add bracket to the URI
59 if self.uri[0] != "<":
60 self.uri = "<" + self.uri + ">"
61 # Add SIP local port to the argument
62 self.arg = arg + " --local-port=" + str(self.sip_port)
63 self.have_reg = have_reg
64 self.have_publish = have_publish
Benny Prijono62a969c2008-06-26 13:29:29 +000065 if have_publish and have_reg and not ("--publish" in self.arg):
Benny Prijonocc1ada52008-06-15 19:43:43 +000066 self.arg = self.arg + " --publish"
67 self.echo_enabled = echo_enabled
68 self.trace_enabled = trace_enabled
Benny Prijono1e65e9a2008-06-27 23:53:00 +000069 self.enable_buffer = enable_buffer
Benny Prijonocc1ada52008-06-15 19:43:43 +000070
71
72############################################
73# Test parameter class
74class TestParam:
75 title = ""
76 # params is list containing InstanceParams objects
77 inst_params = []
Nanang Izzuddin6ee166d2008-06-26 12:26:52 +000078 # flag if this tes should be skipped
79 skip = None
Benny Prijonocc1ada52008-06-15 19:43:43 +000080 # list of Expect instances, to be filled at run-time by
81 # the test program
82 process = []
83 # the function for test body
84 test_func = None
Nanang Izzuddinf810f952008-06-18 21:04:14 +000085 post_func = None
Benny Prijonocc1ada52008-06-15 19:43:43 +000086 def __init__( self,
87 title, # Test title
88 inst_params, # InstanceParam's as list
Nanang Izzuddinf810f952008-06-18 21:04:14 +000089 func=None,
Benny Prijono632be0a2008-06-26 19:51:01 +000090 skip=False,
Benny Prijono1e65e9a2008-06-27 23:53:00 +000091 post_func=None,
92 need_stdout_buffer=False):
Benny Prijonocc1ada52008-06-15 19:43:43 +000093 self.title = title
94 self.inst_params = inst_params
Nanang Izzuddin6ee166d2008-06-26 12:26:52 +000095 self.skip = skip
Benny Prijonocc1ada52008-06-15 19:43:43 +000096 self.test_func = func
Nanang Izzuddinf810f952008-06-18 21:04:14 +000097 self.post_func = post_func
Benny Prijonocc1ada52008-06-15 19:43:43 +000098
99
Benny Prijono7d578a72008-06-20 00:25:55 +0000100###################################
101# TestError exception
102class TestError:
103 desc = ""
104 def __init__(self, desc):
105 self.desc = desc
106
Benny Prijonocc1ada52008-06-15 19:43:43 +0000107