/[resiprocate]/main/resip/stack/test/testStackFlavors.py
ViewVC logotype

Contents of /main/resip/stack/test/testStackFlavors.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 9044 - (show annotations) (download) (as text)
Mon Feb 28 17:40:37 2011 UTC (8 years, 8 months ago) by kwhite
File MIME type: text/x-python
File size: 5431 byte(s)
Extend FdPoll to support FdSet/select (not just epoll)

 * Add FdPollGrpImplFdSet class
 * Extend testStack to use support new mode
 * Whitespace cleanup
1 #!/usr/bin/python
2
3 # Linux-configuration
4 # Some of the test flavors require many open ports, and your system must be
5 # configured to enabled this. In particular:
6 # * This script opens up more than 1024 ports which means it needs to run
7 # as root. Thus do:
8 # sudo ./testStackFlavors.py
9 # * Ports 11000 thru 31000 will be bound. Ports in this range must not be
10 # bound (kill any servers you have running in this range). Further,
11 # client TCP connections must not be configured to run in this range.
12 # This is configured via
13 # /proc/sys/net/ipv4/ip_local_port_range
14 # The default is "32678 61000" which is good. The left number must be
15 # larger than 31000.
16 # * TCP connections will enter TIME_WAIT when each test completes,
17 # which may not leave enough ports for the next test.
18 # The script has a 5sec delay between tests that might help with this.
19 # You might need to tweak one of the following to work:
20 # /proc/sys/net/ipv4/tcp_tw_recycle
21 # /proc/sys/net/ipv4/tcp_tw_reuse
22 # /proc/sys/net/ipv4/tcp_fin_timeout
23 # I don't claim to fully understand this.
24
25 import os
26 import subprocess
27 import re
28 import platform
29 import datetime
30 import time
31
32 def TryUnlink(path):
33 try:
34 os.unlink(path)
35 except OSError:
36 pass
37 return
38
39
40 def RunTest(tag, testArgs):
41 cmdExec = "./testStack"
42 cmdFull = cmdExec + " " + testArgs
43 TryUnlink("./gmon.out")
44 # XXX: perhaps should close stdin
45 p = subprocess.Popen(cmdFull,shell=True,close_fds=True,stdout=subprocess.PIPE)
46 result = None
47 while p.stdout:
48 line = p.stdout.readline()
49 if len(line)==0:
50 break
51 print "%s: %s" % (tag, line.rstrip())
52 mo = re.match(r'(\d+).* performed in (\d+).* ms.*of (\d+).* per second',line)
53 if mo:
54 result = {}
55 result['runs'] = int(mo.group(1))
56 result['dur'] = int(mo.group(2))
57 result['tps'] = int(mo.group(3))
58 # XXX: for calls, need to convert cps into tps!
59
60 p.wait()
61
62 if p.returncode!=0:
63 print "%s: test failed (sts %d)!" % (tag, p.returncode)
64 print "%s: command was:\n---------\n%s\n---------" % (tag, cmdFull)
65 raise ValueError # fix this
66
67 if result is None:
68 print "%s: failed to find transaction rate in test output!"
69 raise ValueError # fix this
70
71 print "%s: runs=%d dur=%dms rate=%dtps" % (tag,
72 result['runs'], result['dur'], result['tps'])
73 return result
74
75 class RunParam:
76 def __init__(self, paramName, optionName, optionValues):
77 self.paramName = paramName
78 self.optionName = optionName
79 # assert optionValue is list
80 self.optionValues = optionValues
81
82 # Compute and return a runSet
83 # A runSet is list of paramSets
84 # A paramSet is a hash. The hashKey is the paramName, and the hash value
85 # is the specific value for this paramSet.
86
87 def CalcRunSet(ptbl):
88 restRunSet = []
89 if len(ptbl)==0:
90 return restRunSet
91 if len(ptbl)>1:
92 restRunSet = CalcRunSet(ptbl[1:])
93 if len(restRunSet)==0:
94 restRunSet = [{}]
95 doParam = ptbl[0]
96 #print "CalcRunSet: expanding param %s" % (doParam.paramName)
97 runSet = []
98 for optVal in doParam.optionValues:
99 #print "CalcRunSet: add param %s = %s" % (doParam.paramName, optVal)
100 for restParamSet in restRunSet:
101 paramSet = restParamSet.copy()
102 paramSet[doParam.paramName] = optVal
103 runSet.append(paramSet)
104 return runSet
105
106 def CalcParamStr(ptbl, pset):
107 popts = ["--%s=%s" % (pdef.optionName, pset[pdef.paramName]) for pdef in ptbl]
108 return ' '.join(popts)
109
110 def CalcParamCsv(ptbl, pset):
111 # TBD: excape and commas
112 popts = ["%s=,%s" % (pdef.paramName, pset[pdef.paramName]) for pdef in ptbl]
113 return ','.join(popts)
114
115 def IsParamSetValid(pset):
116 usingEpoll = pset['intepoll'] or pset['thread']=='epoll'
117 if pset['intepoll'] and (pset['thread'] in ('epoll','fdset')):
118 return False # redundant/silly
119 if pset['ports'] > 100 and not usingEpoll:
120 return False
121 if pset['listen']==0 and pset['protocol']=='udp':
122 return False
123 if usingEpoll and platform.system()=='Windows':
124 return False
125 return True
126
127 def RunParamTbl(ptbl):
128 runSet = CalcRunSet(ptbl)
129 #print runSet
130
131 resfile = open('testStack.results.csv', 'a')
132
133 platdesc = '-'.join(
134 [platform.system(),platform.release(),platform.machine()])
135 platnode = platform.node()
136
137 runCnt = 0
138 for pset in runSet:
139 runCnt += 1
140 pstr = CalcParamStr(ptbl, pset)
141 if not IsParamSetValid(pset):
142 print "skipping pstr: %s" % pstr
143 continue
144 print "running pstr: %s" % pstr
145 result = RunTest(runCnt, "--bind=127.0.0.1 " + pstr)
146 assert( result['runs'] == pset['runs'] )
147 now = datetime.datetime.now()
148 nowfmt = now.strftime("%Y%m%d.%H%M%S")
149 resstr = "tag=,%s,date=,%s,plat=,%s,node=,%s," % (runCnt,nowfmt,platdesc,platnode)
150 resstr += CalcParamCsv(ptbl, pset)
151 resstr += ",dur=,%d,tps=,%d" % (result['dur'], result['tps'])
152 resstr += "\n"
153 resfile.write(resstr)
154 # TCP ports just entered TIME_WAIT. That may create problems
155 # for next test if it tries to bind one of those ports
156 # and/or needs more client ports. Try waiting short time
157 # See comments at top re system configuration.
158 time.sleep(5)
159
160 resfile.close()
161
162
163 TheParamTbl = [
164 RunParam('runs', 'num-runs', [50000]),
165 RunParam('protocol', 'protocol', ['tcp','udp']),
166 RunParam('intepoll', 'intepoll', [0,1]),
167 RunParam('ports', 'numports', [1, 100, 10000]),
168 RunParam('listen', 'listen', [1,0]),
169 RunParam('thread', 'thread-type', ['common','intr','epoll','fdset']),
170 ]
171
172 RunParamTbl(TheParamTbl)

Properties

Name Value
svn:executable *

webmaster AT resiprocate DOT org
ViewVC Help
Powered by ViewVC 1.1.27