OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 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 """Check that explain_binary_size_delta seems to work.""" | 6 """Check that explain_binary_size_delta seems to work.""" |
7 | 7 |
8 import cStringIO | 8 import cStringIO |
9 import sys | 9 import sys |
10 import unittest | 10 import unittest |
11 | 11 |
12 import explain_binary_size_delta | 12 import explain_binary_size_delta |
13 | 13 |
14 | 14 |
15 class ExplainBinarySizeDeltaTest(unittest.TestCase): | 15 class ExplainBinarySizeDeltaTest(unittest.TestCase): |
16 | 16 |
17 def testCompare(self): | 17 def testCompare(self): |
18 # List entries have form: symbol_name, symbol_type, symbol_size, file_path | 18 # List entries have form: |
| 19 # symbol_name, symbol_type, symbol_size, file_path, memory_address |
19 symbol_list1 = ( | 20 symbol_list1 = ( |
20 # File with one symbol, left as-is. | 21 # File with one symbol, left as-is. |
21 ( 'unchanged', 't', 1000, '/file_unchanged' ), | 22 ( 'unchanged', 't', 1000, '/file_unchanged', 0x1 ), |
22 # File with one symbol, changed. | 23 # File with one symbol, changed. |
23 ( 'changed', 't', 1000, '/file_all_changed' ), | 24 ( 'changed', 't', 1000, '/file_all_changed', 0x2 ), |
24 # File with one symbol, deleted. | 25 # File with one symbol, deleted. |
25 ( 'removed', 't', 1000, '/file_all_deleted' ), | 26 ( 'removed', 't', 1000, '/file_all_deleted', 0x3 ), |
26 # File with two symbols, one unchanged, one changed, same bucket | 27 # File with two symbols, one unchanged, one changed, same bucket |
27 ( 'unchanged', 't', 1000, '/file_pair_unchanged_changed' ), | 28 ( 'unchanged', 't', 1000, '/file_pair_unchanged_changed', 0x4 ), |
28 ( 'changed', 't', 1000, '/file_pair_unchanged_changed' ), | 29 ( 'changed', 't', 1000, '/file_pair_unchanged_changed', 0x5 ), |
29 # File with two symbols, one unchanged, one deleted, same bucket | 30 # File with two symbols, one unchanged, one deleted, same bucket |
30 ( 'unchanged', 't', 1000, '/file_pair_unchanged_removed' ), | 31 ( 'unchanged', 't', 1000, '/file_pair_unchanged_removed', 0x6 ), |
31 ( 'removed', 't', 1000, '/file_pair_unchanged_removed' ), | 32 ( 'removed', 't', 1000, '/file_pair_unchanged_removed', 0x7 ), |
32 # File with two symbols, one unchanged, one added, same bucket | 33 # File with two symbols, one unchanged, one added, same bucket |
33 ( 'unchanged', 't', 1000, '/file_pair_unchanged_added' ), | 34 ( 'unchanged', 't', 1000, '/file_pair_unchanged_added', 0x8 ), |
34 # File with two symbols, one unchanged, one changed, different bucket | 35 # File with two symbols, one unchanged, one changed, different bucket |
35 ( 'unchanged', 't', 1000, '/file_pair_unchanged_diffbuck_changed' ), | 36 ( 'unchanged', 't', 1000, '/file_pair_unchanged_diffbuck_changed', 0x9 ), |
36 ( 'changed', '@', 1000, '/file_pair_unchanged_diffbuck_changed' ), | 37 ( 'changed', '@', 1000, '/file_pair_unchanged_diffbuck_changed', 0xa ), |
37 # File with two symbols, one unchanged, one deleted, different bucket | 38 # File with two symbols, one unchanged, one deleted, different bucket |
38 ( 'unchanged', 't', 1000, '/file_pair_unchanged_diffbuck_removed' ), | 39 ( 'unchanged', 't', 1000, '/file_pair_unchanged_diffbuck_removed', 0xb ), |
39 ( 'removed', '@', 1000, '/file_pair_unchanged_diffbuck_removed' ), | 40 ( 'removed', '@', 1000, '/file_pair_unchanged_diffbuck_removed', 0xc ), |
40 # File with two symbols, one unchanged, one added, different bucket | 41 # File with two symbols, one unchanged, one added, different bucket |
41 ( 'unchanged', 't', 1000, '/file_pair_unchanged_diffbuck_added' ), | 42 ( 'unchanged', 't', 1000, '/file_pair_unchanged_diffbuck_added', 0xd ), |
42 # File with four symbols, one added, one removed, | 43 # File with four symbols, one added, one removed, |
43 # one changed, one unchanged | 44 # one changed, one unchanged |
44 ( 'size_changed', 't', 1000, '/file_tetra' ), | 45 ( 'size_changed', 't', 1000, '/file_tetra', 0xe ), |
45 ( 'removed', 't', 1000, '/file_tetra' ), | 46 ( 'removed', 't', 1000, '/file_tetra', 0xf ), |
46 ( 'unchanged', 't', 1000, '/file_tetra' ), | 47 ( 'unchanged', 't', 1000, '/file_tetra', 0x10 ), |
47 ) | 48 ) |
48 | 49 |
49 symbol_list2 = ( | 50 symbol_list2 = ( |
50 # File with one symbol, left as-is. | 51 # File with one symbol, left as-is. |
51 ( 'unchanged', 't', 1000, '/file_unchanged' ), | 52 ( 'unchanged', 't', 1000, '/file_unchanged', 0x1 ), |
52 # File with one symbol, changed. | 53 # File with one symbol, changed. |
53 ( 'changed', 't', 2000, '/file_all_changed' ), | 54 ( 'changed', 't', 2000, '/file_all_changed', 0x2 ), |
54 # File with two symbols, one unchanged, one changed, same bucket | 55 # File with two symbols, one unchanged, one changed, same bucket |
55 ( 'unchanged', 't', 1000, '/file_pair_unchanged_changed' ), | 56 ( 'unchanged', 't', 1000, '/file_pair_unchanged_changed', 0x3 ), |
56 ( 'changed', 't', 2000, '/file_pair_unchanged_changed' ), | 57 ( 'changed', 't', 2000, '/file_pair_unchanged_changed', 0x4 ), |
57 # File with two symbols, one unchanged, one deleted, same bucket | 58 # File with two symbols, one unchanged, one deleted, same bucket |
58 ( 'unchanged', 't', 1000, '/file_pair_unchanged_removed' ), | 59 ( 'unchanged', 't', 1000, '/file_pair_unchanged_removed', 0x5 ), |
59 # File with two symbols, one unchanged, one added, same bucket | 60 # File with two symbols, one unchanged, one added, same bucket |
60 ( 'unchanged', 't', 1000, '/file_pair_unchanged_added' ), | 61 ( 'unchanged', 't', 1000, '/file_pair_unchanged_added', 0x6 ), |
61 ( 'added', 't', 1000, '/file_pair_unchanged_added' ), | 62 ( 'added', 't', 1000, '/file_pair_unchanged_added', 0x7 ), |
62 # File with two symbols, one unchanged, one changed, different bucket | 63 # File with two symbols, one unchanged, one changed, different bucket |
63 ( 'unchanged', 't', 1000, '/file_pair_unchanged_diffbuck_changed' ), | 64 ( 'unchanged', 't', 1000, '/file_pair_unchanged_diffbuck_changed', 0x8 ), |
64 ( 'changed', '@', 2000, '/file_pair_unchanged_diffbuck_changed' ), | 65 ( 'changed', '@', 2000, '/file_pair_unchanged_diffbuck_changed', 0x9 ), |
65 # File with two symbols, one unchanged, one deleted, different bucket | 66 # File with two symbols, one unchanged, one deleted, different bucket |
66 ( 'unchanged', 't', 1000, '/file_pair_unchanged_diffbuck_removed' ), | 67 ( 'unchanged', 't', 1000, '/file_pair_unchanged_diffbuck_removed', 0xa ), |
67 # File with two symbols, one unchanged, one added, different bucket | 68 # File with two symbols, one unchanged, one added, different bucket |
68 ( 'unchanged', 't', 1000, '/file_pair_unchanged_diffbuck_added' ), | 69 ( 'unchanged', 't', 1000, '/file_pair_unchanged_diffbuck_added', 0xb ), |
69 ( 'added', '@', 1000, '/file_pair_unchanged_diffbuck_added' ), | 70 ( 'added', '@', 1000, '/file_pair_unchanged_diffbuck_added', 0xc ), |
70 # File with four symbols, one added, one removed, | 71 # File with four symbols, one added, one removed, |
71 # one changed, one unchanged | 72 # one changed, one unchanged |
72 ( 'size_changed', 't', 2000, '/file_tetra' ), | 73 ( 'size_changed', 't', 2000, '/file_tetra', 0xd ), |
73 ( 'unchanged', 't', 1000, '/file_tetra' ), | 74 ( 'unchanged', 't', 1000, '/file_tetra', 0xe ), |
74 ( 'added', 't', 1000, '/file_tetra' ), | 75 ( 'added', 't', 1000, '/file_tetra', 0xf ), |
75 # New file with one symbol added | 76 # New file with one symbol added |
76 ( 'added', 't', 1000, '/file_new' ), | 77 ( 'added', 't', 1000, '/file_new', 0x10 ), |
77 ) | 78 ) |
78 | 79 |
79 # Here we go | 80 # Here we go |
80 (added, removed, changed, unchanged) = \ | 81 (added, removed, changed, unchanged) = \ |
81 explain_binary_size_delta.Compare(symbol_list1, symbol_list2) | 82 explain_binary_size_delta.Compare(symbol_list1, symbol_list2) |
82 | 83 |
| 84 def delta(file_path, symbol_type, symbol_name, old_size, new_size): |
| 85 delta_info = explain_binary_size_delta.DeltaInfo( |
| 86 file_path, symbol_type, symbol_name, False) |
| 87 delta_info.old_size = old_size |
| 88 delta_info.new_size = new_size |
| 89 return delta_info |
| 90 |
83 # File with one symbol, left as-is. | 91 # File with one symbol, left as-is. |
84 assert ('/file_unchanged', 't', 'unchanged', 1000, 1000) in unchanged | 92 assert delta('/file_unchanged', 't', 'unchanged', 1000, 1000) in unchanged |
85 # File with one symbol, changed. | 93 # File with one symbol, changed. |
86 assert ('/file_all_changed', 't', 'changed', 1000, 2000) in changed | 94 assert delta('/file_all_changed', 't', 'changed', 1000, 2000) in changed |
87 # File with one symbol, deleted. | 95 # File with one symbol, deleted. |
88 assert ('/file_all_deleted', 't', 'removed', 1000, None) in removed | 96 assert delta('/file_all_deleted', 't', 'removed', 1000, None) in removed |
89 # New file with one symbol added | 97 # New file with one symbol added |
90 assert ('/file_new', 't', 'added', None, 1000) in added | 98 assert delta('/file_new', 't', 'added', None, 1000) in added |
91 # File with two symbols, one unchanged, one changed, same bucket | 99 # File with two symbols, one unchanged, one changed, same bucket |
92 assert ('/file_pair_unchanged_changed', | 100 assert delta('/file_pair_unchanged_changed', |
93 't', 'unchanged', 1000, 1000) in unchanged | 101 't', 'unchanged', 1000, 1000) in unchanged |
94 assert ('/file_pair_unchanged_changed', | 102 assert delta('/file_pair_unchanged_changed', |
95 't', 'changed', 1000, 2000) in changed | 103 't', 'changed', 1000, 2000) in changed |
96 # File with two symbols, one unchanged, one removed, same bucket | 104 # File with two symbols, one unchanged, one removed, same bucket |
97 assert ('/file_pair_unchanged_removed', | 105 assert delta('/file_pair_unchanged_removed', |
98 't', 'unchanged', 1000, 1000) in unchanged | 106 't', 'unchanged', 1000, 1000) in unchanged |
99 assert ('/file_pair_unchanged_removed', | 107 assert delta('/file_pair_unchanged_removed', |
100 't', 'removed', 1000, None) in removed | 108 't', 'removed', 1000, None) in removed |
101 # File with two symbols, one unchanged, one added, same bucket | 109 # File with two symbols, one unchanged, one added, same bucket |
102 assert ('/file_pair_unchanged_added', | 110 assert delta('/file_pair_unchanged_added', |
103 't', 'unchanged', 1000, 1000) in unchanged | 111 't', 'unchanged', 1000, 1000) in unchanged |
104 assert ('/file_pair_unchanged_added', | 112 assert delta('/file_pair_unchanged_added', |
105 't', 'added', None, 1000) in added | 113 't', 'added', None, 1000) in added |
106 # File with two symbols, one unchanged, one changed, different bucket | 114 # File with two symbols, one unchanged, one changed, different bucket |
107 assert ('/file_pair_unchanged_diffbuck_changed', | 115 assert delta('/file_pair_unchanged_diffbuck_changed', |
108 't', 'unchanged', 1000, 1000) in unchanged | 116 't', 'unchanged', 1000, 1000) in unchanged |
109 assert ('/file_pair_unchanged_diffbuck_changed', | 117 assert delta('/file_pair_unchanged_diffbuck_changed', |
110 '@', 'changed', 1000, 2000) in changed | 118 '@', 'changed', 1000, 2000) in changed |
111 # File with two symbols, one unchanged, one removed, different bucket | 119 # File with two symbols, one unchanged, one removed, different bucket |
112 assert ('/file_pair_unchanged_diffbuck_removed', | 120 assert delta('/file_pair_unchanged_diffbuck_removed', |
113 't', 'unchanged', 1000, 1000) in unchanged | 121 't', 'unchanged', 1000, 1000) in unchanged |
114 assert ('/file_pair_unchanged_diffbuck_removed', | 122 assert delta('/file_pair_unchanged_diffbuck_removed', |
115 '@', 'removed', 1000, None) in removed | 123 '@', 'removed', 1000, None) in removed |
116 # File with two symbols, one unchanged, one added, different bucket | 124 # File with two symbols, one unchanged, one added, different bucket |
117 assert ('/file_pair_unchanged_diffbuck_added', | 125 assert delta('/file_pair_unchanged_diffbuck_added', |
118 't', 'unchanged', 1000, 1000) in unchanged | 126 't', 'unchanged', 1000, 1000) in unchanged |
119 assert ('/file_pair_unchanged_diffbuck_added', | 127 assert delta('/file_pair_unchanged_diffbuck_added', |
120 '@', 'added', None, 1000) in added | 128 '@', 'added', None, 1000) in added |
121 # File with four symbols, one added, one removed, one changed, one unchanged | 129 # File with four symbols, one added, one removed, one changed, one unchanged |
122 assert ('/file_tetra', 't', 'size_changed', 1000, 2000) in changed | 130 assert delta('/file_tetra', 't', 'size_changed', 1000, 2000) in changed |
123 assert ('/file_tetra', 't', 'unchanged', 1000, 1000) in unchanged | 131 assert delta('/file_tetra', 't', 'unchanged', 1000, 1000) in unchanged |
124 assert ('/file_tetra', 't', 'added', None, 1000) in added | 132 assert delta('/file_tetra', 't', 'added', None, 1000) in added |
125 assert ('/file_tetra', 't', 'removed', 1000, None) in removed | 133 assert delta('/file_tetra', 't', 'removed', 1000, None) in removed |
126 | 134 |
127 # Now check final stats. | 135 # Now check final stats. |
128 orig_stdout = sys.stdout | 136 orig_stdout = sys.stdout |
129 output_collector = cStringIO.StringIO() | 137 output_collector = cStringIO.StringIO() |
130 sys.stdout = output_collector | 138 sys.stdout = output_collector |
131 try: | 139 try: |
132 explain_binary_size_delta.CrunchStats(added, removed, changed, | 140 explain_binary_size_delta.CrunchStats(added, removed, changed, |
133 unchanged, True, True) | 141 unchanged, True, True) |
134 finally: | 142 finally: |
135 sys.stdout = orig_stdout | 143 sys.stdout = orig_stdout |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 | 219 |
212 --------------------------------------------------------------------- | 220 --------------------------------------------------------------------- |
213 -1000 - Source: /file_pair_unchanged_removed - (gained 0, lost 1000) | 221 -1000 - Source: /file_pair_unchanged_removed - (gained 0, lost 1000) |
214 --------------------------------------------------------------------- | 222 --------------------------------------------------------------------- |
215 Removed symbols: | 223 Removed symbols: |
216 -1000: removed type=t, size=1000 bytes | 224 -1000: removed type=t, size=1000 bytes |
217 """ | 225 """ |
218 | 226 |
219 self.maxDiff = None | 227 self.maxDiff = None |
220 self.assertMultiLineEqual(expected_output, result) | 228 self.assertMultiLineEqual(expected_output, result) |
221 print "explain_binary_size_delta_unittest: All tests passed" | |
222 | 229 |
223 | 230 |
224 def testCompareStringEntries(self): | 231 def testCompareStringEntries(self): |
225 # List entries have form: symbol_name, symbol_type, symbol_size, file_path | 232 # List entries have form: |
| 233 # symbol_name, symbol_type, symbol_size, file_path, memory_address |
226 symbol_list1 = ( | 234 symbol_list1 = ( |
227 # File with one string. | 235 # File with one string. |
228 ( '.L.str107', 'r', 8, '/file_with_strs' ), | 236 ( '.L.str107', 'r', 8, '/file_with_strs', 0x1 ), |
229 ) | 237 ) |
230 | 238 |
231 symbol_list2 = ( | 239 symbol_list2 = ( |
232 # Two files with one string each, same name. | 240 # Two files with one string each, same name. |
233 ( '.L.str107', 'r', 8, '/file_with_strs' ), | 241 ( '.L.str107', 'r', 8, '/file_with_strs', 0x1 ), |
234 ( '.L.str107', 'r', 7, '/other_file_with_strs' ), | 242 ( '.L.str107', 'r', 7, '/other_file_with_strs', 0x2 ), |
235 ) | 243 ) |
236 | 244 |
237 # Here we go | 245 # Here we go |
238 (added, removed, changed, unchanged) = \ | 246 (added, removed, changed, unchanged) = \ |
239 explain_binary_size_delta.Compare(symbol_list1, symbol_list2) | 247 explain_binary_size_delta.Compare(symbol_list1, symbol_list2) |
240 | 248 |
241 | 249 |
242 # Now check final stats. | 250 # Now check final stats. |
243 orig_stdout = sys.stdout | 251 orig_stdout = sys.stdout |
244 output_collector = cStringIO.StringIO() | 252 output_collector = cStringIO.StringIO() |
(...skipping 20 matching lines...) Expand all Loading... |
265 | 273 |
266 -------------------------------------------------------- | 274 -------------------------------------------------------- |
267 +7 - Source: /other_file_with_strs - (gained 7, lost 0) | 275 +7 - Source: /other_file_with_strs - (gained 7, lost 0) |
268 -------------------------------------------------------- | 276 -------------------------------------------------------- |
269 New symbols: | 277 New symbols: |
270 +7: .L.str107 type=r, size=7 bytes | 278 +7: .L.str107 type=r, size=7 bytes |
271 """ | 279 """ |
272 | 280 |
273 self.maxDiff = None | 281 self.maxDiff = None |
274 self.assertMultiLineEqual(expected_output, result) | 282 self.assertMultiLineEqual(expected_output, result) |
275 print "explain_binary_size_delta_unittest: All tests passed" | |
276 | 283 |
277 def testCompareStringEntriesWithNoFile(self): | 284 def testCompareStringEntriesWithNoFile(self): |
278 # List entries have form: symbol_name, symbol_type, symbol_size, file_path | 285 # List entries have form: |
| 286 # symbol_name, symbol_type, symbol_size, file_path, memory_address |
279 symbol_list1 = ( | 287 symbol_list1 = ( |
280 ( '.L.str104', 'r', 21, '??' ), # Will change size. | 288 ( '.L.str104', 'r', 21, '??', 0x1 ), # Will change size. |
281 ( '.L.str105', 'r', 17, '??' ), # Same. | 289 ( '.L.str105', 'r', 17, '??', 0x2 ), # Same. |
282 ( '.L.str106', 'r', 13, '??' ), # Will be removed. | 290 ( '.L.str106', 'r', 13, '??', 0x3 ), # Will be removed. |
283 ( '.L.str106', 'r', 3, '??' ), # Same. | 291 ( '.L.str106', 'r', 3, '??', 0x4 ), # Same. |
284 ( '.L.str106', 'r', 3, '??' ), # Will be removed. | 292 ( '.L.str106', 'r', 3, '??', 0x5 ), # Will be removed. |
285 ( '.L.str107', 'r', 8, '??' ), # Will be removed (other sizes). | 293 ( '.L.str107', 'r', 8, '??', 0x6 ), # Will be removed (other sizes). |
286 ) | 294 ) |
287 | 295 |
288 symbol_list2 = ( | 296 symbol_list2 = ( |
289 # Two files with one string each, same name. | 297 # Two files with one string each, same name. |
290 ( '.L.str104', 'r', 19, '??' ), # Changed. | 298 ( '.L.str104', 'r', 19, '??', 0x1 ), # Changed. |
291 ( '.L.str105', 'r', 11, '??' ), # New size for multi-symbol. | 299 ( '.L.str105', 'r', 11, '??', 0x2 ), # New size for multi-symbol. |
292 ( '.L.str105', 'r', 17, '??' ), # New of same size for multi-symbol. | 300 ( '.L.str105', 'r', 17, '??', 0x3 ), # New of same size for multi-symbol. |
293 ( '.L.str105', 'r', 17, '??' ), # Same. | 301 ( '.L.str105', 'r', 17, '??', 0x4 ), # Same. |
294 ( '.L.str106', 'r', 3, '??' ), # Same. | 302 ( '.L.str106', 'r', 3, '??', 0x5 ), # Same. |
295 ( '.L.str107', 'r', 5, '??' ), # New size for symbol. | 303 ( '.L.str107', 'r', 5, '??', 0x6 ), # New size for symbol. |
296 ( '.L.str107', 'r', 7, '??' ), # New size for symbol. | 304 ( '.L.str107', 'r', 7, '??', 0x7 ), # New size for symbol. |
297 ( '.L.str108', 'r', 8, '??' ), # New symbol. | 305 ( '.L.str108', 'r', 8, '??', 0x8 ), # New symbol. |
298 ) | 306 ) |
299 | 307 |
300 # Here we go | 308 # Here we go |
301 (added, removed, changed, unchanged) = \ | 309 (added, removed, changed, unchanged) = \ |
302 explain_binary_size_delta.Compare(symbol_list1, symbol_list2) | 310 explain_binary_size_delta.Compare(symbol_list1, symbol_list2) |
303 | 311 |
304 | 312 |
305 # Now check final stats. | 313 # Now check final stats. |
306 orig_stdout = sys.stdout | 314 orig_stdout = sys.stdout |
307 output_collector = cStringIO.StringIO() | 315 output_collector = cStringIO.StringIO() |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 Removed symbols: | 349 Removed symbols: |
342 -3: .L.str106 type=r, size=3 bytes | 350 -3: .L.str106 type=r, size=3 bytes |
343 -8: .L.str107 type=r, size=8 bytes | 351 -8: .L.str107 type=r, size=8 bytes |
344 -13: .L.str106 type=r, size=13 bytes | 352 -13: .L.str106 type=r, size=13 bytes |
345 Shrunk symbols: | 353 Shrunk symbols: |
346 -2: .L.str104 type=r, (was 21 bytes, now 19 bytes) | 354 -2: .L.str104 type=r, (was 21 bytes, now 19 bytes) |
347 """ | 355 """ |
348 | 356 |
349 self.maxDiff = None | 357 self.maxDiff = None |
350 self.assertMultiLineEqual(expected_output, result) | 358 self.assertMultiLineEqual(expected_output, result) |
351 print "explain_binary_size_delta_unittest: All tests passed" | 359 |
| 360 def testCompareSharedSpace(self): |
| 361 # List entries have form: |
| 362 # symbol_name, symbol_type, symbol_size, file_path, memory_address |
| 363 symbol_list1 = ( |
| 364 # File with two symbols, same address. |
| 365 ( 'sym1', 'r', 8, '/file', 0x1 ), |
| 366 ( 'sym2', 'r', 8, '/file', 0x1 ), |
| 367 ) |
| 368 |
| 369 symbol_list2 = ( |
| 370 # File with two symbols, same address. |
| 371 ( 'sym1', 'r', 4, '/file', 0x1 ), |
| 372 ( 'sym2', 'r', 4, '/file', 0x1 ), |
| 373 ) |
| 374 |
| 375 # Here we go |
| 376 (added, removed, changed, unchanged) = \ |
| 377 explain_binary_size_delta.Compare(symbol_list1, symbol_list2) |
| 378 |
| 379 |
| 380 # Now check final stats. |
| 381 orig_stdout = sys.stdout |
| 382 output_collector = cStringIO.StringIO() |
| 383 sys.stdout = output_collector |
| 384 try: |
| 385 explain_binary_size_delta.CrunchStats(added, removed, changed, |
| 386 unchanged, True, True) |
| 387 finally: |
| 388 sys.stdout = orig_stdout |
| 389 result = output_collector.getvalue() |
| 390 |
| 391 expected_output = """\ |
| 392 Total change: -4 bytes |
| 393 ====================== |
| 394 2 shrunk, for a net change of -4 bytes (8 bytes before, 4 bytes after) \ |
| 395 across 1 sources |
| 396 0 unchanged, totalling 0 bytes |
| 397 Source stats: |
| 398 1 sources encountered. |
| 399 0 completely new. |
| 400 0 removed completely. |
| 401 1 partially changed. |
| 402 0 completely unchanged. |
| 403 Per-source Analysis: |
| 404 |
| 405 ---------------------------------------- |
| 406 -4 - Source: /file - (gained 0, lost 4) |
| 407 ---------------------------------------- |
| 408 Shrunk symbols: |
| 409 -2: sym1 type=r, (was 4 bytes, now 2 bytes) (adjusted sizes because \ |
| 410 of memory sharing) |
| 411 -2: sym2 type=r, (was 4 bytes, now 2 bytes) (adjusted sizes because \ |
| 412 of memory sharing) |
| 413 """ |
| 414 |
| 415 self.maxDiff = None |
| 416 self.assertMultiLineEqual(expected_output, result) |
| 417 |
| 418 |
| 419 def testCompareSharedSpaceDuplicateSymbols(self): |
| 420 # List entries have form: |
| 421 # symbol_name, symbol_type, symbol_size, file_path, memory_address |
| 422 symbol_list1 = ( |
| 423 # File with two symbols, same address. |
| 424 ( 'sym1', 'r', 7, '/file', 0x2 ), |
| 425 ( 'sym1', 'r', 8, '/file', 0x1 ), |
| 426 ( 'sym2', 'r', 8, '/file', 0x1 ), |
| 427 ) |
| 428 |
| 429 symbol_list2 = ( |
| 430 # File with two symbols, same address. |
| 431 ( 'sym1', 'r', 7, '/file', 0x2 ), |
| 432 ( 'sym1', 'r', 4, '/file', 0x1 ), |
| 433 ( 'sym2', 'r', 4, '/file', 0x1 ), |
| 434 ) |
| 435 |
| 436 # Here we go |
| 437 (added, removed, changed, unchanged) = \ |
| 438 explain_binary_size_delta.Compare(symbol_list1, symbol_list2) |
| 439 |
| 440 |
| 441 # Now check final stats. |
| 442 orig_stdout = sys.stdout |
| 443 output_collector = cStringIO.StringIO() |
| 444 sys.stdout = output_collector |
| 445 try: |
| 446 explain_binary_size_delta.CrunchStats(added, removed, changed, |
| 447 unchanged, True, True) |
| 448 finally: |
| 449 sys.stdout = orig_stdout |
| 450 result = output_collector.getvalue() |
| 451 |
| 452 expected_output = """\ |
| 453 Total change: -4 bytes |
| 454 ====================== |
| 455 1 added, totalling +2 bytes across 1 sources |
| 456 1 removed, totalling -4 bytes across 1 sources |
| 457 1 shrunk, for a net change of -2 bytes (4 bytes before, 2 bytes after) \ |
| 458 across 1 sources |
| 459 1 unchanged, totalling 7 bytes |
| 460 Source stats: |
| 461 1 sources encountered. |
| 462 0 completely new. |
| 463 0 removed completely. |
| 464 1 partially changed. |
| 465 0 completely unchanged. |
| 466 Per-source Analysis: |
| 467 |
| 468 ---------------------------------------- |
| 469 -4 - Source: /file - (gained 2, lost 6) |
| 470 ---------------------------------------- |
| 471 New symbols: |
| 472 +2: sym1 type=r, size=2 bytes (adjusted sizes because of memory \ |
| 473 sharing) |
| 474 Removed symbols: |
| 475 -4: sym1 type=r, size=4 bytes (adjusted sizes because of memory \ |
| 476 sharing) |
| 477 Shrunk symbols: |
| 478 -2: sym2 type=r, (was 4 bytes, now 2 bytes) (adjusted sizes because \ |
| 479 of memory sharing) |
| 480 """ |
| 481 |
| 482 self.maxDiff = None |
| 483 self.assertMultiLineEqual(expected_output, result) |
| 484 |
| 485 def testCompareSharedSpaceBecomingUnshared(self): |
| 486 # List entries have form: |
| 487 # symbol_name, symbol_type, symbol_size, file_path, memory_address |
| 488 symbol_list1 = ( |
| 489 # File with two symbols, same address. |
| 490 ( 'sym1', 'r', 8, '/file', 0x1 ), |
| 491 ( 'sym2', 'r', 8, '/file', 0x1 ), |
| 492 ) |
| 493 |
| 494 symbol_list2 = ( |
| 495 # File with two symbols, not the same address. |
| 496 ( 'sym1', 'r', 8, '/file', 0x1 ), |
| 497 ( 'sym2', 'r', 6, '/file', 0x2 ), |
| 498 ) |
| 499 |
| 500 # Here we go |
| 501 (added, removed, changed, unchanged) = \ |
| 502 explain_binary_size_delta.Compare(symbol_list1, symbol_list2) |
| 503 |
| 504 |
| 505 # Now check final stats. |
| 506 orig_stdout = sys.stdout |
| 507 output_collector = cStringIO.StringIO() |
| 508 sys.stdout = output_collector |
| 509 try: |
| 510 explain_binary_size_delta.CrunchStats(added, removed, changed, |
| 511 unchanged, True, True) |
| 512 finally: |
| 513 sys.stdout = orig_stdout |
| 514 result = output_collector.getvalue() |
| 515 |
| 516 expected_output = """\ |
| 517 Total change: +6 bytes |
| 518 ====================== |
| 519 2 grown, for a net change of +6 bytes (8 bytes before, 14 bytes after) \ |
| 520 across 1 sources |
| 521 0 unchanged, totalling 0 bytes |
| 522 Source stats: |
| 523 1 sources encountered. |
| 524 0 completely new. |
| 525 0 removed completely. |
| 526 1 partially changed. |
| 527 0 completely unchanged. |
| 528 Per-source Analysis: |
| 529 |
| 530 ---------------------------------------- |
| 531 +6 - Source: /file - (gained 6, lost 0) |
| 532 ---------------------------------------- |
| 533 Grown symbols: |
| 534 +4: sym1 type=r, (was 4 bytes, now 8 bytes) (adjusted sizes because \ |
| 535 of memory sharing) |
| 536 +2: sym2 type=r, (was 4 bytes, now 6 bytes) (adjusted sizes because \ |
| 537 of memory sharing) |
| 538 """ |
| 539 |
| 540 self.maxDiff = None |
| 541 self.assertMultiLineEqual(expected_output, result) |
| 542 |
| 543 def testCompareSymbolsBecomingUnshared(self): |
| 544 # List entries have form: |
| 545 # symbol_name, symbol_type, symbol_size, file_path, memory_address |
| 546 symbol_list1 = ( |
| 547 # File with two symbols, not the same address. |
| 548 ( 'sym1', 'r', 8, '/file', 0x1 ), |
| 549 ( 'sym2', 'r', 6, '/file', 0x2 ), |
| 550 ) |
| 551 |
| 552 symbol_list2 = ( |
| 553 # File with two symbols, same address. |
| 554 ( 'sym1', 'r', 8, '/file', 0x1 ), |
| 555 ( 'sym2', 'r', 8, '/file', 0x1 ), |
| 556 ) |
| 557 |
| 558 # Here we go |
| 559 (added, removed, changed, unchanged) = \ |
| 560 explain_binary_size_delta.Compare(symbol_list1, symbol_list2) |
| 561 |
| 562 |
| 563 # Now check final stats. |
| 564 orig_stdout = sys.stdout |
| 565 output_collector = cStringIO.StringIO() |
| 566 sys.stdout = output_collector |
| 567 try: |
| 568 explain_binary_size_delta.CrunchStats(added, removed, changed, |
| 569 unchanged, True, True) |
| 570 finally: |
| 571 sys.stdout = orig_stdout |
| 572 result = output_collector.getvalue() |
| 573 |
| 574 expected_output = """\ |
| 575 Total change: -6 bytes |
| 576 ====================== |
| 577 2 shrunk, for a net change of -6 bytes (14 bytes before, 8 bytes after) \ |
| 578 across 1 sources |
| 579 0 unchanged, totalling 0 bytes |
| 580 Source stats: |
| 581 1 sources encountered. |
| 582 0 completely new. |
| 583 0 removed completely. |
| 584 1 partially changed. |
| 585 0 completely unchanged. |
| 586 Per-source Analysis: |
| 587 |
| 588 ---------------------------------------- |
| 589 -6 - Source: /file - (gained 0, lost 6) |
| 590 ---------------------------------------- |
| 591 Shrunk symbols: |
| 592 -2: sym2 type=r, (was 6 bytes, now 4 bytes) (adjusted sizes because \ |
| 593 of memory sharing) |
| 594 -4: sym1 type=r, (was 8 bytes, now 4 bytes) (adjusted sizes because \ |
| 595 of memory sharing) |
| 596 """ |
| 597 |
| 598 self.maxDiff = None |
| 599 self.assertMultiLineEqual(expected_output, result) |
| 600 |
| 601 def testDeltaInfo(self): |
| 602 x = explain_binary_size_delta.DeltaInfo("path", "t", "sym_name", False) |
| 603 assert x == x |
| 604 y = explain_binary_size_delta.DeltaInfo("path", "t", "sym_name", False) |
| 605 assert x == y |
| 606 |
| 607 y.new_size = 12 |
| 608 assert x != y |
| 609 |
| 610 x.new_size = 12 |
| 611 assert x == y |
| 612 |
| 613 z = explain_binary_size_delta.DeltaInfo("path", "t", "sym_name", True) |
| 614 assert not (x == z) |
| 615 assert x != z |
| 616 |
| 617 w = explain_binary_size_delta.DeltaInfo("other_path", "t", "sym_name", True) |
| 618 assert w != z |
352 | 619 |
353 if __name__ == '__main__': | 620 if __name__ == '__main__': |
354 unittest.main() | 621 unittest.main() |
OLD | NEW |