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

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

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

Powered by Google App Engine
This is Rietveld 408576698