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
4 # found in the LICENSE file.
6 """Check that explain_binary_size_delta seems to work."""
12 import explain_binary_size_delta
15 class ExplainBinarySizeDeltaTest(unittest
.TestCase
):
17 def testCompare(self
):
18 # List entries have form: symbol_name, symbol_type, symbol_size, file_path
20 # File with one symbol, left as-is.
21 ( 'unchanged', 't', 1000, '/file_unchanged' ),
22 # File with one symbol, changed.
23 ( 'changed', 't', 1000, '/file_all_changed' ),
24 # File with one symbol, deleted.
25 ( 'removed', 't', 1000, '/file_all_deleted' ),
26 # File with two symbols, one unchanged, one changed, same bucket
27 ( 'unchanged', 't', 1000, '/file_pair_unchanged_changed' ),
28 ( 'changed', 't', 1000, '/file_pair_unchanged_changed' ),
29 # File with two symbols, one unchanged, one deleted, same bucket
30 ( 'unchanged', 't', 1000, '/file_pair_unchanged_removed' ),
31 ( 'removed', 't', 1000, '/file_pair_unchanged_removed' ),
32 # File with two symbols, one unchanged, one added, same bucket
33 ( 'unchanged', 't', 1000, '/file_pair_unchanged_added' ),
34 # File with two symbols, one unchanged, one changed, different bucket
35 ( 'unchanged', 't', 1000, '/file_pair_unchanged_diffbuck_changed' ),
36 ( 'changed', '@', 1000, '/file_pair_unchanged_diffbuck_changed' ),
37 # File with two symbols, one unchanged, one deleted, different bucket
38 ( 'unchanged', 't', 1000, '/file_pair_unchanged_diffbuck_removed' ),
39 ( 'removed', '@', 1000, '/file_pair_unchanged_diffbuck_removed' ),
40 # File with two symbols, one unchanged, one added, different bucket
41 ( 'unchanged', 't', 1000, '/file_pair_unchanged_diffbuck_added' ),
42 # File with four symbols, one added, one removed,
43 # one changed, one unchanged
44 ( 'size_changed', 't', 1000, '/file_tetra' ),
45 ( 'removed', 't', 1000, '/file_tetra' ),
46 ( 'unchanged', 't', 1000, '/file_tetra' ),
50 # File with one symbol, left as-is.
51 ( 'unchanged', 't', 1000, '/file_unchanged' ),
52 # File with one symbol, changed.
53 ( 'changed', 't', 2000, '/file_all_changed' ),
54 # File with two symbols, one unchanged, one changed, same bucket
55 ( 'unchanged', 't', 1000, '/file_pair_unchanged_changed' ),
56 ( 'changed', 't', 2000, '/file_pair_unchanged_changed' ),
57 # File with two symbols, one unchanged, one deleted, same bucket
58 ( 'unchanged', 't', 1000, '/file_pair_unchanged_removed' ),
59 # File with two symbols, one unchanged, one added, same bucket
60 ( 'unchanged', 't', 1000, '/file_pair_unchanged_added' ),
61 ( 'added', 't', 1000, '/file_pair_unchanged_added' ),
62 # File with two symbols, one unchanged, one changed, different bucket
63 ( 'unchanged', 't', 1000, '/file_pair_unchanged_diffbuck_changed' ),
64 ( 'changed', '@', 2000, '/file_pair_unchanged_diffbuck_changed' ),
65 # File with two symbols, one unchanged, one deleted, different bucket
66 ( 'unchanged', 't', 1000, '/file_pair_unchanged_diffbuck_removed' ),
67 # File with two symbols, one unchanged, one added, different bucket
68 ( 'unchanged', 't', 1000, '/file_pair_unchanged_diffbuck_added' ),
69 ( 'added', '@', 1000, '/file_pair_unchanged_diffbuck_added' ),
70 # File with four symbols, one added, one removed,
71 # one changed, one unchanged
72 ( 'size_changed', 't', 2000, '/file_tetra' ),
73 ( 'unchanged', 't', 1000, '/file_tetra' ),
74 ( 'added', 't', 1000, '/file_tetra' ),
75 # New file with one symbol added
76 ( 'added', 't', 1000, '/file_new' ),
80 (added
, removed
, changed
, unchanged
) = \
81 explain_binary_size_delta
.Compare(symbol_list1
, symbol_list2
)
83 # File with one symbol, left as-is.
84 assert ('/file_unchanged', 't', 'unchanged', 1000, 1000) in unchanged
85 # File with one symbol, changed.
86 assert ('/file_all_changed', 't', 'changed', 1000, 2000) in changed
87 # File with one symbol, deleted.
88 assert ('/file_all_deleted', 't', 'removed', 1000, None) in removed
89 # New file with one symbol added
90 assert ('/file_new', 't', 'added', None, 1000) in added
91 # File with two symbols, one unchanged, one changed, same bucket
92 assert ('/file_pair_unchanged_changed',
93 't', 'unchanged', 1000, 1000) in unchanged
94 assert ('/file_pair_unchanged_changed',
95 't', 'changed', 1000, 2000) in changed
96 # File with two symbols, one unchanged, one removed, same bucket
97 assert ('/file_pair_unchanged_removed',
98 't', 'unchanged', 1000, 1000) in unchanged
99 assert ('/file_pair_unchanged_removed',
100 't', 'removed', 1000, None) in removed
101 # File with two symbols, one unchanged, one added, same bucket
102 assert ('/file_pair_unchanged_added',
103 't', 'unchanged', 1000, 1000) in unchanged
104 assert ('/file_pair_unchanged_added',
105 't', 'added', None, 1000) in added
106 # File with two symbols, one unchanged, one changed, different bucket
107 assert ('/file_pair_unchanged_diffbuck_changed',
108 't', 'unchanged', 1000, 1000) in unchanged
109 assert ('/file_pair_unchanged_diffbuck_changed',
110 '@', 'changed', 1000, 2000) in changed
111 # File with two symbols, one unchanged, one removed, different bucket
112 assert ('/file_pair_unchanged_diffbuck_removed',
113 't', 'unchanged', 1000, 1000) in unchanged
114 assert ('/file_pair_unchanged_diffbuck_removed',
115 '@', 'removed', 1000, None) in removed
116 # File with two symbols, one unchanged, one added, different bucket
117 assert ('/file_pair_unchanged_diffbuck_added',
118 't', 'unchanged', 1000, 1000) in unchanged
119 assert ('/file_pair_unchanged_diffbuck_added',
120 '@', 'added', None, 1000) in added
121 # File with four symbols, one added, one removed, one changed, one unchanged
122 assert ('/file_tetra', 't', 'size_changed', 1000, 2000) in changed
123 assert ('/file_tetra', 't', 'unchanged', 1000, 1000) in unchanged
124 assert ('/file_tetra', 't', 'added', None, 1000) in added
125 assert ('/file_tetra', 't', 'removed', 1000, None) in removed
127 # Now check final stats.
128 orig_stdout
= sys
.stdout
129 output_collector
= cStringIO
.StringIO()
130 sys
.stdout
= output_collector
132 explain_binary_size_delta
.CrunchStats(added
, removed
, changed
,
133 unchanged
, True, True)
135 sys
.stdout
= orig_stdout
136 result
= output_collector
.getvalue()
138 expected_output
= """\
140 4 added, totalling 4000 bytes across 4 sources
141 4 removed, totalling 4000 bytes removed across 4 sources
142 4 changed, resulting in a net change of 4000 bytes \
143 (4000 bytes before, 8000 bytes after) across 4 sources
144 8 unchanged, totalling 8000 bytes
146 11 sources encountered.
148 1 removed completely.
150 1 completely unchanged.
152 Source: /file_all_changed
153 Change: 1000 bytes (gained 1000, lost 0)
155 changed type=t, delta=1000 bytes (was 1000 bytes, now 2000 bytes)
156 Source: /file_all_deleted
157 Change: -1000 bytes (gained 0, lost 1000)
159 removed type=t, size=1000 bytes
161 Change: 1000 bytes (gained 1000, lost 0)
163 added type=t, size=1000 bytes
164 Source: /file_pair_unchanged_added
165 Change: 1000 bytes (gained 1000, lost 0)
167 added type=t, size=1000 bytes
168 Source: /file_pair_unchanged_changed
169 Change: 1000 bytes (gained 1000, lost 0)
171 changed type=t, delta=1000 bytes (was 1000 bytes, now 2000 bytes)
172 Source: /file_pair_unchanged_diffbuck_added
173 Change: 1000 bytes (gained 1000, lost 0)
175 added type=@, size=1000 bytes
176 Source: /file_pair_unchanged_diffbuck_changed
177 Change: 1000 bytes (gained 1000, lost 0)
179 changed type=@, delta=1000 bytes (was 1000 bytes, now 2000 bytes)
180 Source: /file_pair_unchanged_diffbuck_removed
181 Change: -1000 bytes (gained 0, lost 1000)
183 removed type=@, size=1000 bytes
184 Source: /file_pair_unchanged_removed
185 Change: -1000 bytes (gained 0, lost 1000)
187 removed type=t, size=1000 bytes
189 Change: 1000 bytes (gained 2000, lost 1000)
191 added type=t, size=1000 bytes
193 removed type=t, size=1000 bytes
195 size_changed type=t, delta=1000 bytes (was 1000 bytes, now 2000 bytes)
199 self
.assertMultiLineEqual(expected_output
, result
)
200 print "explain_binary_size_delta_unittest: All tests passed"
203 if __name__
== '__main__':