diff options
Diffstat (limited to 'golden/vndk_data.py')
-rw-r--r-- | golden/vndk_data.py | 82 |
1 files changed, 78 insertions, 4 deletions
diff --git a/golden/vndk_data.py b/golden/vndk_data.py index 4eb127d..ffa1527 100644 --- a/golden/vndk_data.py +++ b/golden/vndk_data.py @@ -15,9 +15,11 @@ # import collections +import json import logging import os import re +import zipfile try: from importlib import resources @@ -47,9 +49,16 @@ VNDK_SP = "VNDK-SP" # VNDK-SP dependencies that vendor modules cannot directly access. VNDK_SP_PRIVATE = "VNDK-SP-private" -# The ABI dump directories. 64-bit comes before 32-bit in order to sequentially -# search for longest prefix. -_ABI_NAMES = ("arm64", "arm", "mips64", "mips", "x86_64", "x86") +# The tuples of (ABI name, bitness, arch name). 64-bit comes before 32-bit in +# order to sequentially search for longest prefix. +_ABI_LIST = ( + ("arm64", 64, "arm64_armv8-a"), + ("arm64", 32, "arm_armv8-a"), + ("arm", 32, "arm_armv7-a-neon"), + ("x86_64", 64, "x86_x86_64"), + ("x86_64", 32, "x86_64"), + ("x86", 32, "x86"), +) # The data directory. _GOLDEN_DIR = os.path.join("vts", "testcases", "vndk", "golden") @@ -57,6 +66,9 @@ _GOLDEN_DIR = os.path.join("vts", "testcases", "vndk", "golden") # The data package. _RESOURCE_PACKAGE = "vts.testcases.vndk"; +# The name of the zip file containing ABI dumps. +_ABI_DUMP_ZIP_NAME = "abi_dump.zip" + # Regular expression prefix for library name patterns. _REGEX_PREFIX = "[regex]" @@ -95,7 +107,7 @@ def GetAbiDumpDirectory(data_file_path, version, binder_bitness, abi_name, None if there is no directory for the version and ABI. """ try: - abi_dir = next(x for x in _ABI_NAMES if abi_name.startswith(x)) + abi_dir = next(x[0] for x in _ABI_LIST if abi_name.startswith(x[0])) except StopIteration: logging.warning("Unknown ABI %s.", abi_name) return None @@ -117,6 +129,68 @@ def GetAbiDumpDirectory(data_file_path, version, binder_bitness, abi_name, return dump_dir +class AbiDumpResource: + """The class for loading ABI dumps from the zip in resources.""" + + def __init__(self): + self._resource = None + self.zip_file = None + + def __enter__(self): + self._resource = resources.open_binary(_RESOURCE_PACKAGE, + _ABI_DUMP_ZIP_NAME) + self.zip_file = zipfile.ZipFile(self._resource, "r") + return self + + def __exit__(self, exc_type, exc_val, traceback): + if self._resource: + self._resource.close() + if self.zip_file: + self.zip_file.close() + + +def GetAbiDumpPathsFromResources(version, binder_bitness, abi_name, abi_bitness): + """Returns the VNDK dump paths in resources. + + Args: + version: A string, the VNDK version. + binder_bitness: A string or an integer, 32 or 64. + abi_name: A string, the ABI of the library dump. + abi_bitness: A string or an integer, 32 or 64. + + Returns: + A dict of {library name: dump resource path}. For example, + {"libbase.so": "R/64/arm64_armv8-a/source-based/libbase.so.lsdump"}. + If there is no dump for the version and ABI, this function returns an + empty dict. + """ + if not resources: + logging.error("Could not import resources module.") + return dict() + + abi_bitness = int(abi_bitness) + try: + arch_name = next(x[2] for x in _ABI_LIST if + abi_name.startswith(x[0]) and x[1] == abi_bitness) + except StopIteration: + logging.warning("Unknown %d-bit ABI %s.", abi_bitness, abi_name) + return dict() + + # The separator in zipped path is always "/". + dump_dir = "/".join((version, str(binder_bitness), arch_name, + "source-based")) + "/" + + dump_paths = dict() + + with AbiDumpResource() as dump_resource: + for path in dump_resource.zip_file.namelist(): + if path.startswith(dump_dir) and path.endswith(".lsdump"): + lib_name = path[len(dump_dir):-len(".lsdump")] + dump_paths[lib_name] = path + + return dump_paths + + def _LoadVndkLibraryListsFile(vndk_lists, tags, vndk_lib_list_file): """Load VNDK libraries from the file to the specified tuple. |