[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / content / test / gpu / gpu_tests / memory_test.py
blob48a345458104925edca97c21144630445de9c5ac
1 # Copyright (c) 2012 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 memory_test_expectations
6 import page_sets
8 from telemetry.page import page_test
9 from telemetry.timeline import counter
10 from telemetry.timeline import model
11 from telemetry.timeline import tracing_category_filter
12 from telemetry.timeline import tracing_options
14 MEMORY_LIMIT_MB = 192
15 SINGLE_TAB_LIMIT_MB = 192
16 WIGGLE_ROOM_MB = 24
18 test_harness_script = r"""
19 var domAutomationController = {};
20 domAutomationController._finished = false;
22 domAutomationController.send = function(msg) {
23 // This should wait until all effects of memory management complete.
24 // We will need to wait until all
25 // 1. pending commits from the main thread to the impl thread in the
26 // compositor complete (for visible compositors).
27 // 2. allocations that the renderer's impl thread will make due to the
28 // compositor and WebGL are completed.
29 // 3. pending GpuMemoryManager::Manage() calls to manage are made.
30 // 4. renderers' OnMemoryAllocationChanged callbacks in response to
31 // manager are made.
32 // Each step in this sequence can cause trigger the next (as a 1-2-3-4-1
33 // cycle), so we will need to pump this cycle until it stabilizes.
35 // Pump the cycle 8 times (in principle it could take an infinite number
36 // of iterations to settle).
38 var rafCount = 0;
40 // Impl-side painting has changed the behavior of this test.
41 // Currently the background of the page shows up checkerboarded
42 // initially, causing the test to fail because the memory
43 // allocation is too low (no root layer). Temporarily increase the
44 // rAF count to 32 in order to make the test work reliably again.
45 // crbug.com/373098
46 // TODO(kbr): revert this change and put it back to 8 iterations.
47 var totalRafCount = 32;
49 function pumpRAF() {
50 if (rafCount == totalRafCount) {
51 domAutomationController._finished = true;
52 return;
54 ++rafCount;
55 window.requestAnimationFrame(pumpRAF);
57 pumpRAF();
60 window.domAutomationController = domAutomationController;
62 window.addEventListener("load", function() {
63 useGpuMemory(%d);
64 }, false);
65 """ % MEMORY_LIMIT_MB
67 class _MemoryValidator(gpu_test_base.ValidatorBase):
68 def ValidateAndMeasurePageInner(self, page, tab, results):
69 timeline_data = tab.browser.platform.tracing_controller.Stop()
70 timeline_model = model.TimelineModel(timeline_data)
71 for process in timeline_model.GetAllProcesses():
72 if 'gpu.GpuMemoryUsage' in process.counters:
73 counter = process.GetCounter('gpu', 'GpuMemoryUsage')
74 mb_used = counter.samples[-1] / 1048576
76 if mb_used + WIGGLE_ROOM_MB < SINGLE_TAB_LIMIT_MB:
77 raise page_test.Failure(self._FormatException('low', mb_used))
79 if mb_used - WIGGLE_ROOM_MB > MEMORY_LIMIT_MB:
80 raise page_test.Failure(self._FormatException('high', mb_used))
82 def CustomizeBrowserOptions(self, options):
83 options.AppendExtraBrowserArgs('--enable-logging')
84 options.AppendExtraBrowserArgs(
85 '--force-gpu-mem-available-mb=%s' % MEMORY_LIMIT_MB)
87 def WillNavigateToPage(self, page, tab):
88 # FIXME: Remove webkit.console when blink.console lands in chromium and the
89 # ref builds are updated. crbug.com/386847
90 custom_categories = ['webkit.console', 'blink.console', 'gpu']
91 category_filter = tracing_category_filter.TracingCategoryFilter()
92 for c in custom_categories:
93 category_filter.AddIncludedCategory(c)
94 options = tracing_options.TracingOptions()
95 options.enable_chrome_trace = True
96 tab.browser.platform.tracing_controller.Start(options, category_filter, 60)
98 def _FormatException(self, low_or_high, mb_used):
99 return 'Memory allocation too %s (was %d MB, should be %d MB +/- %d MB)' % (
100 low_or_high, mb_used, SINGLE_TAB_LIMIT_MB, WIGGLE_ROOM_MB)
102 class MemoryTest(gpu_test_base.TestBase):
103 """Tests GPU memory limits"""
104 test = _MemoryValidator
106 @classmethod
107 def Name(cls):
108 return 'memory_test'
110 def _CreateExpectations(self):
111 return memory_test_expectations.MemoryTestExpectations()
113 def CreateStorySet(self, options):
114 story_set = page_sets.MemoryTestsStorySet(self.GetExpectations())
115 for page in story_set:
116 page.script_to_evaluate_on_commit = test_harness_script
117 return story_set