def __execute__(self, request): kits = [] try: self.config = request.config self.init_cpp_config() self.config.device = request.config.environment.devices[0] self.__init_nfs_server__(request=request) config_file = request.root.source.config_file json_config = JsonParser(config_file) self._get_driver_config(json_config) bin_file = get_config_value('execute', json_config.get_driver(), False) kits = get_kit_instances(json_config, request.config.resource_path, request.config.testcases_path) from xdevice import Scheduler for kit in kits: if not Scheduler.is_execute: raise ExecuteTerminate() kit.__setup__(request.config.device, request=request) execute_dir = "/".join(bin_file.split("/")[0:-1]) execute_bin = bin_file.split("/")[-1] self.config.device.execute_command_with_timeout( command="cd {}".format(execute_dir), timeout=1) command, report_path, self.has_param = get_execute_command( execute_bin, self.config.xml_output, execute_dir) self.config.device_xml_path = (self.linux_directory + report_path).replace("//", "/") self.set_file_name(request, command) self.need_download = self.is_download( request.config.testcases_path) if self.need_download and self.has_param: self.delete_device_xml(request, self.config.device_xml_path) if os.path.exists(self.result): os.remove(self.result) if request.config.testargs.get("dry_run"): self.config.dry_run = request.config.testargs.get( "dry_run")[0].lower() self.dry_run(command, request.listeners) else: self.run_cpp_test(command, request) self.generate_device_xml(request, execute_bin) device_log_file = get_device_log_file( request.config.report_path, request.config.device.__get_serial__()) with open(device_log_file, "a", encoding="UTF-8") as file_name: file_name.write(self.config.command_result) except (LiteDeviceExecuteCommandError, Exception) as exception: LOG.exception(exception) self.error_message = exception finally: LOG.info("-------------finally-----------------") self._after_command(kits, request)
def __execute__(self, request): kits = [] try: self.config = request.config setattr(self.config, "command_result", "") self.config.device = request.config.environment.devices[0] self.__init_nfs_server__(request=request) config_file = request.root.source.config_file json_config = JsonParser(config_file) pre_cmd = get_config_value('pre_cmd', json_config.get_driver(), False) execute_dir = get_config_value('execute', json_config.get_driver(), False) kits = get_kit_instances(json_config, request.config.resource_path, request.config.testcases_path) from xdevice import Scheduler for kit in kits: if not Scheduler.is_execute: raise ExecuteTerminate() copy_list = kit.__setup__(request.config.device, request=request) self.file_name = request.root.source.test_name self.set_file_name(request, request.root.source.test_name) self.config.device.execute_command_with_timeout( command=pre_cmd, timeout=0.5) self.config.device.execute_command_with_timeout( command="cd {}".format(execute_dir), timeout=1) for test_bin in copy_list: if not test_bin.endswith(".run-test"): continue command, _, _ = get_execute_command(test_bin, False) self._do_test_run(command, request) device_log_file = get_device_log_file( request.config.report_path, request.config.device.__get_serial__()) with open(device_log_file, "a", encoding="UTF-8") as file_name: file_name.write(self.config.command_result) except (LiteDeviceExecuteCommandError, Exception) as exception: LOG.error(exception) self.error_message = exception finally: LOG.info("-------------finally-----------------") # umount the dirs already mount for kit in kits: kit.__teardown__(request.config.device) close_error = self.config.device.close() self.error_message = close_error if close_error else\ "case results are abnormal" report_name = "report" if request.root.source. \ test_name.startswith("{") else get_filename_extension( request.root.source.test_name)[0] self.result = check_result_report( request.config.report_path, self.result, self.error_message, report_name)
def _load_task(self, task_dir, file_name): task_file = os.path.join(task_dir, file_name) if not os.path.exists(task_file): raise ParamError("task file %s not exists" % task_file) # add kits to self.config json_config = JsonParser(task_file) kits = get_kit_instances(json_config, self.config.resource_path, self.config.testcases_path) self.config.kits.extend(kits)
def set_up_env(request, source): if not source.endswith(".json"): source = "%s.json" % source json_config = JsonParser(source) test_args = get_config_value('xml-output', json_config.get_driver()) kits = get_kit_instances(json_config, request.config.resource_path, request.config.testcases_path) kits_copy = copy.deepcopy(kits) from xdevice import Scheduler for kit in kits: if not Scheduler.is_execute: raise ExecuteTerminate() kit.__setup__(request.config.device, request=request) return test_args, kits, kits_copy
def _reset_device(self, request, source): json_config = JsonParser(source) reset_cmd = [] kit_instances = get_kit_instances(json_config, request.config.resource_path, request.config.testcases_path) from xdevice import Scheduler for (kit_instance, kit_info) in zip(kit_instances, json_config.get_kits()): if not isinstance(kit_instance, DeployKit): continue if not self.file_name: self.file_name = get_config_value( 'burn_file', kit_info)[0].split("\\")[-1].split(".")[0] reset_cmd = kit_instance.burn_command if not Scheduler.is_execute: raise ExecuteTerminate() setup_result = kit_instance.__setup__( self.config.device.local_device) if not setup_result: raise DeviceError("set_up wifiiot failed") reset_cmd = [int(item, 16) for item in reset_cmd] return reset_cmd