def __init__(self, generic_error_msg, specific_msg=None):
        """
        Initializes this instance.

        :type generic_error_msg: str
        :param generic_error_msg: this object's generic error message.
        :type specific_msg: str
        :param specific_msg: specific additional error message.
            Optional parameter, defaults to C{None}.
        """
        AcsBaseException.__init__(self, generic_error_msg, specific_msg)
        self._error_code = self._FAILURE
Ejemplo n.º 2
0
    def __init__(self, generic_error_msg, specific_msg=None):
        """
        Initializes this instance.

        :type generic_error_msg: str
        :param generic_error_msg: this object's generic error message.
        :type specific_msg: str
        :param specific_msg: specific additional error message.
            Optional parameter, defaults to C{None}.
        """
        AcsBaseException.__init__(self, generic_error_msg, specific_msg)
        # This exception family is (in most cases) non DUT related so do not fail on it
        self._error_code = self._BLOCKED
Ejemplo n.º 3
0
def int_to_bcd(int_number):
    """
    Convert a int number to a BCD format

    :param int_number: number in int or a string that represents an int number without sign (+-)
    :type int_number: str | int
    :return: bcd_number
    :rtype: int
    """
    binary_dict = {
        '0': "0000",
        '1': "0001",
        '2': "0010",
        '3': "0011",
        '4': "0100",
        '5': "0101",
        '6': "0110",
        '7': "0111",
        '8': "1000",
        '9': "1001",
        'None': ""
    }
    bcd_number = ""
    for i in str(int_number):
        try:
            bcd_number += binary_dict[i]
        except KeyError:
            raise AcsBaseException(
                AcsBaseException.INVALID_PARAMETER,
                "The number \"%s\" to be converted to BCD contains "
                "other char than digits <0..9>" % (str(int_number)))
    return int(bcd_number, 2)
    def execute(self, is_arg_checking=True, **kwargs):
        """
            This function is the entry point of ACS solution when called by Test Runner.
            It parses the arguments given to CampaignEngine,
            parses XML files associated & read the campaign content
            for the TestCaseManager to execute.

            :param is_arg_checking: Whether or not ACS arguments are checked
            :type is_arg_checking: bool

            :param kwargs: ACS arguments
            :type kwargs: dict

        """

        error = None
        global_results = Util.ACSResult(verdict=Util.ExitCode.FAILURE)
        execution_iteration = 1
        # Index of test case inside  loop on campaign
        tc_order = 1
        stop_execution = False
        verdicts = {}
        acs_outcome_verdicts = {}
        acs_outcome_status = False
        self.__campaign_metrics.campaign_start_datetime = datetime.now()

        try:

            arg_checker = ArgChecker(**kwargs)

            if is_arg_checking:
                error = arg_checker.check_args(False)
                if error:
                    raise AcsBaseException("INVALID_PARAMETER", error)

            params = arg_checker.args

            campaign_name = params["campaign_name"]
            params["campaign_relative_path"] = os.path.dirname(campaign_name)
            execution_request_nb = params["execution_request_nb"]
            random_mode = params["random_mode"]
            device_parameters = params["device_parameter_list"]
            Paths.FLASH_FILES = params["flash_file_path"]

            # Log acs param
            self.__log_acs_param(params)

            # Check if device parameters is a list
            if not isinstance(device_parameters, list):
                device_parameters = []

            # Set test campaign status : campaign is in setup phase
            global_results.status = Util.Status.INIT
            setup_status = self._setup(**params)
            # setup successfully completed
            if setup_status is None:
                total_tc_to_execute = execution_request_nb * len(self.__test_case_conf_list)
                if total_tc_to_execute > MAX_TC_NB_AUTHORIZED:
                    self.__logger.warning("Total number of TCs ({0}) exceeds maximum number authorized ({1})."
                                          .format(total_tc_to_execute, MAX_TC_NB_AUTHORIZED))
                    self.__logger.warning("Only first {0} TCs will be executed".format(MAX_TC_NB_AUTHORIZED))
                    total_tc_to_execute = MAX_TC_NB_AUTHORIZED

                self.__campaign_metrics.total_tc_count = total_tc_to_execute
                # Send live report if enabled
                self._send_create_testcase_info(execution_request_nb)
                # Log extra acs param for metrics
                self._log_acs_param_extra(params)

                # Execute test cases of campaign
                # Set test campaign status : campaign is starting
                global_results.status = Util.Status.ONGOING
                while execution_iteration <= execution_request_nb and not stop_execution:
                    stop_execution, tc_order = self._execute_test_cases(verdicts, tc_order, acs_outcome_verdicts)
                    execution_iteration += 1
                    if random_mode:
                        self.__test_case_conf_list = self.__randomize_test_cases(self.__test_case_conf_list)
                    if tc_order > MAX_TC_NB_AUTHORIZED:
                        break
                if not stop_execution:
                    LOGGER_FWK_STATS.info("event=STOP_ON_EOC")
                    # Set test campaign status : campaign is completed
                    global_results.status = Util.Status.COMPLETED
                else:
                    # Set test campaign status : campaign has been interrupted during test suite execution
                    global_results.status = Util.Status.ABORTED
            # Exception occurred during setup
            else:
                self.__log_stop_campaign(setup_status)
                # Set test campaign status
                global_results.status = Util.Status.ABORTED

            (status, acs_outcome_status) = self._all_tests_succeed(verdicts, acs_outcome_verdicts)
            if status:
                global_results.verdict = Util.ExitCode.SUCCESS
        except (KeyboardInterrupt):
            LOGGER_FWK_STATS.info("event=STOP_ON_USER_INTERRUPT")
            self.__log_stop_campaign("USER INTERRUPTION")
            # Set test campaign status
            global_results.status = Util.Status.ABORTED
        except (SystemExit):
            LOGGER_FWK_STATS.info("event=STOP_ON_SYSTEM INTERRUPT")
            self.__log_stop_campaign("SYSTEM INTERRUPTION")
            # Set test campaign status
            global_results.status = Util.Status.ABORTED
        except Exception as exception:
            if isinstance(exception, AcsBaseException):
                error = str(exception)
                LOGGER_FWK_STATS.info("event=STOP_ON_EXCEPTION; error={0}".format(error))
                if self.__logger is not None:
                    self.__logger.error(error)
                else:
                    print(error)
            else:
                ex_code, ex_msg, ex_tb = Util.get_exception_info(exception)
                LOGGER_FWK_STATS.info("event=STOP_ON_EXCEPTION; error={0}".format(ex_msg))
                if self.__logger is not None:
                    self.__logger.error(ex_msg)
                    self.__logger.debug("Traceback: {0}".format(ex_tb))
                    self.__logger.debug("return code is {0}".format(ex_code))
                else:
                    print (ex_msg)
                    print ("Traceback: {0}".format(ex_tb))
                    print ("return code is {0}".format(ex_code))

            # add an explicit message in the last executed TC's comment
            if self.__test_report is not None:
                self.__test_report.add_comment(tc_order, str(exception))
                self.__test_report.add_comment(tc_order,
                                               ("Fatal exception : Test Campaign will be stopped. "
                                                "See log file for more information."))
            # Set test campaign status
            global_results.status = Util.Status.ABORTED
        finally:
            # Sending Campaign Stop info to remote server (for Live Reporting control)
            self._live_reporting_interface.send_stop_campaign_info(verdict=global_results.verdict,
                                                                   status=global_results.status)

            if self.__test_case_manager is not None:
                campaign_error = bool(global_results.verdict)
                try:
                    cleanup_status, global_results.dut_state = self.__test_case_manager.cleanup(campaign_error)
                except AcsBaseException as e:
                    cleanup_status = False
                    global_results.dut_state = Util.DeviceState.UNKNOWN
                    error = str(e)
                if self.__logger is not None:
                    if error:
                        self.__logger.error(error)
                    self.__logger.info("FINAL DEVICE STATE : %s" % (global_results.dut_state,))
                else:
                    if error:
                        print error
                    print ("FINAL DEVICE STATE : %s" % (global_results.dut_state,))
            else:
                cleanup_status = True

            if not cleanup_status:
                global_results.verdict = Util.ExitCode.FAILURE

            for verdict in verdicts:
                if not Util.Verdict.is_pass(verdicts[verdict]):
                    tc_name = str(verdict).split(self.VERDICT_SEPARATOR)[0]
                    tc_verdict = verdicts[verdict]
                    msg = "ISSUE: %s=%s\n" % (tc_name, tc_verdict)
                    sys.stderr.write(msg)

            # Wait for last LiveReporting action requests
            self._live_reporting_interface.wait_for_finish()

            if self.__test_report:
                # write  data in report files
                self.__write_report_info()

                # update the metacampaign result id in xml report file
                # this action is done at the end because the connection retry with live reporting server will done
                # throughout campaign execution
                self.__test_report.write_metacampaign_result_id(self._live_reporting_interface.campaign_id)

            if self.campaign_report_path is not None:
                # Archive test campaign XML report
                self.__logger.info("Archive test campaign report...")
                # Compute checksum
                _, archive_file = zip_folder(self.campaign_report_path, self.campaign_report_path)
                self._live_reporting_interface.send_campaign_resource(archive_file)

            # Display campaign metrics information to the user
            self._display_campaign_metrics(self.__campaign_metrics)

            # Close logger
            ACSLogging.close()

            if acs_outcome_status and cleanup_status:
                global_results.verdict = Util.ExitCode.SUCCESS
            else:
                global_results.verdict = Util.ExitCode.FAILURE

        return global_results