| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2017 The Chromium Authors. All rights reserved. | 2 # Copyright 2017 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 import contextlib | 6 import contextlib |
| 7 import copy | 7 import copy |
| 8 import difflib | 8 import difflib |
| 9 import glob | 9 import glob |
| 10 import itertools | 10 import itertools |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 def real_decorator(func): | 45 def real_decorator(func): |
| 46 basename = name | 46 basename = name |
| 47 if not basename: | 47 if not basename: |
| 48 basename = func.__name__.replace('test_', '') | 48 basename = func.__name__.replace('test_', '') |
| 49 golden_path = os.path.join(_TEST_DATA_DIR, basename + '.golden') | 49 golden_path = os.path.join(_TEST_DATA_DIR, basename + '.golden') |
| 50 | 50 |
| 51 def inner(self): | 51 def inner(self): |
| 52 actual_lines = func(self) | 52 actual_lines = func(self) |
| 53 actual_lines = (re.sub(r'(elf_mtime=).*', r'\1{redacted}', l) | 53 actual_lines = (re.sub(r'(elf_mtime=).*', r'\1{redacted}', l) |
| 54 for l in actual_lines) | 54 for l in actual_lines) |
| 55 actual_lines = (re.sub(r'(Loaded from ).*', r'\1{redacted}', l) |
| 56 for l in actual_lines) |
| 55 | 57 |
| 56 if update_goldens: | 58 if update_goldens: |
| 57 with open(golden_path, 'w') as file_obj: | 59 with open(golden_path, 'w') as file_obj: |
| 58 describe.WriteLines(actual_lines, file_obj.write) | 60 describe.WriteLines(actual_lines, file_obj.write) |
| 59 logging.info('Wrote %s', golden_path) | 61 logging.info('Wrote %s', golden_path) |
| 60 else: | 62 else: |
| 61 with open(golden_path) as file_obj: | 63 with open(golden_path) as file_obj: |
| 62 _AssertGolden(file_obj, actual_lines) | 64 _AssertGolden(file_obj, actual_lines) |
| 63 return inner | 65 return inner |
| 64 return real_decorator | 66 return real_decorator |
| (...skipping 14 matching lines...) Expand all Loading... |
| 79 env = None | 81 env = None |
| 80 if debug_measures: | 82 if debug_measures: |
| 81 env = os.environ.copy() | 83 env = os.environ.copy() |
| 82 env['SUPERSIZE_DISABLE_ASYNC'] = '1' | 84 env['SUPERSIZE_DISABLE_ASYNC'] = '1' |
| 83 env['SUPERSIZE_MEASURE_GZIP'] = '1' | 85 env['SUPERSIZE_MEASURE_GZIP'] = '1' |
| 84 | 86 |
| 85 return subprocess.check_output(argv, env=env).splitlines() | 87 return subprocess.check_output(argv, env=env).splitlines() |
| 86 | 88 |
| 87 | 89 |
| 88 def _DiffCounts(sym): | 90 def _DiffCounts(sym): |
| 89 return (sym.changed_count, sym.added_count, sym.removed_count) | 91 counts = sym.CountsByDiffStatus() |
| 92 return (counts[models.DIFF_STATUS_CHANGED], |
| 93 counts[models.DIFF_STATUS_ADDED], |
| 94 counts[models.DIFF_STATUS_REMOVED]) |
| 90 | 95 |
| 91 | 96 |
| 92 class IntegrationTest(unittest.TestCase): | 97 class IntegrationTest(unittest.TestCase): |
| 93 maxDiff = None # Don't trucate diffs in errors. | 98 maxDiff = None # Don't trucate diffs in errors. |
| 94 cached_size_info = [None, None, None] | 99 cached_size_info = [None, None, None] |
| 95 | 100 |
| 96 def _CloneSizeInfo(self, use_output_directory=True, use_elf=True): | 101 def _CloneSizeInfo(self, use_output_directory=True, use_elf=True): |
| 97 assert not use_elf or use_output_directory | 102 assert not use_elf or use_output_directory |
| 98 i = int(use_output_directory) + int(use_elf) | 103 i = int(use_output_directory) + int(use_elf) |
| 99 if not IntegrationTest.cached_size_info[i]: | 104 if not IntegrationTest.cached_size_info[i]: |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 def test_Diff_Aliases1(self): | 202 def test_Diff_Aliases1(self): |
| 198 size_info1 = self._CloneSizeInfo() | 203 size_info1 = self._CloneSizeInfo() |
| 199 size_info2 = self._CloneSizeInfo() | 204 size_info2 = self._CloneSizeInfo() |
| 200 | 205 |
| 201 # Removing 1 alias should not change the size. | 206 # Removing 1 alias should not change the size. |
| 202 a1, _, _ = ( | 207 a1, _, _ = ( |
| 203 size_info2.raw_symbols.Filter(lambda s: s.num_aliases == 3)[0].aliases) | 208 size_info2.raw_symbols.Filter(lambda s: s.num_aliases == 3)[0].aliases) |
| 204 size_info2.raw_symbols -= [a1] | 209 size_info2.raw_symbols -= [a1] |
| 205 a1.aliases.remove(a1) | 210 a1.aliases.remove(a1) |
| 206 d = diff.Diff(size_info1, size_info2) | 211 d = diff.Diff(size_info1, size_info2) |
| 207 self.assertEquals(d.raw_symbols.size, 0) | 212 self.assertEquals(d.raw_symbols.pss, 0) |
| 208 self.assertEquals((0, 0, 1), _DiffCounts(d.raw_symbols)) | 213 self.assertEquals((0, 0, 1), _DiffCounts(d.raw_symbols)) |
| 209 # shrinkToFit is in a cluster, so removed turns to a changed when clustered. | 214 # shrinkToFit is in a cluster, so removed turns to a changed when clustered. |
| 210 self.assertEquals((1, 0, 0), _DiffCounts(d.symbols.GroupedByFullName())) | 215 self.assertEquals((1, 0, 0), _DiffCounts(d.symbols.GroupedByFullName())) |
| 211 | 216 |
| 212 # Adding one alias should not change size. | 217 # Adding one alias should not change size. |
| 213 d = diff.Diff(size_info2, size_info1) | 218 d = diff.Diff(size_info2, size_info1) |
| 214 self.assertEquals(d.raw_symbols.size, 0) | 219 self.assertEquals(d.raw_symbols.pss, 0) |
| 215 self.assertEquals((0, 1, 0), _DiffCounts(d.raw_symbols)) | 220 self.assertEquals((0, 1, 0), _DiffCounts(d.raw_symbols)) |
| 216 self.assertEquals((1, 0, 0), _DiffCounts(d.symbols.GroupedByFullName())) | 221 self.assertEquals((1, 0, 0), _DiffCounts(d.symbols.GroupedByFullName())) |
| 217 | 222 |
| 218 def test_Diff_Aliases2(self): | 223 def test_Diff_Aliases2(self): |
| 219 size_info1 = self._CloneSizeInfo() | 224 size_info1 = self._CloneSizeInfo() |
| 220 size_info2 = self._CloneSizeInfo() | 225 size_info2 = self._CloneSizeInfo() |
| 221 | 226 |
| 222 # Removing 2 aliases should not change the size. | 227 # Removing 2 aliases should not change the size. |
| 223 a1, a2, _ = ( | 228 a1, a2, _ = ( |
| 224 size_info2.raw_symbols.Filter(lambda s: s.num_aliases == 3)[0].aliases) | 229 size_info2.raw_symbols.Filter(lambda s: s.num_aliases == 3)[0].aliases) |
| 225 size_info2.raw_symbols -= [a1, a2] | 230 size_info2.raw_symbols -= [a1, a2] |
| 226 a1.aliases.remove(a1) | 231 a1.aliases.remove(a1) |
| 227 a1.aliases.remove(a2) | 232 a1.aliases.remove(a2) |
| 228 d = diff.Diff(size_info1, size_info2) | 233 d = diff.Diff(size_info1, size_info2) |
| 229 self.assertEquals(d.raw_symbols.size, 0) | 234 self.assertEquals(d.raw_symbols.pss, 0) |
| 230 self.assertEquals((0, 0, 2), _DiffCounts(d.raw_symbols)) | 235 self.assertEquals((0, 0, 2), _DiffCounts(d.raw_symbols)) |
| 231 self.assertEquals((1, 0, 1), _DiffCounts(d.symbols.GroupedByFullName())) | 236 self.assertEquals((1, 0, 1), _DiffCounts(d.symbols.GroupedByFullName())) |
| 232 | 237 |
| 233 # Adding 2 aliases should not change size. | 238 # Adding 2 aliases should not change size. |
| 234 d = diff.Diff(size_info2, size_info1) | 239 d = diff.Diff(size_info2, size_info1) |
| 235 self.assertEquals(d.raw_symbols.size, 0) | 240 self.assertEquals(d.raw_symbols.pss, 0) |
| 236 self.assertEquals((0, 2, 0), _DiffCounts(d.raw_symbols)) | 241 self.assertEquals((0, 2, 0), _DiffCounts(d.raw_symbols)) |
| 237 self.assertEquals((1, 1, 0), _DiffCounts(d.symbols.GroupedByFullName())) | 242 self.assertEquals((1, 1, 0), _DiffCounts(d.symbols.GroupedByFullName())) |
| 238 | 243 |
| 239 def test_Diff_Aliases3(self): | 244 def test_Diff_Aliases3(self): |
| 240 size_info1 = self._CloneSizeInfo() | 245 size_info1 = self._CloneSizeInfo() |
| 241 size_info2 = self._CloneSizeInfo() | 246 size_info2 = self._CloneSizeInfo() |
| 242 | 247 |
| 243 # Removing all 3 aliases should change the size. | 248 # Removing all 3 aliases should change the size. |
| 244 a1, a2, a3 = ( | 249 a1, a2, a3 = ( |
| 245 size_info2.raw_symbols.Filter(lambda s: s.num_aliases == 3)[0].aliases) | 250 size_info2.raw_symbols.Filter(lambda s: s.num_aliases == 3)[0].aliases) |
| 246 size_info2.raw_symbols -= [a1, a2, a3] | 251 size_info2.raw_symbols -= [a1, a2, a3] |
| 247 d = diff.Diff(size_info1, size_info2) | 252 d = diff.Diff(size_info1, size_info2) |
| 248 self.assertEquals((0, 0, 3), _DiffCounts(d.raw_symbols)) | 253 self.assertEquals((0, 0, 3), _DiffCounts(d.raw_symbols)) |
| 249 self.assertEquals((1, 0, 2), _DiffCounts(d.symbols.GroupedByFullName())) | 254 self.assertEquals((1, 0, 2), _DiffCounts(d.symbols.GroupedByFullName())) |
| 250 | 255 |
| 251 # Adding all 3 aliases should change size. | 256 # Adding all 3 aliases should change size. |
| 252 d = diff.Diff(size_info2, size_info1) | 257 d = diff.Diff(size_info2, size_info1) |
| 253 self.assertEquals(d.raw_symbols.size, a1.size) | 258 self.assertEquals(d.raw_symbols.pss, a1.size) |
| 254 self.assertEquals((0, 3, 0), _DiffCounts(d.raw_symbols)) | 259 self.assertEquals((0, 3, 0), _DiffCounts(d.raw_symbols)) |
| 255 self.assertEquals((1, 2, 0), _DiffCounts(d.symbols.GroupedByFullName())) | 260 self.assertEquals((1, 2, 0), _DiffCounts(d.symbols.GroupedByFullName())) |
| 256 | 261 |
| 257 def test_Diff_Clustering(self): | 262 def test_Diff_Clustering(self): |
| 258 size_info1 = self._CloneSizeInfo() | 263 size_info1 = self._CloneSizeInfo() |
| 259 size_info2 = self._CloneSizeInfo() | 264 size_info2 = self._CloneSizeInfo() |
| 260 S = '.text' | 265 S = '.text' |
| 261 size_info1.symbols += [ | 266 size_info1.symbols += [ |
| 262 models.Symbol(S, 11, name='.L__unnamed_1193', object_path='a'), # 1 | 267 models.Symbol(S, 11, name='.L__unnamed_1193', object_path='a'), # 1 |
| 263 models.Symbol(S, 22, name='.L__unnamed_1194', object_path='a'), # 2 | 268 models.Symbol(S, 22, name='.L__unnamed_1194', object_path='a'), # 2 |
| 264 models.Symbol(S, 33, name='.L__unnamed_1195', object_path='b'), # 3 | 269 models.Symbol(S, 33, name='.L__unnamed_1195', object_path='b'), # 3 |
| 265 models.Symbol(S, 44, name='.L__bar_195', object_path='b'), # 4 | 270 models.Symbol(S, 44, name='.L__bar_195', object_path='b'), # 4 |
| 266 models.Symbol(S, 55, name='.L__bar_1195', object_path='b'), # 5 | 271 models.Symbol(S, 55, name='.L__bar_1195', object_path='b'), # 5 |
| 267 ] | 272 ] |
| 268 size_info2.symbols += [ | 273 size_info2.symbols += [ |
| 269 models.Symbol(S, 33, name='.L__unnamed_2195', object_path='b'), # 3 | 274 models.Symbol(S, 33, name='.L__unnamed_2195', object_path='b'), # 3 |
| 270 models.Symbol(S, 11, name='.L__unnamed_2194', object_path='a'), # 1 | 275 models.Symbol(S, 11, name='.L__unnamed_2194', object_path='a'), # 1 |
| 271 models.Symbol(S, 22, name='.L__unnamed_2193', object_path='a'), # 2 | 276 models.Symbol(S, 22, name='.L__unnamed_2193', object_path='a'), # 2 |
| 272 models.Symbol(S, 44, name='.L__bar_2195', object_path='b'), # 4 | 277 models.Symbol(S, 44, name='.L__bar_2195', object_path='b'), # 4 |
| 273 models.Symbol(S, 55, name='.L__bar_295', object_path='b'), # 5 | 278 models.Symbol(S, 55, name='.L__bar_295', object_path='b'), # 5 |
| 274 ] | 279 ] |
| 275 d = diff.Diff(size_info1, size_info2) | 280 d = diff.Diff(size_info1, size_info2) |
| 276 d.symbols = d.symbols.Sorted() | 281 d.symbols = d.symbols.Sorted() |
| 277 self.assertEquals(d.symbols.added_count, 0) | 282 self.assertEquals(d.symbols.CountsByDiffStatus()[models.DIFF_STATUS_ADDED], |
| 283 0) |
| 278 self.assertEquals(d.symbols.size, 0) | 284 self.assertEquals(d.symbols.size, 0) |
| 279 | 285 |
| 280 @_CompareWithGolden() | 286 @_CompareWithGolden() |
| 281 def test_FullDescription(self): | 287 def test_FullDescription(self): |
| 282 size_info = self._CloneSizeInfo() | 288 size_info = self._CloneSizeInfo() |
| 283 # Show both clustered and non-clustered so that they can be compared. | 289 # Show both clustered and non-clustered so that they can be compared. |
| 284 size_info.symbols = size_info.raw_symbols | 290 size_info.symbols = size_info.raw_symbols |
| 285 return itertools.chain( | 291 return itertools.chain( |
| 286 describe.GenerateLines(size_info, verbose=True), | 292 describe.GenerateLines(size_info, verbose=True), |
| 287 describe.GenerateLines(size_info.symbols._Clustered(), recursive=True, | 293 describe.GenerateLines(size_info.symbols._Clustered(), recursive=True, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 318 global update_goldens | 324 global update_goldens |
| 319 update_goldens = True | 325 update_goldens = True |
| 320 for f in glob.glob(os.path.join(_TEST_DATA_DIR, '*.golden')): | 326 for f in glob.glob(os.path.join(_TEST_DATA_DIR, '*.golden')): |
| 321 os.unlink(f) | 327 os.unlink(f) |
| 322 | 328 |
| 323 unittest.main(argv=argv, verbosity=2) | 329 unittest.main(argv=argv, verbosity=2) |
| 324 | 330 |
| 325 | 331 |
| 326 if __name__ == '__main__': | 332 if __name__ == '__main__': |
| 327 main() | 333 main() |
| OLD | NEW |