OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
3 # Use of this source code is governed by a BSD-style license that can be | |
4 # found in the LICENSE file. | |
5 import os | |
6 import re | |
7 import sys | |
8 | |
9 sys.path.append(os.path.join(os.path.dirname(__file__), '..')) | |
10 | |
11 from telemetry.core import browser_finder | |
12 from telemetry.core import browser_options | |
13 | |
14 def Main(args): | |
15 options = browser_options.BrowserOptions() | |
16 parser = options.CreateParser('rendering_microbenchmark_test.py <sitelist>') | |
17 # TODO(nduca): Add test specific options here, if any. | |
18 options, args = parser.parse_args(args) | |
19 if len(args) != 1: | |
20 parser.print_usage() | |
21 return 255 | |
22 | |
23 urls = [] | |
24 with open(args[0], 'r') as f: | |
25 for url in f.readlines(): | |
26 url = url.strip() | |
27 if not re.match('(.+)://', url): | |
28 url = 'http://%s' % url | |
29 urls.append(url) | |
30 | |
31 options.extra_browser_args.append('--enable-gpu-benchmarking') | |
32 browser_to_create = browser_finder.FindBrowser(options) | |
33 if not browser_to_create: | |
34 sys.stderr.write('No browser found! Supported types: %s' % | |
35 browser_finder.GetAllAvailableBrowserTypes(options)) | |
36 return 255 | |
37 with browser_to_create.Create() as b: | |
38 tab = b.tabs[0] | |
39 # Check browser for benchmark API. Can only be done on non-chrome URLs. | |
40 tab.Navigate('http://www.google.com') | |
41 import time | |
42 time.sleep(2) | |
43 tab.WaitForDocumentReadyStateToBeComplete() | |
44 if tab.EvaluateJavaScript('window.chrome.gpuBenchmarking === undefined'): | |
45 print 'Browser does not support gpu benchmarks API.' | |
46 return 255 | |
47 | |
48 if tab.EvaluateJavaScript( | |
49 'window.chrome.gpuBenchmarking.runRenderingBenchmarks === undefined'): | |
50 print 'Browser does not support rendering benchmarks API.' | |
51 return 255 | |
52 | |
53 # Run the test. :) | |
54 first_line = [] | |
55 def DumpResults(url, results): | |
56 if len(first_line) == 0: | |
57 cols = ['url'] | |
58 for r in results: | |
59 cols.append(r['benchmark']) | |
60 print ','.join(cols) | |
61 first_line.append(0) | |
62 cols = [url] | |
63 for r in results: | |
64 cols.append(str(r['result'])) | |
65 print ','.join(cols) | |
66 | |
67 for u in urls: | |
68 tab.Navigate(u) | |
69 tab.WaitForDocumentReadyStateToBeInteractiveOrBetter() | |
70 results = tab.EvaluateJavaScript( | |
71 'window.chrome.gpuBenchmarking.runRenderingBenchmarks();') | |
72 DumpResults(url, results) | |
73 | |
74 return 0 | |
75 | |
76 if __name__ == '__main__': | |
77 sys.exit(Main(sys.argv[1:])) | |
OLD | NEW |