Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 1 | # $Id$ |
Benny Prijono | cc1ada5 | 2008-06-15 19:43:43 +0000 | [diff] [blame] | 2 | import random |
Benny Prijono | c366aa9 | 2008-08-26 12:13:25 +0000 | [diff] [blame] | 3 | import config_site |
Benny Prijono | cc1ada5 | 2008-06-15 19:43:43 +0000 | [diff] [blame] | 4 | |
| 5 | DEFAULT_ECHO = True |
| 6 | DEFAULT_TRACE = True |
| 7 | DEFAULT_START_SIP_PORT = 50000 |
| 8 | |
Nanang Izzuddin | a680bd6 | 2008-06-27 21:12:12 +0000 | [diff] [blame] | 9 | # Shared vars |
| 10 | ARGS = [] # arguments containing script module & config |
Benny Prijono | c366aa9 | 2008-08-26 12:13:25 +0000 | [diff] [blame] | 11 | HAS_SND_DEV = config_site.HAS_SND_DEV |
Nanang Izzuddin | a680bd6 | 2008-06-27 21:12:12 +0000 | [diff] [blame] | 12 | |
Benny Prijono | cc1ada5 | 2008-06-15 19:43:43 +0000 | [diff] [blame] | 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 |
Benny Prijono | 1e65e9a | 2008-06-27 23:53:00 +0000 | [diff] [blame] | 32 | # Enable stdout buffer? |
| 33 | enable_buffer = False |
Benny Prijono | cc1ada5 | 2008-06-15 19:43:43 +0000 | [diff] [blame] | 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, |
Benny Prijono | 1e65e9a | 2008-06-27 23:53:00 +0000 | [diff] [blame] | 43 | trace_enabled=DEFAULT_TRACE, |
| 44 | enable_buffer = False): |
Benny Prijono | cc1ada5 | 2008-06-15 19:43:43 +0000 | [diff] [blame] | 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 |
Benny Prijono | 62a969c | 2008-06-26 13:29:29 +0000 | [diff] [blame] | 65 | if have_publish and have_reg and not ("--publish" in self.arg): |
Benny Prijono | cc1ada5 | 2008-06-15 19:43:43 +0000 | [diff] [blame] | 66 | self.arg = self.arg + " --publish" |
| 67 | self.echo_enabled = echo_enabled |
| 68 | self.trace_enabled = trace_enabled |
Benny Prijono | 1e65e9a | 2008-06-27 23:53:00 +0000 | [diff] [blame] | 69 | self.enable_buffer = enable_buffer |
Benny Prijono | cc1ada5 | 2008-06-15 19:43:43 +0000 | [diff] [blame] | 70 | |
| 71 | |
| 72 | ############################################ |
| 73 | # Test parameter class |
| 74 | class TestParam: |
| 75 | title = "" |
| 76 | # params is list containing InstanceParams objects |
| 77 | inst_params = [] |
Nanang Izzuddin | 6ee166d | 2008-06-26 12:26:52 +0000 | [diff] [blame] | 78 | # flag if this tes should be skipped |
| 79 | skip = None |
Benny Prijono | cc1ada5 | 2008-06-15 19:43:43 +0000 | [diff] [blame] | 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 |
Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 85 | post_func = None |
Benny Prijono | cc1ada5 | 2008-06-15 19:43:43 +0000 | [diff] [blame] | 86 | def __init__( self, |
| 87 | title, # Test title |
| 88 | inst_params, # InstanceParam's as list |
Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 89 | func=None, |
Benny Prijono | 632be0a | 2008-06-26 19:51:01 +0000 | [diff] [blame] | 90 | skip=False, |
Benny Prijono | 1e65e9a | 2008-06-27 23:53:00 +0000 | [diff] [blame] | 91 | post_func=None, |
| 92 | need_stdout_buffer=False): |
Benny Prijono | cc1ada5 | 2008-06-15 19:43:43 +0000 | [diff] [blame] | 93 | self.title = title |
| 94 | self.inst_params = inst_params |
Nanang Izzuddin | 6ee166d | 2008-06-26 12:26:52 +0000 | [diff] [blame] | 95 | self.skip = skip |
Benny Prijono | cc1ada5 | 2008-06-15 19:43:43 +0000 | [diff] [blame] | 96 | self.test_func = func |
Nanang Izzuddin | f810f95 | 2008-06-18 21:04:14 +0000 | [diff] [blame] | 97 | self.post_func = post_func |
Benny Prijono | cc1ada5 | 2008-06-15 19:43:43 +0000 | [diff] [blame] | 98 | |
| 99 | |
Benny Prijono | 7d578a7 | 2008-06-20 00:25:55 +0000 | [diff] [blame] | 100 | ################################### |
| 101 | # TestError exception |
| 102 | class TestError: |
| 103 | desc = "" |
| 104 | def __init__(self, desc): |
| 105 | self.desc = desc |
| 106 | |
Benny Prijono | cc1ada5 | 2008-06-15 19:43:43 +0000 | [diff] [blame] | 107 | |