framework_test.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  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 == self.JSON and self.json_url != None:
  205. return True
  206. if type == self.DB and self.db_url != None:
  207. return True
  208. if type == self.QUERY and self.query_url != None:
  209. return True
  210. if type == self.FORTUNE and self.fortune_url != None:
  211. return True
  212. if type == self.UPDATE and self.update_url != None:
  213. return True
  214. if type == self.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 == self.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, self.JSON), err)
  236. results = self.__parse_test(self.JSON)
  237. else:
  238. pass
  239. self.benchmarker.report_results(framework=self, test=self.JSON, results=results['results'])
  240. out.write( "Complete\n" )
  241. out.flush()
  242. except AttributeError:
  243. pass
  244. # DB
  245. try:
  246. if self.db_url_passed and (self.benchmarker.type == "all" or self.benchmarker.type == self.DB):
  247. out.write("BENCHMARKING DB ... ")
  248. out.flush()
  249. remote_script = self.__generate_concurrency_script(self.db_url, self.port, self.accept_json)
  250. self.__run_benchmark(remote_script, self.benchmarker.output_file(self.name, self.DB), err)
  251. results = self.__parse_test(self.DB)
  252. self.benchmarker.report_results(framework=self, test=self.DB, results=results['results'])
  253. out.write( "Complete\n" )
  254. except AttributeError:
  255. traceback.print_exc()
  256. pass
  257. # Query
  258. try:
  259. if self.query_url_passed and (self.benchmarker.type == "all" or self.benchmarker.type == self.QUERY):
  260. out.write("BENCHMARKING Query ... ")
  261. out.flush()
  262. remote_script = self.__generate_query_script(self.query_url, self.port, self.accept_json)
  263. self.__run_benchmark(remote_script, self.benchmarker.output_file(self.name, self.QUERY), err)
  264. results = self.__parse_test(self.QUERY)
  265. self.benchmarker.report_results(framework=self, test=self.QUERY, results=results['results'])
  266. out.write( "Complete\n" )
  267. out.flush()
  268. except AttributeError:
  269. traceback.print_exc()
  270. pass
  271. # fortune
  272. try:
  273. if self.fortune_url_passed and (self.benchmarker.type == "all" or self.benchmarker.type == self.FORTUNE):
  274. out.write("BENCHMARKING Fortune ... ")
  275. out.flush()
  276. remote_script = self.__generate_concurrency_script(self.fortune_url, self.port, self.accept_html)
  277. self.__run_benchmark(remote_script, self.benchmarker.output_file(self.name, self.FORTUNE), err)
  278. results = self.__parse_test(self.FORTUNE)
  279. self.benchmarker.report_results(framework=self, test=self.FORTUNE, results=results['results'])
  280. out.write( "Complete\n" )
  281. out.flush()
  282. except AttributeError:
  283. traceback.print_exc()
  284. pass
  285. # update
  286. try:
  287. if self.update_url_passed and (self.benchmarker.type == "all" or self.benchmarker.type == self.UPDATE):
  288. out.write("BENCHMARKING Update ... ")
  289. out.flush()
  290. remote_script = self.__generate_query_script(self.update_url, self.port, self.accept_json)
  291. self.__run_benchmark(remote_script, self.benchmarker.output_file(self.name, self.UPDATE), err)
  292. results = self.__parse_test(self.UPDATE)
  293. self.benchmarker.report_results(framework=self, test=self.UPDATE, results=results['results'])
  294. out.write( "Complete\n" )
  295. out.flush()
  296. except AttributeError:
  297. # TODO - this needs to report some logging
  298. traceback.print_exc()
  299. pass
  300. # plaintext
  301. try:
  302. if self.plaintext_url_passed and (self.benchmarker.type == "all" or self.benchmarker.type == self.PLAINTEXT):
  303. out.write("BENCHMARKING Plaintext ... ")
  304. out.flush()
  305. 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")
  306. self.__run_benchmark(remote_script, self.benchmarker.output_file(self.name, self.PLAINTEXT), err)
  307. results = self.__parse_test(self.PLAINTEXT)
  308. self.benchmarker.report_results(framework=self, test=self.PLAINTEXT, results=results['results'])
  309. out.write( "Complete\n" )
  310. out.flush()
  311. except AttributeError:
  312. traceback.print_exc()
  313. pass
  314. ############################################################
  315. # End benchmark
  316. ############################################################
  317. ############################################################
  318. # parse_all
  319. # Method meant to be run for a given timestamp
  320. ############################################################
  321. def parse_all(self):
  322. # JSON
  323. if os.path.exists(self.benchmarker.output_file(self.name, self.JSON)):
  324. results = self.__parse_test(self.JSON)
  325. self.benchmarker.report_results(framework=self, test=self.JSON, results=results['results'])
  326. # DB
  327. if os.path.exists(self.benchmarker.output_file(self.name, self.DB)):
  328. results = self.__parse_test(self.DB)
  329. self.benchmarker.report_results(framework=self, test=self.DB, results=results['results'])
  330. # Query
  331. if os.path.exists(self.benchmarker.output_file(self.name, self.QUERY)):
  332. results = self.__parse_test(self.QUERY)
  333. self.benchmarker.report_results(framework=self, test=self.QUERY, results=results['results'])
  334. # Fortune
  335. if os.path.exists(self.benchmarker.output_file(self.name, self.FORTUNE)):
  336. results = self.__parse_test(self.FORTUNE)
  337. self.benchmarker.report_results(framework=self, test=self.FORTUNE, results=results['results'])
  338. # Update
  339. if os.path.exists(self.benchmarker.output_file(self.name, self.UPDATE)):
  340. results = self.__parse_test(self.UPDATE)
  341. self.benchmarker.report_results(framework=self, test=self.UPDATE, results=results['results'])
  342. # Plaintext
  343. if os.path.exists(self.benchmarker.output_file(self.name, self.PLAINTEXT)):
  344. results = self.__parse_test(self.PLAINTEXT)
  345. self.benchmarker.report_results(framework=self, test=self.PLAINTEXT, results=results['results'])
  346. ############################################################
  347. # End parse_all
  348. ############################################################
  349. ############################################################
  350. # __parse_test(test_type)
  351. ############################################################
  352. def __parse_test(self, test_type):
  353. try:
  354. results = dict()
  355. results['results'] = []
  356. with open(self.benchmarker.output_file(self.name, test_type)) as raw_data:
  357. is_warmup = True
  358. rawData = None
  359. for line in raw_data:
  360. if "Queries:" in line or "Concurrency:" in line:
  361. is_warmup = False
  362. rawData = None
  363. continue
  364. if "Warmup" in line or "Primer" in line:
  365. is_warmup = True
  366. continue
  367. if not is_warmup:
  368. if rawData == None:
  369. rawData = dict()
  370. results['results'].append(rawData)
  371. #if "Requests/sec:" in line:
  372. # m = re.search("Requests/sec:\s+([0-9]+)", line)
  373. # rawData['reportedResults'] = m.group(1)
  374. # search for weighttp data such as succeeded and failed.
  375. if "Latency" in line:
  376. m = re.findall("([0-9]+\.*[0-9]*[us|ms|s|m|%]+)", line)
  377. if len(m) == 4:
  378. rawData['latencyAvg'] = m[0]
  379. rawData['latencyStdev'] = m[1]
  380. rawData['latencyMax'] = m[2]
  381. # rawData['latencyStdevPercent'] = m[3]
  382. #if "Req/Sec" in line:
  383. # m = re.findall("([0-9]+\.*[0-9]*[k|%]*)", line)
  384. # if len(m) == 4:
  385. # rawData['requestsAvg'] = m[0]
  386. # rawData['requestsStdev'] = m[1]
  387. # rawData['requestsMax'] = m[2]
  388. # rawData['requestsStdevPercent'] = m[3]
  389. #if "requests in" in line:
  390. # m = re.search("requests in ([0-9]+\.*[0-9]*[ms|s|m|h]+)", line)
  391. # if m != None:
  392. # # parse out the raw time, which may be in minutes or seconds
  393. # raw_time = m.group(1)
  394. # if "ms" in raw_time:
  395. # rawData['total_time'] = float(raw_time[:len(raw_time)-2]) / 1000.0
  396. # elif "s" in raw_time:
  397. # rawData['total_time'] = float(raw_time[:len(raw_time)-1])
  398. # elif "m" in raw_time:
  399. # rawData['total_time'] = float(raw_time[:len(raw_time)-1]) * 60.0
  400. # elif "h" in raw_time:
  401. # rawData['total_time'] = float(raw_time[:len(raw_time)-1]) * 3600.0
  402. if "requests in" in line:
  403. m = re.search("([0-9]+) requests in", line)
  404. if m != None:
  405. rawData['totalRequests'] = int(m.group(1))
  406. if "Socket errors" in line:
  407. if "connect" in line:
  408. m = re.search("connect ([0-9]+)", line)
  409. rawData['connect'] = int(m.group(1))
  410. if "read" in line:
  411. m = re.search("read ([0-9]+)", line)
  412. rawData['read'] = int(m.group(1))
  413. if "write" in line:
  414. m = re.search("write ([0-9]+)", line)
  415. rawData['write'] = int(m.group(1))
  416. if "timeout" in line:
  417. m = re.search("timeout ([0-9]+)", line)
  418. rawData['timeout'] = int(m.group(1))
  419. if "Non-2xx" in line:
  420. m = re.search("Non-2xx or 3xx responses: ([0-9]+)", line)
  421. if m != None:
  422. rawData['5xx'] = int(m.group(1))
  423. return results
  424. except IOError:
  425. return None
  426. ############################################################
  427. # End benchmark
  428. ############################################################
  429. ##########################################################################################
  430. # Private Methods
  431. ##########################################################################################
  432. ############################################################
  433. # __run_benchmark(script, output_file)
  434. # Runs a single benchmark using the script which is a bash
  435. # template that uses weighttp to run the test. All the results
  436. # outputed to the output_file.
  437. ############################################################
  438. def __run_benchmark(self, script, output_file, err):
  439. with open(output_file, 'w') as raw_file:
  440. p = subprocess.Popen(self.benchmarker.client_ssh_string.split(" "), stdin=subprocess.PIPE, stdout=raw_file, stderr=err)
  441. p.communicate(script)
  442. err.flush()
  443. ############################################################
  444. # End __run_benchmark
  445. ############################################################
  446. ############################################################
  447. # __generate_concurrency_script(url, port)
  448. # Generates the string containing the bash script that will
  449. # be run on the client to benchmark a single test. This
  450. # specifically works for the variable concurrency tests (JSON
  451. # and DB)
  452. ############################################################
  453. def __generate_concurrency_script(self, url, port, accept_header, wrk_command="wrk", intervals=[], pipeline=""):
  454. if len(intervals) == 0:
  455. intervals = self.benchmarker.concurrency_levels
  456. headers = self.__get_request_headers(accept_header)
  457. return self.concurrency_template.format(max_concurrency=self.benchmarker.max_concurrency,
  458. max_threads=self.benchmarker.max_threads, name=self.name, duration=self.benchmarker.duration,
  459. interval=" ".join("{}".format(item) for item in intervals),
  460. server_host=self.benchmarker.server_host, port=port, url=url, headers=headers, wrk=wrk_command,
  461. pipeline=pipeline)
  462. ############################################################
  463. # End __generate_concurrency_script
  464. ############################################################
  465. ############################################################
  466. # __generate_query_script(url, port)
  467. # Generates the string containing the bash script that will
  468. # be run on the client to benchmark a single test. This
  469. # specifically works for the variable query tests (Query)
  470. ############################################################
  471. def __generate_query_script(self, url, port, accept_header):
  472. headers = self.__get_request_headers(accept_header)
  473. return self.query_template.format(max_concurrency=self.benchmarker.max_concurrency,
  474. max_threads=self.benchmarker.max_threads, name=self.name, duration=self.benchmarker.duration,
  475. interval=" ".join("{}".format(item) for item in self.benchmarker.query_intervals),
  476. server_host=self.benchmarker.server_host, port=port, url=url, headers=headers)
  477. ############################################################
  478. # End __generate_query_script
  479. ############################################################
  480. ############################################################
  481. # __get_request_headers(accept_header)
  482. # Generates the complete HTTP header string
  483. ############################################################
  484. def __get_request_headers(self, accept_header):
  485. return self.headers_template.format(accept=accept_header)
  486. ############################################################
  487. # End __format_request_headers
  488. ############################################################
  489. ############################################################
  490. # __curl_url
  491. # Dump HTTP response and headers. Throw exception if there
  492. # is an HTTP error.
  493. ############################################################
  494. def __curl_url(self, url, testType, out, err):
  495. # Use -i to output response with headers.
  496. # Don't use -f so that the HTTP response code is ignored.
  497. # Use --stderr - to redirect stderr to stdout so we get
  498. # error output for sure in stdout.
  499. # Use -sS to hide progress bar, but show errors.
  500. subprocess.check_call(["curl", "-i", "-sS", url], stderr=err, stdout=out)
  501. out.flush()
  502. err.flush()
  503. # HTTP output may not end in a newline, so add that here.
  504. out.write( "\n" )
  505. out.flush()
  506. # We need to get the respond body from the curl and return it.
  507. p = subprocess.Popen(["curl", "-s", url], stdout=subprocess.PIPE)
  508. output = p.communicate()
  509. # In the curl invocation above we could not use -f because
  510. # then the HTTP response would not be output, so use -f in
  511. # an additional invocation so that if there is an HTTP error,
  512. # subprocess.CalledProcessError will be thrown. Note that this
  513. # uses check_output() instead of check_call() so that we can
  514. # ignore the HTTP response because we already output that in
  515. # the first curl invocation.
  516. subprocess.check_output(["curl", "-fsS", url], stderr=err)
  517. out.flush()
  518. err.flush()
  519. # HTTP output may not end in a newline, so add that here.
  520. out.write( "\n" )
  521. out.flush()
  522. if output:
  523. # We have the response body - return it
  524. return output[0]
  525. ##############################################################
  526. # End __curl_url
  527. ##############################################################
  528. ##########################################################################################
  529. # Constructor
  530. ##########################################################################################
  531. def __init__(self, name, directory, benchmarker, args):
  532. self.name = name
  533. self.directory = directory
  534. self.benchmarker = benchmarker
  535. self.__dict__.update(args)
  536. # ensure directory has __init__.py file so that we can use it as a Python package
  537. if not os.path.exists(os.path.join(directory, "__init__.py")):
  538. open(os.path.join(directory, "__init__.py"), 'w').close()
  539. self.setup_module = setup_module = importlib.import_module(directory + '.' + self.setup_file)
  540. ############################################################
  541. # End __init__
  542. ############################################################
  543. ############################################################
  544. # End FrameworkTest
  545. ############################################################
  546. ##########################################################################################
  547. # Static methods
  548. ##########################################################################################
  549. ##############################################################
  550. # parse_config(config, directory, benchmarker)
  551. # parses a config file and returns a list of FrameworkTest
  552. # objects based on that config file.
  553. ##############################################################
  554. def parse_config(config, directory, benchmarker):
  555. tests = []
  556. # The config object can specify multiple tests, we neep to loop
  557. # over them and parse them out
  558. for test in config['tests']:
  559. for key, value in test.iteritems():
  560. test_name = config['framework']
  561. # if the test uses the 'defualt' keywork, then we don't
  562. # append anything to it's name. All configs should only have 1 default
  563. if key != 'default':
  564. # we need to use the key in the test_name
  565. test_name = test_name + "-" + key
  566. tests.append(FrameworkTest(test_name, directory, benchmarker, value))
  567. return tests
  568. ##############################################################
  569. # End parse_config
  570. ##############################################################