Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(470)

Side by Side Diff: tools/binary_size/explain_binary_size_delta_unittest.py

Issue 551203004: Binary size tool, handle symbols with no path better. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/binary_size/explain_binary_size_delta.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 --------------------------------------------------------------------- 214 ---------------------------------------------------------------------
215 Removed symbols: 215 Removed symbols:
216 -1000: removed type=t, size=1000 bytes 216 -1000: removed type=t, size=1000 bytes
217 """ 217 """
218 218
219 self.maxDiff = None 219 self.maxDiff = None
220 self.assertMultiLineEqual(expected_output, result) 220 self.assertMultiLineEqual(expected_output, result)
221 print "explain_binary_size_delta_unittest: All tests passed" 221 print "explain_binary_size_delta_unittest: All tests passed"
222 222
223 223
224 def testCompareStringEntries(self):
225 # List entries have form: symbol_name, symbol_type, symbol_size, file_path
226 symbol_list1 = (
227 # File with one string.
228 ( '.L.str107', 'r', 8, '/file_with_strs' ),
229 )
230
231 symbol_list2 = (
232 # Two files with one string each, same name.
233 ( '.L.str107', 'r', 8, '/file_with_strs' ),
234 ( '.L.str107', 'r', 7, '/other_file_with_strs' ),
235 )
236
237 # Here we go
238 (added, removed, changed, unchanged) = \
239 explain_binary_size_delta.Compare(symbol_list1, symbol_list2)
240
241
242 # Now check final stats.
243 orig_stdout = sys.stdout
244 output_collector = cStringIO.StringIO()
245 sys.stdout = output_collector
246 try:
247 explain_binary_size_delta.CrunchStats(added, removed, changed,
248 unchanged, True, True)
249 finally:
250 sys.stdout = orig_stdout
251 result = output_collector.getvalue()
252
253 expected_output = """\
254 Total change: +7 bytes
255 ======================
256 1 added, totalling +7 bytes across 1 sources
257 1 unchanged, totalling 8 bytes
258 Source stats:
259 2 sources encountered.
260 1 completely new.
261 0 removed completely.
262 0 partially changed.
263 1 completely unchanged.
264 Per-source Analysis:
265
266 --------------------------------------------------------
267 +7 - Source: /other_file_with_strs - (gained 7, lost 0)
268 --------------------------------------------------------
269 New symbols:
270 +7: .L.str107 type=r, size=7 bytes
271 """
272
273 self.maxDiff = None
274 self.assertMultiLineEqual(expected_output, result)
275 print "explain_binary_size_delta_unittest: All tests passed"
276
277 def testCompareStringEntriesWithNoFile(self):
278 # List entries have form: symbol_name, symbol_type, symbol_size, file_path
279 symbol_list1 = (
280 ( '.L.str104', 'r', 21, '??' ), # Will change size.
281 ( '.L.str105', 'r', 17, '??' ), # Same.
282 ( '.L.str106', 'r', 13, '??' ), # Will be removed.
283 ( '.L.str106', 'r', 3, '??' ), # Same.
284 ( '.L.str106', 'r', 3, '??' ), # Will be removed.
285 ( '.L.str107', 'r', 8, '??' ), # Will be removed (other sizes).
286 )
287
288 symbol_list2 = (
289 # Two files with one string each, same name.
290 ( '.L.str104', 'r', 19, '??' ), # Changed.
291 ( '.L.str105', 'r', 11, '??' ), # New size for multi-symbol.
292 ( '.L.str105', 'r', 17, '??' ), # New of same size for multi-symbol.
293 ( '.L.str105', 'r', 17, '??' ), # Same.
294 ( '.L.str106', 'r', 3, '??' ), # Same.
295 ( '.L.str107', 'r', 5, '??' ), # New size for symbol.
296 ( '.L.str107', 'r', 7, '??' ), # New size for symbol.
297 ( '.L.str108', 'r', 8, '??' ), # New symbol.
298 )
299
300 # Here we go
301 (added, removed, changed, unchanged) = \
302 explain_binary_size_delta.Compare(symbol_list1, symbol_list2)
303
304
305 # Now check final stats.
306 orig_stdout = sys.stdout
307 output_collector = cStringIO.StringIO()
308 sys.stdout = output_collector
309 try:
310 explain_binary_size_delta.CrunchStats(added, removed, changed,
311 unchanged, True, True)
312 finally:
313 sys.stdout = orig_stdout
314 result = output_collector.getvalue()
315
316 expected_output = """\
317 Total change: +22 bytes
318 =======================
319 5 added, totalling +48 bytes across 1 sources
320 3 removed, totalling -24 bytes across 1 sources
321 1 shrunk, for a net change of -2 bytes (21 bytes before, 19 bytes after) \
322 across 1 sources
323 2 unchanged, totalling 20 bytes
324 Source stats:
325 1 sources encountered.
326 0 completely new.
327 0 removed completely.
328 1 partially changed.
329 0 completely unchanged.
330 Per-source Analysis:
331
332 ----------------------------------------
333 +22 - Source: ?? - (gained 48, lost 26)
334 ----------------------------------------
335 New symbols:
336 +17: .L.str105 type=r, size=17 bytes
337 +11: .L.str105 type=r, size=11 bytes
338 +8: .L.str108 type=r, size=8 bytes
339 +7: .L.str107 type=r, size=7 bytes
340 +5: .L.str107 type=r, size=5 bytes
341 Removed symbols:
342 -3: .L.str106 type=r, size=3 bytes
343 -8: .L.str107 type=r, size=8 bytes
344 -13: .L.str106 type=r, size=13 bytes
345 Shrunk symbols:
346 -2: .L.str104 type=r, (was 21 bytes, now 19 bytes)
347 """
348
349 self.maxDiff = None
350 self.assertMultiLineEqual(expected_output, result)
351 print "explain_binary_size_delta_unittest: All tests passed"
352
224 if __name__ == '__main__': 353 if __name__ == '__main__':
225 unittest.main() 354 unittest.main()
OLDNEW
« no previous file with comments | « tools/binary_size/explain_binary_size_delta.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698