blob: 46a7f52bfe7d44cf4f8fc8d11db8417f8bf4eec4 [file] [log] [blame]
Benny Prijonocc1ada52008-06-15 19:43:43 +00001# $Id$
Benny Prijono8c331df2008-06-13 15:32:08 +00002import os
3import sys
Benny Prijono9bc3c182008-06-26 22:17:33 +00004import time
Nanang Izzuddina680bd62008-06-27 21:12:12 +00005import re
6import shutil
7
Benny Prijono8c331df2008-06-13 15:32:08 +00008
Benny Prijonof9bd1f22008-06-16 13:04:44 +00009# Usage:
10# runall.py [test-to-resume]
11
12
Benny Prijono8c331df2008-06-13 15:32:08 +000013# Initialize test list
14tests = []
15
16# Excluded tests (because they fail?)
17excluded_tests = [ "svn",
18 "pyc",
Nanang Izzuddinb40e2872008-06-25 15:05:21 +000019 "scripts-call/150_srtp_2_1", # SRTP optional 'cannot' call SRTP mandatory
Benny Prijono9bc3c182008-06-26 22:17:33 +000020 "scripts-call/301_ice_public_a.py", # Unreliable, proxy returns 408 sometimes
Benny Prijono62a969c2008-06-26 13:29:29 +000021 "scripts-call/301_ice_public_b.py", # Doesn't work because OpenSER modifies SDP
Benny Prijonoe4ddeec2008-06-27 08:51:55 +000022 "scripts-pres/200_publish.py", # Ok from cmdline, error from runall.py
Nanang Izzuddinb40e2872008-06-25 15:05:21 +000023 "scripts-media-playrec/100_resample_lf_8_11.py", # related to clock-rate 11 kHz problem
24 "scripts-media-playrec/100_resample_lf_8_22.py", # related to clock-rate 22 kHz problem
25 "scripts-media-playrec/100_resample_lf_11" # related to clock-rate 11 kHz problem
Benny Prijono7d578a72008-06-20 00:25:55 +000026 ]
Benny Prijono8c331df2008-06-13 15:32:08 +000027
Benny Prijonocc1ada52008-06-15 19:43:43 +000028# Add basic tests
Benny Prijono8c331df2008-06-13 15:32:08 +000029for f in os.listdir("scripts-run"):
30 tests.append("mod_run.py scripts-run/" + f)
31
Benny Prijonocc1ada52008-06-15 19:43:43 +000032# Add basic call tests
Benny Prijono8c331df2008-06-13 15:32:08 +000033for f in os.listdir("scripts-call"):
34 tests.append("mod_call.py scripts-call/" + f)
35
Benny Prijonocc1ada52008-06-15 19:43:43 +000036# Add presence tests
37for f in os.listdir("scripts-pres"):
38 tests.append("mod_pres.py scripts-pres/" + f)
39
Benny Prijono7d578a72008-06-20 00:25:55 +000040# Add mod_sendto tests
41for f in os.listdir("scripts-sendto"):
42 tests.append("mod_sendto.py scripts-sendto/" + f)
43
Nanang Izzuddinb40e2872008-06-25 15:05:21 +000044# Add mod_media_playrec tests
45for f in os.listdir("scripts-media-playrec"):
46 tests.append("mod_media_playrec.py scripts-media-playrec/" + f)
47
48# Add mod_pesq tests
49for f in os.listdir("scripts-pesq"):
50 tests.append("mod_pesq.py scripts-pesq/" + f)
51
Benny Prijono8c331df2008-06-13 15:32:08 +000052# Filter-out excluded tests
53for pat in excluded_tests:
54 tests = [t for t in tests if t.find(pat)==-1]
55
Benny Prijonof9bd1f22008-06-16 13:04:44 +000056# Resume test?
57resume_script=""
58if len(sys.argv) > 1:
Nanang Izzuddina680bd62008-06-27 21:12:12 +000059 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':
Benny Prijonof9bd1f22008-06-16 13:04:44 +000062 print "Usage:"
Nanang Izzuddin65417bd2008-06-27 22:15:41 +000063 print " runall.py [OPTIONS] [run.py-OPTIONS]"
Nanang Izzuddina680bd62008-06-27 21:12:12 +000064 print "Options:"
65 print " --resume,-r RESUME"
Nanang Izzuddina680bd62008-06-27 21:12:12 +000066 print " RESUME is string/substring to specify where to resume tests."
67 print " If this argument is omited, tests will start from the beginning."
Nanang Izzuddin65417bd2008-06-27 22:15:41 +000068 print " run.py-OPTIONS are applicable here"
Benny Prijonof9bd1f22008-06-16 13:04:44 +000069 sys.exit(0)
Benny Prijonof9bd1f22008-06-16 13:04:44 +000070
71
Nanang Izzuddina680bd62008-06-27 21:12:12 +000072# 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
Nanang Izzuddin65417bd2008-06-27 22:15:41 +000086fails_cnt = 0
87tests_cnt = 0
Nanang Izzuddina680bd62008-06-27 21:12:12 +000088
Nanang Izzuddin65417bd2008-06-27 22:15:41 +000089# Re-create "logs" directory
90try:
91 shutil.rmtree("logs")
92except:
93 print "Warning: failed in removing directory 'logs'"
94
Nanang Izzuddina680bd62008-06-27 21:12:12 +000095try:
96 os.mkdir("logs")
97except:
Nanang Izzuddin65417bd2008-06-27 22:15:41 +000098 print "Warning: failed in creating directory 'logs'"
Nanang Izzuddina680bd62008-06-27 21:12:12 +000099
Benny Prijono8c331df2008-06-13 15:32:08 +0000100# Now run the tests
101for t in tests:
Benny Prijonof9bd1f22008-06-16 13:04:44 +0000102 if resume_script!="" and t.find(resume_script)==-1:
103 print "Skipping " + t +".."
104 continue
105 resume_script=""
Nanang Izzuddina680bd62008-06-27 21:12:12 +0000106 cmdline = "python run.py " + argv_st + t
Benny Prijono9bc3c182008-06-26 22:17:33 +0000107 t0 = time.time()
108 print "Running " + cmdline + "...",
Benny Prijono8c331df2008-06-13 15:32:08 +0000109 ret = os.system(cmdline + " > output.log")
Benny Prijono9bc3c182008-06-26 22:17:33 +0000110 t1 = time.time()
Benny Prijono8c331df2008-06-13 15:32:08 +0000111 if ret != 0:
Benny Prijono9bc3c182008-06-26 22:17:33 +0000112 dur = int(t1 - t0)
113 print " failed!! [" + str(dur) + "s]"
Nanang Izzuddina680bd62008-06-27 21:12:12 +0000114 logname = re.search(".*\s+(.*)", t).group(1)
115 logname = re.sub("[\\\/]", "_", logname)
Nanang Izzuddin65417bd2008-06-27 22:15:41 +0000116 logname = re.sub("\.py$", ".log", logname)
Nanang Izzuddina680bd62008-06-27 21:12:12 +0000117 logname = "logs/" + logname
118 shutil.move("output.log", logname)
119 print "Please see '" + logname + "' for the test log."
Nanang Izzuddin65417bd2008-06-27 22:15:41 +0000120 fails_cnt += 1
Benny Prijono9bc3c182008-06-26 22:17:33 +0000121 else:
122 dur = int(t1 - t0)
123 print " ok [" + str(dur) + "s]"
Nanang Izzuddin65417bd2008-06-27 22:15:41 +0000124 tests_cnt += 1
Benny Prijono8c331df2008-06-13 15:32:08 +0000125
Nanang Izzuddina680bd62008-06-27 21:12:12 +0000126if failed_cnt == 0:
Nanang Izzuddin65417bd2008-06-27 22:15:41 +0000127 print "All " + str(tests_cnt) + " tests completed successfully"
Nanang Izzuddina680bd62008-06-27 21:12:12 +0000128else:
Nanang Izzuddin65417bd2008-06-27 22:15:41 +0000129 print str(tests_cnt) + " tests completed, " + str(fails_cnt) + " test(s) failed"
Nanang Izzuddina680bd62008-06-27 21:12:12 +0000130