| 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 archive |
| 16 import describe | 17 import describe |
| 17 import file_format | 18 import file_format |
| 18 import map2size | |
| 19 import models | 19 import models |
| 20 import paths | 20 import paths |
| 21 | 21 |
| 22 | 22 |
| 23 _SCRIPT_DIR = os.path.dirname(__file__) | 23 _SCRIPT_DIR = os.path.dirname(__file__) |
| 24 _TEST_DATA_DIR = os.path.join(_SCRIPT_DIR, 'testdata') | 24 _TEST_DATA_DIR = os.path.join(_SCRIPT_DIR, 'testdata') |
| 25 _TEST_MAP_PATH = os.path.join(_TEST_DATA_DIR, 'test.map') | 25 _TEST_MAP_PATH = os.path.join(_TEST_DATA_DIR, 'test.map') |
| 26 | 26 |
| 27 update_goldens = False | 27 update_goldens = False |
| 28 | 28 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 45 with open(golden_path, 'w') as file_obj: | 45 with open(golden_path, 'w') as file_obj: |
| 46 describe.WriteLines(actual_lines, file_obj.write) | 46 describe.WriteLines(actual_lines, file_obj.write) |
| 47 logging.info('Wrote %s', golden_path) | 47 logging.info('Wrote %s', golden_path) |
| 48 else: | 48 else: |
| 49 with open(golden_path) as file_obj: | 49 with open(golden_path) as file_obj: |
| 50 _AssertGolden(file_obj, actual_lines) | 50 _AssertGolden(file_obj, actual_lines) |
| 51 return inner | 51 return inner |
| 52 | 52 |
| 53 | 53 |
| 54 def _RunApp(name, *args): | 54 def _RunApp(name, *args): |
| 55 argv = [os.path.join(_SCRIPT_DIR, name), '--no-pypy'] | 55 argv = [os.path.join(_SCRIPT_DIR, 'main.py'), name, '--no-pypy'] |
| 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 = ( | 66 IntegrationTest.size_info = ( |
| 67 map2size.CreateSizeInfo(_TEST_MAP_PATH, lazy_paths)) | 67 archive.CreateSizeInfo(_TEST_MAP_PATH, lazy_paths)) |
| 68 return copy.deepcopy(IntegrationTest.size_info) | 68 return copy.deepcopy(IntegrationTest.size_info) |
| 69 | 69 |
| 70 @_CompareWithGolden | 70 @_CompareWithGolden |
| 71 def test_Map2Size(self): | 71 def test_Archive(self): |
| 72 with tempfile.NamedTemporaryFile(suffix='.size') as temp_file: | 72 with tempfile.NamedTemporaryFile(suffix='.size') as temp_file: |
| 73 _RunApp('map2size.py', '--output-directory', _TEST_DATA_DIR, | 73 _RunApp('archive', temp_file.name, '--output-directory', _TEST_DATA_DIR, |
| 74 '--map-file', _TEST_MAP_PATH, '--elf-file', '', | 74 '--map-file', _TEST_MAP_PATH, '--elf-file', '') |
| 75 '--output-file', temp_file.name) | 75 size_info = archive.LoadAndPostProcessSizeInfo(temp_file.name) |
| 76 size_info = map2size.LoadAndPostProcessSizeInfo(temp_file.name) | |
| 77 # Check that saving & loading is the same as directly parsing the .map. | 76 # Check that saving & loading is the same as directly parsing the .map. |
| 78 expected_size_info = self._CloneSizeInfo() | 77 expected_size_info = self._CloneSizeInfo() |
| 79 self.assertEquals(expected_size_info.metadata, size_info.metadata) | 78 self.assertEquals(expected_size_info.metadata, size_info.metadata) |
| 80 expected = '\n'.join(describe.GenerateLines( | 79 expected = '\n'.join(describe.GenerateLines( |
| 81 expected_size_info, verbose=True, recursive=True)), | 80 expected_size_info, verbose=True, recursive=True)), |
| 82 actual = '\n'.join(describe.GenerateLines( | 81 actual = '\n'.join(describe.GenerateLines( |
| 83 size_info, verbose=True, recursive=True)), | 82 size_info, verbose=True, recursive=True)), |
| 84 self.assertEquals(expected, actual) | 83 self.assertEquals(expected, actual) |
| 85 | 84 |
| 86 sym_strs = (repr(sym) for sym in size_info.symbols) | 85 sym_strs = (repr(sym) for sym in size_info.symbols) |
| 87 stats = describe.DescribeSizeInfoCoverage(size_info) | 86 stats = describe.DescribeSizeInfoCoverage(size_info) |
| 88 return itertools.chain(stats, sym_strs) | 87 return itertools.chain(stats, sym_strs) |
| 89 | 88 |
| 90 def test_Map2Size_NoSourcePaths(self): | 89 def test_Archive_NoSourcePaths(self): |
| 91 # Just tests that it doesn't crash. | 90 # Just tests that it doesn't crash. |
| 92 with tempfile.NamedTemporaryFile(suffix='.size') as temp_file: | 91 with tempfile.NamedTemporaryFile(suffix='.size') as temp_file: |
| 93 _RunApp('map2size.py', '--no-source-paths', | 92 _RunApp('archive', temp_file.name, '--no-source-paths', |
| 94 '--map-file', _TEST_MAP_PATH, '--elf-file', '', | 93 '--map-file', _TEST_MAP_PATH, '--elf-file', '') |
| 95 '--output-file', temp_file.name) | 94 archive.LoadAndPostProcessSizeInfo(temp_file.name) |
| 96 map2size.LoadAndPostProcessSizeInfo(temp_file.name) | |
| 97 | 95 |
| 98 @_CompareWithGolden | 96 @_CompareWithGolden |
| 99 def test_ConsoleNullDiff(self): | 97 def test_ConsoleNullDiff(self): |
| 100 with tempfile.NamedTemporaryFile(suffix='.size') as temp_file: | 98 with tempfile.NamedTemporaryFile(suffix='.size') as temp_file: |
| 101 file_format.SaveSizeInfo(self._CloneSizeInfo(), temp_file.name) | 99 file_format.SaveSizeInfo(self._CloneSizeInfo(), temp_file.name) |
| 102 return _RunApp('console.py', '--query', 'Diff(size_info1, size_info2)', | 100 return _RunApp('console', '--query', 'Diff(size_info1, size_info2)', |
| 103 temp_file.name, temp_file.name) | 101 temp_file.name, temp_file.name) |
| 104 | 102 |
| 105 @_CompareWithGolden | 103 @_CompareWithGolden |
| 106 def test_ActualDiff(self): | 104 def test_ActualDiff(self): |
| 107 size_info1 = self._CloneSizeInfo() | 105 size_info1 = self._CloneSizeInfo() |
| 108 size_info2 = self._CloneSizeInfo() | 106 size_info2 = self._CloneSizeInfo() |
| 109 size_info1.metadata = {"foo": 1, "bar": [1,2,3], "baz": "yes"} | 107 size_info1.metadata = {"foo": 1, "bar": [1,2,3], "baz": "yes"} |
| 110 size_info2.metadata = {"foo": 1, "bar": [1,3], "baz": "yes"} | 108 size_info2.metadata = {"foo": 1, "bar": [1,3], "baz": "yes"} |
| 111 size_info1.symbols -= size_info1.symbols[:2] | 109 size_info1.symbols -= size_info1.symbols[:2] |
| 112 size_info2.symbols -= size_info2.symbols[-3:] | 110 size_info2.symbols -= size_info2.symbols[-3:] |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 if len(argv) > 1 and argv[1] == '--update': | 145 if len(argv) > 1 and argv[1] == '--update': |
| 148 argv.pop(0) | 146 argv.pop(0) |
| 149 global update_goldens | 147 global update_goldens |
| 150 update_goldens = True | 148 update_goldens = True |
| 151 | 149 |
| 152 unittest.main(argv=argv, verbosity=2) | 150 unittest.main(argv=argv, verbosity=2) |
| 153 | 151 |
| 154 | 152 |
| 155 if __name__ == '__main__': | 153 if __name__ == '__main__': |
| 156 main() | 154 main() |
| OLD | NEW |