Commit 2f103f00 authored by Andrew Grieve's avatar Andrew Grieve Committed by Commit Bot

SuperSize: Add integration test for .sizediff loading

Also opts aliases into symbol sorting.

Bug: None
Change-Id: I62b01b7a59156b7599769666f854209e9cd63ae0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2438872
Commit-Queue: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: default avatarSamuel Huang <huangs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811928}
parent 7d5f24ac
...@@ -166,9 +166,18 @@ def SortSymbols(raw_symbols): ...@@ -166,9 +166,18 @@ def SortSymbols(raw_symbols):
# detecting duplicate symbols. # detecting duplicate symbols.
# (s.full_name, s.object_path) are important for sort stability when called by # (s.full_name, s.object_path) are important for sort stability when called by
# _ExpandSparseSymbols(). # _ExpandSparseSymbols().
raw_symbols.sort( def sort_key(s):
key=lambda s: (s.IsPak(), s.IsBss(), s.section_name, s.address, s. return (s.IsPak(), s.IsBss(), s.section_name, s.address,
size_without_padding > 0, s.full_name, s.object_path)) s.size_without_padding > 0, s.full_name, s.object_path)
raw_symbols.sort(key=sort_key)
seen_aliases = set()
for s in raw_symbols:
if s.aliases:
if s.aliases[0] not in seen_aliases:
s.aliases.sort(key=sort_key)
seen_aliases.add(s.aliases[0])
logging.info('Processed %d symbols', len(raw_symbols)) logging.info('Processed %d symbols', len(raw_symbols))
...@@ -187,8 +196,11 @@ def CalculatePadding(raw_symbols): ...@@ -187,8 +196,11 @@ def CalculatePadding(raw_symbols):
if (prev_symbol.container.name != symbol.container.name if (prev_symbol.container.name != symbol.container.name
or prev_symbol.section_name != symbol.section_name): or prev_symbol.section_name != symbol.section_name):
container_and_section = (symbol.container.name, symbol.section_name) container_and_section = (symbol.container.name, symbol.section_name)
assert container_and_section not in seen_container_and_sections, ( assert container_and_section not in seen_container_and_sections, """\
'Input symbols must be sorted by container, section, then address.') Input symbols must be sorted by container, section, then address.
Found: {}
Then: {}
""".format(prev_symbol, symbol)
seen_container_and_sections.add(container_and_section) seen_container_and_sections.add(container_and_section)
continue continue
if (symbol.address <= 0 or prev_symbol.address <= 0 if (symbol.address <= 0 or prev_symbol.address <= 0
...@@ -219,20 +231,20 @@ def _ExpandSparseSymbols(sparse_symbols): ...@@ -219,20 +231,20 @@ def _ExpandSparseSymbols(sparse_symbols):
sparse_symbols: A list or SymbolGroup to expand. sparse_symbols: A list or SymbolGroup to expand.
""" """
representative_symbols = set() representative_symbols = set()
raw_symbols = set() raw_symbols = []
logging.debug('Expanding sparse_symbols with aliases of included symbols') logging.debug('Expanding sparse_symbols with aliases of included symbols')
for sym in sparse_symbols: for sym in sparse_symbols:
if sym.aliases: if sym.aliases:
num_syms = len(representative_symbols)
representative_symbols.add(sym.aliases[0]) representative_symbols.add(sym.aliases[0])
if num_syms < len(representative_symbols):
raw_symbols.extend(sym.aliases)
else: else:
raw_symbols.add(sym) raw_symbols.append(sym)
for sym in representative_symbols:
raw_symbols.update(set(sym.aliases))
raw_symbols = list(raw_symbols)
SortSymbols(raw_symbols)
logging.debug('Done expanding sparse_symbols') logging.debug('Done expanding sparse_symbols')
return models.SymbolGroup(raw_symbols) return models.SymbolGroup(raw_symbols)
def _SaveSizeInfoToFile(size_info, def _SaveSizeInfoToFile(size_info,
file_obj, file_obj,
include_padding=False, include_padding=False,
...@@ -465,6 +477,10 @@ def _LoadSizeInfoFromFile(file_obj, size_path): ...@@ -465,6 +477,10 @@ def _LoadSizeInfoFromFile(file_obj, size_path):
_ReadValuesFromLine(lines, split='\t') for _ in range(num_path_tuples) _ReadValuesFromLine(lines, split='\t') for _ in range(num_path_tuples)
] ]
if num_path_tuples == 0:
logging.warning('File contains no symbols: %s', size_path)
return models.SizeInfo(build_config, containers, [], size_path=size_path)
# Component list. # Component list.
if has_components: if has_components:
num_components = int(_ReadLine(lines)) # Number of components in list. num_components = int(_ReadLine(lines)) # Number of components in list.
......
...@@ -357,6 +357,26 @@ class IntegrationTest(unittest.TestCase): ...@@ -357,6 +357,26 @@ class IntegrationTest(unittest.TestCase):
use_aux_elf=True, use_aux_elf=True,
include_padding=True) include_padding=True)
def test_SaveDeltaSizeInfo(self):
# Check that saving & loading is the same as directly parsing.
orig_info1 = self._CloneSizeInfo(use_apk=True, use_aux_elf=True)
orig_info2 = self._CloneSizeInfo(use_elf=True)
orig_delta = diff.Diff(orig_info1, orig_info2)
with tempfile.NamedTemporaryFile(suffix='.sizediff') as sizediff_file:
file_format.SaveDeltaSizeInfo(orig_delta, sizediff_file.name)
new_info1, new_info2 = archive.LoadAndPostProcessDeltaSizeInfo(
sizediff_file.name)
new_delta = diff.Diff(new_info1, new_info2)
# File format discards unchanged symbols.
orig_delta.raw_symbols = orig_delta.raw_symbols.WhereDiffStatusIs(
models.DIFF_STATUS_UNCHANGED).Inverted()
self.assertEqual(
'\n'.join(describe.GenerateLines(orig_delta, verbose=True)),
'\n'.join(describe.GenerateLines(new_delta, verbose=True)))
@_CompareWithGolden() @_CompareWithGolden()
def test_Console(self): def test_Console(self):
with tempfile.NamedTemporaryFile(suffix='.size') as size_file, \ with tempfile.NamedTemporaryFile(suffix='.size') as size_file, \
......
...@@ -10,6 +10,8 @@ Description of common properties: ...@@ -10,6 +10,8 @@ Description of common properties:
May be 0 (e.g. for .bss or for SymbolGroups). May be 0 (e.g. for .bss or for SymbolGroups).
* size: The number of bytes this symbol takes up, including padding that comes * size: The number of bytes this symbol takes up, including padding that comes
before |address|. before |address|.
* aliases: List of symbols that represent the same bytes. The |aliases| of
each symbol in this list points to the same list instance.
* num_aliases: The number of symbols with the same address (including self). * num_aliases: The number of symbols with the same address (including self).
* pss: size / num_aliases. * pss: size / num_aliases.
* padding: The number of bytes of padding before |address| due to this symbol. * padding: The number of bytes of padding before |address| due to this symbol.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment