Changeset 2078


Ignore:
Timestamp:
Jun 27, 2008 9:12:12 PM (16 years ago)
Author:
nanang
Message:

Ticket #543:

  • added options to run.py
  • passing options in runall.py to run.py
  • removing userdata in module callback functions
Location:
pjproject/trunk/pjsip-apps/src/test-pjsua
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjsip-apps/src/test-pjsua/inc_cfg.py

    r2066 r2078  
    11# $Id$ 
    22import random 
    3 from config_site import * 
    43 
    54DEFAULT_ECHO = True 
    65DEFAULT_TRACE = True 
    76DEFAULT_START_SIP_PORT = 50000 
     7 
     8# Shared vars 
     9ARGS = []               # arguments containing script module & config 
     10HAS_SND_DEV = 1         # specify 1 if system has sound device and prefer to use sound device in the tests 
    811 
    912# Individual pjsua instance configuration class 
     
    7679        test_func = None 
    7780        post_func = None 
    78         user_data = None 
    7981        def __init__(   self,  
    8082                        title,          # Test title 
     
    8284                        func=None, 
    8385                        skip=False, 
    84                         post_func=None, 
    85                         user_data=None): 
     86                        post_func=None): 
    8687                self.title = title 
    8788                self.inst_params = inst_params 
     
    8990                self.test_func = func 
    9091                self.post_func = post_func 
    91                 self.user_data = user_data 
    9292 
    9393 
  • pjproject/trunk/pjsip-apps/src/test-pjsua/mod_call.py

    r2071 r2078  
    77 
    88# Load configuration 
    9 cfg_file = imp.load_source("cfg_file", sys.argv[2]) 
     9cfg_file = imp.load_source("cfg_file", ARGS[1]) 
    1010 
    1111# Check media flow between ua1 and ua2 
     
    2121 
    2222# Test body function 
    23 def test_func(t, user_data): 
     23def test_func(t): 
    2424        callee = t.process[0] 
    2525        caller = t.process[1] 
  • pjproject/trunk/pjsip-apps/src/test-pjsua/mod_media_playrec.py

    r2052 r2078  
    1515import subprocess 
    1616import inc_const as const 
     17from inc_cfg import * 
    1718 
    1819# Load configuration 
    19 cfg_file = imp.load_source("cfg_file", sys.argv[2]) 
     20cfg_file = imp.load_source("cfg_file", ARGS[1]) 
    2021 
    2122# WAV similarity calculator 
     
    2526COMPARE_THRESHOLD = 2 
    2627 
    27 # UserData 
    28 class mod_media_playrec_user_data: 
    29         input_filename = "" 
    30         output_filename = "" 
     28# COMPARE params 
     29input_filename  = ""                    # Input filename 
     30output_filename = ""                    # Output filename 
    3131 
    3232# Test body function 
    3333def test_func(t, ud): 
     34        global input_filename 
     35        global output_filename 
     36 
    3437        endpt = t.process[0] 
    3538         
     
    6871# Post body function 
    6972def post_func(t, ud): 
     73        global input_filename 
     74        global output_filename 
     75 
    7076        endpt = t.process[0] 
    7177 
     
    94100test.test_func = test_func 
    95101test.post_func = post_func 
    96 test.user_data = mod_media_playrec_user_data() 
  • pjproject/trunk/pjsip-apps/src/test-pjsua/mod_pesq.py

    r2075 r2078  
    2222 
    2323# Load configuration 
    24 cfg_file = imp.load_source("cfg_file", sys.argv[2]) 
     24cfg_file = imp.load_source("cfg_file", ARGS[1]) 
    2525 
    2626# PESQ configs 
    27 # PESQ_THRESHOLD specifies the minimum acceptable PESQ MOS value, so test can be declared successful 
    28 PESQ = "tools/pesq.exe" 
    29 PESQ_DEFAULT_THRESHOLD = 3.4 
     27PESQ = "tools/pesq.exe"                 # PESQ executable path 
     28PESQ_DEFAULT_THRESHOLD = 3.4            # Default minimum acceptable PESQ MOS value 
    3029 
    31 # UserData 
    32 class mod_pesq_user_data: 
    33         # Sample rate option for PESQ 
    34         pesq_sample_rate_opt = "" 
    35         # Input/Reference filename 
    36         input_filename = "" 
    37         # Output/Degraded filename 
    38         output_filename = "" 
     30# PESQ params 
     31pesq_sample_rate_opt = ""               # Sample rate option for PESQ 
     32input_filename  = ""                    # Input/Reference filename 
     33output_filename = ""                    # Output/Degraded filename 
     34 
    3935 
    4036# Test body function 
    41 def test_func(t, user_data): 
     37def test_func(t): 
     38        global pesq_sample_rate_opt 
     39        global input_filename 
     40        global output_filename 
    4241 
    4342        ua1 = t.process[0] 
     
    4544 
    4645        # Get input file name 
    47         user_data.input_filename = re.compile(const.MEDIA_PLAY_FILE).search(ua1.inst_param.arg).group(1) 
     46        input_filename = re.compile(const.MEDIA_PLAY_FILE).search(ua1.inst_param.arg).group(1) 
    4847 
    4948        # Get output file name 
    50         user_data.output_filename = re.compile(const.MEDIA_REC_FILE).search(ua2.inst_param.arg).group(1) 
     49        output_filename = re.compile(const.MEDIA_REC_FILE).search(ua2.inst_param.arg).group(1) 
    5150 
    5251        # Get WAV input length, in seconds 
    53         fin = wave.open(user_data.input_filename, "r") 
     52        fin = wave.open(input_filename, "r") 
    5453        if fin == None: 
    5554                raise TestError("Failed opening input WAV file") 
     
    6059 
    6160        # Get clock rate of the output 
    62         mo_clock_rate = re.compile("\.(\d+)\.wav").search(user_data.output_filename) 
     61        mo_clock_rate = re.compile("\.(\d+)\.wav").search(output_filename) 
    6362        if (mo_clock_rate==None): 
    6463                raise TestError("Cannot compare input & output, incorrect output filename format") 
     
    7372        # (PESQ evaluates only files whose same clock rate & channel count) 
    7473        if channel_count == 2: 
    75             if re.search("\.\d+\.\d+\.wav", user_data.input_filename) != None: 
    76                     user_data.input_filename = re.sub("\.\d+\.\d+\.wav",  
    77                                                       "." + str(channel_count) + "."+clock_rate+".wav", user_data.input_filename) 
     74            if re.search("\.\d+\.\d+\.wav", input_filename) != None: 
     75                    input_filename = re.sub("\.\d+\.\d+\.wav", "." + str(channel_count) + "."+clock_rate+".wav", input_filename) 
    7876            else: 
    79                     user_data.input_filename = re.sub("\.\d+\.wav",  
    80                                                       "." + str(channel_count) + "."+clock_rate+".wav", user_data.input_filename) 
     77                    input_filename = re.sub("\.\d+\.wav", "." + str(channel_count) + "."+clock_rate+".wav", input_filename) 
    8178 
    8279        if (clock_rate != "8") & (clock_rate != "16"): 
     
    8481 
    8582        # Get conference clock rate of UA2 for PESQ sample rate option 
    86         user_data.pesq_sample_rate_opt = "+" + clock_rate + "000" 
     83        pesq_sample_rate_opt = "+" + clock_rate + "000" 
    8784 
    8885        # UA1 making call 
     
    114111 
    115112# Post body function 
    116 def post_func(t, user_data): 
     113def post_func(t): 
     114        global pesq_sample_rate_opt 
     115        global input_filename 
     116        global output_filename 
     117 
    117118        endpt = t.process[0] 
    118119 
    119120        # Execute PESQ 
    120         fullcmd = PESQ + " " + user_data.pesq_sample_rate_opt + " " + user_data.input_filename + " " + user_data.output_filename 
     121        fullcmd = PESQ + " " + pesq_sample_rate_opt + " " + input_filename + " " + output_filename 
    121122        endpt.trace("Popen " + fullcmd) 
    122123        pesq_proc = subprocess.Popen(fullcmd, stdout=subprocess.PIPE, universal_newlines=True) 
     
    147148test.test_func = test_func 
    148149test.post_func = post_func 
    149 test.user_data = mod_pesq_user_data() 
    150150 
  • pjproject/trunk/pjsip-apps/src/test-pjsua/mod_pres.py

    r2070 r2078  
    44import sys 
    55import inc_const as const 
     6from inc_cfg import * 
    67 
    78# Load configuration 
    8 cfg_file = imp.load_source("cfg_file", sys.argv[2]) 
     9cfg_file = imp.load_source("cfg_file", ARGS[1]) 
    910 
    1011 
    1112# Test body function 
    12 def test_func(t, user_data): 
     13def test_func(t): 
    1314        u1 = t.process[0] 
    1415        uri1 = cfg_file.test_param.inst_params[0].uri 
  • pjproject/trunk/pjsip-apps/src/test-pjsua/mod_run.py

    r2025 r2078  
    1 # $Id:$ 
     1# $Id$ 
    22import imp 
    33import sys 
    44 
     5from inc_cfg import * 
    56 
    67# Read configuration 
    7 cfg_file = imp.load_source("cfg_file", sys.argv[2]) 
     8cfg_file = imp.load_source("cfg_file", ARGS[1]) 
    89 
    910# Here where it all comes together 
  • pjproject/trunk/pjsip-apps/src/test-pjsua/mod_sendto.py

    r2066 r2078  
    88 
    99# Read configuration 
    10 cfg_file = imp.load_source("cfg_file", sys.argv[2]) 
     10cfg_file = imp.load_source("cfg_file", ARGS[1]) 
    1111 
    1212# Test body function 
    13 def test_func(t, userdata): 
     13def test_func(t): 
    1414        pjsua = t.process[0] 
    1515        # Create dialog 
  • pjproject/trunk/pjsip-apps/src/test-pjsua/run.py

    r2069 r2078  
    77import random 
    88import time 
     9import getopt 
    910 
    1011import inc_const as const 
    11 from inc_cfg import * 
     12import inc_cfg as inc 
     13 
     14# Vars 
     15G_EXE = ""              # pjsua executable path 
     16G_INUNIX = False        # flags that test is running in Unix 
     17 
     18 
     19# Usage string 
     20usage = \ 
     21""" 
     22run.py - Automated test driver 
     23 
     24Usage: 
     25        run.py [options] MODULE CONFIG 
     26Options: 
     27        --exe, -e               pjsua executable path 
     28        --null-audio, -n        use null audio 
     29Sample: 
     30        run.py -n mod_run.py scripts-run/100_simple.py 
     31""" 
     32 
     33# Parse arguments 
     34try: 
     35    opts, args = getopt.getopt(sys.argv[1:], "hne:", ["help", "null-audio", "exe="]) 
     36except getopt.GetoptError, err: 
     37    print str(err) 
     38    print usage 
     39    sys.exit(2) 
     40for o, a in opts: 
     41    if o in ("-h", "--help"): 
     42        print usage 
     43        sys.exit() 
     44    elif o in ("-n", "--null-audio"): 
     45        inc.HAS_SND_DEV = 0 
     46    elif o in ("-e", "--exe"): 
     47        G_EXE = a 
     48    else: 
     49        print "Unknown options" 
     50        sys.exit(2) 
     51 
     52if len(args) != 2: 
     53        print "Invalid arguments" 
     54        print usage 
     55        sys.exit(2) 
     56 
     57# Set global ARGS to be used by modules 
     58inc.ARGS = args 
    1259 
    1360# Get the pjsua executable name 
    14 if sys.platform.find("win32")!=-1: 
    15     e = "../../bin/pjsua_vc6d.exe" 
    16     st1 = os.stat(e) 
    17     if st1 != None: 
    18         G_EXE = e 
    19     e = "../../bin/pjsua_vc6d.exe" 
    20     st2 = os.stat(e) 
    21     if st2 != None and st2.st_mtime > st1.st_mtime: 
    22         G_EXE = e 
    23         st1 = st2 
    24     if G_EXE=="": 
    25         print "Unable to find valid pjsua. Please build pjsip first" 
    26         sys.exit(1) 
    27     G_INUNIX = False 
    28 else: 
    29     f = open("../../../build.mak", "r") 
    30     while True: 
    31         line = f.readline() 
    32         if not line: 
    33             break 
    34         if line.find("TARGET_NAME")!=-1: 
    35             print line 
    36             G_EXE="../../bin/pjsua-" + line.split(":= ")[1] 
    37             break 
    38     if G_EXE=="": 
    39         print "Unable to find ../../../build.mak. Please build pjsip first" 
    40         sys.exit(1) 
    41     G_INUNIX = True 
     61if G_EXE == "": 
     62        if sys.platform.find("win32")!=-1: 
     63            e = "../../bin/pjsua_vc6d.exe" 
     64            st1 = os.stat(e) 
     65            if st1 != None: 
     66                G_EXE = e 
     67            e = "../../bin/pjsua_vc6d.exe" 
     68            st2 = os.stat(e) 
     69            if st2 != None and st2.st_mtime > st1.st_mtime: 
     70                G_EXE = e 
     71                st1 = st2 
     72            if G_EXE=="": 
     73                print "Unable to find valid pjsua. Please build pjsip first" 
     74                sys.exit(1) 
     75            G_INUNIX = False 
     76        else: 
     77            f = open("../../../build.mak", "r") 
     78            while True: 
     79                line = f.readline() 
     80                if not line: 
     81                    break 
     82                if line.find("TARGET_NAME")!=-1: 
     83                    print line 
     84                    G_EXE="../../bin/pjsua-" + line.split(":= ")[1] 
     85                    break 
     86            if G_EXE=="": 
     87                print "Unable to find ../../../build.mak. Please build pjsip first" 
     88                sys.exit(1) 
     89            G_INUNIX = True 
    4290 
    4391 
     
    75123                        line = self.proc.stdout.readline() 
    76124                        if line == "": 
    77                                 raise TestError(self.name + ": Premature EOF") 
     125                                raise inc.TestError(self.name + ": Premature EOF") 
    78126                        # Print the line if echo is ON 
    79127                        if self.echo: 
     
    82130                        if self.ra.search(line) != None: 
    83131                                if raise_on_error: 
    84                                         raise TestError(self.name + ": " + line) 
     132                                        raise inc.TestError(self.name + ": " + line) 
    85133                                else: 
    86134                                        return None 
     
    91139                                        self.trace("Timed-out!") 
    92140                                        if raise_on_error: 
    93                                                 raise TestError(self.name + " " + title + ": Timeout expecting pattern: \"" + pattern + "\"") 
     141                                                raise inc.TestError(self.name + " " + title + ": Timeout expecting pattern: \"" + pattern + "\"") 
    94142                                        else: 
    95143                                                return None             # timeout 
     
    131179# MAIN   
    132180 
    133 if len(sys.argv)!=3: 
    134         print "Usage: run.py MODULE CONFIG" 
    135         print "Sample:" 
    136         print "  run.py mod_run.py scripts-run/100_simple.py" 
    137         sys.exit(1) 
    138  
    139  
    140181# Import the test script 
    141 script = imp.load_source("script", sys.argv[1])   
     182script = imp.load_source("script", inc.ARGS[0])   
    142183 
    143184# Init random seed 
     
    177218                script.test.process.append(p) 
    178219 
    179         except TestError, e: 
     220        except inc.TestError, e: 
    180221                handle_error(e.desc, script.test) 
    181222 
     
    183224if script.test.test_func != None: 
    184225        try: 
    185                 script.test.test_func(script.test, script.test.user_data) 
    186         except TestError, e: 
     226                script.test.test_func(script.test) 
     227        except inc.TestError, e: 
    187228                handle_error(e.desc, script.test) 
    188229 
     
    204245if script.test.post_func != None: 
    205246        try: 
    206                 script.test.post_func(script.test, script.test.user_data) 
    207         except TestError, e: 
     247                script.test.post_func(script.test) 
     248        except inc.TestError, e: 
    208249                handle_error(e.desc, script.test, False) 
    209250 
  • pjproject/trunk/pjsip-apps/src/test-pjsua/runall.py

    r2071 r2078  
    33import sys 
    44import time 
     5import re 
     6import shutil 
     7 
    58 
    69# Usage: 
     
    5457resume_script="" 
    5558if len(sys.argv) > 1: 
    56     if sys.argv[1][0]=='-' or sys.argv[1][0]=='/': 
     59    if sys.argv[1]=='-r' or sys.argv[1]=='--resume': 
     60        resume_script=sys.argv[2] 
     61    if sys.argv[1]=='/h' or sys.argv[1]=='-h' or sys.argv[1]=='--help' or sys.argv[1]=='/help': 
    5762        print "Usage:" 
    58         print "  runall.py [RESUME]" 
    59         print "where" 
    60         print "  RESUME is string/substring to specify where to resume tests." 
    61         print "  If this argument is omited, tests will start from the beginning." 
     63        print "  runall.py [OPTIONS] [run.py OPTIONS]" 
     64        print "Options:" 
     65        print "  --resume,-r RESUME" 
     66        print "  where" 
     67        print "      RESUME is string/substring to specify where to resume tests." 
     68        print "      If this argument is omited, tests will start from the beginning." 
    6269        sys.exit(0) 
    63     resume_script=sys.argv[1] 
    6470 
     71 
     72# Generate arguments for run.py 
     73argv = sys.argv 
     74argv_to_skip = 1 
     75if resume_script != "": 
     76    argv_to_skip += 2 
     77argv_st = "" 
     78for a in argv: 
     79    if argv_to_skip > 0: 
     80        argv_to_skip -= 1 
     81    else: 
     82        argv_st += a + " " 
     83 
     84 
     85# Init vars 
     86failed_cnt = 0 
     87 
     88# Create "logs" directory 
     89try: 
     90    os.mkdir("logs") 
     91except: 
     92    print 
    6593 
    6694# Now run the tests 
     
    7098            continue 
    7199        resume_script="" 
    72         cmdline = "python run.py " + t 
     100        cmdline = "python run.py " + argv_st + t 
    73101        t0 = time.time() 
    74102        print "Running " + cmdline + "...", 
     
    78106                dur = int(t1 - t0) 
    79107                print " failed!! [" + str(dur) + "s]" 
    80                 print "Please see 'output.log' for the test log." 
    81                 sys.exit(1) 
     108                logname = re.search(".*\s+(.*)", t).group(1) 
     109                logname = re.sub("[\\\/]", "_", logname) 
     110                logname = "logs/" + logname 
     111                shutil.move("output.log", logname) 
     112                print "Please see '" + logname + "' for the test log." 
    82113        else: 
    83114                dur = int(t1 - t0) 
    84115                print " ok [" + str(dur) + "s]" 
    85116 
    86 print "All tests completed successfully" 
     117if failed_cnt == 0: 
     118        print "All tests completed successfully" 
     119else: 
     120        print "Tests completed, with " +  str(failed_cnt) + " test(s) failed" 
     121 
Note: See TracChangeset for help on using the changeset viewer.