Home | History | Annotate | Download | only in golden
      1 #
      2 # Copyright (C) 2017 The Android Open Source Project
      3 #
      4 # Licensed under the Apache License, Version 2.0 (the "License");
      5 # you may not use this file except in compliance with the License.
      6 # You may obtain a copy of the License at
      7 #
      8 #      http://www.apache.org/licenses/LICENSE-2.0
      9 #
     10 # Unless required by applicable law or agreed to in writing, software
     11 # distributed under the License is distributed on an "AS IS" BASIS,
     12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 # See the License for the specific language governing permissions and
     14 # limitations under the License.
     15 #
     16 
     17 import csv
     18 import logging
     19 import os
     20 
     21 # The tags in VNDK spreadsheet:
     22 # Low-level NDK libraries that can be used by framework and vendor modules.
     23 LL_NDK = "LL-NDK"
     24 
     25 # LL-NDK dependencies that vendor modules cannot directly access.
     26 LL_NDK_PRIVATE = "LL-NDK-Private"
     27 
     28 # Same-process HAL implementation in vendor partition.
     29 SP_HAL = "SP-HAL"
     30 
     31 # Framework libraries that can be used by vendor modules except same-process HAL
     32 # and its dependencies in vendor partition.
     33 VNDK = "VNDK"
     34 
     35 # VNDK dependencies that vendor modules cannot directly access.
     36 VNDK_PRIVATE = "VNDK-Private"
     37 
     38 # Same-process HAL dependencies in framework.
     39 VNDK_SP = "VNDK-SP"
     40 
     41 # VNDK-SP dependencies that vendor modules cannot directly access.
     42 VNDK_SP_PRIVATE = "VNDK-SP-Private"
     43 
     44 # The ABI dump directories. 64-bit comes before 32-bit in order to sequentially
     45 # search for longest prefix.
     46 _ABI_NAMES = ("arm64", "arm", "mips64", "mips", "x86_64", "x86")
     47 
     48 # The data directory.
     49 _GOLDEN_DIR = os.path.join("vts", "testcases", "vndk", "golden")
     50 
     51 
     52 def LoadDefaultVndkVersion(data_file_path):
     53     """Loads the name of the data directory for devices with no VNDK version.
     54 
     55     Args:
     56         data_file_path: The path to VTS data directory.
     57 
     58     Returns:
     59         A string, the directory name.
     60         None if fails to load the name.
     61     """
     62     try:
     63         with open(os.path.join(data_file_path, _GOLDEN_DIR,
     64                                "platform_vndk_version.txt"), "r") as f:
     65             return f.read().strip()
     66     except IOError:
     67         logging.error("Cannot load default VNDK version.")
     68         return None
     69 
     70 
     71 def GetAbiDumpDirectory(data_file_path, version, binder_bitness, abi_name,
     72                         abi_bitness):
     73     """Returns the VNDK dump directory on host.
     74 
     75     Args:
     76         data_file_path: The path to VTS data directory.
     77         version: A string, the VNDK version.
     78         binder_bitness: A string or an integer, 32 or 64.
     79         abi_name: A string, the ABI of the library dump.
     80         abi_bitness: A string or an integer, 32 or 64.
     81 
     82     Returns:
     83         A string, the path to the dump directory.
     84         None if there is no directory for the version and ABI.
     85     """
     86     try:
     87         abi_dir = next(x for x in _ABI_NAMES if abi_name.startswith(x))
     88     except StopIteration:
     89         logging.warning("Unknown ABI %s.", abi_name)
     90         return None
     91 
     92     version_dir = (version if version else
     93                    LoadDefaultVndkVersion(data_file_path))
     94     if not version_dir:
     95         return None
     96 
     97     dump_dir = os.path.join(
     98         data_file_path, _GOLDEN_DIR, version_dir,
     99         "binder64" if str(binder_bitness) == "64" else "binder32",
    100         abi_dir, "lib64" if str(abi_bitness) == "64" else "lib")
    101 
    102     if not os.path.isdir(dump_dir):
    103         logging.warning("%s is not a directory.", dump_dir)
    104         return None
    105 
    106     return dump_dir
    107 
    108 
    109 def LoadVndkLibraryLists(data_file_path, version, *tags):
    110     """Find the VNDK libraries with specific tags.
    111 
    112     Args:
    113         data_file_path: The path to VTS data directory.
    114         version: A string, the VNDK version.
    115         *tags: Strings, the tags of the libraries to find.
    116 
    117     Returns:
    118         A tuple of lists containing library names. Each list corresponds to
    119         one tag in the argument. For SP-HAL, the returned names are regular
    120         expressions.
    121         None if the spreadsheet for the version is not found.
    122     """
    123     version_dir = (version if version else
    124                    LoadDefaultVndkVersion(data_file_path))
    125     if not version_dir:
    126         return None
    127 
    128     path = os.path.join(
    129         data_file_path, _GOLDEN_DIR, version_dir, "eligible-list.csv")
    130     if not os.path.isfile(path):
    131         logging.warning("Cannot load %s.", path)
    132         return None
    133 
    134     dir_suffix = "-" + version if version else ""
    135     vndk_lists = tuple([] for x in tags)
    136     with open(path) as csv_file:
    137         # Skip header
    138         next(csv_file)
    139         reader = csv.reader(csv_file)
    140         for cells in reader:
    141             for tag_index, tag in enumerate(tags):
    142                 if tag == cells[1]:
    143                     lib_name = cells[0].replace("${VNDK_VER}", dir_suffix)
    144                     if lib_name.startswith("[regex]"):
    145                         lib_name = lib_name[len("[regex]"):]
    146                     vndk_lists[tag_index].extend(
    147                         lib_name.replace("${LIB}", lib)
    148                         for lib in ("lib", "lib64"))
    149     return vndk_lists
    150