| 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 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 argv.extend(args) | 56 argv.extend(args) |
| 57 return subprocess.check_output(argv).splitlines() | 57 return subprocess.check_output(argv).splitlines() |
| 58 | 58 |
| 59 | 59 |
| 60 class IntegrationTest(unittest.TestCase): | 60 class IntegrationTest(unittest.TestCase): |
| 61 size_info = None | 61 size_info = None |
| 62 | 62 |
| 63 def _CloneSizeInfo(self): | 63 def _CloneSizeInfo(self): |
| 64 if not IntegrationTest.size_info: | 64 if not IntegrationTest.size_info: |
| 65 lazy_paths = paths.LazyPaths(output_directory=_TEST_DATA_DIR) | 65 lazy_paths = paths.LazyPaths(output_directory=_TEST_DATA_DIR) |
| 66 IntegrationTest.size_info = map2size.Analyze(_TEST_MAP_PATH, lazy_paths) | 66 IntegrationTest.size_info = ( |
| 67 map2size.CreateSizeInfo(_TEST_MAP_PATH, lazy_paths)) |
| 67 return copy.deepcopy(IntegrationTest.size_info) | 68 return copy.deepcopy(IntegrationTest.size_info) |
| 68 | 69 |
| 69 @_CompareWithGolden | 70 @_CompareWithGolden |
| 70 def test_Map2Size(self): | 71 def test_Map2Size(self): |
| 71 with tempfile.NamedTemporaryFile(suffix='.size') as temp_file: | 72 with tempfile.NamedTemporaryFile(suffix='.size') as temp_file: |
| 72 _RunApp('map2size.py', '--output-directory', _TEST_DATA_DIR, | 73 _RunApp('map2size.py', '--output-directory', _TEST_DATA_DIR, |
| 73 '--map-file', _TEST_MAP_PATH, '', temp_file.name) | 74 '--map-file', _TEST_MAP_PATH, '--elf-file', '', |
| 74 size_info = map2size.Analyze(temp_file.name) | 75 '--output-file', temp_file.name) |
| 76 size_info = map2size.LoadAndPostProcessSizeInfo(temp_file.name) |
| 77 # Check that saving & loading is the same as directly parsing the .map. |
| 78 expected_size_info = self._CloneSizeInfo() |
| 79 self.assertEquals(expected_size_info.metadata, size_info.metadata) |
| 80 expected = '\n'.join(describe.GenerateLines( |
| 81 expected_size_info, verbose=True, recursive=True)), |
| 82 actual = '\n'.join(describe.GenerateLines( |
| 83 size_info, verbose=True, recursive=True)), |
| 84 self.assertEquals(expected, actual) |
| 85 |
| 75 sym_strs = (repr(sym) for sym in size_info.symbols) | 86 sym_strs = (repr(sym) for sym in size_info.symbols) |
| 76 stats = describe.DescribeSizeInfoCoverage(size_info) | 87 stats = describe.DescribeSizeInfoCoverage(size_info) |
| 77 return itertools.chain(stats, sym_strs) | 88 return itertools.chain(stats, sym_strs) |
| 78 | 89 |
| 90 def test_Map2Size_NoSourcePaths(self): |
| 91 # Just tests that it doesn't crash. |
| 92 with tempfile.NamedTemporaryFile(suffix='.size') as temp_file: |
| 93 _RunApp('map2size.py', '--no-source-paths', |
| 94 '--map-file', _TEST_MAP_PATH, '--elf-file', '', |
| 95 '--output-file', temp_file.name) |
| 96 map2size.LoadAndPostProcessSizeInfo(temp_file.name) |
| 97 |
| 79 @_CompareWithGolden | 98 @_CompareWithGolden |
| 80 def test_ConsoleNullDiff(self): | 99 def test_ConsoleNullDiff(self): |
| 81 with tempfile.NamedTemporaryFile(suffix='.size') as temp_file: | 100 with tempfile.NamedTemporaryFile(suffix='.size') as temp_file: |
| 82 file_format.SaveSizeInfo(self._CloneSizeInfo(), temp_file.name) | 101 file_format.SaveSizeInfo(self._CloneSizeInfo(), temp_file.name) |
| 83 return _RunApp('console.py', '--query', 'Diff(size_info1, size_info2)', | 102 return _RunApp('console.py', '--query', 'Diff(size_info1, size_info2)', |
| 84 temp_file.name, temp_file.name) | 103 temp_file.name, temp_file.name) |
| 85 | 104 |
| 86 @_CompareWithGolden | 105 @_CompareWithGolden |
| 87 def test_ActualDiff(self): | 106 def test_ActualDiff(self): |
| 88 size_info1 = self._CloneSizeInfo() | 107 size_info1 = self._CloneSizeInfo() |
| 89 size_info2 = self._CloneSizeInfo() | 108 size_info2 = self._CloneSizeInfo() |
| 90 size_info1.metadata = {"foo": 1, "bar": [1,2,3], "baz": "yes"} | 109 size_info1.metadata = {"foo": 1, "bar": [1,2,3], "baz": "yes"} |
| 91 size_info2.metadata = {"foo": 1, "bar": [1,3], "baz": "yes"} | 110 size_info2.metadata = {"foo": 1, "bar": [1,3], "baz": "yes"} |
| 92 size_info1.symbols -= size_info1.symbols[:2] | 111 size_info1.symbols -= size_info1.symbols[:2] |
| 93 size_info2.symbols -= size_info2.symbols[-3:] | 112 size_info2.symbols -= size_info2.symbols[-3:] |
| 94 size_info1.symbols[1].size -= 10 | 113 size_info1.symbols[1].size -= 10 |
| 95 diff = models.Diff(size_info1, size_info2) | 114 diff = models.Diff(size_info1, size_info2) |
| 96 return describe.GenerateLines(diff, verbose=True) | 115 return describe.GenerateLines(diff, verbose=True) |
| 97 | 116 |
| 98 @_CompareWithGolden | 117 @_CompareWithGolden |
| 118 def test_FullDescription(self): |
| 119 return describe.GenerateLines(self._CloneSizeInfo()) |
| 120 |
| 121 @_CompareWithGolden |
| 99 def test_SymbolGroupMethods(self): | 122 def test_SymbolGroupMethods(self): |
| 100 all_syms = self._CloneSizeInfo().symbols | 123 all_syms = self._CloneSizeInfo().symbols |
| 101 global_syms = all_syms.WhereNameMatches('GLOBAL') | 124 global_syms = all_syms.WhereNameMatches('GLOBAL') |
| 102 # Tests Filter(), Inverted(), and __sub__(). | 125 # Tests Filter(), Inverted(), and __sub__(). |
| 103 non_global_syms = global_syms.Inverted() | 126 non_global_syms = global_syms.Inverted() |
| 104 self.assertEqual(non_global_syms, (all_syms - global_syms)) | 127 self.assertEqual(non_global_syms, (all_syms - global_syms)) |
| 105 # Tests Sorted() and __add__(). | 128 # Tests Sorted() and __add__(). |
| 106 self.assertEqual(all_syms.Sorted(), | 129 self.assertEqual(all_syms.Sorted(), |
| 107 (global_syms + non_global_syms).Sorted()) | 130 (global_syms + non_global_syms).Sorted()) |
| 108 # Tests GroupByNamespace() and __len__(). | 131 # Tests GroupByNamespace() and __len__(). |
| (...skipping 15 matching lines...) Expand all Loading... |
| 124 if len(argv) > 1 and argv[1] == '--update': | 147 if len(argv) > 1 and argv[1] == '--update': |
| 125 argv.pop(0) | 148 argv.pop(0) |
| 126 global update_goldens | 149 global update_goldens |
| 127 update_goldens = True | 150 update_goldens = True |
| 128 | 151 |
| 129 unittest.main(argv=argv, verbosity=2) | 152 unittest.main(argv=argv, verbosity=2) |
| 130 | 153 |
| 131 | 154 |
| 132 if __name__ == '__main__': | 155 if __name__ == '__main__': |
| 133 main() | 156 main() |
| OLD | NEW |