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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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" | 229 print "explain_binary_size_delta_unittest: All tests passed" |
222 | 230 |
223 | 231 |
224 def testCompareStringEntries(self): | 232 def testCompareStringEntries(self): |
225 # List entries have form: symbol_name, symbol_type, symbol_size, file_path | 233 # List entries have form: |
234 # symbol_name, symbol_type, symbol_size, file_path, memory_address | |
226 symbol_list1 = ( | 235 symbol_list1 = ( |
227 # File with one string. | 236 # File with one string. |
228 ( '.L.str107', 'r', 8, '/file_with_strs' ), | 237 ( '.L.str107', 'r', 8, '/file_with_strs', 0x1 ), |
229 ) | 238 ) |
230 | 239 |
231 symbol_list2 = ( | 240 symbol_list2 = ( |
232 # Two files with one string each, same name. | 241 # Two files with one string each, same name. |
233 ( '.L.str107', 'r', 8, '/file_with_strs' ), | 242 ( '.L.str107', 'r', 8, '/file_with_strs', 0x1 ), |
234 ( '.L.str107', 'r', 7, '/other_file_with_strs' ), | 243 ( '.L.str107', 'r', 7, '/other_file_with_strs', 0x2 ), |
235 ) | 244 ) |
236 | 245 |
237 # Here we go | 246 # Here we go |
238 (added, removed, changed, unchanged) = \ | 247 (added, removed, changed, unchanged) = \ |
239 explain_binary_size_delta.Compare(symbol_list1, symbol_list2) | 248 explain_binary_size_delta.Compare(symbol_list1, symbol_list2) |
240 | 249 |
241 | 250 |
242 # Now check final stats. | 251 # Now check final stats. |
243 orig_stdout = sys.stdout | 252 orig_stdout = sys.stdout |
244 output_collector = cStringIO.StringIO() | 253 output_collector = cStringIO.StringIO() |
(...skipping 23 matching lines...) Expand all Loading... | |
268 -------------------------------------------------------- | 277 -------------------------------------------------------- |
269 New symbols: | 278 New symbols: |
270 +7: .L.str107 type=r, size=7 bytes | 279 +7: .L.str107 type=r, size=7 bytes |
271 """ | 280 """ |
272 | 281 |
273 self.maxDiff = None | 282 self.maxDiff = None |
274 self.assertMultiLineEqual(expected_output, result) | 283 self.assertMultiLineEqual(expected_output, result) |
275 print "explain_binary_size_delta_unittest: All tests passed" | 284 print "explain_binary_size_delta_unittest: All tests passed" |
276 | 285 |
277 def testCompareStringEntriesWithNoFile(self): | 286 def testCompareStringEntriesWithNoFile(self): |
278 # List entries have form: symbol_name, symbol_type, symbol_size, file_path | 287 # List entries have form: |
288 # symbol_name, symbol_type, symbol_size, file_path, memory_address | |
279 symbol_list1 = ( | 289 symbol_list1 = ( |
280 ( '.L.str104', 'r', 21, '??' ), # Will change size. | 290 ( '.L.str104', 'r', 21, '??', 0x1 ), # Will change size. |
281 ( '.L.str105', 'r', 17, '??' ), # Same. | 291 ( '.L.str105', 'r', 17, '??', 0x2 ), # Same. |
282 ( '.L.str106', 'r', 13, '??' ), # Will be removed. | 292 ( '.L.str106', 'r', 13, '??', 0x3 ), # Will be removed. |
283 ( '.L.str106', 'r', 3, '??' ), # Same. | 293 ( '.L.str106', 'r', 3, '??', 0x4 ), # Same. |
284 ( '.L.str106', 'r', 3, '??' ), # Will be removed. | 294 ( '.L.str106', 'r', 3, '??', 0x5 ), # Will be removed. |
285 ( '.L.str107', 'r', 8, '??' ), # Will be removed (other sizes). | 295 ( '.L.str107', 'r', 8, '??', 0x6 ), # Will be removed (other sizes). |
286 ) | 296 ) |
287 | 297 |
288 symbol_list2 = ( | 298 symbol_list2 = ( |
289 # Two files with one string each, same name. | 299 # Two files with one string each, same name. |
290 ( '.L.str104', 'r', 19, '??' ), # Changed. | 300 ( '.L.str104', 'r', 19, '??', 0x1 ), # Changed. |
291 ( '.L.str105', 'r', 11, '??' ), # New size for multi-symbol. | 301 ( '.L.str105', 'r', 11, '??', 0x2 ), # New size for multi-symbol. |
292 ( '.L.str105', 'r', 17, '??' ), # New of same size for multi-symbol. | 302 ( '.L.str105', 'r', 17, '??', 0x3 ), # New of same size for multi-symbol. |
293 ( '.L.str105', 'r', 17, '??' ), # Same. | 303 ( '.L.str105', 'r', 17, '??', 0x4 ), # Same. |
294 ( '.L.str106', 'r', 3, '??' ), # Same. | 304 ( '.L.str106', 'r', 3, '??', 0x5 ), # Same. |
295 ( '.L.str107', 'r', 5, '??' ), # New size for symbol. | 305 ( '.L.str107', 'r', 5, '??', 0x6 ), # New size for symbol. |
296 ( '.L.str107', 'r', 7, '??' ), # New size for symbol. | 306 ( '.L.str107', 'r', 7, '??', 0x7 ), # New size for symbol. |
297 ( '.L.str108', 'r', 8, '??' ), # New symbol. | 307 ( '.L.str108', 'r', 8, '??', 0x8 ), # New symbol. |
298 ) | 308 ) |
299 | 309 |
300 # Here we go | 310 # Here we go |
301 (added, removed, changed, unchanged) = \ | 311 (added, removed, changed, unchanged) = \ |
302 explain_binary_size_delta.Compare(symbol_list1, symbol_list2) | 312 explain_binary_size_delta.Compare(symbol_list1, symbol_list2) |
303 | 313 |
304 | 314 |
305 # Now check final stats. | 315 # Now check final stats. |
306 orig_stdout = sys.stdout | 316 orig_stdout = sys.stdout |
307 output_collector = cStringIO.StringIO() | 317 output_collector = cStringIO.StringIO() |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
343 -8: .L.str107 type=r, size=8 bytes | 353 -8: .L.str107 type=r, size=8 bytes |
344 -13: .L.str106 type=r, size=13 bytes | 354 -13: .L.str106 type=r, size=13 bytes |
345 Shrunk symbols: | 355 Shrunk symbols: |
346 -2: .L.str104 type=r, (was 21 bytes, now 19 bytes) | 356 -2: .L.str104 type=r, (was 21 bytes, now 19 bytes) |
347 """ | 357 """ |
348 | 358 |
349 self.maxDiff = None | 359 self.maxDiff = None |
350 self.assertMultiLineEqual(expected_output, result) | 360 self.assertMultiLineEqual(expected_output, result) |
351 print "explain_binary_size_delta_unittest: All tests passed" | 361 print "explain_binary_size_delta_unittest: All tests passed" |
352 | 362 |
363 def testCompareSharedSpace(self): | |
364 # List entries have form: | |
365 # symbol_name, symbol_type, symbol_size, file_path, memory_address | |
366 symbol_list1 = ( | |
367 # File with two symbols, same address. | |
368 ( 'sym1', 'r', 8, '/file', 0x1 ), | |
369 ( 'sym2', 'r', 8, '/file', 0x1 ), | |
370 ) | |
371 | |
372 symbol_list2 = ( | |
373 # File with two symbols, same address. | |
374 ( 'sym1', 'r', 4, '/file', 0x1 ), | |
375 ( 'sym2', 'r', 4, '/file', 0x1 ), | |
376 ) | |
377 | |
378 # Here we go | |
379 (added, removed, changed, unchanged) = \ | |
380 explain_binary_size_delta.Compare(symbol_list1, symbol_list2) | |
381 | |
382 | |
383 # Now check final stats. | |
384 orig_stdout = sys.stdout | |
385 output_collector = cStringIO.StringIO() | |
386 sys.stdout = output_collector | |
387 try: | |
388 explain_binary_size_delta.CrunchStats(added, removed, changed, | |
389 unchanged, True, True) | |
390 finally: | |
391 sys.stdout = orig_stdout | |
392 result = output_collector.getvalue() | |
393 | |
394 expected_output = """\ | |
395 Total change: -4 bytes | |
396 ====================== | |
397 2 shrunk, for a net change of -4 bytes (8 bytes before, 4 bytes after) \ | |
398 across 1 sources | |
399 0 unchanged, totalling 0 bytes | |
400 Source stats: | |
401 1 sources encountered. | |
402 0 completely new. | |
403 0 removed completely. | |
404 1 partially changed. | |
405 0 completely unchanged. | |
406 Per-source Analysis: | |
407 | |
408 ---------------------------------------- | |
409 -4 - Source: /file - (gained 0, lost 4) | |
410 ---------------------------------------- | |
411 Shrunk symbols: | |
412 -2: sym1 type=r, (was 4 bytes, now 2 bytes) (adjusted sizes because \ | |
413 of memory sharing) | |
414 -2: sym2 type=r, (was 4 bytes, now 2 bytes) (adjusted sizes because \ | |
415 of memory sharing) | |
416 """ | |
417 | |
418 self.maxDiff = None | |
419 self.assertMultiLineEqual(expected_output, result) | |
420 print "explain_binary_size_delta_unittest: All tests passed" | |
421 | |
422 | |
423 def testCompareSharedSpaceDuplicateSymbols(self): | |
424 # List entries have form: | |
425 # symbol_name, symbol_type, symbol_size, file_path, memory_address | |
426 symbol_list1 = ( | |
427 # File with two symbols, same address. | |
428 ( 'sym1', 'r', 7, '/file', 0x2 ), | |
429 ( 'sym1', 'r', 8, '/file', 0x1 ), | |
430 ( 'sym2', 'r', 8, '/file', 0x1 ), | |
431 ) | |
432 | |
433 symbol_list2 = ( | |
434 # File with two symbols, same address. | |
435 ( 'sym1', 'r', 7, '/file', 0x2 ), | |
436 ( 'sym1', 'r', 4, '/file', 0x1 ), | |
437 ( 'sym2', 'r', 4, '/file', 0x1 ), | |
438 ) | |
439 | |
440 # Here we go | |
441 (added, removed, changed, unchanged) = \ | |
442 explain_binary_size_delta.Compare(symbol_list1, symbol_list2) | |
443 | |
444 | |
445 # Now check final stats. | |
446 orig_stdout = sys.stdout | |
447 output_collector = cStringIO.StringIO() | |
448 sys.stdout = output_collector | |
449 try: | |
450 explain_binary_size_delta.CrunchStats(added, removed, changed, | |
451 unchanged, True, True) | |
452 finally: | |
453 sys.stdout = orig_stdout | |
454 result = output_collector.getvalue() | |
455 | |
456 expected_output = """\ | |
457 Total change: -4 bytes | |
458 ====================== | |
459 1 added, totalling +2 bytes across 1 sources | |
460 1 removed, totalling -4 bytes across 1 sources | |
461 1 shrunk, for a net change of -2 bytes (4 bytes before, 2 bytes after) \ | |
462 across 1 sources | |
463 1 unchanged, totalling 7 bytes | |
464 Source stats: | |
465 1 sources encountered. | |
466 0 completely new. | |
467 0 removed completely. | |
468 1 partially changed. | |
469 0 completely unchanged. | |
470 Per-source Analysis: | |
471 | |
472 ---------------------------------------- | |
473 -4 - Source: /file - (gained 2, lost 6) | |
474 ---------------------------------------- | |
475 New symbols: | |
476 +2: sym1 type=r, size=2 bytes (adjusted sizes because of memory \ | |
477 sharing) | |
478 Removed symbols: | |
479 -4: sym1 type=r, size=4 bytes (adjusted sizes because of memory \ | |
480 sharing) | |
481 Shrunk symbols: | |
482 -2: sym2 type=r, (was 4 bytes, now 2 bytes) (adjusted sizes because \ | |
483 of memory sharing) | |
484 """ | |
485 | |
486 self.maxDiff = None | |
487 self.assertMultiLineEqual(expected_output, result) | |
488 print "explain_binary_size_delta_unittest: All tests passed" | |
489 | |
490 def testCompareSharedSpaceBecomingUnshared(self): | |
491 # List entries have form: | |
492 # symbol_name, symbol_type, symbol_size, file_path, memory_address | |
493 symbol_list1 = ( | |
494 # File with two symbols, same address. | |
495 ( 'sym1', 'r', 8, '/file', 0x1 ), | |
496 ( 'sym2', 'r', 8, '/file', 0x1 ), | |
497 ) | |
498 | |
499 symbol_list2 = ( | |
500 # File with two symbols, not the same address. | |
501 ( 'sym1', 'r', 8, '/file', 0x1 ), | |
502 ( 'sym2', 'r', 6, '/file', 0x2 ), | |
503 ) | |
504 | |
505 # Here we go | |
506 (added, removed, changed, unchanged) = \ | |
507 explain_binary_size_delta.Compare(symbol_list1, symbol_list2) | |
508 | |
509 | |
510 # Now check final stats. | |
511 orig_stdout = sys.stdout | |
512 output_collector = cStringIO.StringIO() | |
513 sys.stdout = output_collector | |
514 try: | |
515 explain_binary_size_delta.CrunchStats(added, removed, changed, | |
516 unchanged, True, True) | |
517 finally: | |
518 sys.stdout = orig_stdout | |
519 result = output_collector.getvalue() | |
520 | |
521 expected_output = """\ | |
522 Total change: +6 bytes | |
523 ====================== | |
524 2 grown, for a net change of +6 bytes (8 bytes before, 14 bytes after) \ | |
525 across 1 sources | |
526 0 unchanged, totalling 0 bytes | |
527 Source stats: | |
528 1 sources encountered. | |
529 0 completely new. | |
530 0 removed completely. | |
531 1 partially changed. | |
532 0 completely unchanged. | |
533 Per-source Analysis: | |
534 | |
535 ---------------------------------------- | |
536 +6 - Source: /file - (gained 6, lost 0) | |
537 ---------------------------------------- | |
538 Grown symbols: | |
539 +4: sym1 type=r, (was 4 bytes, now 8 bytes) (adjusted sizes because \ | |
540 of memory sharing) | |
541 +2: sym2 type=r, (was 4 bytes, now 6 bytes) (adjusted sizes because \ | |
542 of memory sharing) | |
543 """ | |
544 | |
545 self.maxDiff = None | |
546 self.assertMultiLineEqual(expected_output, result) | |
547 print "explain_binary_size_delta_unittest: All tests passed" | |
548 | |
549 def testCompareSymbolsBecomingUnshared(self): | |
550 # List entries have form: | |
551 # symbol_name, symbol_type, symbol_size, file_path, memory_address | |
552 symbol_list1 = ( | |
553 # File with two symbols, not the same address. | |
554 ( 'sym1', 'r', 8, '/file', 0x1 ), | |
555 ( 'sym2', 'r', 6, '/file', 0x2 ), | |
556 ) | |
557 | |
558 symbol_list2 = ( | |
559 # File with two symbols, same address. | |
560 ( 'sym1', 'r', 8, '/file', 0x1 ), | |
561 ( 'sym2', 'r', 8, '/file', 0x1 ), | |
562 ) | |
563 | |
564 # Here we go | |
565 (added, removed, changed, unchanged) = \ | |
566 explain_binary_size_delta.Compare(symbol_list1, symbol_list2) | |
567 | |
568 | |
569 # Now check final stats. | |
570 orig_stdout = sys.stdout | |
571 output_collector = cStringIO.StringIO() | |
572 sys.stdout = output_collector | |
573 try: | |
574 explain_binary_size_delta.CrunchStats(added, removed, changed, | |
575 unchanged, True, True) | |
576 finally: | |
577 sys.stdout = orig_stdout | |
578 result = output_collector.getvalue() | |
579 | |
580 expected_output = """\ | |
581 Total change: -6 bytes | |
582 ====================== | |
583 2 shrunk, for a net change of -6 bytes (14 bytes before, 8 bytes after) \ | |
584 across 1 sources | |
585 0 unchanged, totalling 0 bytes | |
586 Source stats: | |
587 1 sources encountered. | |
588 0 completely new. | |
589 0 removed completely. | |
590 1 partially changed. | |
591 0 completely unchanged. | |
592 Per-source Analysis: | |
593 | |
594 ---------------------------------------- | |
595 -6 - Source: /file - (gained 0, lost 6) | |
596 ---------------------------------------- | |
597 Shrunk symbols: | |
598 -2: sym2 type=r, (was 6 bytes, now 4 bytes) (adjusted sizes because \ | |
599 of memory sharing) | |
600 -4: sym1 type=r, (was 8 bytes, now 4 bytes) (adjusted sizes because \ | |
601 of memory sharing) | |
602 """ | |
603 | |
604 self.maxDiff = None | |
605 self.assertMultiLineEqual(expected_output, result) | |
606 print "explain_binary_size_delta_unittest: All tests passed" | |
Andrew Hayden (chromium.org)
2015/02/18 13:48:24
I have no idea why the first "All tests passed" go
| |
607 | |
608 def testDeltaInfo(self): | |
609 x = explain_binary_size_delta.DeltaInfo("path", "t", "sym_name", False) | |
610 assert x == x | |
611 y = explain_binary_size_delta.DeltaInfo("path", "t", "sym_name", False) | |
612 assert x == y | |
613 | |
614 y.new_size = 12 | |
615 assert x != y | |
616 | |
617 x.new_size = 12 | |
618 assert x == y | |
619 | |
620 z = explain_binary_size_delta.DeltaInfo("path", "t", "sym_name", True) | |
621 assert not (x == z) | |
622 assert x != z | |
623 | |
624 w = explain_binary_size_delta.DeltaInfo("other_path", "t", "sym_name", True) | |
625 assert w != z | |
626 | |
353 if __name__ == '__main__': | 627 if __name__ == '__main__': |
354 unittest.main() | 628 unittest.main() |
OLD | NEW |