| OLD | NEW |
| (Empty) |
| 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 from gpu_tests import gpu_test_base | |
| 5 from gpu_tests import trace_test_expectations | |
| 6 import page_sets | |
| 7 | |
| 8 from telemetry.page import legacy_page_test | |
| 9 from telemetry.timeline import model as model_module | |
| 10 from telemetry.timeline import tracing_config | |
| 11 | |
| 12 TOPLEVEL_GL_CATEGORY = 'gpu_toplevel' | |
| 13 TOPLEVEL_SERVICE_CATEGORY = 'disabled-by-default-gpu.service' | |
| 14 TOPLEVEL_DEVICE_CATEGORY = 'disabled-by-default-gpu.device' | |
| 15 TOPLEVEL_CATEGORIES = [TOPLEVEL_SERVICE_CATEGORY, TOPLEVEL_DEVICE_CATEGORY] | |
| 16 | |
| 17 test_harness_script = r""" | |
| 18 var domAutomationController = {}; | |
| 19 | |
| 20 domAutomationController._finished = false; | |
| 21 | |
| 22 domAutomationController.setAutomationId = function(id) {} | |
| 23 | |
| 24 domAutomationController.send = function(msg) { | |
| 25 // Issue a read pixel to synchronize the gpu process to ensure | |
| 26 // the asynchronous category enabling is finished. | |
| 27 var temp_canvas = document.createElement("canvas") | |
| 28 temp_canvas.width = 1; | |
| 29 temp_canvas.height = 1; | |
| 30 var temp_gl = temp_canvas.getContext("experimental-webgl") || | |
| 31 temp_canvas.getContext("webgl"); | |
| 32 if (temp_gl) { | |
| 33 temp_gl.clear(temp_gl.COLOR_BUFFER_BIT); | |
| 34 var id = new Uint8Array(4); | |
| 35 temp_gl.readPixels(0, 0, 1, 1, temp_gl.RGBA, temp_gl.UNSIGNED_BYTE, id); | |
| 36 } else { | |
| 37 console.log('Failed to get WebGL context.'); | |
| 38 } | |
| 39 | |
| 40 domAutomationController._finished = true; | |
| 41 } | |
| 42 | |
| 43 window.domAutomationController = domAutomationController; | |
| 44 """ | |
| 45 | |
| 46 | |
| 47 class TraceValidatorBase(gpu_test_base.ValidatorBase): | |
| 48 def GetCategoryName(self): | |
| 49 raise NotImplementedError("GetCategoryName() Not implemented!") | |
| 50 | |
| 51 def ValidateAndMeasurePage(self, page, tab, results): | |
| 52 timeline_data = tab.browser.platform.tracing_controller.StopTracing() | |
| 53 timeline_model = model_module.TimelineModel(timeline_data) | |
| 54 | |
| 55 category_name = self.GetCategoryName() | |
| 56 event_iter = timeline_model.IterAllEvents( | |
| 57 event_type_predicate=model_module.IsSliceOrAsyncSlice) | |
| 58 for event in event_iter: | |
| 59 if (event.args.get('gl_category', None) == TOPLEVEL_GL_CATEGORY and | |
| 60 event.category == category_name): | |
| 61 break | |
| 62 else: | |
| 63 raise legacy_page_test.Failure(self._FormatException(category_name)) | |
| 64 | |
| 65 def CustomizeBrowserOptions(self, options): | |
| 66 options.AppendExtraBrowserArgs('--enable-logging') | |
| 67 options.AppendExtraBrowserArgs('--enable-experimental-canvas-features') | |
| 68 | |
| 69 def WillNavigateToPage(self, page, tab): | |
| 70 config = tracing_config.TracingConfig() | |
| 71 config.chrome_trace_config.category_filter.AddExcludedCategory('*') | |
| 72 for cat in TOPLEVEL_CATEGORIES: | |
| 73 config.chrome_trace_config.category_filter.AddDisabledByDefault( | |
| 74 cat) | |
| 75 config.enable_chrome_trace = True | |
| 76 tab.browser.platform.tracing_controller.StartTracing(config, 60) | |
| 77 | |
| 78 def _FormatException(self, category): | |
| 79 return 'Trace markers for GPU category was not found: %s' % category | |
| 80 | |
| 81 | |
| 82 class _TraceValidator(TraceValidatorBase): | |
| 83 def GetCategoryName(self): | |
| 84 return TOPLEVEL_SERVICE_CATEGORY | |
| 85 | |
| 86 | |
| 87 class _DeviceTraceValidator(TraceValidatorBase): | |
| 88 def GetCategoryName(self): | |
| 89 return TOPLEVEL_DEVICE_CATEGORY | |
| 90 | |
| 91 | |
| 92 class TraceTestBase(gpu_test_base.TestBase): | |
| 93 """Base class for the trace tests.""" | |
| 94 def CreateStorySet(self, options): | |
| 95 # Utilize pixel tests page set as a set of simple pages to load. | |
| 96 story_set = page_sets.PixelTestsStorySet(self.GetExpectations(), | |
| 97 base_name=self.Name()) | |
| 98 for story in story_set: | |
| 99 story.script_to_evaluate_on_commit = test_harness_script | |
| 100 return story_set | |
| 101 | |
| 102 | |
| 103 class TraceTest(TraceTestBase): | |
| 104 """Tests GPU traces are plumbed through properly.""" | |
| 105 test = _TraceValidator | |
| 106 name = 'TraceTest' | |
| 107 | |
| 108 @classmethod | |
| 109 def Name(cls): | |
| 110 return 'trace_test' | |
| 111 | |
| 112 def _CreateExpectations(self): | |
| 113 return trace_test_expectations.TraceTestExpectations() | |
| 114 | |
| 115 | |
| 116 class DeviceTraceTest(TraceTestBase): | |
| 117 """Tests GPU Device traces show up on devices that support it.""" | |
| 118 test = _DeviceTraceValidator | |
| 119 name = 'DeviceTraceTest' | |
| 120 | |
| 121 @classmethod | |
| 122 def Name(cls): | |
| 123 return 'device_trace_test' | |
| 124 | |
| 125 def _CreateExpectations(self): | |
| 126 return trace_test_expectations.DeviceTraceTestExpectations() | |
| OLD | NEW |