tester.py 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. #
  2. # Copyright (C) 2015-2017 Savoir-faire Linux Inc.
  3. #
  4. # Author: Eloi Bail <eloi.bail@savoirfairelinux.com>
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. #
  20. import sys
  21. import os
  22. import time
  23. try:
  24. import configparser
  25. except ImportError as e:
  26. import ConfigParser as configparser
  27. except Exception as e:
  28. print(str(e))
  29. exit(1)
  30. from threading import Thread
  31. from random import shuffle
  32. from errors import *
  33. ALL_TEST_NAME = {
  34. 'TestConfig': 'testConfig',
  35. 'LoopCallDht': 'testLoopCallDht',
  36. 'VideoBitrateDHT': 'testLoopCallDhtWithIncBitrate',
  37. 'SimultenousDHTCall' : 'testSimultaneousLoopCallDht',
  38. 'DhtCallHold' : 'testLoopCallDhtWithHold'
  39. }
  40. class DRingTester():
  41. # init to default values
  42. dhtAccountId = ''
  43. sipAccountId = ''
  44. dhtTestAccount = ''
  45. sipTestAccount = ''
  46. inputFile = ''
  47. minBitrate = 0
  48. maxBitrate = 0
  49. incBitrate = 0
  50. codecAudio = ''
  51. codecVideo = ''
  52. def testConfig(self, ctrl):
  53. print("**[BEGIN] test config")
  54. allCodecs = ctrl.getAllCodecs()
  55. if len(allCodecs) == 0:
  56. print("error no codec on the system")
  57. return 0
  58. print("**[SUCCESS] test config")
  59. print("**[END] test config")
  60. return 1
  61. #
  62. # Helpers
  63. #
  64. def getTestName(self):
  65. return ALL_TEST_NAME.keys()
  66. def checkIP2IPAccount(self, ctrl):
  67. ipAccount = ctrl.getAllAccounts()
  68. print(ipAccount)
  69. if len(ipAccount) == 0:
  70. print("no IP2IP account")
  71. return 0
  72. return 1
  73. def registerAccount(self, ctrl, account):
  74. print("registering:" + account)
  75. ctrl.setAccountRegistered(account, True)
  76. def setActiveCodecs(self, ctrl, account):
  77. codecList = ctrl.getAllCodecs()
  78. shuffle(codecList)
  79. codecVideoId = codecAudioId = 0
  80. nameCodecAudio = nameCodecVideo = ''
  81. if (self.codecVideo == 'H264'):
  82. codecVideoId = 1
  83. nameCodecVideo = 'H264'
  84. elif (self.codecVideo == 'VP8'):
  85. codecVideoId = 2
  86. nameCodecVideo = 'VP8'
  87. elif (self.codecVideo == 'MPEG4'):
  88. codecVideoId = 3
  89. nameCodecVideo = 'MPEG4'
  90. elif (self.codecVideo == 'H263'):
  91. codecVideoId = 4
  92. nameCodecVideo = 'H263'
  93. elif (self.codecVideo == 'RANDOM'):
  94. for aCodec in codecList:
  95. detail = ctrl.getCodecDetails(account, aCodec)
  96. if ( detail['CodecInfo.type'] == 'VIDEO'):
  97. codecVideoId = aCodec
  98. nameCodecVideo = detail['CodecInfo.name']
  99. break
  100. if (self.codecAudio == 'OPUS'):
  101. codecAudioId = 5
  102. nameCodecAudio = 'OPUS'
  103. if (self.codecAudio == 'G722'):
  104. codecAudioId = 6
  105. nameCodecAudio = 'G722'
  106. if (self.codecAudio == 'SPEEX32'):
  107. codecAudioId = 7
  108. nameCodecAudio = 'SPEEX32'
  109. elif (self.codecAudio == 'SPEEX16'):
  110. codecAudioId = 8
  111. nameCodecAudio = 'SPEEX16'
  112. elif (self.codecAudio == 'SPEEX8'):
  113. codecAudioId = 9
  114. nameCodecAudio = 'SPEEX8'
  115. elif (self.codecAudio == 'PCMA'):
  116. codecAudioId = 10
  117. nameCodecAudio = 'PCMA'
  118. elif (self.codecAudio == 'PCMU'):
  119. codecAudioId = 11
  120. nameCodecAudio = 'PCMU'
  121. elif (self.codecAudio == 'RANDOM'):
  122. for aCodec in codecList:
  123. detail = ctrl.getCodecDetails(account, aCodec)
  124. if ( detail['CodecInfo.type'] == 'AUDIO'):
  125. codecAudioId = aCodec
  126. nameCodecAudio = detail['CodecInfo.name']
  127. break
  128. if (codecAudioId == 0 or codecVideoId == 0):
  129. print ("please configure at least one A/V codec !")
  130. return
  131. print ("selecting codecs audio= "+nameCodecAudio + " video= "+nameCodecVideo)
  132. ctrl.setActiveCodecList(account, (str(codecVideoId)+","+ str(codecAudioId)))
  133. def holdToggle(self, ctrl, callId, delay):
  134. time.sleep(delay)
  135. print("Holding: " + callId)
  136. ctrl.Hold(callId)
  137. time.sleep(delay)
  138. print("UnHolding: " + callId)
  139. ctrl.UnHold(callId)
  140. #
  141. # tests
  142. #
  143. # testLoopCallDht
  144. # perform <nbIteration> DHT calls using <delay> between each call
  145. def testLoopCallDht(self, ctrl, nbIteration, delay):
  146. print("**[BEGIN] DHT Call Test")
  147. count = 0
  148. currBitrate = self.minBitrate
  149. while count < nbIteration:
  150. print("[%s/%s]" % (count, nbIteration))
  151. self.setActiveCodecs(ctrl, self.dhtAccountId)
  152. print("setting video bitrate to "+str(currBitrate))
  153. ctrl.setVideoCodecBitrate(self.dhtAccountId, currBitrate)
  154. callId = ctrl.Call(self.dhtTestAccount)
  155. # switch to file input
  156. ctrl.switchInput(callId,'file://'+self.inputFile)
  157. time.sleep(delay)
  158. ctrl.HangUp(callId)
  159. count += 1
  160. print("**[SUCCESS] DHT Call Test")
  161. print("**[END] DHT Call Test")
  162. # testLoopCallDhtWithHold
  163. # perform <nbIteration> DHT calls using <delay> between each call
  164. # perform stress hold/unhold between each call
  165. def testLoopCallDhtWithHold(self, ctrl, nbIteration, delay):
  166. print("**[BEGIN] DHT Call Test With Hold")
  167. count = 0
  168. while count < nbIteration:
  169. print("[%s/%s]" % (count, nbIteration))
  170. self.setActiveCodecs(ctrl, self.dhtAccountId)
  171. callId = ctrl.Call(self.dhtTestAccount)
  172. # switch to file input
  173. ctrl.switchInput(callId,'file://'+self.inputFile)
  174. delayHold = 5
  175. nbHold = delay / (delayHold * 2)
  176. countHold = 0
  177. while countHold < nbHold:
  178. self.holdToggle(ctrl, callId, delayHold)
  179. countHold = countHold + 1
  180. ctrl.HangUp(callId)
  181. count += 1
  182. print("**[SUCCESS] DHT Call Test With Hold")
  183. print("**[END] DHT Call Test With Hold")
  184. # testLoopCallDhtWithIncBitrate
  185. # perform <nbIteration> DHT calls using <delay> between each call
  186. # inc bitrate between each iteration
  187. def testLoopCallDhtWithIncBitrate(self, ctrl, nbIteration, delay):
  188. print("**[BEGIN] VIDEO Bitrate Test")
  189. count = 0
  190. currBitrate = self.minBitrate
  191. while count < nbIteration:
  192. print("[%s/%s]" % (count, nbIteration))
  193. self.setActiveCodecs(ctrl, self.dhtAccountId)
  194. print("setting video bitrate to "+str(currBitrate))
  195. ctrl.setVideoCodecBitrate(self.dhtAccountId, currBitrate)
  196. callId = ctrl.Call(self.dhtTestAccount)
  197. # switch to file input
  198. ctrl.switchInput(callId,'file://'+self.inputFile)
  199. time.sleep(delay)
  200. ctrl.HangUp(callId)
  201. count += 1
  202. currBitrate += self.incBitrate
  203. if (currBitrate > self.maxBitrate):
  204. currBitrate = self.minBitrate
  205. print("**[SUCESS] VIDEO Bitrate Test")
  206. print("**[END] VIDEO Bitrate Test")
  207. # testSimultaneousLoopCallDht
  208. # perform <nbIteration> simultaneous DHT calls using <delay> between each call
  209. def testSimultaneousLoopCallDht(self, ctrl, nbIteration, delay):
  210. print("**[BEGIN] Simultaneous DHT call test")
  211. count = 0
  212. while count < nbIteration:
  213. print("[%s/%s]" % (count, nbIteration))
  214. self.setActiveCodecs(ctrl, self.dhtAccountId)
  215. # do all the calls
  216. currCall = 0
  217. NB_SIMULTANEOUS_CALL = 10;
  218. while currCall <= NB_SIMULTANEOUS_CALL:
  219. ctrl.Call(self.dhtTestAccount)
  220. time.sleep(1)
  221. currCall = currCall + 1
  222. time.sleep(delay)
  223. # hangup each call
  224. for callId in ctrl.getAllCalls():
  225. ctrl.HangUp(callId)
  226. count += 1
  227. print("**[SUCESS] Simultaneous DHT call test")
  228. print("**[END] Simultaneous DHT call test")
  229. # Main function
  230. def start(self, ctrl, testName):
  231. if not testName in ALL_TEST_NAME:
  232. print(("wrong test name"))
  233. return
  234. #getConfig
  235. self.dhtAccountId = ctrl.getAllAccounts('RING')[0]
  236. self.sipAccountId = ctrl.getAllAccounts('SIP')[0]
  237. config = configparser.ConfigParser()
  238. config.read('test_config.ini')
  239. self.dhtTestAccount = str(config['dht']['testAccount'])
  240. self.sipTestAccount = str(config['sip']['testAccount'])
  241. self.inputFile = str(config['codec']['inputFile'])
  242. self.minBitrate = int(config['codec']['minBitrate'])
  243. self.maxBitrate = int(config['codec']['maxBitrate'])
  244. self.incBitrate = int(config['codec']['incBitrate'])
  245. self.codecAudio = str(config['codec']['codecAudio'])
  246. self.codecVideo = str(config['codec']['codecVideo'])
  247. testNbIteration = config['iteration']['nbIteration']
  248. delay = config['iteration']['delay']
  249. getattr(self, ALL_TEST_NAME[testName])(ctrl,int(testNbIteration), int(delay))