Alexandre Lision | 8af73cb | 2013-12-10 14:11:20 -0500 | [diff] [blame^] | 1 | # $Id$ |
| 2 | import random |
| 3 | import config_site |
| 4 | |
| 5 | DEFAULT_ECHO = True |
| 6 | DEFAULT_TRACE = True |
| 7 | DEFAULT_START_SIP_PORT = 50000 |
| 8 | |
| 9 | # Shared vars |
| 10 | ARGS = [] # arguments containing script module & config |
| 11 | HAS_SND_DEV = config_site.HAS_SND_DEV |
| 12 | |
| 13 | # Individual pjsua instance configuration class |
| 14 | class 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 |
| 32 | # Enable stdout buffer? |
| 33 | enable_buffer = False |
| 34 | 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, |
| 43 | trace_enabled=DEFAULT_TRACE, |
| 44 | enable_buffer = False): |
| 45 | # 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 |
| 65 | if have_publish and have_reg and not ("--publish" in self.arg): |
| 66 | self.arg = self.arg + " --publish" |
| 67 | self.echo_enabled = echo_enabled |
| 68 | self.trace_enabled = trace_enabled |
| 69 | self.enable_buffer = enable_buffer |
| 70 | |
| 71 | |
| 72 | ############################################ |
| 73 | # Test parameter class |
| 74 | class TestParam: |
| 75 | title = "" |
| 76 | # params is list containing InstanceParams objects |
| 77 | inst_params = [] |
| 78 | # flag if this tes should be skipped |
| 79 | skip = None |
| 80 | # 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 |
| 85 | post_func = None |
| 86 | def __init__( self, |
| 87 | title, # Test title |
| 88 | inst_params, # InstanceParam's as list |
| 89 | func=None, |
| 90 | skip=False, |
| 91 | post_func=None, |
| 92 | need_stdout_buffer=False): |
| 93 | self.title = title |
| 94 | self.inst_params = inst_params |
| 95 | self.skip = skip |
| 96 | self.test_func = func |
| 97 | self.post_func = post_func |
| 98 | |
| 99 | |
| 100 | ################################### |
| 101 | # TestError exception |
| 102 | class TestError: |
| 103 | desc = "" |
| 104 | def __init__(self, desc): |
| 105 | self.desc = desc |
| 106 | |
| 107 | |