1 # Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4 import trace_test_expectations
7 from telemetry
import benchmark
8 from telemetry
.page
import page_test
9 from telemetry
.core
.platform
import tracing_category_filter
10 from telemetry
.core
.platform
import tracing_options
11 from telemetry
.timeline
import model
13 TOPLEVEL_GL_CATEGORY
= 'gpu_toplevel'
14 TOPLEVEL_CATEGORIES
= ['disabled-by-default-gpu.device',
15 'disabled-by-default-gpu.service']
17 test_harness_script
= r
"""
18 var domAutomationController = {};
20 domAutomationController._finished = false;
22 domAutomationController.setAutomationId = function(id) {}
24 domAutomationController.send = function(msg) {
25 domAutomationController._finished = true;
28 window.domAutomationController = domAutomationController;
31 class _TraceValidator(page_test
.PageTest
):
32 def ValidateAndMeasurePage(self
, page
, tab
, results
):
33 timeline_data
= tab
.browser
.platform
.tracing_controller
.Stop()
34 timeline_model
= model
.TimelineModel(timeline_data
)
36 categories_set
= set(TOPLEVEL_CATEGORIES
)
37 for event
in timeline_model
.IterAllEvents():
38 if event
.args
.get('gl_category', None) == TOPLEVEL_GL_CATEGORY
:
39 categories_set
.discard(event
.category
)
40 if not categories_set
:
43 raise page_test
.Failure(self
._FormatException
(sorted(categories_set
)))
45 def CustomizeBrowserOptions(self
, options
):
46 options
.AppendExtraBrowserArgs('--enable-logging')
48 def WillNavigateToPage(self
, page
, tab
):
49 cat_string
= ','.join(TOPLEVEL_CATEGORIES
)
50 cat_filter
= tracing_category_filter
.TracingCategoryFilter(cat_string
)
51 options
= tracing_options
.TracingOptions()
52 options
.enable_chrome_trace
= True
53 tab
.browser
.platform
.tracing_controller
.Start(options
, cat_filter
, 60)
55 def _FormatException(self
, categories
):
56 return 'Trace markers for GPU categories were not found: %s' % categories
58 class TraceTest(benchmark
.Benchmark
):
59 """Tests GPU traces"""
60 test
= _TraceValidator
66 def CreateExpectations(self
):
67 return trace_test_expectations
.TraceTestExpectations()
69 def CreatePageSet(self
, options
):
70 # Utilize pixel tests page set as a set of simple pages to load.
71 page_set
= page_sets
.PixelTestsPageSet()
72 for page
in page_set
.pages
:
73 page
.script_to_evaluate_on_commit
= test_harness_script