| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2017 The Chromium Authors. All rights reserved. | 2 # Copyright 2017 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 import copy | 6 import copy |
| 7 import difflib | 7 import difflib |
| 8 import itertools | 8 import itertools |
| 9 import logging | 9 import logging |
| 10 import os | 10 import os |
| 11 import unittest | 11 import unittest |
| 12 import subprocess | 12 import subprocess |
| 13 import sys | 13 import sys |
| 14 import tempfile | 14 import tempfile |
| 15 | 15 |
| 16 import describe | 16 import describe |
| 17 import file_format |
| 17 import map2size | 18 import map2size |
| 18 import models | 19 import models |
| 20 import paths |
| 19 | 21 |
| 20 | 22 |
| 21 _SCRIPT_DIR = os.path.dirname(__file__) | 23 _SCRIPT_DIR = os.path.dirname(__file__) |
| 22 _TEST_DATA_DIR = os.path.join(_SCRIPT_DIR, 'testdata') | 24 _TEST_DATA_DIR = os.path.join(_SCRIPT_DIR, 'testdata') |
| 23 _TEST_MAP_PATH = os.path.join(_TEST_DATA_DIR, 'test.map') | 25 _TEST_MAP_PATH = os.path.join(_TEST_DATA_DIR, 'test.map') |
| 24 | 26 |
| 25 update_goldens = False | 27 update_goldens = False |
| 26 | 28 |
| 27 | 29 |
| 28 def _AssertGolden(expected_lines, actual_lines): | 30 def _AssertGolden(expected_lines, actual_lines): |
| (...skipping 22 matching lines...) Expand all Loading... |
| 51 | 53 |
| 52 def _RunApp(name, *args): | 54 def _RunApp(name, *args): |
| 53 argv = [os.path.join(_SCRIPT_DIR, name), '--no-pypy'] | 55 argv = [os.path.join(_SCRIPT_DIR, name), '--no-pypy'] |
| 54 argv.extend(args) | 56 argv.extend(args) |
| 55 return subprocess.check_output(argv).splitlines() | 57 return subprocess.check_output(argv).splitlines() |
| 56 | 58 |
| 57 | 59 |
| 58 class IntegrationTest(unittest.TestCase): | 60 class IntegrationTest(unittest.TestCase): |
| 59 size_info = None | 61 size_info = None |
| 60 | 62 |
| 61 def _GetParsedMap(self): | 63 def _CloneSizeInfo(self): |
| 62 if not IntegrationTest.size_info: | 64 if not IntegrationTest.size_info: |
| 63 IntegrationTest.size_info = map2size.Analyze( | 65 lazy_paths = paths.LazyPaths(output_directory=_TEST_DATA_DIR) |
| 64 _TEST_MAP_PATH, output_directory=_TEST_DATA_DIR) | 66 IntegrationTest.size_info = map2size.Analyze(_TEST_MAP_PATH, lazy_paths) |
| 65 return copy.deepcopy(IntegrationTest.size_info) | 67 return copy.deepcopy(IntegrationTest.size_info) |
| 66 | 68 |
| 67 @_CompareWithGolden | 69 @_CompareWithGolden |
| 68 def test_Map2Size(self): | 70 def test_Map2Size(self): |
| 69 with tempfile.NamedTemporaryFile(suffix='.size') as temp_file: | 71 with tempfile.NamedTemporaryFile(suffix='.size') as temp_file: |
| 70 _RunApp('map2size.py', '--output-directory', _TEST_DATA_DIR, | 72 _RunApp('map2size.py', '--output-directory', _TEST_DATA_DIR, |
| 71 _TEST_MAP_PATH, temp_file.name) | 73 '--map-file', _TEST_MAP_PATH, '', temp_file.name) |
| 72 size_info = map2size.Analyze(temp_file.name) | 74 size_info = map2size.Analyze(temp_file.name) |
| 73 sym_strs = (repr(sym) for sym in size_info.symbols) | 75 sym_strs = (repr(sym) for sym in size_info.symbols) |
| 74 stats = describe.DescribeSizeInfoCoverage(size_info) | 76 stats = describe.DescribeSizeInfoCoverage(size_info) |
| 75 return itertools.chain(stats, sym_strs) | 77 return itertools.chain(stats, sym_strs) |
| 76 | 78 |
| 77 @_CompareWithGolden | 79 @_CompareWithGolden |
| 78 def test_ConsoleNullDiff(self): | 80 def test_ConsoleNullDiff(self): |
| 79 return _RunApp('console.py', '--output-directory', _TEST_DATA_DIR, | 81 with tempfile.NamedTemporaryFile(suffix='.size') as temp_file: |
| 80 '--query', 'Diff(size_info1, size_info2)', | 82 file_format.SaveSizeInfo(self._CloneSizeInfo(), temp_file.name) |
| 81 _TEST_MAP_PATH, _TEST_MAP_PATH) | 83 return _RunApp('console.py', '--query', 'Diff(size_info1, size_info2)', |
| 84 temp_file.name, temp_file.name) |
| 82 | 85 |
| 83 @_CompareWithGolden | 86 @_CompareWithGolden |
| 84 def test_ActualDiff(self): | 87 def test_ActualDiff(self): |
| 85 map1 = self._GetParsedMap() | 88 map1 = self._CloneSizeInfo() |
| 86 map2 = self._GetParsedMap() | 89 map2 = self._CloneSizeInfo() |
| 87 map1.symbols -= map1.symbols[0] | 90 map1.symbols -= map1.symbols[0] |
| 88 map2.symbols -= map2.symbols[-1] | 91 map2.symbols -= map2.symbols[-1] |
| 89 map1.symbols[1].size -= 10 | 92 map1.symbols[1].size -= 10 |
| 90 diff = models.Diff(map1, map2) | 93 diff = models.Diff(map1, map2) |
| 91 return describe.GenerateLines(diff, verbose=True) | 94 return describe.GenerateLines(diff, verbose=True) |
| 92 | 95 |
| 93 @_CompareWithGolden | 96 @_CompareWithGolden |
| 94 def test_SymbolGroupMethods(self): | 97 def test_SymbolGroupMethods(self): |
| 95 all_syms = self._GetParsedMap().symbols | 98 all_syms = self._CloneSizeInfo().symbols |
| 96 global_syms = all_syms.WhereNameMatches('GLOBAL') | 99 global_syms = all_syms.WhereNameMatches('GLOBAL') |
| 97 # Tests Filter(), Inverted(), and __sub__(). | 100 # Tests Filter(), Inverted(), and __sub__(). |
| 98 non_global_syms = global_syms.Inverted() | 101 non_global_syms = global_syms.Inverted() |
| 99 self.assertEqual(non_global_syms, (all_syms - global_syms)) | 102 self.assertEqual(non_global_syms, (all_syms - global_syms)) |
| 100 # Tests Sorted() and __add__(). | 103 # Tests Sorted() and __add__(). |
| 101 self.assertEqual(all_syms.Sorted(), | 104 self.assertEqual(all_syms.Sorted(), |
| 102 (global_syms + non_global_syms).Sorted()) | 105 (global_syms + non_global_syms).Sorted()) |
| 103 # Tests GroupByNamespace() and __len__(). | 106 # Tests GroupByNamespace() and __len__(). |
| 104 return itertools.chain( | 107 return itertools.chain( |
| 105 ['GroupByNamespace()'], | 108 ['GroupByNamespace()'], |
| (...skipping 13 matching lines...) Expand all Loading... |
| 119 if len(argv) > 1 and argv[1] == '--update': | 122 if len(argv) > 1 and argv[1] == '--update': |
| 120 argv.pop(0) | 123 argv.pop(0) |
| 121 global update_goldens | 124 global update_goldens |
| 122 update_goldens = True | 125 update_goldens = True |
| 123 | 126 |
| 124 unittest.main(argv=argv, verbosity=2) | 127 unittest.main(argv=argv, verbosity=2) |
| 125 | 128 |
| 126 | 129 |
| 127 if __name__ == '__main__': | 130 if __name__ == '__main__': |
| 128 main() | 131 main() |
| OLD | NEW |