Subclass Benchmark Runner script for WebDriver support
[WebKit-https.git] / Tools / Scripts / webkitpy / benchmark_runner / webserver_benchmark_runner.py
1 #!/usr/bin/env python
2
3 import json
4 import logging
5 import urlparse
6
7 from benchmark_runner import BenchmarkRunner
8 from http_server_driver.http_server_driver_factory import HTTPServerDriverFactory
9 from utils import timeout
10
11
12 _log = logging.getLogger(__name__)
13
14
15 class WebServerBenchmarkRunner(BenchmarkRunner):
16     name = 'webserver'
17
18     def __init__(self, plan_file, local_copy, count_override, build_dir, output_file, platform, browser, scale_unit=True, device_id=None):
19         self._http_server_driver = HTTPServerDriverFactory.create(platform)
20         self._http_server_driver.set_device_id(device_id)
21         super(WebServerBenchmarkRunner, self).__init__(plan_file, local_copy, count_override, build_dir, output_file, platform, browser, scale_unit, device_id)
22
23     def _get_result(self, test_url):
24         result = self._browser_driver.add_additional_results(test_url, self._http_server_driver.fetch_result())
25         assert(not self._http_server_driver.get_return_code())
26         return result
27
28     def _run_one_test(self, web_root, test_file):
29         result = None
30         try:
31             self._http_server_driver.serve(web_root)
32             url = urlparse.urljoin(self._http_server_driver.base_url(), self._plan_name + '/' + test_file)
33             self._browser_driver.launch_url(url, self._plan['options'], self._build_dir)
34             with timeout(self._plan['timeout']):
35                 result = self._get_result(url)
36         finally:
37             self._browser_driver.close_browsers()
38             self._http_server_driver.kill_server()
39
40         return json.loads(result)