Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / test / gpu / gpu_tests / trace_test.py
blobd62d4ca379f149f5d3d019d5647c5f5f5c3e53e3
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 gpu_test_base
5 import page_sets
6 import trace_test_expectations
8 from telemetry.page import page_test
9 from telemetry.timeline import model as model_module
10 from telemetry.timeline import tracing_category_filter
11 from telemetry.timeline import tracing_options
13 TOPLEVEL_GL_CATEGORY = 'gpu_toplevel'
14 TOPLEVEL_SERVICE_CATEGORY = 'disabled-by-default-gpu.service'
15 TOPLEVEL_DEVICE_CATEGORY = 'disabled-by-default-gpu.device'
16 TOPLEVEL_CATEGORIES = [TOPLEVEL_SERVICE_CATEGORY, TOPLEVEL_DEVICE_CATEGORY]
18 test_harness_script = r"""
19 var domAutomationController = {};
21 domAutomationController._finished = false;
23 domAutomationController.setAutomationId = function(id) {}
25 domAutomationController.send = function(msg) {
26 domAutomationController._finished = true;
29 window.domAutomationController = domAutomationController;
30 """
33 class TraceValidatorBase(gpu_test_base.ValidatorBase):
34 def GetCategoryName(self):
35 raise NotImplementedError("GetCategoryName() Not implemented!")
37 def ValidateAndMeasurePage(self, page, tab, results):
38 timeline_data = tab.browser.platform.tracing_controller.Stop()
39 timeline_model = model_module.TimelineModel(timeline_data)
41 category_name = self.GetCategoryName()
42 event_iter = timeline_model.IterAllEvents(
43 event_type_predicate=model_module.IsSliceOrAsyncSlice)
44 for event in event_iter:
45 if (event.args.get('gl_category', None) == TOPLEVEL_GL_CATEGORY and
46 event.category == category_name):
47 break
48 else:
49 raise page_test.Failure(self._FormatException(category_name))
51 def CustomizeBrowserOptions(self, options):
52 options.AppendExtraBrowserArgs('--enable-logging')
54 def WillNavigateToPage(self, page, tab):
55 cat_string = ','.join(TOPLEVEL_CATEGORIES)
56 cat_filter = tracing_category_filter.TracingCategoryFilter(cat_string)
57 options = tracing_options.TracingOptions()
58 options.enable_chrome_trace = True
59 tab.browser.platform.tracing_controller.Start(options, cat_filter, 60)
61 def _FormatException(self, category):
62 return 'Trace markers for GPU category was not found: %s' % category
65 class _TraceValidator(TraceValidatorBase):
66 def GetCategoryName(self):
67 return TOPLEVEL_SERVICE_CATEGORY
70 class _DeviceTraceValidator(TraceValidatorBase):
71 def GetCategoryName(self):
72 return TOPLEVEL_DEVICE_CATEGORY
75 class TraceTestBase(gpu_test_base.TestBase):
76 """Base class for the trace tests."""
77 def CreateStorySet(self, options):
78 # Utilize pixel tests page set as a set of simple pages to load.
79 story_set = page_sets.PixelTestsStorySet(self.GetExpectations(),
80 base_name=self.name)
81 for story in story_set:
82 story.script_to_evaluate_on_commit = test_harness_script
83 return story_set
86 class TraceTest(TraceTestBase):
87 """Tests GPU traces are plumbed through properly."""
88 test = _TraceValidator
89 name = 'TraceTest'
91 @classmethod
92 def Name(cls):
93 return 'trace_test'
95 def _CreateExpectations(self):
96 return trace_test_expectations.TraceTestExpectations()
99 class DeviceTraceTest(TraceTestBase):
100 """Tests GPU Device traces show up on devices that support it."""
101 test = _DeviceTraceValidator
102 name = 'DeviceTraceTest'
104 @classmethod
105 def Name(cls):
106 return 'device_trace_test'
108 def _CreateExpectations(self):
109 return trace_test_expectations.DeviceTraceTestExpectations()