Chromium Code Reviews| Index: tools/unittests/ignition_perf_report_test.py |
| diff --git a/tools/unittests/ignition_perf_report_test.py b/tools/unittests/ignition_perf_report_test.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..245dadaabe0c16aa5ebf9d51b464af47a649db3e |
| --- /dev/null |
| +++ b/tools/unittests/ignition_perf_report_test.py |
| @@ -0,0 +1,135 @@ |
| +# Copyright 2016 the V8 project authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import ignition_perf_report as ipr |
| +import StringIO |
| +import unittest |
| + |
| + |
| +## perf script test output. |
| + |
| +PERF_SCRIPT_OUTPUT = """ |
| +# This line is a comment |
| +# This should be ignored too |
| +# |
| +# cdefab01 aRandomSymbol::Name(to, be, ignored) |
| + |
| + 00000000 firstSymbol |
| + 00000123 secondSymbol |
| + |
| + 01234567 foo |
| + abcdef76 BytecodeHandler:bar |
| + 76543210 baz |
| + |
| +# Indentation shouldn't matter (neither should this line) |
| + |
| + 01234567 foo |
| + abcdef76 BytecodeHandler:bar |
| + 76543210 baz |
| + |
| + 01234567 beep |
| + abcdef76 BytecodeHandler:bar |
| + 76543210 baz |
| + |
| + 01234567 hello |
| + abcdef76 Builtin:CompileLazy |
| + 76543210 world |
| + 11111111 BytecodeHandler:nope |
| +""" |
| + |
| +## hide_compile_time = False test data. |
| + |
| +PERF_SCRIPT_YIELDED_CALLCHAINS = [ |
| + ["foo", "BytecodeHandler:bar"], |
| + ["foo", "BytecodeHandler:bar"], |
| + ["beep", "BytecodeHandler:bar"], |
| + ["hello", "Builtin:CompileLazy", "world", "BytecodeHandler:nope"], |
| +] |
| + |
| + |
| +CALLCHAINS_COUNTERS = [ |
| + ('BytecodeHandler:bar;foo', 2), |
| + ('BytecodeHandler:bar;beep', 1), |
| + ('BytecodeHandler:nope;world;Builtin:CompileLazy;hello', 1), |
| +] |
| + |
| + |
| +HANDLER_SAMPLE_COUNTERS = [ |
| + ("bar", 3), |
| + ("nope", 1), |
| +] |
| + |
| + |
| +## hide_compile_time = True test data. |
| + |
| +PERF_SCRIPT_YIELDED_CALLCHAINS_HIDE_COMPILE = [ |
| + ["foo", "BytecodeHandler:bar"], |
| + ["foo", "BytecodeHandler:bar"], |
| + ["beep", "BytecodeHandler:bar"], |
| +] |
| + |
| + |
| +CALLCHAINS_COUNTERS_HIDE_COMPILE = [ |
| + ('BytecodeHandler:bar;foo', 2), |
| + ('BytecodeHandler:bar;beep', 1), |
| +] |
| + |
| + |
| +HANDLER_SAMPLE_COUNTERS_HIDE_COMPILE = [ |
| + ("bar", 3), |
| +] |
| + |
| +## Regex test cases. |
| + |
| +COMPILER_SYMBOLS = [ |
| + "Builtin:CompileLazy", |
| + "Builtin:CompileOptimizedConcurrent", |
| + "LazyCompile:foo", |
| + "v8::internal::Compile::foo", |
| +] |
| + |
| + |
| +SYMBOLS_AND_NAMES = [ |
| + ("foo::(anonymous namespace)::bar(baz)", "foo::(anonymous namespace)::bar"), |
| + ("foo::bar<baz<beep>, blop>(hello, world)", "foo::bar<baz<beep>, blop>"), |
| + ("hello(world)", "hello"), |
| +] |
| + |
| + |
| +class IgnitionPerfReportTest(unittest.TestCase): |
|
rmcilroy
2016/03/11 11:26:49
Are these tests run on the bots? If not they are p
|
| + def testYieldCollapsedCallchains(self): |
| + perf_stream = StringIO.StringIO(PERF_SCRIPT_OUTPUT) |
| + callchains = list(ipr.yield_collapsed_callchains(perf_stream, False)) |
| + self.assertListEqual(callchains, PERF_SCRIPT_YIELDED_CALLCHAINS) |
| + |
| + def testYieldCollapsedCallchainsHideCompile(self): |
| + perf_stream = StringIO.StringIO(PERF_SCRIPT_OUTPUT) |
| + callchains = list(ipr.yield_collapsed_callchains(perf_stream, True)) |
| + self.assertListEqual(callchains, |
| + PERF_SCRIPT_YIELDED_CALLCHAINS_HIDE_COMPILE) |
| + |
| + def testCountCallchains(self): |
| + counters = ipr.count_callchains(PERF_SCRIPT_YIELDED_CALLCHAINS) |
| + self.assertItemsEqual(counters, CALLCHAINS_COUNTERS) |
|
rmcilroy
2016/03/11 11:26:49
nit - could you make CALLCHAINS_COUNTERS a constan
Stefano Sanfilippo
2016/03/11 16:33:51
I'd prefer to keep them all outside, in case we ad
rmcilroy
2016/03/14 12:26:52
I disagree - the tests should be easy to reason ab
Stefano Sanfilippo
2016/03/14 13:14:20
I see. Done.
|
| + |
| + def testCountCallchainsHideCompile(self): |
| + counters = ipr.count_callchains(PERF_SCRIPT_YIELDED_CALLCHAINS_HIDE_COMPILE) |
| + self.assertItemsEqual(counters, CALLCHAINS_COUNTERS_HIDE_COMPILE) |
| + |
| + def testCountHandlerSamples(self): |
| + counters = ipr.count_handler_samples(PERF_SCRIPT_YIELDED_CALLCHAINS) |
| + self.assertItemsEqual(counters, HANDLER_SAMPLE_COUNTERS) |
| + |
| + def testCountHandlerSamplesHideCompile(self): |
| + counters = ipr.count_handler_samples( |
| + PERF_SCRIPT_YIELDED_CALLCHAINS_HIDE_COMPILE) |
| + self.assertItemsEqual(counters, HANDLER_SAMPLE_COUNTERS_HIDE_COMPILE) |
| + |
| + def testCompilerSymbolsRegex(self): |
| + for compiler_symbol in COMPILER_SYMBOLS: |
| + self.assertTrue(ipr.COMPILER_SYMBOLS_RE.match(compiler_symbol)) |
| + |
| + def testSymbolNameRegex(self): |
| + for symbol, name in SYMBOLS_AND_NAMES: |
| + self.assertEqual(ipr.SYMBOL_NAME_RE.match(symbol).group(1), name) |