| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 with _AddMocksToPath(): | 78 with _AddMocksToPath(): |
| 79 env = None | 79 env = None |
| 80 if debug_measures: | 80 if debug_measures: |
| 81 env = os.environ.copy() | 81 env = os.environ.copy() |
| 82 env['SUPERSIZE_DISABLE_ASYNC'] = '1' | 82 env['SUPERSIZE_DISABLE_ASYNC'] = '1' |
| 83 env['SUPERSIZE_MEASURE_GZIP'] = '1' | 83 env['SUPERSIZE_MEASURE_GZIP'] = '1' |
| 84 | 84 |
| 85 return subprocess.check_output(argv, env=env).splitlines() | 85 return subprocess.check_output(argv, env=env).splitlines() |
| 86 | 86 |
| 87 | 87 |
| 88 def _DiffCounts(sym): |
| 89 return (sym.changed_count, sym.added_count, sym.removed_count) |
| 90 |
| 91 |
| 88 class IntegrationTest(unittest.TestCase): | 92 class IntegrationTest(unittest.TestCase): |
| 89 maxDiff = None # Don't trucate diffs in errors. | 93 maxDiff = None # Don't trucate diffs in errors. |
| 90 cached_size_info = [None, None, None] | 94 cached_size_info = [None, None, None] |
| 91 | 95 |
| 92 def _CloneSizeInfo(self, use_output_directory=True, use_elf=True): | 96 def _CloneSizeInfo(self, use_output_directory=True, use_elf=True): |
| 93 assert not use_elf or use_output_directory | 97 assert not use_elf or use_output_directory |
| 94 i = int(use_output_directory) + int(use_elf) | 98 i = int(use_output_directory) + int(use_elf) |
| 95 if not IntegrationTest.cached_size_info[i]: | 99 if not IntegrationTest.cached_size_info[i]: |
| 96 elf_path = _TEST_ELF_PATH if use_elf else None | 100 elf_path = _TEST_ELF_PATH if use_elf else None |
| 97 output_directory = _TEST_OUTPUT_DIR if use_output_directory else None | 101 output_directory = _TEST_OUTPUT_DIR if use_output_directory else None |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 size_info1 = self._CloneSizeInfo() | 195 size_info1 = self._CloneSizeInfo() |
| 192 size_info2 = self._CloneSizeInfo() | 196 size_info2 = self._CloneSizeInfo() |
| 193 | 197 |
| 194 # Removing 1 alias should not change the size. | 198 # Removing 1 alias should not change the size. |
| 195 a1, _, _ = ( | 199 a1, _, _ = ( |
| 196 size_info2.symbols.Filter(lambda s: s.num_aliases == 3)[0].aliases) | 200 size_info2.symbols.Filter(lambda s: s.num_aliases == 3)[0].aliases) |
| 197 size_info2.symbols -= [a1] | 201 size_info2.symbols -= [a1] |
| 198 a1.aliases.remove(a1) | 202 a1.aliases.remove(a1) |
| 199 d = diff.Diff(size_info1, size_info2) | 203 d = diff.Diff(size_info1, size_info2) |
| 200 self.assertEquals(d.symbols.size, 0) | 204 self.assertEquals(d.symbols.size, 0) |
| 201 self.assertEquals(d.symbols.removed_count, 1) | 205 self.assertEquals((0, 0, 1), _DiffCounts(d.symbols)) |
| 206 # shrinkToFit is in a cluster, so removed turns to a changed when clustered. |
| 207 self.assertEquals((1, 0, 0), _DiffCounts(d.symbols.Clustered())) |
| 202 | 208 |
| 203 # Adding one alias should not change size. | 209 # Adding one alias should not change size. |
| 204 d = diff.Diff(size_info2, size_info1) | 210 d = diff.Diff(size_info2, size_info1) |
| 205 self.assertEquals(d.symbols.size, 0) | 211 self.assertEquals(d.symbols.size, 0) |
| 206 self.assertEquals(d.symbols.added_count, 1) | 212 self.assertEquals((0, 1, 0), _DiffCounts(d.symbols)) |
| 213 self.assertEquals((1, 0, 0), _DiffCounts(d.symbols.Clustered())) |
| 207 | 214 |
| 208 def test_Diff_Aliases2(self): | 215 def test_Diff_Aliases2(self): |
| 209 size_info1 = self._CloneSizeInfo() | 216 size_info1 = self._CloneSizeInfo() |
| 210 size_info2 = self._CloneSizeInfo() | 217 size_info2 = self._CloneSizeInfo() |
| 211 | 218 |
| 212 # Removing 2 aliases should not change the size. | 219 # Removing 2 aliases should not change the size. |
| 213 a1, a2, _ = ( | 220 a1, a2, _ = ( |
| 214 size_info2.symbols.Filter(lambda s: s.num_aliases == 3)[0].aliases) | 221 size_info2.symbols.Filter(lambda s: s.num_aliases == 3)[0].aliases) |
| 215 size_info2.symbols -= [a1, a2] | 222 size_info2.symbols -= [a1, a2] |
| 216 a1.aliases.remove(a1) | 223 a1.aliases.remove(a1) |
| 217 a1.aliases.remove(a2) | 224 a1.aliases.remove(a2) |
| 218 d = diff.Diff(size_info1, size_info2) | 225 d = diff.Diff(size_info1, size_info2) |
| 219 self.assertEquals(d.symbols.size, 0) | 226 self.assertEquals(d.symbols.size, 0) |
| 220 self.assertEquals(d.symbols.removed_count, 2) | 227 self.assertEquals((0, 0, 2), _DiffCounts(d.symbols)) |
| 228 self.assertEquals((1, 0, 1), _DiffCounts(d.symbols.Clustered())) |
| 221 | 229 |
| 222 # Adding 2 aliases should not change size. | 230 # Adding 2 aliases should not change size. |
| 223 d = diff.Diff(size_info2, size_info1) | 231 d = diff.Diff(size_info2, size_info1) |
| 224 self.assertEquals(d.symbols.size, 0) | 232 self.assertEquals(d.symbols.size, 0) |
| 225 self.assertEquals(d.symbols.added_count, 2) | 233 self.assertEquals((0, 2, 0), _DiffCounts(d.symbols)) |
| 234 self.assertEquals((1, 1, 0), _DiffCounts(d.symbols.Clustered())) |
| 226 | 235 |
| 227 def test_Diff_Aliases3(self): | 236 def test_Diff_Aliases3(self): |
| 228 size_info1 = self._CloneSizeInfo() | 237 size_info1 = self._CloneSizeInfo() |
| 229 size_info2 = self._CloneSizeInfo() | 238 size_info2 = self._CloneSizeInfo() |
| 230 | 239 |
| 231 # Removing all 3 aliases should change the size. | 240 # Removing all 3 aliases should change the size. |
| 232 a1, a2, a3 = ( | 241 a1, a2, a3 = ( |
| 233 size_info2.symbols.Filter(lambda s: s.num_aliases == 3)[0].aliases) | 242 size_info2.symbols.Filter(lambda s: s.num_aliases == 3)[0].aliases) |
| 234 size_info2.symbols -= [a1, a2, a3] | 243 size_info2.symbols -= [a1, a2, a3] |
| 235 d = diff.Diff(size_info1, size_info2) | 244 d = diff.Diff(size_info1, size_info2) |
| 236 self.assertEquals(d.symbols.size, -a1.size) | 245 self.assertEquals(d.symbols.size, -a1.size) |
| 237 self.assertEquals(d.symbols.removed_count, 3) | 246 self.assertEquals((0, 0, 3), _DiffCounts(d.symbols)) |
| 247 self.assertEquals((1, 0, 2), _DiffCounts(d.symbols.Clustered())) |
| 238 | 248 |
| 239 # Adding all 3 aliases should change size. | 249 # Adding all 3 aliases should change size. |
| 240 d = diff.Diff(size_info2, size_info1) | 250 d = diff.Diff(size_info2, size_info1) |
| 241 self.assertEquals(d.symbols.size, a1.size) | 251 self.assertEquals(d.symbols.size, a1.size) |
| 242 self.assertEquals(d.symbols.added_count, 3) | 252 self.assertEquals((0, 3, 0), _DiffCounts(d.symbols)) |
| 253 self.assertEquals((1, 2, 0), _DiffCounts(d.symbols.Clustered())) |
| 243 | 254 |
| 244 def test_Diff_Clustering(self): | 255 def test_Diff_Clustering(self): |
| 245 size_info1 = self._CloneSizeInfo() | 256 size_info1 = self._CloneSizeInfo() |
| 246 size_info2 = self._CloneSizeInfo() | 257 size_info2 = self._CloneSizeInfo() |
| 247 S = '.text' | 258 S = '.text' |
| 248 size_info1.symbols += [ | 259 size_info1.symbols += [ |
| 249 models.Symbol(S, 11, name='.L__unnamed_1193', object_path='a'), # 1 | 260 models.Symbol(S, 11, name='.L__unnamed_1193', object_path='a'), # 1 |
| 250 models.Symbol(S, 22, name='.L__unnamed_1194', object_path='a'), # 2 | 261 models.Symbol(S, 22, name='.L__unnamed_1194', object_path='a'), # 2 |
| 251 models.Symbol(S, 33, name='.L__unnamed_1195', object_path='b'), # 3 | 262 models.Symbol(S, 33, name='.L__unnamed_1195', object_path='b'), # 3 |
| 252 models.Symbol(S, 44, name='.L__bar_195', object_path='b'), # 4 | 263 models.Symbol(S, 44, name='.L__bar_195', object_path='b'), # 4 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 global update_goldens | 311 global update_goldens |
| 301 update_goldens = True | 312 update_goldens = True |
| 302 for f in glob.glob(os.path.join(_TEST_DATA_DIR, '*.golden')): | 313 for f in glob.glob(os.path.join(_TEST_DATA_DIR, '*.golden')): |
| 303 os.unlink(f) | 314 os.unlink(f) |
| 304 | 315 |
| 305 unittest.main(argv=argv, verbosity=2) | 316 unittest.main(argv=argv, verbosity=2) |
| 306 | 317 |
| 307 | 318 |
| 308 if __name__ == '__main__': | 319 if __name__ == '__main__': |
| 309 main() | 320 main() |
| OLD | NEW |