Commit 079c6a64 authored by Samuel Huang's avatar Samuel Huang Committed by Commit Bot

[SuperSize] Clean up SuperSize-archive arguments for "main input".

SuperSize-archive takes a "main input" file parameter. Ideally it is
given and is unique. However, the following complicate things:
(1) --map-file can be a main input as well as an auxiliary input for
    another main input.
(2) integration_test.py often specifies an ELF file alongside, e.g., an
    APK file, to represent an extracted ELF file.
(3) --ssargs-file a valid "main input" only at command line, and cannot
    be nested within an .ssargs file.
(4) -f identifies main input file, and can be used in .ssargs files.

This CL cleans up main input processing and address the above. Details:
* Renamed _ParseSsargs() to ParseSsargs() for upcoming use.
  * Move more checking logic there.
* For (1): Resolve exclusion with custom logic in _GetMainFiles() and
  error handling in _DeduceDerivedArgsAndCheckMainInput(), which was
  _DeduceDerivedArgs().
* For (2): Add new parameter --aux-elf-file and update tests to use it.
  Did NOT add --aux-map-file due to low usage.
* For (3) and (4): Simplify code by allowing --ssargs-file (and -f with
  .ssargs) in argparse, and have a single check to reject this in
  ParseSsargs().

Bug: 1040645
Change-Id: I28e510747b43f3ebcc9dcd9c53006913c97f02dd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2263012
Commit-Queue: Samuel Huang <huangs@chromium.org>
Reviewed-by: default avatarAndrew Grieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781871}
parent 67522a3c
This diff is collapsed.
...@@ -170,14 +170,19 @@ class IntegrationTest(unittest.TestCase): ...@@ -170,14 +170,19 @@ class IntegrationTest(unittest.TestCase):
'source_directory': _TEST_SOURCE_DIR, 'source_directory': _TEST_SOURCE_DIR,
}) })
def _CloneSizeInfo(self, use_output_directory=True, use_elf=True, def _CloneSizeInfo(self,
use_apk=False, use_minimal_apks=False, use_pak=False): use_output_directory=True,
use_elf=False,
use_apk=False,
use_minimal_apks=False,
use_pak=False,
use_aux_elf=False):
assert not use_elf or use_output_directory assert not use_elf or use_output_directory
assert not (use_apk and use_pak) assert not (use_apk and use_pak)
cache_key = ( cache_key = (use_output_directory, use_elf, use_apk, use_minimal_apks,
use_output_directory, use_elf, use_apk, use_minimal_apks, use_pak) use_pak, use_aux_elf)
if cache_key not in IntegrationTest.cached_size_info: if cache_key not in IntegrationTest.cached_size_info:
elf_path = _TEST_ELF_PATH if use_elf else None elf_path = _TEST_ELF_PATH if use_elf or use_aux_elf else None
output_directory = _TEST_OUTPUT_DIR if use_output_directory else None output_directory = _TEST_OUTPUT_DIR if use_output_directory else None
knobs = archive.SectionSizeKnobs() knobs = archive.SectionSizeKnobs()
opts = archive.ContainerArchiveOptions(self._CreateTestArgs()) opts = archive.ContainerArchiveOptions(self._CreateTestArgs())
...@@ -237,10 +242,11 @@ class IntegrationTest(unittest.TestCase): ...@@ -237,10 +242,11 @@ class IntegrationTest(unittest.TestCase):
def _DoArchive(self, def _DoArchive(self,
archive_path, archive_path,
use_output_directory=True, use_output_directory=True,
use_elf=True, use_elf=False,
use_apk=False, use_apk=False,
use_minimal_apks=False, use_minimal_apks=False,
use_pak=False, use_pak=False,
use_aux_elf=None,
debug_measures=False, debug_measures=False,
include_padding=False): include_padding=False):
args = [ args = [
...@@ -258,42 +264,46 @@ class IntegrationTest(unittest.TestCase): ...@@ -258,42 +264,46 @@ class IntegrationTest(unittest.TestCase):
args += ['-f', _TEST_APK_PATH] args += ['-f', _TEST_APK_PATH]
elif use_minimal_apks: elif use_minimal_apks:
args += ['-f', _TEST_MINIMAL_APKS_PATH] args += ['-f', _TEST_MINIMAL_APKS_PATH]
if use_elf: elif use_elf:
if use_apk or use_minimal_apks: args += ['-f', _TEST_ELF_PATH]
args += ['--elf-file', _TEST_ELF_PATH]
else:
args += ['-f', _TEST_ELF_PATH]
if use_pak: if use_pak:
args += ['--pak-file', _TEST_APK_LOCALE_PAK_PATH, args += ['--pak-file', _TEST_APK_LOCALE_PAK_PATH,
'--pak-file', _TEST_APK_PAK_PATH, '--pak-file', _TEST_APK_PAK_PATH,
'--pak-info-file', _TEST_PAK_INFO_PATH] '--pak-info-file', _TEST_PAK_INFO_PATH]
if use_aux_elf:
args += ['--aux-elf-file', _TEST_ELF_PATH]
if include_padding: if include_padding:
args += ['--include-padding'] args += ['--include-padding']
_RunApp('archive', args, debug_measures=debug_measures) _RunApp('archive', args, debug_measures=debug_measures)
def _DoArchiveTest(self, def _DoArchiveTest(self,
use_output_directory=True, use_output_directory=True,
use_elf=True, use_elf=False,
use_apk=False, use_apk=False,
use_minimal_apks=False, use_minimal_apks=False,
use_pak=False, use_pak=False,
use_aux_elf=False,
debug_measures=False, debug_measures=False,
include_padding=False): include_padding=False):
with tempfile.NamedTemporaryFile(suffix='.size') as temp_file: with tempfile.NamedTemporaryFile(suffix='.size') as temp_file:
self._DoArchive( self._DoArchive(temp_file.name,
temp_file.name, use_output_directory=use_output_directory,
use_output_directory=use_output_directory, use_elf=use_elf,
use_elf=use_elf, use_apk=use_apk,
use_apk=use_apk, use_minimal_apks=use_minimal_apks,
use_minimal_apks=use_minimal_apks, use_pak=use_pak,
use_pak=use_pak, use_aux_elf=use_aux_elf,
debug_measures=debug_measures, debug_measures=debug_measures,
include_padding=include_padding) include_padding=include_padding)
size_info = archive.LoadAndPostProcessSizeInfo(temp_file.name) size_info = archive.LoadAndPostProcessSizeInfo(temp_file.name)
# Check that saving & loading is the same as directly parsing. # Check that saving & loading is the same as directly parsing.
expected_size_info = self._CloneSizeInfo( expected_size_info = self._CloneSizeInfo(
use_output_directory=use_output_directory, use_elf=use_elf, use_output_directory=use_output_directory,
use_apk=use_apk, use_minimal_apks=use_minimal_apks, use_pak=use_pak) use_elf=use_elf,
use_apk=use_apk,
use_minimal_apks=use_minimal_apks,
use_pak=use_pak,
use_aux_elf=use_aux_elf)
self.assertEqual(expected_size_info.metadata, size_info.metadata) self.assertEqual(expected_size_info.metadata, size_info.metadata)
# Don't cluster. # Don't cluster.
expected_size_info.symbols = expected_size_info.raw_symbols expected_size_info.symbols = expected_size_info.raw_symbols
...@@ -320,38 +330,38 @@ class IntegrationTest(unittest.TestCase): ...@@ -320,38 +330,38 @@ class IntegrationTest(unittest.TestCase):
@_CompareWithGolden() @_CompareWithGolden()
def test_Archive_OutputDirectory(self): def test_Archive_OutputDirectory(self):
return self._DoArchiveTest(use_elf=False) return self._DoArchiveTest()
@_CompareWithGolden() @_CompareWithGolden()
def test_Archive_Elf(self): def test_Archive_Elf(self):
return self._DoArchiveTest() return self._DoArchiveTest(use_elf=True)
@_CompareWithGolden() @_CompareWithGolden()
def test_Archive_Apk(self): def test_Archive_Apk(self):
return self._DoArchiveTest(use_apk=True) return self._DoArchiveTest(use_apk=True, use_aux_elf=True)
@_CompareWithGolden() @_CompareWithGolden()
def test_Archive_MinimalApks(self): def test_Archive_MinimalApks(self):
return self._DoArchiveTest(use_minimal_apks=True) return self._DoArchiveTest(use_minimal_apks=True, use_aux_elf=True)
@_CompareWithGolden() @_CompareWithGolden()
def test_Archive_Pak_Files(self): def test_Archive_Pak_Files(self):
return self._DoArchiveTest(use_pak=True) return self._DoArchiveTest(use_pak=True, use_aux_elf=True)
@_CompareWithGolden(name='Archive_Elf') @_CompareWithGolden(name='Archive_Elf')
def test_Archive_Elf_DebugMeasures(self): def test_Archive_Elf_DebugMeasures(self):
return self._DoArchiveTest(debug_measures=True) return self._DoArchiveTest(use_elf=True, debug_measures=True)
@_CompareWithGolden(name='Archive') @_CompareWithGolden(name='Archive')
def test_ArchiveSparse(self): def test_ArchiveSparse(self):
return self._DoArchiveTest( return self._DoArchiveTest(use_output_directory=False, include_padding=True)
use_output_directory=False, use_elf=False, include_padding=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, \
tempfile.NamedTemporaryFile(suffix='.txt') as output_file: tempfile.NamedTemporaryFile(suffix='.txt') as output_file:
file_format.SaveSizeInfo(self._CloneSizeInfo(), size_file.name) file_format.SaveSizeInfo(self._CloneSizeInfo(use_elf=True),
size_file.name)
query = [ query = [
'ShowExamples()', 'ShowExamples()',
'ExpandRegex("_foo_")', 'ExpandRegex("_foo_")',
...@@ -373,7 +383,8 @@ class IntegrationTest(unittest.TestCase): ...@@ -373,7 +383,8 @@ class IntegrationTest(unittest.TestCase):
def test_Csv(self): def test_Csv(self):
with tempfile.NamedTemporaryFile(suffix='.size') as size_file, \ with tempfile.NamedTemporaryFile(suffix='.size') as size_file, \
tempfile.NamedTemporaryFile(suffix='.txt') as output_file: tempfile.NamedTemporaryFile(suffix='.txt') as output_file:
file_format.SaveSizeInfo(self._CloneSizeInfo(), size_file.name) file_format.SaveSizeInfo(self._CloneSizeInfo(use_elf=True),
size_file.name)
query = [ query = [
'Csv(size_info, to_file=%r)' % output_file.name, 'Csv(size_info, to_file=%r)' % output_file.name,
] ]
...@@ -385,7 +396,8 @@ class IntegrationTest(unittest.TestCase): ...@@ -385,7 +396,8 @@ class IntegrationTest(unittest.TestCase):
@_CompareWithGolden() @_CompareWithGolden()
def test_Diff_NullDiff(self): def test_Diff_NullDiff(self):
with tempfile.NamedTemporaryFile(suffix='.size') as temp_file: with tempfile.NamedTemporaryFile(suffix='.size') as temp_file:
file_format.SaveSizeInfo(self._CloneSizeInfo(), temp_file.name) file_format.SaveSizeInfo(self._CloneSizeInfo(use_elf=True),
temp_file.name)
return _RunApp('diff', [temp_file.name, temp_file.name]) return _RunApp('diff', [temp_file.name, temp_file.name])
# Runs archive 3 times, and asserts the contents are the same each time. # Runs archive 3 times, and asserts the contents are the same each time.
...@@ -400,8 +412,8 @@ class IntegrationTest(unittest.TestCase): ...@@ -400,8 +412,8 @@ class IntegrationTest(unittest.TestCase):
@_CompareWithGolden() @_CompareWithGolden()
def test_Diff_Basic(self): def test_Diff_Basic(self):
size_info1 = self._CloneSizeInfo(use_elf=False, use_pak=True) size_info1 = self._CloneSizeInfo(use_pak=True)
size_info2 = self._CloneSizeInfo(use_elf=False, use_pak=True) size_info2 = self._CloneSizeInfo(use_pak=True)
size_info2.build_config['git_revision'] = 'xyz789' size_info2.build_config['git_revision'] = 'xyz789'
container1 = size_info1.containers[0] container1 = size_info1.containers[0]
container2 = size_info2.containers[0] container2 = size_info2.containers[0]
...@@ -444,7 +456,7 @@ class IntegrationTest(unittest.TestCase): ...@@ -444,7 +456,7 @@ class IntegrationTest(unittest.TestCase):
@_CompareWithGolden() @_CompareWithGolden()
def test_FullDescription(self): def test_FullDescription(self):
size_info = self._CloneSizeInfo() size_info = self._CloneSizeInfo(use_elf=True)
# Show both clustered and non-clustered so that they can be compared. # Show both clustered and non-clustered so that they can be compared.
size_info.symbols = size_info.raw_symbols size_info.symbols = size_info.raw_symbols
return itertools.chain( return itertools.chain(
...@@ -455,7 +467,7 @@ class IntegrationTest(unittest.TestCase): ...@@ -455,7 +467,7 @@ class IntegrationTest(unittest.TestCase):
@_CompareWithGolden() @_CompareWithGolden()
def test_SymbolGroupMethods(self): def test_SymbolGroupMethods(self):
all_syms = self._CloneSizeInfo().symbols all_syms = self._CloneSizeInfo(use_elf=True).symbols
global_syms = all_syms.WhereNameMatches('GLOBAL') global_syms = all_syms.WhereNameMatches('GLOBAL')
# Tests Filter(), Inverted(), and __sub__(). # Tests Filter(), Inverted(), and __sub__().
non_global_syms = global_syms.Inverted() non_global_syms = global_syms.Inverted()
......
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