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): |
Andrew Hayden (chromium.org)
2015/02/16 12:47:38
Can you add a test that exercises your new effecti
Daniel Bratell
2015/02/18 13:31:53
Done.
| |
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 |
83 # File with one symbol, left as-is. | 84 # File with one symbol, left as-is. |
84 assert ('/file_unchanged', 't', 'unchanged', 1000, 1000) in unchanged | 85 assert ('/file_unchanged', 't', 'unchanged', 1000, 1000) in unchanged |
85 # File with one symbol, changed. | 86 # File with one symbol, changed. |
86 assert ('/file_all_changed', 't', 'changed', 1000, 2000) in changed | 87 assert ('/file_all_changed', 't', 'changed', 1000, 2000) in changed |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 | 219 |
219 self.maxDiff = None | 220 self.maxDiff = None |
220 self.assertMultiLineEqual(expected_output, result) | 221 self.assertMultiLineEqual(expected_output, result) |
221 print "explain_binary_size_delta_unittest: All tests passed" | 222 print "explain_binary_size_delta_unittest: All tests passed" |
222 | 223 |
223 | 224 |
224 def testCompareStringEntries(self): | 225 def testCompareStringEntries(self): |
225 # List entries have form: symbol_name, symbol_type, symbol_size, file_path | 226 # List entries have form: symbol_name, symbol_type, symbol_size, file_path |
226 symbol_list1 = ( | 227 symbol_list1 = ( |
227 # File with one string. | 228 # File with one string. |
228 ( '.L.str107', 'r', 8, '/file_with_strs' ), | 229 ( '.L.str107', 'r', 8, '/file_with_strs', 0x1 ), |
229 ) | 230 ) |
230 | 231 |
231 symbol_list2 = ( | 232 symbol_list2 = ( |
232 # Two files with one string each, same name. | 233 # Two files with one string each, same name. |
233 ( '.L.str107', 'r', 8, '/file_with_strs' ), | 234 ( '.L.str107', 'r', 8, '/file_with_strs', 0x1 ), |
234 ( '.L.str107', 'r', 7, '/other_file_with_strs' ), | 235 ( '.L.str107', 'r', 7, '/other_file_with_strs', 0x2 ), |
235 ) | 236 ) |
236 | 237 |
237 # Here we go | 238 # Here we go |
238 (added, removed, changed, unchanged) = \ | 239 (added, removed, changed, unchanged) = \ |
239 explain_binary_size_delta.Compare(symbol_list1, symbol_list2) | 240 explain_binary_size_delta.Compare(symbol_list1, symbol_list2) |
240 | 241 |
241 | 242 |
242 # Now check final stats. | 243 # Now check final stats. |
243 orig_stdout = sys.stdout | 244 orig_stdout = sys.stdout |
244 output_collector = cStringIO.StringIO() | 245 output_collector = cStringIO.StringIO() |
(...skipping 25 matching lines...) Expand all Loading... | |
270 +7: .L.str107 type=r, size=7 bytes | 271 +7: .L.str107 type=r, size=7 bytes |
271 """ | 272 """ |
272 | 273 |
273 self.maxDiff = None | 274 self.maxDiff = None |
274 self.assertMultiLineEqual(expected_output, result) | 275 self.assertMultiLineEqual(expected_output, result) |
275 print "explain_binary_size_delta_unittest: All tests passed" | 276 print "explain_binary_size_delta_unittest: All tests passed" |
276 | 277 |
277 def testCompareStringEntriesWithNoFile(self): | 278 def testCompareStringEntriesWithNoFile(self): |
278 # List entries have form: symbol_name, symbol_type, symbol_size, file_path | 279 # List entries have form: symbol_name, symbol_type, symbol_size, file_path |
279 symbol_list1 = ( | 280 symbol_list1 = ( |
280 ( '.L.str104', 'r', 21, '??' ), # Will change size. | 281 ( '.L.str104', 'r', 21, '??', 0x1 ), # Will change size. |
281 ( '.L.str105', 'r', 17, '??' ), # Same. | 282 ( '.L.str105', 'r', 17, '??', 0x2 ), # Same. |
282 ( '.L.str106', 'r', 13, '??' ), # Will be removed. | 283 ( '.L.str106', 'r', 13, '??', 0x3 ), # Will be removed. |
283 ( '.L.str106', 'r', 3, '??' ), # Same. | 284 ( '.L.str106', 'r', 3, '??', 0x4 ), # Same. |
284 ( '.L.str106', 'r', 3, '??' ), # Will be removed. | 285 ( '.L.str106', 'r', 3, '??', 0x5 ), # Will be removed. |
285 ( '.L.str107', 'r', 8, '??' ), # Will be removed (other sizes). | 286 ( '.L.str107', 'r', 8, '??', 0x6 ), # Will be removed (other sizes). |
286 ) | 287 ) |
287 | 288 |
288 symbol_list2 = ( | 289 symbol_list2 = ( |
289 # Two files with one string each, same name. | 290 # Two files with one string each, same name. |
290 ( '.L.str104', 'r', 19, '??' ), # Changed. | 291 ( '.L.str104', 'r', 19, '??', 0x1 ), # Changed. |
291 ( '.L.str105', 'r', 11, '??' ), # New size for multi-symbol. | 292 ( '.L.str105', 'r', 11, '??', 0x2 ), # New size for multi-symbol. |
292 ( '.L.str105', 'r', 17, '??' ), # New of same size for multi-symbol. | 293 ( '.L.str105', 'r', 17, '??', 0x3 ), # New of same size for multi-symbol. |
293 ( '.L.str105', 'r', 17, '??' ), # Same. | 294 ( '.L.str105', 'r', 17, '??', 0x4 ), # Same. |
294 ( '.L.str106', 'r', 3, '??' ), # Same. | 295 ( '.L.str106', 'r', 3, '??', 0x5 ), # Same. |
295 ( '.L.str107', 'r', 5, '??' ), # New size for symbol. | 296 ( '.L.str107', 'r', 5, '??', 0x6 ), # New size for symbol. |
296 ( '.L.str107', 'r', 7, '??' ), # New size for symbol. | 297 ( '.L.str107', 'r', 7, '??', 0x7 ), # New size for symbol. |
297 ( '.L.str108', 'r', 8, '??' ), # New symbol. | 298 ( '.L.str108', 'r', 8, '??', 0x8 ), # New symbol. |
298 ) | 299 ) |
299 | 300 |
300 # Here we go | 301 # Here we go |
301 (added, removed, changed, unchanged) = \ | 302 (added, removed, changed, unchanged) = \ |
302 explain_binary_size_delta.Compare(symbol_list1, symbol_list2) | 303 explain_binary_size_delta.Compare(symbol_list1, symbol_list2) |
303 | 304 |
304 | 305 |
305 # Now check final stats. | 306 # Now check final stats. |
306 orig_stdout = sys.stdout | 307 orig_stdout = sys.stdout |
307 output_collector = cStringIO.StringIO() | 308 output_collector = cStringIO.StringIO() |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
345 Shrunk symbols: | 346 Shrunk symbols: |
346 -2: .L.str104 type=r, (was 21 bytes, now 19 bytes) | 347 -2: .L.str104 type=r, (was 21 bytes, now 19 bytes) |
347 """ | 348 """ |
348 | 349 |
349 self.maxDiff = None | 350 self.maxDiff = None |
350 self.assertMultiLineEqual(expected_output, result) | 351 self.assertMultiLineEqual(expected_output, result) |
351 print "explain_binary_size_delta_unittest: All tests passed" | 352 print "explain_binary_size_delta_unittest: All tests passed" |
352 | 353 |
353 if __name__ == '__main__': | 354 if __name__ == '__main__': |
354 unittest.main() | 355 unittest.main() |
OLD | NEW |