Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2015 The Chromium Authors. All rights reserved. | 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 | 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 import trace_test_expectations | 4 import trace_test_expectations |
| 5 import page_sets | 5 import page_sets |
| 6 | 6 |
| 7 from telemetry import benchmark | 7 from telemetry import benchmark |
| 8 from telemetry.page import page_test | 8 from telemetry.page import page_test |
| 9 from telemetry.core.platform import tracing_category_filter | 9 from telemetry.core.platform import tracing_category_filter |
| 10 from telemetry.core.platform import tracing_options | 10 from telemetry.core.platform import tracing_options |
| 11 from telemetry.timeline import model | 11 from telemetry.timeline import model as model_module |
| 12 | 12 |
| 13 TOPLEVEL_GL_CATEGORY = 'gpu_toplevel' | 13 TOPLEVEL_GL_CATEGORY = 'gpu_toplevel' |
| 14 TOPLEVEL_CATEGORIES = ['disabled-by-default-gpu.device', | 14 TOPLEVEL_SERVICE_CATEGORY = 'disabled-by-default-gpu.service' |
| 15 'disabled-by-default-gpu.service'] | 15 TOPLEVEL_DEVICE_CATEGORY = 'disabled-by-default-gpu.device' |
| 16 TOPLEVEL_CATEGORIES = [TOPLEVEL_SERVICE_CATEGORY, TOPLEVEL_DEVICE_CATEGORY] | |
| 16 | 17 |
| 17 test_harness_script = r""" | 18 test_harness_script = r""" |
| 18 var domAutomationController = {}; | 19 var domAutomationController = {}; |
| 19 | 20 |
| 20 domAutomationController._finished = false; | 21 domAutomationController._finished = false; |
| 21 | 22 |
| 22 domAutomationController.setAutomationId = function(id) {} | 23 domAutomationController.setAutomationId = function(id) {} |
| 23 | 24 |
| 24 domAutomationController.send = function(msg) { | 25 domAutomationController.send = function(msg) { |
| 25 domAutomationController._finished = true; | 26 domAutomationController._finished = true; |
| 26 } | 27 } |
| 27 | 28 |
| 28 window.domAutomationController = domAutomationController; | 29 window.domAutomationController = domAutomationController; |
| 29 """ | 30 """ |
| 30 | 31 |
| 31 class _TraceValidator(page_test.PageTest): | 32 |
| 33 class _TraceValidatorBase(page_test.PageTest): | |
| 34 def GetCategoryName(self): | |
| 35 raise NotImplementedError("GetCategoryName() Not implemented!") | |
| 36 | |
| 32 def ValidateAndMeasurePage(self, page, tab, results): | 37 def ValidateAndMeasurePage(self, page, tab, results): |
| 33 timeline_data = tab.browser.platform.tracing_controller.Stop() | 38 timeline_data = tab.browser.platform.tracing_controller.Stop() |
| 34 timeline_model = model.TimelineModel(timeline_data) | 39 timeline_model = model_module.TimelineModel(timeline_data) |
| 35 | 40 |
| 36 categories_set = set(TOPLEVEL_CATEGORIES) | 41 category_name = self.GetCategoryName() |
| 37 for event in timeline_model.IterAllEvents(): | 42 event_iter = timeline_model.IterAllEvents( |
| 38 if event.args.get('gl_category', None) == TOPLEVEL_GL_CATEGORY: | 43 event_type_predicate=model_module.IsSliceOrAsyncSlice) |
| 39 categories_set.discard(event.category) | 44 for event in event_iter: |
| 40 if not categories_set: | 45 if (event.args.get('gl_category', None) == TOPLEVEL_GL_CATEGORY and |
| 46 event.category == category_name): | |
| 41 break | 47 break |
| 42 else: | 48 else: |
| 43 raise page_test.Failure(self._FormatException(sorted(categories_set))) | 49 raise page_test.Failure(self._FormatException(category_name)) |
| 44 | 50 |
| 45 def CustomizeBrowserOptions(self, options): | 51 def CustomizeBrowserOptions(self, options): |
| 46 options.AppendExtraBrowserArgs('--enable-logging') | 52 options.AppendExtraBrowserArgs('--enable-logging') |
| 47 | 53 |
| 48 def WillNavigateToPage(self, page, tab): | 54 def WillNavigateToPage(self, page, tab): |
| 49 cat_string = ','.join(TOPLEVEL_CATEGORIES) | 55 cat_string = ','.join(TOPLEVEL_CATEGORIES) |
| 50 cat_filter = tracing_category_filter.TracingCategoryFilter(cat_string) | 56 cat_filter = tracing_category_filter.TracingCategoryFilter(cat_string) |
| 51 options = tracing_options.TracingOptions() | 57 options = tracing_options.TracingOptions() |
| 52 options.enable_chrome_trace = True | 58 options.enable_chrome_trace = True |
| 53 tab.browser.platform.tracing_controller.Start(options, cat_filter, 60) | 59 tab.browser.platform.tracing_controller.Start(options, cat_filter, 60) |
| 54 | 60 |
| 55 def _FormatException(self, categories): | 61 def _FormatException(self, category): |
| 56 return 'Trace markers for GPU categories were not found: %s' % categories | 62 return 'Trace markers for GPU category was not found: %s' % category |
| 57 | 63 |
| 58 class TraceTest(benchmark.Benchmark): | 64 |
| 59 """Tests GPU traces""" | 65 class _TraceValidator(_TraceValidatorBase): |
|
vmiura
2015/02/02 23:42:15
nit: "Service"TraceValidator, and similar in the o
David Yen
2015/02/02 23:52:46
I actually had this name originally, but I think a
| |
| 66 def GetCategoryName(self): | |
| 67 return TOPLEVEL_SERVICE_CATEGORY | |
| 68 | |
| 69 | |
| 70 class _DeviceTraceValidator(_TraceValidatorBase): | |
| 71 def GetCategoryName(self): | |
| 72 return TOPLEVEL_DEVICE_CATEGORY | |
| 73 | |
| 74 | |
| 75 class _TraceTestBase(benchmark.Benchmark): | |
| 76 """Base class for the trace tests.""" | |
| 77 def CreatePageSet(self, options): | |
| 78 # Utilize pixel tests page set as a set of simple pages to load. | |
| 79 page_set = page_sets.PixelTestsPageSet() | |
| 80 for page in page_set.pages: | |
| 81 page.script_to_evaluate_on_commit = test_harness_script | |
| 82 return page_set | |
| 83 | |
| 84 | |
| 85 class TraceTest(_TraceTestBase): | |
| 86 """Tests GPU traces are plumbed through properly.""" | |
| 60 test = _TraceValidator | 87 test = _TraceValidator |
| 61 | 88 |
| 62 @classmethod | 89 @classmethod |
| 63 def Name(cls): | 90 def Name(cls): |
| 64 return 'trace_test' | 91 return 'trace_test' |
| 65 | 92 |
| 66 def CreateExpectations(self): | 93 def CreateExpectations(self): |
| 67 return trace_test_expectations.TraceTestExpectations() | 94 return trace_test_expectations.TraceTestExpectations() |
| 68 | 95 |
| 69 def CreatePageSet(self, options): | 96 |
| 70 # Utilize pixel tests page set as a set of simple pages to load. | 97 class DeviceTraceTest(_TraceTestBase): |
| 71 page_set = page_sets.PixelTestsPageSet() | 98 """Tests GPU Device traces show up on devices that support it.""" |
| 72 for page in page_set.pages: | 99 test = _DeviceTraceValidator |
| 73 page.script_to_evaluate_on_commit = test_harness_script | 100 |
| 74 return page_set | 101 @classmethod |
| 102 def Name(cls): | |
| 103 return 'device_trace_test' | |
| 104 | |
| 105 def CreateExpectations(self): | |
| 106 return trace_test_expectations.DeviceTraceTestExpectations() | |
| OLD | NEW |