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 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 else: | 119 else: |
120 args += ['--no-source-paths'] | 120 args += ['--no-source-paths'] |
121 if use_elf: | 121 if use_elf: |
122 args += ['--elf-file', _TEST_ELF_PATH] | 122 args += ['--elf-file', _TEST_ELF_PATH] |
123 _RunApp('archive', args, debug_measures=debug_measures) | 123 _RunApp('archive', args, debug_measures=debug_measures) |
124 size_info = archive.LoadAndPostProcessSizeInfo(temp_file.name) | 124 size_info = archive.LoadAndPostProcessSizeInfo(temp_file.name) |
125 # Check that saving & loading is the same as directly parsing the .map. | 125 # Check that saving & loading is the same as directly parsing the .map. |
126 expected_size_info = self._CloneSizeInfo( | 126 expected_size_info = self._CloneSizeInfo( |
127 use_output_directory=use_output_directory, use_elf=use_elf) | 127 use_output_directory=use_output_directory, use_elf=use_elf) |
128 self.assertEquals(expected_size_info.metadata, size_info.metadata) | 128 self.assertEquals(expected_size_info.metadata, size_info.metadata) |
129 expected = list(describe.GenerateLines(expected_size_info.Clustered())) | 129 # Don't cluster. |
130 actual = list(describe.GenerateLines(size_info.Clustered())) | 130 expected_size_info.symbols = expected_size_info.raw_symbols |
| 131 size_info.symbols = size_info.raw_symbols |
| 132 expected = list(describe.GenerateLines(expected_size_info)) |
| 133 actual = list(describe.GenerateLines(size_info)) |
131 self.assertEquals(expected, actual) | 134 self.assertEquals(expected, actual) |
132 | 135 |
133 sym_strs = (repr(sym) for sym in size_info.symbols) | 136 sym_strs = (repr(sym) for sym in size_info.symbols) |
134 stats = describe.DescribeSizeInfoCoverage(size_info) | 137 stats = describe.DescribeSizeInfoCoverage(size_info) |
135 if size_info.metadata: | 138 if size_info.metadata: |
136 metadata = describe.DescribeMetadata(size_info.metadata) | 139 metadata = describe.DescribeMetadata(size_info.metadata) |
137 else: | 140 else: |
138 metadata = [] | 141 metadata = [] |
139 return itertools.chain(metadata, stats, sym_strs) | 142 return itertools.chain(metadata, stats, sym_strs) |
140 | 143 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 @_CompareWithGolden() | 184 @_CompareWithGolden() |
182 def test_Diff_Basic(self): | 185 def test_Diff_Basic(self): |
183 size_info1 = self._CloneSizeInfo(use_elf=False) | 186 size_info1 = self._CloneSizeInfo(use_elf=False) |
184 size_info2 = self._CloneSizeInfo(use_elf=False) | 187 size_info2 = self._CloneSizeInfo(use_elf=False) |
185 size_info1.metadata = {"foo": 1, "bar": [1,2,3], "baz": "yes"} | 188 size_info1.metadata = {"foo": 1, "bar": [1,2,3], "baz": "yes"} |
186 size_info2.metadata = {"foo": 1, "bar": [1,3], "baz": "yes"} | 189 size_info2.metadata = {"foo": 1, "bar": [1,3], "baz": "yes"} |
187 size_info1.symbols -= size_info1.symbols[:2] | 190 size_info1.symbols -= size_info1.symbols[:2] |
188 size_info2.symbols -= size_info2.symbols[-3:] | 191 size_info2.symbols -= size_info2.symbols[-3:] |
189 size_info1.symbols[1].size -= 10 | 192 size_info1.symbols[1].size -= 10 |
190 d = diff.Diff(size_info1, size_info2) | 193 d = diff.Diff(size_info1, size_info2) |
191 d.symbols = d.symbols.Clustered().Sorted() | 194 d.symbols = d.symbols.Sorted() |
192 return describe.GenerateLines(d, verbose=True) | 195 return describe.GenerateLines(d, verbose=True) |
193 | 196 |
194 def test_Diff_Aliases1(self): | 197 def test_Diff_Aliases1(self): |
195 size_info1 = self._CloneSizeInfo() | 198 size_info1 = self._CloneSizeInfo() |
196 size_info2 = self._CloneSizeInfo() | 199 size_info2 = self._CloneSizeInfo() |
197 | 200 |
198 # Removing 1 alias should not change the size. | 201 # Removing 1 alias should not change the size. |
199 a1, _, _ = ( | 202 a1, _, _ = ( |
200 size_info2.symbols.Filter(lambda s: s.num_aliases == 3)[0].aliases) | 203 size_info2.raw_symbols.Filter(lambda s: s.num_aliases == 3)[0].aliases) |
201 size_info2.symbols -= [a1] | 204 size_info2.raw_symbols -= [a1] |
202 a1.aliases.remove(a1) | 205 a1.aliases.remove(a1) |
203 d = diff.Diff(size_info1, size_info2) | 206 d = diff.Diff(size_info1, size_info2) |
204 self.assertEquals(d.symbols.size, 0) | 207 self.assertEquals(d.raw_symbols.size, 0) |
205 self.assertEquals((0, 0, 1), _DiffCounts(d.symbols)) | 208 self.assertEquals((0, 0, 1), _DiffCounts(d.raw_symbols)) |
206 # shrinkToFit is in a cluster, so removed turns to a changed when clustered. | 209 # shrinkToFit is in a cluster, so removed turns to a changed when clustered. |
207 self.assertEquals((1, 0, 0), _DiffCounts(d.symbols.Clustered())) | 210 self.assertEquals((1, 0, 0), _DiffCounts(d.symbols)) |
208 | 211 |
209 # Adding one alias should not change size. | 212 # Adding one alias should not change size. |
210 d = diff.Diff(size_info2, size_info1) | 213 d = diff.Diff(size_info2, size_info1) |
211 self.assertEquals(d.symbols.size, 0) | 214 self.assertEquals(d.raw_symbols.size, 0) |
212 self.assertEquals((0, 1, 0), _DiffCounts(d.symbols)) | 215 self.assertEquals((0, 1, 0), _DiffCounts(d.raw_symbols)) |
213 self.assertEquals((1, 0, 0), _DiffCounts(d.symbols.Clustered())) | 216 self.assertEquals((1, 0, 0), _DiffCounts(d.symbols)) |
214 | 217 |
215 def test_Diff_Aliases2(self): | 218 def test_Diff_Aliases2(self): |
216 size_info1 = self._CloneSizeInfo() | 219 size_info1 = self._CloneSizeInfo() |
217 size_info2 = self._CloneSizeInfo() | 220 size_info2 = self._CloneSizeInfo() |
218 | 221 |
219 # Removing 2 aliases should not change the size. | 222 # Removing 2 aliases should not change the size. |
220 a1, a2, _ = ( | 223 a1, a2, _ = ( |
221 size_info2.symbols.Filter(lambda s: s.num_aliases == 3)[0].aliases) | 224 size_info2.raw_symbols.Filter(lambda s: s.num_aliases == 3)[0].aliases) |
222 size_info2.symbols -= [a1, a2] | 225 size_info2.raw_symbols -= [a1, a2] |
223 a1.aliases.remove(a1) | 226 a1.aliases.remove(a1) |
224 a1.aliases.remove(a2) | 227 a1.aliases.remove(a2) |
225 d = diff.Diff(size_info1, size_info2) | 228 d = diff.Diff(size_info1, size_info2) |
226 self.assertEquals(d.symbols.size, 0) | 229 self.assertEquals(d.raw_symbols.size, 0) |
227 self.assertEquals((0, 0, 2), _DiffCounts(d.symbols)) | 230 self.assertEquals((0, 0, 2), _DiffCounts(d.raw_symbols)) |
228 self.assertEquals((1, 0, 1), _DiffCounts(d.symbols.Clustered())) | 231 self.assertEquals((1, 0, 1), _DiffCounts(d.symbols)) |
229 | 232 |
230 # Adding 2 aliases should not change size. | 233 # Adding 2 aliases should not change size. |
231 d = diff.Diff(size_info2, size_info1) | 234 d = diff.Diff(size_info2, size_info1) |
232 self.assertEquals(d.symbols.size, 0) | 235 self.assertEquals(d.raw_symbols.size, 0) |
233 self.assertEquals((0, 2, 0), _DiffCounts(d.symbols)) | 236 self.assertEquals((0, 2, 0), _DiffCounts(d.raw_symbols)) |
234 self.assertEquals((1, 1, 0), _DiffCounts(d.symbols.Clustered())) | 237 self.assertEquals((1, 1, 0), _DiffCounts(d.symbols)) |
235 | 238 |
236 def test_Diff_Aliases3(self): | 239 def test_Diff_Aliases3(self): |
237 size_info1 = self._CloneSizeInfo() | 240 size_info1 = self._CloneSizeInfo() |
238 size_info2 = self._CloneSizeInfo() | 241 size_info2 = self._CloneSizeInfo() |
239 | 242 |
240 # Removing all 3 aliases should change the size. | 243 # Removing all 3 aliases should change the size. |
241 a1, a2, a3 = ( | 244 a1, a2, a3 = ( |
242 size_info2.symbols.Filter(lambda s: s.num_aliases == 3)[0].aliases) | 245 size_info2.raw_symbols.Filter(lambda s: s.num_aliases == 3)[0].aliases) |
243 size_info2.symbols -= [a1, a2, a3] | 246 size_info2.raw_symbols -= [a1, a2, a3] |
244 d = diff.Diff(size_info1, size_info2) | 247 d = diff.Diff(size_info1, size_info2) |
245 self.assertEquals(d.symbols.size, -a1.size) | 248 self.assertEquals((0, 0, 3), _DiffCounts(d.raw_symbols)) |
246 self.assertEquals((0, 0, 3), _DiffCounts(d.symbols)) | 249 self.assertEquals((1, 0, 2), _DiffCounts(d.symbols)) |
247 self.assertEquals((1, 0, 2), _DiffCounts(d.symbols.Clustered())) | |
248 | 250 |
249 # Adding all 3 aliases should change size. | 251 # Adding all 3 aliases should change size. |
250 d = diff.Diff(size_info2, size_info1) | 252 d = diff.Diff(size_info2, size_info1) |
251 self.assertEquals(d.symbols.size, a1.size) | 253 self.assertEquals(d.raw_symbols.size, a1.size) |
252 self.assertEquals((0, 3, 0), _DiffCounts(d.symbols)) | 254 self.assertEquals((0, 3, 0), _DiffCounts(d.raw_symbols)) |
253 self.assertEquals((1, 2, 0), _DiffCounts(d.symbols.Clustered())) | 255 self.assertEquals((1, 2, 0), _DiffCounts(d.symbols)) |
254 | 256 |
255 def test_Diff_Clustering(self): | 257 def test_Diff_Clustering(self): |
256 size_info1 = self._CloneSizeInfo() | 258 size_info1 = self._CloneSizeInfo() |
257 size_info2 = self._CloneSizeInfo() | 259 size_info2 = self._CloneSizeInfo() |
258 S = '.text' | 260 S = '.text' |
259 size_info1.symbols += [ | 261 size_info1.symbols += [ |
260 models.Symbol(S, 11, name='.L__unnamed_1193', object_path='a'), # 1 | 262 models.Symbol(S, 11, name='.L__unnamed_1193', object_path='a'), # 1 |
261 models.Symbol(S, 22, name='.L__unnamed_1194', object_path='a'), # 2 | 263 models.Symbol(S, 22, name='.L__unnamed_1194', object_path='a'), # 2 |
262 models.Symbol(S, 33, name='.L__unnamed_1195', object_path='b'), # 3 | 264 models.Symbol(S, 33, name='.L__unnamed_1195', object_path='b'), # 3 |
263 models.Symbol(S, 44, name='.L__bar_195', object_path='b'), # 4 | 265 models.Symbol(S, 44, name='.L__bar_195', object_path='b'), # 4 |
264 models.Symbol(S, 55, name='.L__bar_1195', object_path='b'), # 5 | 266 models.Symbol(S, 55, name='.L__bar_1195', object_path='b'), # 5 |
265 ] | 267 ] |
266 size_info2.symbols += [ | 268 size_info2.symbols += [ |
267 models.Symbol(S, 33, name='.L__unnamed_2195', object_path='b'), # 3 | 269 models.Symbol(S, 33, name='.L__unnamed_2195', object_path='b'), # 3 |
268 models.Symbol(S, 11, name='.L__unnamed_2194', object_path='a'), # 1 | 270 models.Symbol(S, 11, name='.L__unnamed_2194', object_path='a'), # 1 |
269 models.Symbol(S, 22, name='.L__unnamed_2193', object_path='a'), # 2 | 271 models.Symbol(S, 22, name='.L__unnamed_2193', object_path='a'), # 2 |
270 models.Symbol(S, 44, name='.L__bar_2195', object_path='b'), # 4 | 272 models.Symbol(S, 44, name='.L__bar_2195', object_path='b'), # 4 |
271 models.Symbol(S, 55, name='.L__bar_295', object_path='b'), # 5 | 273 models.Symbol(S, 55, name='.L__bar_295', object_path='b'), # 5 |
272 ] | 274 ] |
273 d = diff.Diff(size_info1, size_info2) | 275 d = diff.Diff(size_info1, size_info2) |
274 d.symbols = d.symbols.Clustered().Sorted() | 276 d.symbols = d.symbols.Sorted() |
275 self.assertEquals(d.symbols.added_count, 0) | 277 self.assertEquals(d.symbols.added_count, 0) |
276 self.assertEquals(d.symbols.size, 0) | 278 self.assertEquals(d.symbols.size, 0) |
277 | 279 |
278 | |
279 @_CompareWithGolden() | 280 @_CompareWithGolden() |
280 def test_FullDescription(self): | 281 def test_FullDescription(self): |
281 return describe.GenerateLines(self._CloneSizeInfo().Clustered(), | 282 size_info = self._CloneSizeInfo() |
282 recursive=True, verbose=True) | 283 # Show both clustered and non-clustered so that they can be compared. |
| 284 size_info.symbols = size_info.raw_symbols |
| 285 return itertools.chain( |
| 286 describe.GenerateLines(size_info, verbose=True), |
| 287 describe.GenerateLines(size_info.symbols._Clustered(), recursive=True, |
| 288 verbose=True), |
| 289 ) |
283 | 290 |
284 @_CompareWithGolden() | 291 @_CompareWithGolden() |
285 def test_SymbolGroupMethods(self): | 292 def test_SymbolGroupMethods(self): |
286 all_syms = self._CloneSizeInfo().symbols | 293 all_syms = self._CloneSizeInfo().symbols |
287 global_syms = all_syms.WhereNameMatches('GLOBAL') | 294 global_syms = all_syms.WhereNameMatches('GLOBAL') |
288 # Tests Filter(), Inverted(), and __sub__(). | 295 # Tests Filter(), Inverted(), and __sub__(). |
289 non_global_syms = global_syms.Inverted() | 296 non_global_syms = global_syms.Inverted() |
290 self.assertEqual(non_global_syms, (all_syms - global_syms)) | 297 self.assertEqual(non_global_syms, (all_syms - global_syms)) |
291 # Tests Sorted() and __add__(). | 298 # Tests Sorted() and __add__(). |
292 self.assertEqual(all_syms.Sorted(), | 299 self.assertEqual(all_syms.Sorted(), |
(...skipping 18 matching lines...) Expand all Loading... |
311 global update_goldens | 318 global update_goldens |
312 update_goldens = True | 319 update_goldens = True |
313 for f in glob.glob(os.path.join(_TEST_DATA_DIR, '*.golden')): | 320 for f in glob.glob(os.path.join(_TEST_DATA_DIR, '*.golden')): |
314 os.unlink(f) | 321 os.unlink(f) |
315 | 322 |
316 unittest.main(argv=argv, verbosity=2) | 323 unittest.main(argv=argv, verbosity=2) |
317 | 324 |
318 | 325 |
319 if __name__ == '__main__': | 326 if __name__ == '__main__': |
320 main() | 327 main() |
OLD | NEW |