OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 memory_expectations | 4 import memory_expectations |
5 | 5 |
6 from telemetry import test | 6 from telemetry import test |
7 from telemetry.page import page_test | 7 from telemetry.page import page_test |
8 from telemetry.core.timeline import counter | 8 from telemetry.core.timeline import counter |
9 from telemetry.core.timeline import model | 9 from telemetry.core.timeline import model |
10 | 10 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 class _MemoryValidator(page_test.PageTest): | 56 class _MemoryValidator(page_test.PageTest): |
57 def ValidatePage(self, page, tab, results): | 57 def ValidatePage(self, page, tab, results): |
58 timeline_data = tab.browser.StopTracing() | 58 timeline_data = tab.browser.StopTracing() |
59 timeline_model = model.TimelineModel(timeline_data) | 59 timeline_model = model.TimelineModel(timeline_data) |
60 for process in timeline_model.GetAllProcesses(): | 60 for process in timeline_model.GetAllProcesses(): |
61 if 'gpu.GpuMemoryUsage' in process.counters: | 61 if 'gpu.GpuMemoryUsage' in process.counters: |
62 counter = process.GetCounter('gpu', 'GpuMemoryUsage') | 62 counter = process.GetCounter('gpu', 'GpuMemoryUsage') |
63 mb_used = counter.samples[-1] / 1048576 | 63 mb_used = counter.samples[-1] / 1048576 |
64 | 64 |
65 if mb_used + WIGGLE_ROOM_MB < SINGLE_TAB_LIMIT_MB: | 65 if mb_used + WIGGLE_ROOM_MB < SINGLE_TAB_LIMIT_MB: |
66 raise page_test.Failure('Memory allocation too low') | 66 raise page_test.Failure(self._FormatException('low', mb_used)) |
67 | 67 |
68 if mb_used - WIGGLE_ROOM_MB > MEMORY_LIMIT_MB: | 68 if mb_used - WIGGLE_ROOM_MB > MEMORY_LIMIT_MB: |
69 raise page_test.Failure('Memory allocation too high') | 69 raise page_test.Failure(self._FormatException('high', mb_used)) |
70 | 70 |
71 def CustomizeBrowserOptions(self, options): | 71 def CustomizeBrowserOptions(self, options): |
72 options.AppendExtraBrowserArgs('--enable-logging') | 72 options.AppendExtraBrowserArgs('--enable-logging') |
73 options.AppendExtraBrowserArgs( | 73 options.AppendExtraBrowserArgs( |
74 '--force-gpu-mem-available-mb=%s' % MEMORY_LIMIT_MB) | 74 '--force-gpu-mem-available-mb=%s' % MEMORY_LIMIT_MB) |
75 | 75 |
76 def WillNavigateToPage(self, page, tab): | 76 def WillNavigateToPage(self, page, tab): |
77 custom_categories = ['webkit.console', 'gpu'] | 77 custom_categories = ['webkit.console', 'gpu'] |
78 tab.browser.StartTracing(','.join(custom_categories), 60) | 78 tab.browser.StartTracing(','.join(custom_categories), 60) |
79 | 79 |
| 80 def _FormatException(self, low_or_high, mb_used): |
| 81 return 'Memory allocation too %s (was %d MB, should be %d MB +/- %d MB)' % ( |
| 82 low_or_high, mb_used, SINGLE_TAB_LIMIT_MB, WIGGLE_ROOM_MB) |
| 83 |
80 class Memory(test.Test): | 84 class Memory(test.Test): |
81 """Tests GPU memory limits""" | 85 """Tests GPU memory limits""" |
82 test = _MemoryValidator | 86 test = _MemoryValidator |
83 page_set = 'page_sets/memory_tests.py' | 87 page_set = 'page_sets/memory_tests.py' |
84 | 88 |
85 def CreateExpectations(self, page_set): | 89 def CreateExpectations(self, page_set): |
86 return memory_expectations.MemoryExpectations() | 90 return memory_expectations.MemoryExpectations() |
87 | 91 |
88 def CreatePageSet(self, options): | 92 def CreatePageSet(self, options): |
89 page_set = super(Memory, self).CreatePageSet(options) | 93 page_set = super(Memory, self).CreatePageSet(options) |
90 for page in page_set.pages: | 94 for page in page_set.pages: |
91 page.script_to_evaluate_on_commit = test_harness_script | 95 page.script_to_evaluate_on_commit = test_harness_script |
92 return page_set | 96 return page_set |
OLD | NEW |