def _loadElfObjects(self, host_dir, target_dir, elf_error_handler): """Scans a host directory recursively and loads all ELF files in it. Args: host_dir: The host directory to scan. target_dir: The path from which host_dir is copied. elf_error_handler: A function that takes 2 arguments (target_path, exception). It is called when the parser fails to read an ELF file. Returns: List of ElfObject. """ objs = [] for root_dir, file_name in utils.iterate_files(host_dir): full_path = os.path.join(root_dir, file_name) rel_path = os.path.relpath(full_path, host_dir) target_path = path_utils.JoinTargetPath( target_dir, *rel_path.split(os.path.sep)) try: elf = elf_parser.ElfParser(full_path) except elf_parser.ElfError: logging.debug("%s is not an ELF file", target_path) continue try: deps = elf.ListDependencies() except elf_parser.ElfError as e: elf_error_handler(target_path, e) continue finally: elf.Close() logging.info("%s depends on: %s", target_path, ", ".join(deps)) objs.append(self.ElfObject(target_path, elf.bitness, deps)) return objs
def SetFetchedDirectory(self, dir_path, root_path=None): """Adds every file in a directory to one of the dictionaries. This method follows symlink to file, but skips symlink to directory. Args: dir_path: string, the directory to find files in. root_path: string, the temporary directory that dir_path is in. The default value is dir_path. """ for dir_name, file_name in utils.iterate_files(dir_path): full_path = os.path.join(dir_name, file_name) self.SetFetchedFile(full_path, (root_path if root_path else dir_path))
def Run(self, arg_line): """Executes a command using a *TS-TF instance. Args: arg_line: string, line of command arguments. """ args = self.arg_parser.ParseLine(arg_line) if args.serial: serials = args.serial.split(",") elif self.console.GetSerials(): serials = self.console.GetSerials() else: serials = [] if args.test_exec_mode == "subprocess": if args.suite not in self.console.test_suite_info: logging.error("test_suite_info doesn't have '%s': %s", args.suite, self.console.test_suite_info) return if args.keep_result: self._ClearResultDir() result_dir = self._result_dir else: result_dir = None cmd = self._GenerateTestSuiteCommand( self.console.test_suite_info[args.suite], args.command, serials, result_dir) logging.info("Command: %s", cmd) self._ExecuteCommand(cmd) if result_dir: result_paths = [ os.path.join(dir_name, file_name) for dir_name, file_name in utils.iterate_files(result_dir) if file_name.startswith("log-result") and file_name.endswith(".zip") ] if len(result_paths) != 1: logging.warning("Unexpected number of results: %s", result_paths) self.console.test_result.clear() result = {} if len(result_paths) > 0: with zipfile.ZipFile( result_paths[0], mode="r") as result_zip: with result_zip.open( "log-result.xml", mode="rU") as result_xml: result = xml_utils.GetAttributes( result_xml, self._RESULT_TAG, self._RESULT_ATTRIBUTES) if not result: logging.warning("Nothing loaded from report.") result["result_zip"] = result_paths[0] result_paths_full = [ os.path.join(dir_name, file_name) for dir_name, file_name in utils.iterate_files(result_dir) if file_name.endswith(".zip") ] result["result_full"] = " ".join(result_paths_full) result["suite_name"] = args.suite logging.debug(result) self.console.test_result.update(result) else: logging.error("unsupported exec mode: %s", args.test_exec_mode) return False
def Run(self, arg_line): """Executes a command using a VTS-TF instance. Args: arg_line: string, line of command arguments. """ args = self.arg_parser.ParseLine(arg_line) if args.serial: serials = args.serial.split(",") elif self.console.GetSerials(): serials = self.console.GetSerials() else: serials = [] if args.test_exec_mode == "subprocess": if "vts" not in self.console.test_suite_info: print("test_suite_info doesn't have 'vts': %s" % self.console.test_suite_info) return if args.keep_result: self._ClearResultDir() result_dir = self._result_dir else: result_dir = None cmd = self._GenerateVtsCommand(self.console.test_suite_info["vts"], args.command, serials, result_dir) print("Command: %s" % cmd) self._ExecuteCommand(cmd) if result_dir: result_paths = [ os.path.join(dir_name, file_name) for dir_name, file_name in utils.iterate_files(result_dir) if file_name.startswith("log-result") and file_name.endswith(".zip") ] if len(result_paths) != 1: logging.warning("Unexpected number of results: %s", result_paths) self.console.test_result.clear() if len(result_paths) > 0: with zipfile.ZipFile( result_paths[0], mode="r") as result_zip: with result_zip.open( "log-result.xml", mode="rU") as result_xml: result = self._LoadReport(result_xml) result["result_zip"] = result_paths[0] result_paths_full = [ os.path.join(dir_name, file_name) for dir_name, file_name in utils.iterate_files(result_dir) if file_name.endswith(".zip")] result["result_full"] = " ".join(result_paths_full) logging.debug(result) self.console.test_result.update(result) else: print("unsupported exec mode: %s", args.test_exec_mode) return False