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

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

Issue 2854173003: supersize: Don't cluster by default. Make Diff() accept only SizeInfo. (Closed)
Patch Set: Created 3 years, 7 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/libsupersize/file_format.py ('k') | tools/binary_size/libsupersize/models.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 contextlib 6 import contextlib
7 import copy 7 import copy
8 import difflib 8 import difflib
9 import glob 9 import glob
10 import itertools 10 import itertools
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 else: 114 else:
115 args += ['--no-source-paths'] 115 args += ['--no-source-paths']
116 if use_elf: 116 if use_elf:
117 args += ['--elf-file', _TEST_ELF_PATH] 117 args += ['--elf-file', _TEST_ELF_PATH]
118 _RunApp('archive', args, debug_measures=debug_measures) 118 _RunApp('archive', args, debug_measures=debug_measures)
119 size_info = archive.LoadAndPostProcessSizeInfo(temp_file.name) 119 size_info = archive.LoadAndPostProcessSizeInfo(temp_file.name)
120 # Check that saving & loading is the same as directly parsing the .map. 120 # Check that saving & loading is the same as directly parsing the .map.
121 expected_size_info = self._CloneSizeInfo( 121 expected_size_info = self._CloneSizeInfo(
122 use_output_directory=use_output_directory, use_elf=use_elf) 122 use_output_directory=use_output_directory, use_elf=use_elf)
123 self.assertEquals(expected_size_info.metadata, size_info.metadata) 123 self.assertEquals(expected_size_info.metadata, size_info.metadata)
124 expected = list(describe.GenerateLines( 124 expected = list(describe.GenerateLines(expected_size_info.Cluster()))
125 expected_size_info, verbose=True, recursive=True)) 125 actual = list(describe.GenerateLines(size_info.Cluster()))
126 actual = list(describe.GenerateLines(
127 size_info, verbose=True, recursive=True))
128 self.assertEquals(expected, actual) 126 self.assertEquals(expected, actual)
129 127
130 sym_strs = (repr(sym) for sym in size_info.symbols) 128 sym_strs = (repr(sym) for sym in size_info.symbols)
131 stats = describe.DescribeSizeInfoCoverage(size_info) 129 stats = describe.DescribeSizeInfoCoverage(size_info)
132 if size_info.metadata: 130 if size_info.metadata:
133 metadata = describe.DescribeMetadata(size_info.metadata) 131 metadata = describe.DescribeMetadata(size_info.metadata)
134 else: 132 else:
135 metadata = [] 133 metadata = []
136 return itertools.chain(metadata, stats, sym_strs) 134 return itertools.chain(metadata, stats, sym_strs)
137 135
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 size_info2 = self._CloneSizeInfo(use_elf=False) 176 size_info2 = self._CloneSizeInfo(use_elf=False)
179 size_info1.metadata = {"foo": 1, "bar": [1,2,3], "baz": "yes"} 177 size_info1.metadata = {"foo": 1, "bar": [1,2,3], "baz": "yes"}
180 size_info2.metadata = {"foo": 1, "bar": [1,3], "baz": "yes"} 178 size_info2.metadata = {"foo": 1, "bar": [1,3], "baz": "yes"}
181 size_info1.symbols -= size_info1.symbols[:2] 179 size_info1.symbols -= size_info1.symbols[:2]
182 size_info2.symbols -= size_info2.symbols[-3:] 180 size_info2.symbols -= size_info2.symbols[-3:]
183 size_info1.symbols[1].size -= 10 181 size_info1.symbols[1].size -= 10
184 d = diff.Diff(size_info1, size_info2) 182 d = diff.Diff(size_info1, size_info2)
185 return describe.GenerateLines(d, verbose=True) 183 return describe.GenerateLines(d, verbose=True)
186 184
187 def test_Diff_Aliases1(self): 185 def test_Diff_Aliases1(self):
188 symbols1 = self._CloneSizeInfo().symbols 186 size_info1 = self._CloneSizeInfo()
189 symbols2 = self._CloneSizeInfo().symbols 187 size_info2 = self._CloneSizeInfo()
190 188
191 # Removing 1 alias should not change the size. 189 # Removing 1 alias should not change the size.
192 a1, _, _ = symbols2.Filter(lambda s: s.num_aliases == 3)[0].aliases 190 a1, _, _ = (
193 symbols2 -= [a1] 191 size_info2.symbols.Filter(lambda s: s.num_aliases == 3)[0].aliases)
192 size_info2.symbols -= [a1]
194 a1.aliases.remove(a1) 193 a1.aliases.remove(a1)
195 d = diff.Diff(symbols1, symbols2) 194 d = diff.Diff(size_info1, size_info2)
196 self.assertEquals(d.size, 0) 195 self.assertEquals(d.symbols.size, 0)
197 self.assertEquals(d.removed_count, 1) 196 self.assertEquals(d.symbols.removed_count, 1)
198 197
199 # Adding one alias should not change size. 198 # Adding one alias should not change size.
200 d = diff.Diff(symbols2, symbols1) 199 d = diff.Diff(size_info2, size_info1)
201 self.assertEquals(d.size, 0) 200 self.assertEquals(d.symbols.size, 0)
202 self.assertEquals(d.added_count, 1) 201 self.assertEquals(d.symbols.added_count, 1)
203 202
204 def test_Diff_Aliases2(self): 203 def test_Diff_Aliases2(self):
205 symbols1 = self._CloneSizeInfo().symbols 204 size_info1 = self._CloneSizeInfo()
206 symbols2 = self._CloneSizeInfo().symbols 205 size_info2 = self._CloneSizeInfo()
207 206
208 # Removing 2 aliases should not change the size. 207 # Removing 2 aliases should not change the size.
209 a1, a2, _ = symbols2.Filter(lambda s: s.num_aliases == 3)[0].aliases 208 a1, a2, _ = (
210 symbols2 -= [a1, a2] 209 size_info2.symbols.Filter(lambda s: s.num_aliases == 3)[0].aliases)
210 size_info2.symbols -= [a1, a2]
211 a1.aliases.remove(a1) 211 a1.aliases.remove(a1)
212 a1.aliases.remove(a2) 212 a1.aliases.remove(a2)
213 d = diff.Diff(symbols1, symbols2) 213 d = diff.Diff(size_info1, size_info2)
214 self.assertEquals(d.size, 0) 214 self.assertEquals(d.symbols.size, 0)
215 self.assertEquals(d.removed_count, 2) 215 self.assertEquals(d.symbols.removed_count, 2)
216 216
217 # Adding 2 aliases should not change size. 217 # Adding 2 aliases should not change size.
218 d = diff.Diff(symbols2, symbols1) 218 d = diff.Diff(size_info2, size_info1)
219 self.assertEquals(d.size, 0) 219 self.assertEquals(d.symbols.size, 0)
220 self.assertEquals(d.added_count, 2) 220 self.assertEquals(d.symbols.added_count, 2)
221 221
222 def test_Diff_Aliases3(self): 222 def test_Diff_Aliases3(self):
223 symbols1 = self._CloneSizeInfo().symbols 223 size_info1 = self._CloneSizeInfo()
224 symbols2 = self._CloneSizeInfo().symbols 224 size_info2 = self._CloneSizeInfo()
225 225
226 # Removing all 3 aliases should change the size. 226 # Removing all 3 aliases should change the size.
227 a1, a2, a3 = symbols2.Filter(lambda s: s.num_aliases == 3)[0].aliases 227 a1, a2, a3 = (
228 symbols2 -= [a1, a2, a3] 228 size_info2.symbols.Filter(lambda s: s.num_aliases == 3)[0].aliases)
229 d = diff.Diff(symbols1, symbols2) 229 size_info2.symbols -= [a1, a2, a3]
230 self.assertEquals(d.size, -a1.size) 230 d = diff.Diff(size_info1, size_info2)
231 self.assertEquals(d.removed_count, 3) 231 self.assertEquals(d.symbols.size, -a1.size)
232 self.assertEquals(d.symbols.removed_count, 3)
232 233
233 # Adding all 3 aliases should change size. 234 # Adding all 3 aliases should change size.
234 d = diff.Diff(symbols2, symbols1) 235 d = diff.Diff(size_info2, size_info1)
235 self.assertEquals(d.size, a1.size) 236 self.assertEquals(d.symbols.size, a1.size)
236 self.assertEquals(d.added_count, 3) 237 self.assertEquals(d.symbols.added_count, 3)
237 238
238 @_CompareWithGolden() 239 @_CompareWithGolden()
239 def test_FullDescription(self): 240 def test_FullDescription(self):
240 return describe.GenerateLines(self._CloneSizeInfo()) 241 return describe.GenerateLines(self._CloneSizeInfo().Cluster(),
242 recursive=True, verbose=True)
241 243
242 @_CompareWithGolden() 244 @_CompareWithGolden()
243 def test_SymbolGroupMethods(self): 245 def test_SymbolGroupMethods(self):
244 all_syms = self._CloneSizeInfo().symbols 246 all_syms = self._CloneSizeInfo().symbols
245 global_syms = all_syms.WhereNameMatches('GLOBAL') 247 global_syms = all_syms.WhereNameMatches('GLOBAL')
246 # Tests Filter(), Inverted(), and __sub__(). 248 # Tests Filter(), Inverted(), and __sub__().
247 non_global_syms = global_syms.Inverted() 249 non_global_syms = global_syms.Inverted()
248 self.assertEqual(non_global_syms, (all_syms - global_syms)) 250 self.assertEqual(non_global_syms, (all_syms - global_syms))
249 # Tests Sorted() and __add__(). 251 # Tests Sorted() and __add__().
250 self.assertEqual(all_syms.Sorted(), 252 self.assertEqual(all_syms.Sorted(),
(...skipping 19 matching lines...) Expand all
270 global update_goldens 272 global update_goldens
271 update_goldens = True 273 update_goldens = True
272 for f in glob.glob(os.path.join(_TEST_DATA_DIR, '*.golden')): 274 for f in glob.glob(os.path.join(_TEST_DATA_DIR, '*.golden')):
273 os.unlink(f) 275 os.unlink(f)
274 276
275 unittest.main(argv=argv, verbosity=2) 277 unittest.main(argv=argv, verbosity=2)
276 278
277 279
278 if __name__ == '__main__': 280 if __name__ == '__main__':
279 main() 281 main()
OLDNEW
« no previous file with comments | « tools/binary_size/libsupersize/file_format.py ('k') | tools/binary_size/libsupersize/models.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698