OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 logging | 4 import logging |
5 import os | 5 import os |
6 import unittest | 6 import unittest |
7 | 7 |
8 from telemetry.core import util | 8 from telemetry.core import util |
9 from telemetry.internal.platform.profiler import perf_profiler | 9 from telemetry.internal.platform.profiler import perf_profiler |
| 10 from telemetry.internal.util import binary_manager |
10 from telemetry.testing import options_for_unittests | 11 from telemetry.testing import options_for_unittests |
11 from telemetry.testing import simple_mock | 12 from telemetry.testing import simple_mock |
12 | 13 |
13 | 14 |
14 class TestPerfProfiler(unittest.TestCase): | 15 class TestPerfProfiler(unittest.TestCase): |
15 def testPerfProfiler(self): | 16 def testPerfProfiler(self): |
16 options = options_for_unittests.GetCopy() | 17 options = options_for_unittests.GetCopy() |
17 if not perf_profiler.PerfProfiler.is_supported(options.browser_type): | 18 if not perf_profiler.PerfProfiler.is_supported(options.browser_type): |
18 logging.warning('PerfProfiler is not supported. Skipping test') | 19 logging.warning('PerfProfiler is not supported. Skipping test') |
19 return | 20 return |
20 | 21 |
21 profile_file = os.path.join( | 22 profile_file = os.path.join( |
22 util.GetUnittestDataDir(), 'perf_report_output.txt') | 23 util.GetUnittestDataDir(), 'perf_report_output.txt') |
23 with open(profile_file) as f: | 24 with open(profile_file) as f: |
24 perf_report_output = f.read() | 25 perf_report_output = f.read() |
25 | 26 |
26 mock_popen = simple_mock.MockObject() | 27 mock_popen = simple_mock.MockObject() |
27 mock_popen.ExpectCall('communicate').WillReturn([perf_report_output]) | 28 mock_popen.ExpectCall('communicate').WillReturn([perf_report_output]) |
28 | 29 |
29 mock_subprocess = simple_mock.MockObject() | 30 mock_subprocess = simple_mock.MockObject() |
30 mock_subprocess.ExpectCall( | 31 mock_subprocess.ExpectCall( |
31 'Popen').WithArgs(simple_mock.DONT_CARE).WillReturn(mock_popen) | 32 'Popen').WithArgs(simple_mock.DONT_CARE).WillReturn(mock_popen) |
32 mock_subprocess.SetAttribute('PIPE', simple_mock.MockObject()) | 33 mock_subprocess.SetAttribute('PIPE', simple_mock.MockObject()) |
33 | 34 |
34 real_subprocess = perf_profiler.subprocess | 35 real_subprocess = perf_profiler.subprocess |
35 perf_profiler.subprocess = mock_subprocess | 36 perf_profiler.subprocess = mock_subprocess |
| 37 |
| 38 binary_manager.InitDependencyManagerForUnittests() |
36 try: | 39 try: |
37 self.assertEqual( | 40 self.assertEqual( |
38 perf_profiler.PerfProfiler.GetTopSamples(profile_file, 10), | 41 perf_profiler.PerfProfiler.GetTopSamples(profile_file, 10), |
39 {'v8::internal::StaticMarkingVisitor::MarkMapContents': 63615201, | 42 {'v8::internal::StaticMarkingVisitor::MarkMapContents': 63615201, |
40 'v8::internal::RelocIterator::next': 38271931, | 43 'v8::internal::RelocIterator::next': 38271931, |
41 'v8::internal::LAllocator::MeetConstraintsBetween': 42913933, | 44 'v8::internal::LAllocator::MeetConstraintsBetween': 42913933, |
42 'v8::internal::FlexibleBodyVisitor::Visit': 31909537, | 45 'v8::internal::FlexibleBodyVisitor::Visit': 31909537, |
43 'v8::internal::LiveRange::CreateAssignedOperand': 42913933, | 46 'v8::internal::LiveRange::CreateAssignedOperand': 42913933, |
44 'void v8::internal::RelocInfo::Visit': 96878864, | 47 'void v8::internal::RelocInfo::Visit': 96878864, |
45 'WebCore::HTMLTokenizer::nextToken': 48240439, | 48 'WebCore::HTMLTokenizer::nextToken': 48240439, |
46 'v8::internal::Scanner::ScanIdentifierOrKeyword': 46054550, | 49 'v8::internal::Scanner::ScanIdentifierOrKeyword': 46054550, |
47 'sk_memset32_SSE2': 45121317, | 50 'sk_memset32_SSE2': 45121317, |
48 'v8::internal::HeapObject::Size': 39786862 | 51 'v8::internal::HeapObject::Size': 39786862 |
49 }) | 52 }) |
50 finally: | 53 finally: |
51 perf_profiler.subprocess = real_subprocess | 54 perf_profiler.subprocess = real_subprocess |
OLD | NEW |