framework_test.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. import importlib
  2. import os
  3. import subprocess
  4. import time
  5. import re
  6. import pprint
  7. import sys
  8. import traceback
  9. import json
  10. class FrameworkTest:
  11. ##########################################################################################
  12. # Class variables
  13. ##########################################################################################
  14. headers_template = "-H 'Host: localhost' -H '{accept}' -H 'Connection: keep-alive'"
  15. headers_full_template = "-H 'Host: localhost' -H '{accept}' -H 'Accept-Language: en-US,en;q=0.5' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) Gecko/20130501 Firefox/30.0 AppleWebKit/600.00 Chrome/30.0.0000.0 Trident/10.0 Safari/600.00' -H 'Cookie: uid=12345678901234567890; __utma=1.1234567890.1234567890.1234567890.1234567890.12; wd=2560x1600' -H 'Connection: keep-alive'"
  16. accept_json = "Accept: application/json,text/html;q=0.9,application/xhtml+xml;q=0.9,application/xml;q=0.8,*/*;q=0.7"
  17. accept_html = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
  18. accept_plaintext = "Accept: text/plain,text/html;q=0.9,application/xhtml+xml;q=0.9,application/xml;q=0.8,*/*;q=0.7"
  19. concurrency_template = """
  20. echo ""
  21. echo "---------------------------------------------------------"
  22. echo " Running Primer {name}"
  23. echo " {wrk} {headers} -d 5 -c 8 -t 8 \"http://{server_host}:{port}{url}\""
  24. echo "---------------------------------------------------------"
  25. echo ""
  26. {wrk} {headers} -d 5 -c 8 -t 8 "http://{server_host}:{port}{url}"
  27. sleep 5
  28. echo ""
  29. echo "---------------------------------------------------------"
  30. echo " Running Warmup {name}"
  31. echo " {wrk} {headers} -d {duration} -c {max_concurrency} -t {max_threads} \"http://{server_host}:{port}{url}\""
  32. echo "---------------------------------------------------------"
  33. echo ""
  34. {wrk} {headers} -d {duration} -c {max_concurrency} -t {max_threads} "http://{server_host}:{port}{url}"
  35. sleep 5
  36. for c in {interval}
  37. do
  38. echo ""
  39. echo "---------------------------------------------------------"
  40. echo " Concurrency: $c for {name}"
  41. echo " {wrk} {headers} {pipeline} -d {duration} -c $c -t $(($c>{max_threads}?{max_threads}:$c)) \"http://{server_host}:{port}{url}\""
  42. echo "---------------------------------------------------------"
  43. echo ""
  44. {wrk} {headers} {pipeline} -d {duration} -c "$c" -t "$(($c>{max_threads}?{max_threads}:$c))" http://{server_host}:{port}{url}
  45. sleep 2
  46. done
  47. """
  48. query_template = """
  49. echo ""
  50. echo "---------------------------------------------------------"
  51. echo " Running Primer {name}"
  52. echo " wrk {headers} -d 5 -c 8 -t 8 \"http://{server_host}:{port}{url}2\""
  53. echo "---------------------------------------------------------"
  54. echo ""
  55. wrk {headers} -d 5 -c 8 -t 8 "http://{server_host}:{port}{url}2"
  56. sleep 5
  57. echo ""
  58. echo "---------------------------------------------------------"
  59. echo " Running Warmup {name}"
  60. echo " wrk {headers} -d {duration} -c {max_concurrency} -t {max_threads} \"http://{server_host}:{port}{url}2\""
  61. echo "---------------------------------------------------------"
  62. echo ""
  63. wrk {headers} -d {duration} -c {max_concurrency} -t {max_threads} "http://{server_host}:{port}{url}2"
  64. sleep 5
  65. for c in {interval}
  66. do
  67. echo ""
  68. echo "---------------------------------------------------------"
  69. echo " Queries: $c for {name}"
  70. echo " wrk {headers} -d {duration} -c {max_concurrency} -t {max_threads} \"http://{server_host}:{port}{url}$c\""
  71. echo "---------------------------------------------------------"
  72. echo ""
  73. wrk {headers} -d {duration} -c {max_concurrency} -t {max_threads} "http://{server_host}:{port}{url}$c"
  74. sleep 2
  75. done
  76. """
  77. language = None
  78. platform = None
  79. webserver = None
  80. classification = None
  81. database = None
  82. approach = None
  83. orm = None
  84. framework = None
  85. os = None
  86. database_os = None
  87. display_name = None
  88. notes = None
  89. versus = None
  90. ############################################################
  91. # Test Variables
  92. ############################################################
  93. JSON = "JSON"
  94. DB = "DB"
  95. QUERY = "QUERY"
  96. FORTUNE = "FORTUNE"
  97. UPDATE = "UPDATE"
  98. PLAINTEXT = "PLAINTEXT"
  99. ##########################################################################################
  100. # Public Methods
  101. ##########################################################################################
  102. def validateJson(self, jsonString):
  103. obj = json.loads(jsonString)
  104. if not obj:
  105. return False
  106. if not obj.message:
  107. return False
  108. if not obj.message.lower() == "hello, world!":
  109. return False
  110. return True
  111. ############################################################
  112. # start(benchmarker)
  113. # Start the test using it's setup file
  114. ############################################################
  115. def start(self, out, err):
  116. return self.setup_module.start(self.benchmarker, out, err)
  117. ############################################################
  118. # End start
  119. ############################################################
  120. ############################################################
  121. # stop(benchmarker)
  122. # Stops the test using it's setup file
  123. ############################################################
  124. def stop(self, out, err):
  125. return self.setup_module.stop(out, err)
  126. ############################################################
  127. # End stop
  128. ############################################################
  129. ############################################################
  130. # verify_urls
  131. # Verifys each of the URLs for this test. THis will sinply
  132. # curl the URL and check for it's return status.
  133. # For each url, a flag will be set on this object for whether
  134. # or not it passed
  135. ############################################################
  136. def verify_urls(self, out, err):
  137. # JSON
  138. try:
  139. out.write( "VERIFYING JSON (" + self.json_url + ") ...\n" )
  140. out.flush()
  141. url = self.benchmarker.generate_url(self.json_url, self.port)
  142. output = self.__curl_url(url, self.JSON, out, err)
  143. if self.validateJson(output):
  144. self.json_url_passed = True
  145. else:
  146. self.json_url_passed = False
  147. except (AttributeError, subprocess.CalledProcessError) as e:
  148. self.json_url_passed = False
  149. # DB
  150. try:
  151. out.write( "VERIFYING DB (" + self.db_url + ") ...\n" )
  152. out.flush()
  153. url = self.benchmarker.generate_url(self.db_url, self.port)
  154. output = self.__curl_url(url, self.DB, out, err)
  155. self.db_url_passed = True
  156. except (AttributeError, subprocess.CalledProcessError) as e:
  157. self.db_url_passed = False
  158. # Query
  159. try:
  160. out.write( "VERIFYING Query (" + self.query_url + "2) ...\n" )
  161. out.flush()
  162. url = self.benchmarker.generate_url(self.query_url + "2", self.port)
  163. output = self.__curl_url(url, self.QUERY, out, err)
  164. self.query_url_passed = True
  165. except (AttributeError, subprocess.CalledProcessError) as e:
  166. self.query_url_passed = False
  167. # Fortune
  168. try:
  169. out.write( "VERIFYING Fortune (" + self.fortune_url + ") ...\n" )
  170. out.flush()
  171. url = self.benchmarker.generate_url(self.fortune_url, self.port)
  172. output = self.__curl_url(url, self.FORTUNE, out, err)
  173. self.fortune_url_passed = True
  174. except (AttributeError, subprocess.CalledProcessError) as e:
  175. self.fortune_url_passed = False
  176. # Update
  177. try:
  178. out.write( "VERIFYING Update (" + self.update_url + "2) ...\n" )
  179. out.flush()
  180. url = self.benchmarker.generate_url(self.update_url + "2", self.port)
  181. output = self.__curl_url(url, self.UPDATE, out, err)
  182. self.update_url_passed = True
  183. except (AttributeError, subprocess.CalledProcessError) as e:
  184. self.update_url_passed = False
  185. # plaintext
  186. try:
  187. out.write( "VERIFYING Plaintext (" + self.plaintext_url + ") ...\n" )
  188. out.flush()
  189. url = self.benchmarker.generate_url(self.plaintext_url, self.port)
  190. output = self.__curl_url(url, self.PLAINTEXT, out, err)
  191. self.plaintext_url_passed = True
  192. except (AttributeError, subprocess.CalledProcessError) as e:
  193. self.plaintext_url_passed = False
  194. ############################################################
  195. # End verify_urls
  196. ############################################################
  197. ############################################################
  198. # contains_type(type)
  199. # true if this test contains an implementation of the given
  200. # test type (json, db, etc.)
  201. ############################################################
  202. def contains_type(self, type):
  203. try:
  204. if type == 'json' and self.json_url != None:
  205. return True
  206. if type == 'db' and self.db_url != None:
  207. return True
  208. if type == 'query' and self.query_url != None:
  209. return True
  210. if type == 'fortune' and self.fortune_url != None:
  211. return True
  212. if type == 'update' and self.update_url != None:
  213. return True
  214. if type == 'plaintext' and self.plaintext_url != None:
  215. return True
  216. except AttributeError:
  217. pass
  218. return False
  219. ############################################################
  220. # End stop
  221. ############################################################
  222. ############################################################
  223. # benchmark
  224. # Runs the benchmark for each type of test that it implements
  225. # JSON/DB/Query.
  226. ############################################################
  227. def benchmark(self, out, err):
  228. # JSON
  229. try:
  230. if self.benchmarker.type == "all" or self.benchmarker.type == "json":
  231. out.write("BENCHMARKING JSON ... ")
  232. out.flush()
  233. if self.json_url_passed:
  234. remote_script = self.__generate_concurrency_script(self.json_url, self.port, self.accept_json)
  235. self.__run_benchmark(remote_script, self.benchmarker.output_file(self.name, 'json'), err)
  236. results = self.__parse_test('json')
  237. else:
  238. self.benchmarker.report_results(framework=self, test="json", results=results['results'])
  239. out.write( "Complete\n" )
  240. out.flush()
  241. except AttributeError:
  242. pass
  243. # DB
  244. try:
  245. if self.db_url_passed and (self.benchmarker.type == "all" or self.benchmarker.type == "db"):
  246. out.write("BENCHMARKING DB ... ")
  247. out.flush()
  248. remote_script = self.__generate_concurrency_script(self.db_url, self.port, self.accept_json)
  249. self.__run_benchmark(remote_script, self.benchmarker.output_file(self.name, 'db'), err)
  250. results = self.__parse_test('db')
  251. self.benchmarker.report_results(framework=self, test="db", results=results['results'])
  252. out.write( "Complete\n" )
  253. except AttributeError:
  254. traceback.print_exc()
  255. pass
  256. # Query
  257. try:
  258. if self.query_url_passed and (self.benchmarker.type == "all" or self.benchmarker.type == "query"):
  259. out.write("BENCHMARKING Query ... ")
  260. out.flush()
  261. remote_script = self.__generate_query_script(self.query_url, self.port, self.accept_json)
  262. self.__run_benchmark(remote_script, self.benchmarker.output_file(self.name, 'query'), err)
  263. results = self.__parse_test('query')
  264. self.benchmarker.report_results(framework=self, test="query", results=results['results'])
  265. out.write( "Complete\n" )
  266. out.flush()
  267. except AttributeError:
  268. traceback.print_exc()
  269. pass
  270. # fortune
  271. try:
  272. if self.fortune_url_passed and (self.benchmarker.type == "all" or self.benchmarker.type == "fortune"):
  273. out.write("BENCHMARKING Fortune ... ")
  274. out.flush()
  275. remote_script = self.__generate_concurrency_script(self.fortune_url, self.port, self.accept_html)
  276. self.__run_benchmark(remote_script, self.benchmarker.output_file(self.name, 'fortune'), err)
  277. results = self.__parse_test('fortune')
  278. self.benchmarker.report_results(framework=self, test="fortune", results=results['results'])
  279. out.write( "Complete\n" )
  280. out.flush()
  281. except AttributeError:
  282. traceback.print_exc()
  283. pass
  284. # update
  285. try:
  286. if self.update_url_passed and (self.benchmarker.type == "all" or self.benchmarker.type == "update"):
  287. out.write("BENCHMARKING Update ... ")
  288. out.flush()
  289. remote_script = self.__generate_query_script(self.update_url, self.port, self.accept_json)
  290. self.__run_benchmark(remote_script, self.benchmarker.output_file(self.name, 'update'), err)
  291. results = self.__parse_test('update')
  292. self.benchmarker.report_results(framework=self, test="update", results=results['results'])
  293. out.write( "Complete\n" )
  294. out.flush()
  295. except AttributeError:
  296. # TODO - this needs to report some logging
  297. traceback.print_exc()
  298. pass
  299. # plaintext
  300. try:
  301. if self.plaintext_url_passed and (self.benchmarker.type == "all" or self.benchmarker.type == "plaintext"):
  302. out.write("BENCHMARKING Plaintext ... ")
  303. out.flush()
  304. remote_script = self.__generate_concurrency_script(self.plaintext_url, self.port, self.accept_plaintext, wrk_command="wrk-pipeline", intervals=[256,1024,4096,16384], pipeline="--pipeline 16")
  305. self.__run_benchmark(remote_script, self.benchmarker.output_file(self.name, 'plaintext'), err)
  306. results = self.__parse_test('plaintext')
  307. self.benchmarker.report_results(framework=self, test="plaintext", results=results['results'])
  308. out.write( "Complete\n" )
  309. out.flush()
  310. except AttributeError:
  311. traceback.print_exc()
  312. pass
  313. ############################################################
  314. # End benchmark
  315. ############################################################
  316. ############################################################
  317. # parse_all
  318. # Method meant to be run for a given timestamp
  319. ############################################################
  320. def parse_all(self):
  321. # JSON
  322. if os.path.exists(self.benchmarker.output_file(self.name, 'json')):
  323. results = self.__parse_test('json')
  324. self.benchmarker.report_results(framework=self, test="json", results=results['results'])
  325. # DB
  326. if os.path.exists(self.benchmarker.output_file(self.name, 'db')):
  327. results = self.__parse_test('db')
  328. self.benchmarker.report_results(framework=self, test="db", results=results['results'])
  329. # Query
  330. if os.path.exists(self.benchmarker.output_file(self.name, 'query')):
  331. results = self.__parse_test('query')
  332. self.benchmarker.report_results(framework=self, test="query", results=results['results'])
  333. # Fortune
  334. if os.path.exists(self.benchmarker.output_file(self.name, 'fortune')):
  335. results = self.__parse_test('fortune')
  336. self.benchmarker.report_results(framework=self, test="fortune", results=results['results'])
  337. # Update
  338. if os.path.exists(self.benchmarker.output_file(self.name, 'update')):
  339. results = self.__parse_test('update')
  340. self.benchmarker.report_results(framework=self, test="update", results=results['results'])
  341. # Plaintext
  342. if os.path.exists(self.benchmarker.output_file(self.name, 'plaintext')):
  343. results = self.__parse_test('plaintext')
  344. self.benchmarker.report_results(framework=self, test="plaintext", results=results['results'])
  345. ############################################################
  346. # End parse_all
  347. ############################################################
  348. ############################################################
  349. # __parse_test(test_type)
  350. ############################################################
  351. def __parse_test(self, test_type):
  352. try:
  353. results = dict()
  354. results['results'] = []
  355. with open(self.benchmarker.output_file(self.name, test_type)) as raw_data:
  356. is_warmup = True
  357. rawData = None
  358. for line in raw_data:
  359. if "Queries:" in line or "Concurrency:" in line:
  360. is_warmup = False
  361. rawData = None
  362. continue
  363. if "Warmup" in line or "Primer" in line:
  364. is_warmup = True
  365. continue
  366. if not is_warmup:
  367. if rawData == None:
  368. rawData = dict()
  369. results['results'].append(rawData)
  370. #if "Requests/sec:" in line:
  371. # m = re.search("Requests/sec:\s+([0-9]+)", line)
  372. # rawData['reportedResults'] = m.group(1)
  373. # search for weighttp data such as succeeded and failed.
  374. if "Latency" in line:
  375. m = re.findall("([0-9]+\.*[0-9]*[us|ms|s|m|%]+)", line)
  376. if len(m) == 4:
  377. rawData['latencyAvg'] = m[0]
  378. rawData['latencyStdev'] = m[1]
  379. rawData['latencyMax'] = m[2]
  380. # rawData['latencyStdevPercent'] = m[3]
  381. #if "Req/Sec" in line:
  382. # m = re.findall("([0-9]+\.*[0-9]*[k|%]*)", line)
  383. # if len(m) == 4:
  384. # rawData['requestsAvg'] = m[0]
  385. # rawData['requestsStdev'] = m[1]
  386. # rawData['requestsMax'] = m[2]
  387. # rawData['requestsStdevPercent'] = m[3]
  388. #if "requests in" in line:
  389. # m = re.search("requests in ([0-9]+\.*[0-9]*[ms|s|m|h]+)", line)
  390. # if m != None:
  391. # # parse out the raw time, which may be in minutes or seconds
  392. # raw_time = m.group(1)
  393. # if "ms" in raw_time:
  394. # rawData['total_time'] = float(raw_time[:len(raw_time)-2]) / 1000.0
  395. # elif "s" in raw_time:
  396. # rawData['total_time'] = float(raw_time[:len(raw_time)-1])
  397. # elif "m" in raw_time:
  398. # rawData['total_time'] = float(raw_time[:len(raw_time)-1]) * 60.0
  399. # elif "h" in raw_time:
  400. # rawData['total_time'] = float(raw_time[:len(raw_time)-1]) * 3600.0
  401. if "requests in" in line:
  402. m = re.search("([0-9]+) requests in", line)
  403. if m != None:
  404. rawData['totalRequests'] = int(m.group(1))
  405. if "Socket errors" in line:
  406. if "connect" in line:
  407. m = re.search("connect ([0-9]+)", line)
  408. rawData['connect'] = int(m.group(1))
  409. if "read" in line:
  410. m = re.search("read ([0-9]+)", line)
  411. rawData['read'] = int(m.group(1))
  412. if "write" in line:
  413. m = re.search("write ([0-9]+)", line)
  414. rawData['write'] = int(m.group(1))
  415. if "timeout" in line:
  416. m = re.search("timeout ([0-9]+)", line)
  417. rawData['timeout'] = int(m.group(1))
  418. if "Non-2xx" in line:
  419. m = re.search("Non-2xx or 3xx responses: ([0-9]+)", line)
  420. if m != None:
  421. rawData['5xx'] = int(m.group(1))
  422. return results
  423. except IOError:
  424. return None
  425. ############################################################
  426. # End benchmark
  427. ############################################################
  428. ##########################################################################################
  429. # Private Methods
  430. ##########################################################################################
  431. ############################################################
  432. # __run_benchmark(script, output_file)
  433. # Runs a single benchmark using the script which is a bash
  434. # template that uses weighttp to run the test. All the results
  435. # outputed to the output_file.
  436. ############################################################
  437. def __run_benchmark(self, script, output_file, err):
  438. with open(output_file, 'w') as raw_file:
  439. p = subprocess.Popen(self.benchmarker.client_ssh_string.split(" "), stdin=subprocess.PIPE, stdout=raw_file, stderr=err)
  440. p.communicate(script)
  441. err.flush()
  442. ############################################################
  443. # End __run_benchmark
  444. ############################################################
  445. ############################################################
  446. # __generate_concurrency_script(url, port)
  447. # Generates the string containing the bash script that will
  448. # be run on the client to benchmark a single test. This
  449. # specifically works for the variable concurrency tests (JSON
  450. # and DB)
  451. ############################################################
  452. def __generate_concurrency_script(self, url, port, accept_header, wrk_command="wrk", intervals=[], pipeline=""):
  453. if len(intervals) == 0:
  454. intervals = self.benchmarker.concurrency_levels
  455. headers = self.__get_request_headers(accept_header)
  456. return self.concurrency_template.format(max_concurrency=self.benchmarker.max_concurrency,
  457. max_threads=self.benchmarker.max_threads, name=self.name, duration=self.benchmarker.duration,
  458. interval=" ".join("{}".format(item) for item in intervals),
  459. server_host=self.benchmarker.server_host, port=port, url=url, headers=headers, wrk=wrk_command,
  460. pipeline=pipeline)
  461. ############################################################
  462. # End __generate_concurrency_script
  463. ############################################################
  464. ############################################################
  465. # __generate_query_script(url, port)
  466. # Generates the string containing the bash script that will
  467. # be run on the client to benchmark a single test. This
  468. # specifically works for the variable query tests (Query)
  469. ############################################################
  470. def __generate_query_script(self, url, port, accept_header):
  471. headers = self.__get_request_headers(accept_header)
  472. return self.query_template.format(max_concurrency=self.benchmarker.max_concurrency,
  473. max_threads=self.benchmarker.max_threads, name=self.name, duration=self.benchmarker.duration,
  474. interval=" ".join("{}".format(item) for item in self.benchmarker.query_intervals),
  475. server_host=self.benchmarker.server_host, port=port, url=url, headers=headers)
  476. ############################################################
  477. # End __generate_query_script
  478. ############################################################
  479. ############################################################
  480. # __get_request_headers(accept_header)
  481. # Generates the complete HTTP header string
  482. ############################################################
  483. def __get_request_headers(self, accept_header):
  484. return self.headers_template.format(accept=accept_header)
  485. ############################################################
  486. # End __format_request_headers
  487. ############################################################
  488. ############################################################
  489. # __curl_url
  490. # Dump HTTP response and headers. Throw exception if there
  491. # is an HTTP error.
  492. ############################################################
  493. def __curl_url(self, url, testType, out, err):
  494. # Use -i to output response with headers.
  495. # Don't use -f so that the HTTP response code is ignored.
  496. # Use --stderr - to redirect stderr to stdout so we get
  497. # error output for sure in stdout.
  498. # Use -sS to hide progress bar, but show errors.
  499. subprocess.check_call(["curl", "-i", "-sS", url], stderr=err, stdout=out)
  500. out.flush()
  501. err.flush()
  502. # HTTP output may not end in a newline, so add that here.
  503. out.write( "\n" )
  504. out.flush()
  505. # We need to get the respond body from the curl and return it.
  506. p = subprocess.Popen(["curl", "-s", url], stdout=subprocess.PIPE)
  507. output = p.communicate()
  508. # In the curl invocation above we could not use -f because
  509. # then the HTTP response would not be output, so use -f in
  510. # an additional invocation so that if there is an HTTP error,
  511. # subprocess.CalledProcessError will be thrown. Note that this
  512. # uses check_output() instead of check_call() so that we can
  513. # ignore the HTTP response because we already output that in
  514. # the first curl invocation.
  515. subprocess.check_output(["curl", "-fsS", url], stderr=err)
  516. out.flush()
  517. err.flush()
  518. # HTTP output may not end in a newline, so add that here.
  519. out.write( "\n" )
  520. out.flush()
  521. if output:
  522. # We have the response body - return it
  523. return output[0]
  524. ##############################################################
  525. # End __curl_url
  526. ##############################################################
  527. ##########################################################################################
  528. # Constructor
  529. ##########################################################################################
  530. def __init__(self, name, directory, benchmarker, args):
  531. self.name = name
  532. self.directory = directory
  533. self.benchmarker = benchmarker
  534. self.__dict__.update(args)
  535. # ensure directory has __init__.py file so that we can use it as a Python package
  536. if not os.path.exists(os.path.join(directory, "__init__.py")):
  537. open(os.path.join(directory, "__init__.py"), 'w').close()
  538. self.setup_module = setup_module = importlib.import_module(directory + '.' + self.setup_file)
  539. ############################################################
  540. # End __init__
  541. ############################################################
  542. ############################################################
  543. # End FrameworkTest
  544. ############################################################
  545. ##########################################################################################
  546. # Static methods
  547. ##########################################################################################
  548. ##############################################################
  549. # parse_config(config, directory, benchmarker)
  550. # parses a config file and returns a list of FrameworkTest
  551. # objects based on that config file.
  552. ##############################################################
  553. def parse_config(config, directory, benchmarker):
  554. tests = []
  555. # The config object can specify multiple tests, we neep to loop
  556. # over them and parse them out
  557. for test in config['tests']:
  558. for key, value in test.iteritems():
  559. test_name = config['framework']
  560. # if the test uses the 'defualt' keywork, then we don't
  561. # append anything to it's name. All configs should only have 1 default
  562. if key != 'default':
  563. # we need to use the key in the test_name
  564. test_name = test_name + "-" + key
  565. tests.append(FrameworkTest(test_name, directory, benchmarker, value))
  566. return tests
  567. ##############################################################
  568. # End parse_config
  569. ##############################################################