OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Runs Canvasmark HTML5, Canvas 2D rendering and javascript benchmark. | 5 """Runs Canvasmark HTML5, Canvas 2D rendering and javascript benchmark. |
6 | 6 |
7 CanvasMark tests the HTML5 <canvas> rendering performance for commonly used | 7 CanvasMark tests the HTML5 <canvas> rendering performance for commonly used |
8 operations in HTML5 games: bitmaps, canvas drawing, alpha blending, polygon | 8 operations in HTML5 games: bitmaps, canvas drawing, alpha blending, polygon |
9 fills, shadows and text functions. | 9 fills, shadows and text functions. |
10 """ | 10 """ |
11 | 11 |
12 import os | 12 import os |
13 | 13 |
| 14 from measurements import PageTestMeasurement |
14 from telemetry import benchmark | 15 from telemetry import benchmark |
15 from telemetry.page import page_set | 16 from telemetry.page import page_set |
16 from telemetry.page import page_test | |
17 from telemetry.value import scalar | 17 from telemetry.value import scalar |
18 | 18 |
19 | 19 |
20 class _CanvasMarkMeasurement(page_test.PageTest): | 20 class _CanvasMarkMeasurement(PageTestMeasurement): |
21 | 21 |
22 def WillNavigateToPage(self, page, tab): | 22 def WillNavigateToPage(self, page, tab): |
23 page.script_to_evaluate_on_commit = """ | 23 page.script_to_evaluate_on_commit = """ |
24 var __results = []; | 24 var __results = []; |
25 var __real_log = window.console.log; | 25 var __real_log = window.console.log; |
26 window.console.log = function(msg) { | 26 window.console.log = function(msg) { |
27 __results.push(msg); | 27 __results.push(msg); |
28 __real_log.apply(this, [msg]); | 28 __real_log.apply(this, [msg]); |
29 } | 29 } |
30 """ | 30 """ |
31 | 31 |
32 def ValidateAndMeasurePage(self, _, tab, results): | 32 def ValidateAndMeasurePage(self, page, tab, results): |
33 tab.WaitForJavaScriptExpression('__results.length == 8', 300) | 33 tab.WaitForJavaScriptExpression('__results.length == 8', 300) |
34 results_log = tab.EvaluateJavaScript('__results') | 34 results_log = tab.EvaluateJavaScript('__results') |
35 total = 0 | 35 total = 0 |
36 for output in results_log: | 36 for output in results_log: |
37 # Split the results into score and test name. | 37 # Split the results into score and test name. |
38 # results log e.g., "489 [Test 1 - Asteroids - Bitmaps]" | 38 # results log e.g., "489 [Test 1 - Asteroids - Bitmaps]" |
39 score_and_name = output.split(' [', 2) | 39 score_and_name = output.split(' [', 2) |
40 assert len(score_and_name) == 2, \ | 40 assert len(score_and_name) == 2, \ |
41 'Unexpected result format "%s"' % score_and_name | 41 'Unexpected result format "%s"' % score_and_name |
42 score = int(score_and_name[0]) | 42 score = int(score_and_name[0]) |
43 name = score_and_name[1][:-1] | 43 name = score_and_name[1][:-1] |
44 results.AddValue(scalar.ScalarValue( | 44 results.AddValue(scalar.ScalarValue( |
45 results.current_page, name, 'score', score, important=False)) | 45 results.current_page, name, 'score', score, important=False)) |
46 # Aggregate total score for all tests. | 46 # Aggregate total score for all tests. |
47 total += score | 47 total += score |
48 results.AddValue(scalar.ScalarValue( | 48 results.AddValue(scalar.ScalarValue( |
49 results.current_page, 'Score', 'score', total)) | 49 results.current_page, 'Score', 'score', total)) |
50 | 50 |
| 51 super(_CanvasMarkMeasurement, self).ValidateAndMeasurePage( |
| 52 page, tab, results) |
51 | 53 |
52 @benchmark.Disabled | 54 @benchmark.Disabled |
53 class CanvasMark(benchmark.Benchmark): | 55 class CanvasMark(benchmark.Benchmark): |
54 test = _CanvasMarkMeasurement | 56 test = _CanvasMarkMeasurement |
55 | 57 |
56 def CreatePageSet(self, options): | 58 def CreatePageSet(self, options): |
57 ps = page_set.PageSet( | 59 ps = page_set.PageSet( |
58 file_path=os.path.abspath(__file__), | 60 file_path=os.path.abspath(__file__), |
59 archive_data_file='../page_sets/data/canvasmark.json', | 61 archive_data_file='../page_sets/data/canvasmark.json', |
60 make_javascript_deterministic=False) | 62 make_javascript_deterministic=False) |
61 ps.AddPageWithDefaultRunNavigate( | 63 ps.AddPageWithDefaultRunNavigate( |
62 'http://www.kevs3d.co.uk/dev/canvasmark/?auto=true') | 64 'http://www.kevs3d.co.uk/dev/canvasmark/?auto=true') |
63 return ps | 65 return ps |
OLD | NEW |