framework_test.py 26 KB

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