| 1 |
import os |
| 2 |
import sys |
| 3 |
import time |
| 4 |
import re |
| 5 |
import shutil |
| 6 |
import platform |
| 7 |
|
| 8 |
PYTHON = os.path.basename(sys.executable) |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
tests = [] |
| 16 |
|
| 17 |
|
| 18 |
excluded_tests = [ |
| 19 |
"svn", |
| 20 |
"pyc", |
| 21 |
"__pycache__", |
| 22 |
"scripts-call/150_srtp_2_1", |
| 23 |
"scripts-call/150_srtp_2_3.py", |
| 24 |
"scripts-call/301_ice_public_a.py", |
| 25 |
"scripts-call/301_ice_public_b.py", |
| 26 |
"scripts-pres/200_publish.py", |
| 27 |
"scripts-media-playrec/100_resample_lf_8_11.py", |
| 28 |
"scripts-media-playrec/100_resample_lf_8_22.py", |
| 29 |
"scripts-media-playrec/100_resample_lf_11", |
| 30 |
|
| 31 |
"call_305_ice_comp_1_2", |
| 32 |
"scripts-sendto/155_err_sdp_bad_syntax", |
| 33 |
"transfer-attended", |
| 34 |
"uac-inv-and-ack-without-sdp", |
| 35 |
"uac-subscribe", |
| 36 |
"uac-ticket-1148", |
| 37 |
"uas-422-then-200-bad-se", |
| 38 |
"uas-answer-180-multiple-fmts-support-update", |
| 39 |
"uas-inv-answered-with-srtp", |
| 40 |
"uas-mwi-0", |
| 41 |
"uas-mwi", |
| 42 |
"uas-register-ip-change-port-only", |
| 43 |
"uas-register-ip-change", |
| 44 |
"uas-timer-update", |
| 45 |
|
| 46 |
"alt-pjsua-uac-custom-sdp", |
| 47 |
"alt-pjsua-uas-custom-sdp", |
| 48 |
] |
| 49 |
|
| 50 |
|
| 51 |
if platform.system()=='Darwin': |
| 52 |
excluded_tests.append("scripts-sipp/uac-reinvite-bad-via-branch") |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
for f in os.listdir("scripts-run"): |
| 57 |
tests.append("mod_run.py scripts-run/" + f) |
| 58 |
|
| 59 |
|
| 60 |
for f in os.listdir("scripts-call"): |
| 61 |
tests.append("mod_call.py scripts-call/" + f) |
| 62 |
|
| 63 |
|
| 64 |
for f in os.listdir("scripts-call-wav"): |
| 65 |
tests.append("mod_call_playrec.py scripts-call-wav/" + f) |
| 66 |
|
| 67 |
|
| 68 |
for f in os.listdir("scripts-pres"): |
| 69 |
tests.append("mod_pres.py scripts-pres/" + f) |
| 70 |
|
| 71 |
|
| 72 |
for f in os.listdir("scripts-sendto"): |
| 73 |
tests.append("mod_sendto.py scripts-sendto/" + f) |
| 74 |
|
| 75 |
|
| 76 |
for f in os.listdir("scripts-media-playrec"): |
| 77 |
tests.append("mod_media_playrec.py scripts-media-playrec/" + f) |
| 78 |
|
| 79 |
|
| 80 |
for f in os.listdir("scripts-pesq"): |
| 81 |
tests.append("mod_pesq.py scripts-pesq/" + f) |
| 82 |
|
| 83 |
|
| 84 |
for f in os.listdir("scripts-recvfrom"): |
| 85 |
tests.append("mod_recvfrom.py scripts-recvfrom/" + f) |
| 86 |
|
| 87 |
|
| 88 |
for f in os.listdir("scripts-sipp"): |
| 89 |
if f.endswith(".xml"): |
| 90 |
tests.append("mod_sipp.py scripts-sipp/" + f) |
| 91 |
|
| 92 |
|
| 93 |
resume_script="" |
| 94 |
retry_num=0 |
| 95 |
shell_cmd="" |
| 96 |
with_log=True |
| 97 |
|
| 98 |
|
| 99 |
sys.argv.pop(0) |
| 100 |
while len(sys.argv): |
| 101 |
if sys.argv[0]=='/h' or sys.argv[0]=='-h' or sys.argv[0]=='--help' or sys.argv[0]=='/help': |
| 102 |
sys.argv.pop(0) |
| 103 |
print("Usage:") |
| 104 |
print(" runall.py [OPTIONS] [run.py-OPTIONS]") |
| 105 |
print("OPTIONS:") |
| 106 |
print(" --list") |
| 107 |
print(" List the tests") |
| 108 |
print(" --list-xml") |
| 109 |
print(" List the tests as XML format suitable for ccdash") |
| 110 |
print(" --resume,-r RESUME") |
| 111 |
print(" RESUME is string/substring to specify where to resume tests.") |
| 112 |
print(" If this argument is omited, tests will start from the beginning.") |
| 113 |
print(" --disable,-d TEST_NAME") |
| 114 |
print(" Disable a specific test that contains the specified TEST_NAME.") |
| 115 |
print(" --retry,-t RETRY_NUM") |
| 116 |
print(" Retry a specific test RETRY_NUM times before marking it as failed.") |
| 117 |
print(" Default is 0 (no retry).") |
| 118 |
print(" --shell,-s SHELL") |
| 119 |
print(" Run the tests with the specified SHELL cmd. This can also be") |
| 120 |
print(" used to run the test with ccdash. Example:") |
| 121 |
print(" --shell '/bin/sh -c'") |
| 122 |
print(" --no-log") |
| 123 |
print(" Do not generate log files. By default log files will be generated") |
| 124 |
print(" and put in 'logs' dir.") |
| 125 |
print("") |
| 126 |
print(" run.py-OPTIONS are applicable here") |
| 127 |
sys.exit(0) |
| 128 |
elif sys.argv[0] == '-r' or sys.argv[0] == '--resume': |
| 129 |
if len(sys.argv) > 1: |
| 130 |
resume_script=sys.argv[1] |
| 131 |
sys.argv.pop(0) |
| 132 |
sys.argv.pop(0) |
| 133 |
else: |
| 134 |
sys.argv.pop(0) |
| 135 |
sys.stderr.write("Error: argument value required") |
| 136 |
sys.exit(1) |
| 137 |
elif sys.argv[0] == '-t' or sys.argv[0] == '--retry': |
| 138 |
if len(sys.argv) > 1: |
| 139 |
retry_num=int(sys.argv[1]) |
| 140 |
sys.argv.pop(0) |
| 141 |
sys.argv.pop(0) |
| 142 |
else: |
| 143 |
sys.argv.pop(0) |
| 144 |
sys.stderr.write("Error: argument value required") |
| 145 |
sys.exit(1) |
| 146 |
elif sys.argv[0] == '--list': |
| 147 |
sys.argv.pop(0) |
| 148 |
for t in tests: |
| 149 |
print(t) |
| 150 |
sys.exit(0) |
| 151 |
elif sys.argv[0] == '--list-xml': |
| 152 |
sys.argv.pop(0) |
| 153 |
for t in tests: |
| 154 |
(mod,param) = t.split(None,2) |
| 155 |
tname = mod[4:mod.find(".py")] + "_" + \ |
| 156 |
param[param.find("/")+1:param.rfind(".")] |
| 157 |
c = "" |
| 158 |
if len(sys.argv): |
| 159 |
c = " ".join(sys.argv) + " " |
| 160 |
tcmd = PYTHON + ' run.py ' + c + t |
| 161 |
print('\t\t<Test name="%s" cmd="%s" wdir="tests/pjsua" />' % (tname, tcmd)) |
| 162 |
sys.exit(0) |
| 163 |
elif sys.argv[0] == '-s' or sys.argv[0] == '--shell': |
| 164 |
if len(sys.argv) > 1: |
| 165 |
shell_cmd = sys.argv[1] |
| 166 |
sys.argv.pop(0) |
| 167 |
sys.argv.pop(0) |
| 168 |
else: |
| 169 |
sys.argv.pop(0) |
| 170 |
sys.stderr.write("Error: argument value required") |
| 171 |
sys.exit(1) |
| 172 |
elif sys.argv[0] == '-d' or sys.argv[0] == '--disable': |
| 173 |
if len(sys.argv) > 1: |
| 174 |
excluded_tests.append(sys.argv[1]) |
| 175 |
sys.argv.pop(0) |
| 176 |
sys.argv.pop(0) |
| 177 |
else: |
| 178 |
sys.argv.pop(0) |
| 179 |
sys.stderr.write("Error: argument value required") |
| 180 |
sys.exit(1) |
| 181 |
elif sys.argv[0] == '--no-log': |
| 182 |
sys.argv.pop(0) |
| 183 |
with_log=False |
| 184 |
else: |
| 185 |
|
| 186 |
break |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
argv_st = " ".join(sys.argv) + " " |
| 191 |
|
| 192 |
|
| 193 |
fails_cnt = 0 |
| 194 |
tests_cnt = 0 |
| 195 |
|
| 196 |
|
| 197 |
for pat in excluded_tests: |
| 198 |
tests = [t for t in tests if t.find(pat)==-1] |
| 199 |
|
| 200 |
|
| 201 |
total_cnt = len(tests) |
| 202 |
print("Total tests : " + str(total_cnt)) |
| 203 |
for t in tests: |
| 204 |
if resume_script!="" and t.find(resume_script)==-1: |
| 205 |
print("Skipping " + t +"..") |
| 206 |
total_cnt = total_cnt - 1 |
| 207 |
continue |
| 208 |
resume_script="" |
| 209 |
cmdline = "python run.py " + argv_st + t |
| 210 |
if shell_cmd: |
| 211 |
cmdline = "%s '%s'" % (shell_cmd, cmdline) |
| 212 |
for i in range(1, retry_num+2): |
| 213 |
t0 = time.time() |
| 214 |
msg = "Running %3d/%d (#%d): %s..." % (tests_cnt+1, total_cnt, i, cmdline) |
| 215 |
sys.stdout.write(msg) |
| 216 |
sys.stdout.flush() |
| 217 |
if with_log: |
| 218 |
logname = re.search(".*\s+(.*)", t).group(1) |
| 219 |
logname = re.sub("[\\\/]", "_", logname) |
| 220 |
logname = re.sub("\.py$", ".log", logname) |
| 221 |
logname = re.sub("\.xml$", ".log", logname) |
| 222 |
logname = "logs/" + logname |
| 223 |
else: |
| 224 |
logname = os.devnull |
| 225 |
ret = os.system(cmdline + " > " + logname) |
| 226 |
t1 = time.time() |
| 227 |
if ret != 0: |
| 228 |
dur = int(t1 - t0) |
| 229 |
print(" failed!! [" + str(dur) + "s]") |
| 230 |
if (i < retry_num + 1): |
| 231 |
continue |
| 232 |
if with_log: |
| 233 |
lines = open(logname, "r", encoding='utf-8', errors='ignore').readlines() |
| 234 |
print(''.join(lines)) |
| 235 |
print("Log file: '" + logname + "'.") |
| 236 |
fails_cnt += 1 |
| 237 |
else: |
| 238 |
dur = int(t1 - t0) |
| 239 |
print(" ok [" + str(dur) + "s]") |
| 240 |
break |
| 241 |
tests_cnt += 1 |
| 242 |
|
| 243 |
if fails_cnt == 0: |
| 244 |
print("All " + str(tests_cnt) + " tests completed successfully") |
| 245 |
else: |
| 246 |
print(str(tests_cnt) + " tests completed, " + str(fails_cnt) + " test(s) failed") |
| 247 |
|
| 248 |
sys.exit(fails_cnt) |