Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(121)

Side by Side Diff: tools/binary_size/integration_test.py

Issue 2778963003: Revert of V2 of //tools/binary_size rewrite (diffs). (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/binary_size/helpers.py ('k') | tools/binary_size/linker_map_parser.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
5
6 import copy
7 import difflib
8 import itertools
9 import logging
10 import os
11 import unittest
12 import subprocess
13 import sys
14 import tempfile
15
16 import describe
17 import map2size
18 import models
19
20
21 _SCRIPT_DIR = os.path.dirname(__file__)
22 _TEST_DATA_DIR = os.path.join(_SCRIPT_DIR, 'testdata')
23 _TEST_MAP_PATH = os.path.join(_TEST_DATA_DIR, 'test.map')
24
25 update_goldens = False
26
27
28 def _AssertGolden(expected_lines, actual_lines):
29 expected = list(expected_lines)
30 actual = list(l + '\n' for l in actual_lines)
31 assert actual == expected, ('Did not match .golden.\n' +
32 ''.join(difflib.unified_diff(expected, actual, 'expected', 'actual')))
33
34
35 def _CompareWithGolden(func):
36 name = func.__name__.replace('test_', '')
37 golden_path = os.path.join(_TEST_DATA_DIR, name + '.golden')
38
39 def inner(self):
40 actual_lines = func(self)
41
42 if update_goldens:
43 with open(golden_path, 'w') as file_obj:
44 describe.WriteLines(actual_lines, file_obj.write)
45 logging.info('Wrote %s', golden_path)
46 else:
47 with open(golden_path) as file_obj:
48 _AssertGolden(file_obj, actual_lines)
49 return inner
50
51
52 def _RunApp(name, *args):
53 argv = [os.path.join(_SCRIPT_DIR, name), '--no-pypy']
54 argv.extend(args)
55 return subprocess.check_output(argv).splitlines()
56
57
58 class IntegrationTest(unittest.TestCase):
59 size_info = None
60
61 def _GetParsedMap(self):
62 if not IntegrationTest.size_info:
63 IntegrationTest.size_info = map2size.Analyze(_TEST_MAP_PATH)
64 return copy.deepcopy(IntegrationTest.size_info)
65
66 @_CompareWithGolden
67 def test_Map2Size(self):
68 with tempfile.NamedTemporaryFile(suffix='.size') as temp_file:
69 _RunApp('map2size.py', _TEST_MAP_PATH, temp_file.name)
70 size_info = map2size.Analyze(temp_file.name)
71 sym_strs = (repr(sym) for sym in size_info.symbols)
72 stats = describe.DescribeSizeInfoCoverage(size_info)
73 return itertools.chain(stats, sym_strs)
74
75 @_CompareWithGolden
76 def test_ConsoleNullDiff(self):
77 return _RunApp('console.py', '--query', 'Diff(size_info1, size_info2)',
78 _TEST_MAP_PATH, _TEST_MAP_PATH)
79
80 @_CompareWithGolden
81 def test_ActualDiff(self):
82 map1 = self._GetParsedMap()
83 map2 = self._GetParsedMap()
84 map1.symbols.symbols.pop(-1)
85 map2.symbols.symbols.pop(0)
86 map1.symbols[1].size -= 10
87 diff = models.Diff(map1, map2)
88 return describe.GenerateLines(diff)
89
90 def test_SymbolGroupMethods(self):
91 all_syms = self._GetParsedMap().symbols
92 global_syms = all_syms.WhereNameMatches('GLOBAL')
93 # Tests Filter(), Inverted(), and __sub__().
94 non_global_syms = global_syms.Inverted()
95 self.assertEqual(non_global_syms.symbols, (all_syms - global_syms).symbols)
96 # Tests Sorted() and __add__().
97 self.assertEqual(all_syms.Sorted().symbols,
98 (global_syms + non_global_syms).Sorted().symbols)
99 # Tests GroupByPath() and __len__().
100 self.assertEqual(6, len(all_syms.GroupByPath()))
101
102
103 def main():
104 argv = sys.argv
105 if len(argv) > 1 and argv[1] == '--update':
106 argv.pop(0)
107 global update_goldens
108 update_goldens = True
109
110 unittest.main(argv=argv, verbosity=2)
111
112
113 if __name__ == '__main__':
114 main()
OLDNEW
« no previous file with comments | « tools/binary_size/helpers.py ('k') | tools/binary_size/linker_map_parser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698