summaryrefslogtreecommitdiff
path: root/chromium/tools/binary_size/libsupersize/integration_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/tools/binary_size/libsupersize/integration_test.py')
-rwxr-xr-xchromium/tools/binary_size/libsupersize/integration_test.py67
1 files changed, 52 insertions, 15 deletions
diff --git a/chromium/tools/binary_size/libsupersize/integration_test.py b/chromium/tools/binary_size/libsupersize/integration_test.py
index edaf2895edd..65c07929cb6 100755
--- a/chromium/tools/binary_size/libsupersize/integration_test.py
+++ b/chromium/tools/binary_size/libsupersize/integration_test.py
@@ -42,6 +42,7 @@ _TEST_APK_PAK_PATH = os.path.join(_TEST_APK_ROOT_DIR, 'assets/resources.pak')
# The following files are dynamically created.
_TEST_ELF_PATH = os.path.join(_TEST_OUTPUT_DIR, 'elf')
_TEST_APK_PATH = os.path.join(_TEST_OUTPUT_DIR, 'test.apk')
+_TEST_MINIMAL_APKS_PATH = os.path.join(_TEST_OUTPUT_DIR, 'Bundle.minimal.apks')
# Generated file paths relative to apk
_TEST_APK_SO_PATH = 'test.so'
@@ -121,6 +122,7 @@ class IntegrationTest(unittest.TestCase):
# Exactly 128MB of data (2^27), extra bytes will be accounted in overhead.
with open(_TEST_ELF_PATH, 'a') as elf_file:
elf_file.write(IntegrationTest._CreateBlankData(27))
+
with zipfile.ZipFile(_TEST_APK_PATH, 'w') as apk_file:
apk_file.write(_TEST_ELF_PATH, _TEST_APK_SO_PATH)
# Exactly 4MB of data (2^22).
@@ -141,18 +143,27 @@ class IntegrationTest(unittest.TestCase):
apk_file.writestr(
_TEST_APK_DEX_PATH, IntegrationTest._CreateBlankData(23))
+ with zipfile.ZipFile(_TEST_MINIMAL_APKS_PATH, 'w') as apk_file:
+ apk_file.write(_TEST_APK_PATH, 'splits/base-master.apk')
+ apk_file.writestr('splits/base-en.apk', 'x' * 10)
+ apk_file.writestr('splits/vr-master.apk', 'x' * 20)
+ apk_file.writestr('splits/vr-en.apk', 'x' * 40)
+ apk_file.writestr('toc.pb', 'x' * 80)
+
@classmethod
def tearDownClass(cls):
IntegrationTest._SafeRemoveFiles([
_TEST_ELF_PATH,
_TEST_APK_PATH,
+ _TEST_MINIMAL_APKS_PATH,
])
def _CloneSizeInfo(self, use_output_directory=True, use_elf=True,
- use_apk=False, use_pak=False):
+ use_apk=False, use_minimal_apks=False, use_pak=False):
assert not use_elf or use_output_directory
assert not (use_apk and use_pak)
- cache_key = (use_output_directory, use_elf, use_apk, use_pak)
+ cache_key = (
+ use_output_directory, use_elf, use_apk, use_minimal_apks, use_pak)
if cache_key not in IntegrationTest.cached_size_info:
elf_path = _TEST_ELF_PATH if use_elf else None
output_directory = _TEST_OUTPUT_DIR if use_output_directory else None
@@ -162,10 +173,24 @@ class IntegrationTest(unittest.TestCase):
knobs.max_same_name_alias_count = 3
knobs.src_root = _TEST_SOURCE_DIR
apk_path = None
+ minimal_apks_path = None
apk_so_path = None
+ size_info_prefix = None
+ extracted_minimal_apk_path = None
if use_apk:
apk_path = _TEST_APK_PATH
+ elif use_minimal_apks:
+ minimal_apks_path = _TEST_MINIMAL_APKS_PATH
+ extracted_minimal_apk_path = _TEST_APK_PATH
+ if use_apk or use_minimal_apks:
apk_so_path = _TEST_APK_SO_PATH
+ if output_directory:
+ if use_apk:
+ orig_path = _TEST_APK_PATH
+ else:
+ orig_path = _TEST_MINIMAL_APKS_PATH.replace('.minimal.apks', '.aab')
+ size_info_prefix = os.path.join(
+ output_directory, 'size-info', os.path.basename(orig_path))
pak_files = None
pak_info_file = None
if use_pak:
@@ -176,20 +201,22 @@ class IntegrationTest(unittest.TestCase):
if use_elf:
with _AddMocksToPath():
metadata = archive.CreateMetadata(
- _TEST_MAP_PATH, elf_path, apk_path, _TEST_TOOL_PREFIX,
- output_directory, linker_name)
+ _TEST_MAP_PATH, elf_path, apk_path, minimal_apks_path,
+ _TEST_TOOL_PREFIX, output_directory, linker_name)
section_sizes, raw_symbols = archive.CreateSectionSizesAndSymbols(
map_path=_TEST_MAP_PATH, tool_prefix=_TEST_TOOL_PREFIX,
elf_path=elf_path, output_directory=output_directory,
- apk_path=apk_path, apk_so_path=apk_so_path, metadata=metadata,
- pak_files=pak_files, pak_info_file=pak_info_file,
- linker_name=linker_name, knobs=knobs)
+ apk_path=apk_path or extracted_minimal_apk_path,
+ apk_so_path=apk_so_path, metadata=metadata, pak_files=pak_files,
+ pak_info_file=pak_info_file, linker_name=linker_name,
+ size_info_prefix=size_info_prefix, knobs=knobs)
IntegrationTest.cached_size_info[cache_key] = archive.CreateSizeInfo(
section_sizes, raw_symbols, metadata=metadata)
return copy.deepcopy(IntegrationTest.cached_size_info[cache_key])
def _DoArchive(self, archive_path, use_output_directory=True, use_elf=True,
- use_apk=False, use_pak=False, debug_measures=False):
+ use_apk=False, use_minimal_apks=False, use_pak=False,
+ debug_measures=False):
args = [
archive_path,
'--map-file', _TEST_MAP_PATH,
@@ -201,10 +228,15 @@ class IntegrationTest(unittest.TestCase):
args += ['--output-directory', _TEST_OUTPUT_DIR]
else:
args += ['--no-source-paths']
- if use_elf:
- args += ['--elf-file', _TEST_ELF_PATH]
if use_apk:
- args += ['--apk-file', _TEST_APK_PATH]
+ args += ['-f', _TEST_APK_PATH]
+ elif use_minimal_apks:
+ args += ['-f', _TEST_MINIMAL_APKS_PATH]
+ if use_elf:
+ if use_apk or use_minimal_apks:
+ args += ['--elf-file', _TEST_ELF_PATH]
+ else:
+ args += ['-f', _TEST_ELF_PATH]
if use_pak:
args += ['--pak-file', _TEST_APK_LOCALE_PAK_PATH,
'--pak-file', _TEST_APK_PAK_PATH,
@@ -212,17 +244,18 @@ class IntegrationTest(unittest.TestCase):
_RunApp('archive', args, debug_measures=debug_measures)
def _DoArchiveTest(self, use_output_directory=True, use_elf=True,
- use_apk=False, use_pak=False, debug_measures=False):
+ use_apk=False, use_minimal_apks=False, use_pak=False,
+ debug_measures=False):
with tempfile.NamedTemporaryFile(suffix='.size') as temp_file:
self._DoArchive(
temp_file.name, use_output_directory=use_output_directory,
- use_elf=use_elf, use_apk=use_apk, use_pak=use_pak,
- debug_measures=debug_measures)
+ use_elf=use_elf, use_apk=use_apk, use_minimal_apks=use_minimal_apks,
+ use_pak=use_pak, debug_measures=debug_measures)
size_info = archive.LoadAndPostProcessSizeInfo(temp_file.name)
# Check that saving & loading is the same as directly parsing.
expected_size_info = self._CloneSizeInfo(
use_output_directory=use_output_directory, use_elf=use_elf,
- use_apk=use_apk, use_pak=use_pak)
+ use_apk=use_apk, use_minimal_apks=use_minimal_apks, use_pak=use_pak)
self.assertEquals(expected_size_info.metadata, size_info.metadata)
# Don't cluster.
expected_size_info.symbols = expected_size_info.raw_symbols
@@ -256,6 +289,10 @@ class IntegrationTest(unittest.TestCase):
return self._DoArchiveTest(use_apk=True)
@_CompareWithGolden()
+ def test_Archive_MinimalApks(self):
+ return self._DoArchiveTest(use_minimal_apks=True)
+
+ @_CompareWithGolden()
def test_Archive_Pak_Files(self):
return self._DoArchiveTest(use_pak=True)