Add support for ICE/STUN/TURN in res_rtp_asterisk and chan_sip.
[asterisk/asterisk.git] / res / pjproject / tests / pjsua / runall.py
1 # $Id$
2 import os
3 import sys
4 import time
5 import re
6 import shutil
7
8 PYTHON = os.path.basename(sys.executable)
9
10 # Usage:
11 #  runall.py [test-to-resume]
12
13
14 # Initialize test list
15 tests = []
16
17 # Excluded tests (because they fail?)
18 excluded_tests = [ "svn",
19                    "pyc",
20                    "scripts-call/150_srtp_2_1",                         # SRTP optional 'cannot' call SRTP mandatory
21                    "scripts-call/150_srtp_2_3.py",                      # temporarily disabled until #1267 done
22                    "scripts-call/301_ice_public_a.py",                  # Unreliable, proxy returns 408 sometimes
23                    "scripts-call/301_ice_public_b.py",                  # Doesn't work because OpenSER modifies SDP
24                    "scripts-pres/200_publish.py",                       # Ok from cmdline, error from runall.py
25                    "scripts-media-playrec/100_resample_lf_8_11.py",     # related to clock-rate 11 kHz problem
26                    "scripts-media-playrec/100_resample_lf_8_22.py",     # related to clock-rate 22 kHz problem
27                    "scripts-media-playrec/100_resample_lf_11"           # related to clock-rate 11 kHz problem
28                    ]
29
30 # Add basic tests
31 for f in os.listdir("scripts-run"):
32     tests.append("mod_run.py scripts-run/" + f)
33
34 # Add basic call tests
35 for f in os.listdir("scripts-call"):
36     tests.append("mod_call.py scripts-call/" + f)
37
38 # Add presence tests
39 for f in os.listdir("scripts-pres"):
40     tests.append("mod_pres.py scripts-pres/" + f)
41
42 # Add mod_sendto tests
43 for f in os.listdir("scripts-sendto"):
44     tests.append("mod_sendto.py scripts-sendto/" + f)
45
46 # Add mod_media_playrec tests
47 for f in os.listdir("scripts-media-playrec"):
48     tests.append("mod_media_playrec.py scripts-media-playrec/" + f)
49
50 # Add mod_pesq tests
51 for f in os.listdir("scripts-pesq"):
52     tests.append("mod_pesq.py scripts-pesq/" + f)
53
54 # Add recvfrom tests
55 for f in os.listdir("scripts-recvfrom"):
56     tests.append("mod_recvfrom.py scripts-recvfrom/" + f)
57
58 # Filter-out excluded tests
59 for pat in excluded_tests:
60     tests = [t for t in tests if t.find(pat)==-1]
61
62
63 resume_script=""
64 shell_cmd=""
65
66 # Parse arguments
67 sys.argv.pop(0)
68 while len(sys.argv):
69         if sys.argv[0]=='/h' or sys.argv[0]=='-h' or sys.argv[0]=='--help' or sys.argv[0]=='/help':
70                 sys.argv.pop(0)
71                 print "Usage:"
72                 print "  runall.py [OPTIONS] [run.py-OPTIONS]"
73                 print "OPTIONS:"
74                 print " --list"
75                 print "     List the tests"
76                 print "  --list-xml"
77                 print "     List the tests as XML format suitable for ccdash"
78                 print "  --resume,-r RESUME"
79                 print "      RESUME is string/substring to specify where to resume tests."
80                 print "      If this argument is omited, tests will start from the beginning."
81                 print "  --shell,-s SHELL"
82                 print "      Run the tests with the specified SHELL cmd. This can also be"
83                 print "      used to run the test with ccdash. Example:"
84                 print "        --shell '/bin/sh -c'"
85                 print "  run.py-OPTIONS are applicable here"
86                 sys.exit(0)
87         elif sys.argv[0] == '-r' or sys.argv[0] == '--resume':
88                 if len(sys.argv) > 1:
89                         resume_script=sys.argv[1]
90                         sys.argv.pop(0)
91                         sys.argv.pop(1)
92                 else:
93                         sys.argv.pop(0)
94                         sys.stderr.write("Error: argument value required")
95                         sys.exit(1)
96         elif sys.argv[0] == '--list':
97                 sys.argv.pop(0)
98                 for t in tests:
99                       print t
100                 sys.exit(0)
101         elif sys.argv[0] == '--list-xml':
102                 sys.argv.pop(0)
103                 for t in tests:
104                         (mod,param) = t.split(None,2)
105                         tname = mod[4:mod.find(".py")] + "_" + \
106                                 param[param.find("/")+1:param.find(".py")]
107                         c = ""
108                         if len(sys.argv):
109                                 c = " ".join(sys.argv) + " "
110                         tcmd = PYTHON + ' run.py ' + c + t
111                         print '\t\t<Test name="%s" cmd="%s" wdir="tests/pjsua" />' % (tname, tcmd)
112                 sys.exit(0)
113         elif sys.argv[0] == '-s' or sys.argv[0] == '--shell':
114                 if len(sys.argv) > 1:
115                         shell_cmd = sys.argv[1]
116                         sys.argv.pop(0)
117                         sys.argv.pop(1)
118                 else:
119                         sys.argv.pop(0)
120                         sys.stderr.write("Error: argument value required")
121                         sys.exit(1)
122
123
124 # Generate arguments for run.py
125 argv_st = " ".join(sys.argv)
126
127 # Init vars
128 fails_cnt = 0
129 tests_cnt = 0
130
131 # Re-create "logs" directory
132 try:
133     shutil.rmtree("logs")
134 except:
135     print "Warning: failed in removing directory 'logs'"
136
137 try:
138     os.mkdir("logs")
139 except:
140     print "Warning: failed in creating directory 'logs'"
141
142 # Now run the tests
143 total_cnt = len(tests)
144 for t in tests:
145         if resume_script!="" and t.find(resume_script)==-1:
146             print "Skipping " + t +".."
147             total_cnt = total_cnt - 1
148             continue
149         resume_script=""
150         cmdline = "python run.py " + argv_st + t
151         if shell_cmd:
152                 cmdline = "%s '%s'" % (shell_cmd, cmdline)
153         t0 = time.time()
154         msg = "Running %d/%d: %s..." % (tests_cnt+1, total_cnt, cmdline)
155         sys.stdout.write(msg)
156         sys.stdout.flush()
157         ret = os.system(cmdline + " > output.log")
158         t1 = time.time()
159         if ret != 0:
160                 dur = int(t1 - t0)
161                 print " failed!! [" + str(dur) + "s]"
162                 logname = re.search(".*\s+(.*)", t).group(1)
163                 logname = re.sub("[\\\/]", "_", logname)
164                 logname = re.sub("\.py$", ".log", logname)
165                 logname = "logs/" + logname
166                 shutil.move("output.log", logname)
167                 print "Please see '" + logname + "' for the test log."
168                 fails_cnt += 1
169         else:
170                 dur = int(t1 - t0)
171                 print " ok [" + str(dur) + "s]"
172         tests_cnt += 1
173
174 if fails_cnt == 0:
175         print "All " + str(tests_cnt) + " tests completed successfully"
176 else:
177         print str(tests_cnt) + " tests completed, " +  str(fails_cnt) + " test(s) failed"
178