def __execute__(self, request):
        from xdevice import Variables
        try:
            self.config = request.config
            self.config.device = request.config.environment.devices[0]
            current_dir = request.config.resource_path if \
                request.config.resource_path else Variables.exec_dir
            if request.root.source.source_file.strip():
                source = os.path.join(current_dir,
                                      request.root.source.source_file.strip())
                self.file_name = os.path.basename(
                    request.root.source.source_file.strip()).split(".")[0]
            else:
                source = request.root.source.source_string.strip()

            self._run_ctest(source=source, request=request)

        except (LiteDeviceExecuteCommandError, Exception) as exception:
            LOG.error(exception)
            self.error_message = exception
        finally:
            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)
示例#2
0
def _make_test_descriptors_from_testsources(test_sources, config):
    test_descriptors = []

    for test_source in test_sources:
        filename, ext = test_source.split()[0], "str"
        if os.path.isfile(test_source):
            filename, ext = get_filename_extension(test_source)

        test_driver = config.testdriver
        if is_config_str(test_source):
            test_driver = _get_test_driver(test_source)

        # get params
        config_file = _get_config_file(
            os.path.join(os.path.dirname(test_source), filename))
        test_type = _get_test_type(config_file, test_driver, ext)
        if not test_type:
            LOG.error("no driver to execute '%s'" % test_source)
            continue

        desc = _create_descriptor(config_file, filename, test_source,
                                  test_type)
        test_descriptors.append(desc)

    return test_descriptors
    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 _get_module_name(cls, data_report, root):
     # get module name from data report
     from _core.utils import get_filename_extension
     module_name = get_filename_extension(data_report)[0]
     if "report" in module_name or "summary" in module_name or \
             "<" in data_report or ">" in data_report:
         module_name = root.get(ReportConstant.name,
                                ReportConstant.empty_name)
         if "report" in module_name or "summary" in module_name:
             module_name = ReportConstant.empty_name
     return module_name
示例#5
0
def _make_test_descriptor(file_path, test_type_key):
    from _core.executor.request import Descriptor
    if test_type_key is None:
        return None

    # get params
    filename, _ = get_filename_extension(file_path)
    uid = unique_id("TestSource", filename)
    test_type = TEST_TYPE_DICT[test_type_key]
    config_file = _get_config_file(
        os.path.join(os.path.dirname(file_path), filename))

    # make test descriptor
    desc = Descriptor(uuid=uid, name=filename,
                      source=TestSource(file_path, "", config_file, filename,
                                        test_type))
    return desc
    def _after_command(self, kits, request):
        self.config.device.execute_command_with_timeout(
            command="cd /", timeout=1)
        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"
        self.delete_device_xml(request, self.linux_directory)

        report_name = "report" if request.root.source. \
            test_name.startswith("{") else get_filename_extension(
            request.root.source.test_name)[0]
        if not self.config.dry_run:
            self.result = check_result_report(
                request.config.report_path, self.result, self.error_message,
                report_name)
 def _find_test_root_descriptor(config):
     # read test list from testfile, testlist or task
     if getattr(config, "testfile", "") or getattr(config, "testlist", "") \
             or getattr(config, "task", ""):
         test_set = config.testfile or config.testlist or config.task
         fname, _ = get_filename_extension(test_set)
         uid = unique_id("Scheduler", fname)
         root = Descriptor(uuid=uid,
                           name=fname,
                           source=TestSetSource(test_set),
                           container=True)
         root.children = find_test_descriptors(config)
         return root
     # read test list from testdict
     elif getattr(config, "testdict", "") != "":
         uid = unique_id("Scheduler", "testdict")
         root = Descriptor(uuid=uid,
                           name="testdict",
                           source=TestSetSource(config.testdict),
                           container=True)
         root.children = find_testdict_descriptors(config)
         return root
     else:
         raise ParamError("no test file, list, dict or task found")