diff options
author | Hsin-Yi Chen <hsinyichen@google.com> | 2018-10-15 18:31:45 +0800 |
---|---|---|
committer | Hsin-Yi Chen <hsinyichen@google.com> | 2018-10-16 19:05:10 +0800 |
commit | 3f7247c16be7c1cfcb0716b5cb399b161daac4ae (patch) | |
tree | bf267044f022777859d2bcc29b240264b267a24f | |
parent | 7e4e7f9c9d8218f5dd23c5baf2f170fc86690480 (diff) | |
download | vndk-3f7247c16be7c1cfcb0716b5cb399b161daac4ae.tar.gz |
Pull vndk directories instead of lib directories from device
The dump files in VTS package are converted from source-based dumps and
don't follow the relative paths on device. Instead of whole lib
directories, the test case pulls vndk directories and finds dump data by
file name.
Test: vts-tradefed run vts -m VtsVndkAbi
Bug: 80217511
Change-Id: Iabb9351fb762e1f56d99c65ca1de6a6157a77080
-rw-r--r-- | abi/VtsVndkAbiTest.py | 146 |
1 files changed, 60 insertions, 86 deletions
diff --git a/abi/VtsVndkAbiTest.py b/abi/VtsVndkAbiTest.py index 2cac46f..89d12e2 100644 --- a/abi/VtsVndkAbiTest.py +++ b/abi/VtsVndkAbiTest.py @@ -23,33 +23,14 @@ import tempfile from vts.runners.host import asserts from vts.runners.host import base_test -from vts.runners.host import const from vts.runners.host import keys from vts.runners.host import test_runner +from vts.runners.host import utils from vts.testcases.vndk.golden import vndk_data +from vts.utils.python.file import target_file_utils from vts.utils.python.library import elf_parser from vts.utils.python.library.vtable import vtable_dumper - - -def _IterateFiles(root_dir): - """A generator yielding relative and full paths in a directory. - - Args: - root_dir: The directory to search. - - Yields: - A tuple of (relative_path, full_path) for each regular file. - relative_path is the relative path to root_dir. full_path is the path - starting with root_dir. - """ - for dir_path, dir_names, file_names in os.walk(root_dir): - if dir_path == root_dir: - rel_dir = "" - else: - rel_dir = os.path.relpath(dir_path, root_dir) - for file_name in file_names: - yield (os.path.join(rel_dir, file_name), - os.path.join(dir_path, file_name)) +from vts.utils.python.vndk import vndk_utils class VtsVndkAbiTest(base_test.BaseTestClass): @@ -61,12 +42,6 @@ class VtsVndkAbiTest(base_test.BaseTestClass): _vndk_version: String, the VNDK version supported by the device. data_file_path: The path to VTS data directory. """ - _ODM_LIB_DIR_32 = "/odm/lib" - _ODM_LIB_DIR_64 = "/odm/lib64" - _VENDOR_LIB_DIR_32 = "/vendor/lib" - _VENDOR_LIB_DIR_64 = "/vendor/lib64" - _SYSTEM_LIB_DIR_32 = "/system/lib" - _SYSTEM_LIB_DIR_64 = "/system/lib64" def setUpClass(self): """Initializes data file path, device, and temporary directory.""" @@ -88,16 +63,20 @@ class VtsVndkAbiTest(base_test.BaseTestClass): target_dir: The directory to copy from device. host_dir: The directory to copy to host. """ - test_cmd = "test -d " + target_dir - logging.info("adb shell %s", test_cmd) - result = self._dut.adb.shell(test_cmd, no_except=True) - if result[const.EXIT_CODE]: + if not target_file_utils.IsDirectory(target_dir, self._dut.shell): logging.info("%s doesn't exist. Create %s.", target_dir, host_dir) - os.mkdir(host_dir, 0750) + os.makedirs(host_dir) return + parent_dir = os.path.dirname(host_dir) + if parent_dir and not os.path.isdir(parent_dir): + os.makedirs(parent_dir) logging.info("adb pull %s %s", target_dir, host_dir) self._dut.adb.pull(target_dir, host_dir) + def _ToHostPath(self, target_path): + """Maps target path to host path in self._temp_dir.""" + return os.path.join(self._temp_dir, *target_path.strip("/").split("/")) + @staticmethod def _LoadGlobalSymbolsFromDump(dump_obj): """Loads global symbols from a dump object. @@ -266,52 +245,43 @@ class VtsVndkAbiTest(base_test.BaseTestClass): error_count = 0 dump_paths = dict() lib_paths = dict() - for dump_rel_path, dump_path in _IterateFiles(dump_dir): - if dump_rel_path.endswith(".dump"): - lib_name = dump_rel_path.rpartition(".dump")[0] + for parent_dir, dump_name in utils.iterate_files(dump_dir): + dump_path = os.path.join(parent_dir, dump_name) + if dump_path.endswith(".dump"): + lib_name = dump_name.rpartition(".dump")[0] dump_paths[lib_name] = dump_path else: logging.warning("Unknown dump: %s", dump_path) - continue - lib_paths[lib_name] = None for lib_dir in lib_dirs: - for lib_rel_path, lib_path in _IterateFiles(lib_dir): - try: - vndk_dir = next(x for x in ("vndk", "vndk-sp") if - lib_rel_path.startswith(x + os.path.sep)) - lib_name = lib_rel_path.replace( - vndk_dir, vndk_dir + "-" + dump_version, 1) - except StopIteration: - lib_name = lib_rel_path - - if lib_name in lib_paths and not lib_paths[lib_name]: - lib_paths[lib_name] = lib_path - - for lib_name, lib_path in lib_paths.iteritems(): - if not lib_path: + for parent_dir, lib_name in utils.iterate_files(lib_dir): + if lib_name not in lib_paths: + lib_paths[lib_name] = os.path.join(parent_dir, lib_name) + + for lib_name, dump_path in dump_paths.iteritems(): + if lib_name not in lib_paths: logging.info("%s: Not found on target", lib_name) continue + lib_path = lib_paths[lib_name] rel_path = os.path.relpath(lib_path, self._temp_dir) has_exception = False missing_symbols = [] vtable_diff = [] - if lib_name in dump_paths: - try: - with open(dump_paths[lib_name], "r") as dump_file: - dump_obj = json.load(dump_file) - with vtable_dumper.VtableDumper(lib_path) as dumper: - missing_symbols = self._DiffElfSymbols( - dump_obj, dumper) - vtable_diff = self._DiffVtableComponents( - dump_obj, dumper) - except (IOError, - elf_parser.ElfError, - vtable_dumper.VtableError) as e: - logging.exception("%s: Cannot diff ABI", rel_path) - has_exception = True + try: + with open(dump_path, "r") as dump_file: + dump_obj = json.load(dump_file) + with vtable_dumper.VtableDumper(lib_path) as dumper: + missing_symbols = self._DiffElfSymbols( + dump_obj, dumper) + vtable_diff = self._DiffVtableComponents( + dump_obj, dumper) + except (IOError, + elf_parser.ElfError, + vtable_dumper.VtableError) as e: + logging.exception("%s: Cannot diff ABI", rel_path) + has_exception = True if missing_symbols: logging.error("%s: Missing Symbols:\n%s", @@ -327,6 +297,16 @@ class VtsVndkAbiTest(base_test.BaseTestClass): logging.info("%s: Pass", rel_path) return error_count + @staticmethod + def _GetLinkerSearchIndex(target_path): + """Returns the key for sorting linker search paths.""" + index = 0 + for prefix in ("/odm", "/vendor", "/system"): + if target_path.startswith(prefix): + return index + index += 1 + return index + def testAbiCompatibility(self): """Checks ABI compliance of VNDK libraries.""" primary_abi = self._dut.getCpuAbiList()[0] @@ -350,26 +330,20 @@ class VtsVndkAbiTest(base_test.BaseTestClass): self._vndk_version, primary_abi, self.abi_bitness)) logging.info("dump dir: %s", dump_dir) - odm_lib_dir = os.path.join( - self._temp_dir, "odm_lib_dir_" + self.abi_bitness) - vendor_lib_dir = os.path.join( - self._temp_dir, "vendor_lib_dir_" + self.abi_bitness) - system_lib_dir = os.path.join( - self._temp_dir, "system_lib_dir_" + self.abi_bitness) - logging.info("host lib dir: %s %s %s", - odm_lib_dir, vendor_lib_dir, system_lib_dir) - self._PullOrCreateDir( - getattr(self, "_ODM_LIB_DIR_" + self.abi_bitness), - odm_lib_dir) - self._PullOrCreateDir( - getattr(self, "_VENDOR_LIB_DIR_" + self.abi_bitness), - vendor_lib_dir) - self._PullOrCreateDir( - getattr(self, "_SYSTEM_LIB_DIR_" + self.abi_bitness), - system_lib_dir) - - error_count = self._ScanLibDirs( - dump_dir, [odm_lib_dir, vendor_lib_dir, system_lib_dir], dump_version) + target_vndk_dir = vndk_utils.GetVndkCoreDirectory(self.abi_bitness, + self._vndk_version) + target_vndk_sp_dir = vndk_utils.GetVndkSpDirectory(self.abi_bitness, + self._vndk_version) + target_dirs = vndk_utils.GetVndkExtDirectories(self.abi_bitness) + target_dirs += vndk_utils.GetVndkSpExtDirectories(self.abi_bitness) + target_dirs += [target_vndk_dir, target_vndk_sp_dir] + target_dirs.sort(key=self._GetLinkerSearchIndex) + + host_dirs = [self._ToHostPath(x) for x in target_dirs] + for target_dir, host_dir in zip(target_dirs, host_dirs): + self._PullOrCreateDir(target_dir, host_dir) + + error_count = self._ScanLibDirs(dump_dir, host_dirs, dump_version) asserts.assertEqual(error_count, 0, "Total number of errors: " + str(error_count)) |