Debian Codegraph @

Xpjproject/tests/pjsua/inc_cfg.py

raw symbols SCIP
1 import random
2 import config_site
3 import socket
4 import errno
5 import time
6
7 DEFAULT_ECHO = True
8 DEFAULT_TRACE = True
9 DEFAULT_START_SIP_PORT = 50000
10 DEFAULT_TELNET = True
11 DEFAULT_START_TELNET_PORT = 60000
12
13 # Shared vars
14 ARGS = [] # arguments containing script module & config
15 HAS_SND_DEV = config_site.HAS_SND_DEV
16
17 # Individual pjsua instance configuration class
18 class InstanceParam:
19 # Name to identify this pjsua instance (e.g. "caller", "callee", etc.)
20 name = ""
21 # pjsua command line arguments, concatenated in string
22 arg = ""
23 # Specify whether pjsua telnet CLI is enabled
24 telnet_enabled = DEFAULT_TELNET
25 # Telnet port number, zero to automatically assign
26 telnet_port = 0
27 # Specify whether pjsua output should be echoed to stdout
28 echo_enabled = DEFAULT_ECHO
29 # Enable/disable test tracing
30 trace_enabled = DEFAULT_TRACE
31 # SIP URI to send request to this instance
32 uri = ""
33 # SIP port number, zero to automatically assign
34 sip_port = 0
35 # Does this have registration? If yes then the test function will
36 # wait until the UA is registered before doing anything else
37 have_reg = False
38 # Does this have PUBLISH?
39 have_publish = False
40 # Enable stdout buffer?
41 enable_buffer = False
42 def __init__( self,
43 name, # Instance name
44 arg, # Cmd-line arguments
45 uri="", # URI
46 uri_param="", # Additional URI param
47 telnet_port=0, # Telnet port
48 sip_port=0, # SIP port
49 have_reg=False, # Have registration?
50 have_publish=False, # Have publish?
51 echo_enabled=DEFAULT_ECHO,
52 trace_enabled=DEFAULT_TRACE,
53 telnet_enabled = DEFAULT_TELNET,
54 enable_buffer = False):
55 # Instance name
56 self.name = name
57 # Give random telnet_port if it's not specified and telnet CLI is enabled
58 if telnet_enabled and telnet_port==0:
59 # avoid port conflict
60 cnt = 0
61 port = 0
62 while cnt < 10:
63 cnt = cnt + 1
64 port = random.randint(DEFAULT_START_TELNET_PORT, 65534)
65 s = socket.socket(socket.AF_INET)
66 try:
67 s.bind(("0.0.0.0", port))
68 except socket.error as serr:
69 s.close()
70 if serr.errno == errno.EADDRINUSE or serr.errno == errno.EACCES:
71 continue
72 s.close()
73 break;
74 self.telnet_port = port
75 else:
76 self.telnet_port = telnet_port
77 # Give random sip_port if it's not specified
78 if sip_port==0:
79 # avoid port conflict
80 cnt = 0
81 port = 0
82 while cnt < 10:
83 port = random.randint(DEFAULT_START_SIP_PORT, 60000)
84 if port==self.telnet_port:
85 continue
86 cnt = cnt + 1
87 s = socket.socket(socket.AF_INET)
88 try:
89 s.bind(("0.0.0.0", port))
90 except socket.error as serr:
91 s.close()
92 if serr.errno == errno.EADDRINUSE or serr.errno == errno.EACCES:
93 continue
94 s.close()
95 break;
96 self.sip_port = port
97 # Give some time for socket close
98 time.sleep(0.5)
99 else:
100 self.sip_port = sip_port
101 # Autogenerate URI if it's empty.
102 self.uri = uri
103 if self.uri=="":
104 self.uri = "sip:[email protected]:" + str(self.sip_port)
105 # Add uri_param to the URI
106 self.uri = self.uri + uri_param
107 # Add bracket to the URI
108 if self.uri[0] != "<":
109 self.uri = "<" + self.uri + ">"
110 # Add SIP local port to the argument
111 self.arg = arg + " --local-port=" + str(self.sip_port)
112 self.have_reg = have_reg
113 self.have_publish = have_publish
114 if have_publish and have_reg and not ("--publish" in self.arg):
115 self.arg = self.arg + " --publish"
116 self.echo_enabled = echo_enabled
117 self.trace_enabled = trace_enabled
118 self.enable_buffer = enable_buffer
119
120
121 ############################################
122 # Test parameter class
123 class TestParam:
124 title = ""
125 # params is list containing InstanceParams objects
126 inst_params = []
127 # flag if this tes should be skipped
128 skip = None
129 # list of Expect instances, to be filled at run-time by
130 # the test program
131 process = []
132 # the function for test body
133 test_func = None
134 post_func = None
135 def __init__( self,
136 title, # Test title
137 inst_params, # InstanceParam's as list
138 func=None,
139 skip=False,
140 post_func=None,
141 need_stdout_buffer=False):
142 self.title = title
143 self.inst_params = inst_params
144 self.skip = skip
145 self.test_func = func
146 self.post_func = post_func
147
148
149 ###################################
150 # TestError exception
151 class TestError(Exception):
152 desc = ""
153 def __init__(self, desc):
154 self.desc = desc
155
156