Example #1
0
    def __test_variable_width(self):
        """
        Test variable width.
        """
        if self.verbose:
            print('Running __test_variable_width()...')
        models = CrcModels()
        m = models.get_params('crc-64-jones')

        for width in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 23, 24, 25, 31, 32, 33, 63, 64]:
            mask = (1 << width) - 1
            mw = {
                'width':         width,
                'poly':          m['poly'] & mask,
                'reflect_in':    m['reflect_in'],
                'xor_in':        m['xor_in'] & mask,
                'reflect_out':   m['reflect_out'],
                'xor_out':       m['xor_out'] & mask,
            }
            args = '--width {width:d} --poly {poly:#x} --xor-in {xor_in:#x} --reflect-in {reflect_in} --xor-out {xor_out:#x} --reflect-out {reflect_out}'.format(**mw)

            check = self.__get_crc(mw)
            if check is None:
                return False

            if self.use_algo_bit_by_bit:
                if self.crc_bin_bbb_c99 is not None:
                    if not self.__check_command(self.crc_bin_bbb_c99 + ' ' + args, check):
                        return False

                if not self.__compile_and_check_res('--algorithm bit-by-bit' + ' ' + args, None, 'crc_bbb_arg', check):
                    return False

            if self.use_algo_bit_by_bit_fast:
                if self.crc_bin_bbf_c99 is not None:
                    if not self.__check_command(self.crc_bin_bbf_c99 + ' ' + args, check):
                        return False

                if not self.__compile_and_check_res('--algorithm bit-by-bit-fast' + ' ' + args, None, 'crc_bbf_arg', check):
                    return False

            if self.use_algo_table_driven:
                if self.crc_bin_tbl_c99 is not None:
                    if not self.__check_command(self.crc_bin_tbl_c99 + ' ' + args, check):
                        return False

                if not self.__compile_and_check_res('--algorithm table-driven' + ' ' + args, None, 'crc_tbl_arg', check):
                    return False
        return True
Example #2
0
File: test.py Project: mgk/pycrc
    def __test_variable_width(self):
        """
        Test variable width.
        """
        if self.verbose:
            print('Running __test_variable_width()...')
        models = CrcModels()
        m = models.get_params('crc-64-jones')

        for width in [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 23, 24, 25, 31, 32, 33, 63, 64]:
            mask = (1 << width) - 1
            mw = {
                'width':         width,
                'poly':          m['poly'] & mask,
                'reflect_in':    m['reflect_in'],
                'xor_in':        m['xor_in'] & mask,
                'reflect_out':   m['reflect_out'],
                'xor_out':       m['xor_out'] & mask,
            }
            args = '--width {width:d} --poly {poly:#x} --xor-in {xor_in:#x} --reflect-in {reflect_in} --xor-out {xor_out:#x} --reflect-out {reflect_out}'.format(**mw)

            check = self.__get_crc(mw)
            if check is None:
                return False

            if self.use_algo_bit_by_bit:
                if self.crc_bin_bbb_c99 is not None:
                    if not self.__check_command(self.crc_bin_bbb_c99 + ' ' + args, check):
                        return False

                if not self.__compile_and_check_res('--algorithm bit-by-bit' + ' ' + args, None, 'crc_bbb_arg', check):
                    return False

            if self.use_algo_bit_by_bit_fast:
                if self.crc_bin_bbf_c99 is not None:
                    if not self.__check_command(self.crc_bin_bbf_c99 + ' ' + args, check):
                        return False

                if not self.__compile_and_check_res('--algorithm bit-by-bit-fast' + ' ' + args, None, 'crc_bbf_arg', check):
                    return False

            if self.use_algo_table_driven:
                if self.crc_bin_tbl_c99 is not None:
                    if not self.__check_command(self.crc_bin_tbl_c99 + ' ' + args, check):
                        return False

                if not self.__compile_and_check_res('--algorithm table-driven' + ' ' + args, None, 'crc_tbl_arg', check):
                    return False
        return True
Example #3
0
def _model_cb(option, opt_str, value, parser):
    """
    This function sets up the single parameters if the 'model' option has been selected
    by the user.
    """
    model_name = value.lower()
    models = CrcModels()
    model = models.get_params(model_name)
    if model != None:
        setattr(parser.values, "width", model["width"])
        setattr(parser.values, "poly", model["poly"])
        setattr(parser.values, "reflect_in", model["reflect_in"])
        setattr(parser.values, "xor_in", model["xor_in"])
        setattr(parser.values, "reflect_out", model["reflect_out"])
        setattr(parser.values, "xor_out", model["xor_out"])
    else:
        models = CrcModels()
        model_list = ", ".join(models.get_list())
        raise OptionValueError("unsupported model {0:s}. Supported models are: {1:s}.".format(value, model_list))
Example #4
0
def _model_cb(option, opt_str, value, parser):
    """
    This function sets up the single parameters if the 'model' option has been selected
    by the user.
    """
    model_name = value.lower()
    models = CrcModels()
    model = models.get_params(model_name)
    if model != None:
        setattr(parser.values, 'width', model['width'])
        setattr(parser.values, 'poly', model['poly'])
        setattr(parser.values, 'reflect_in', model['reflect_in'])
        setattr(parser.values, 'xor_in', model['xor_in'])
        setattr(parser.values, 'reflect_out', model['reflect_out'])
        setattr(parser.values, 'xor_out', model['xor_out'])
    else:
        models = CrcModels()
        model_list = ", ".join(models.names())
        raise OptionValueError(
            "unsupported model {0:s}. Supported models are: {1:s}."
            .format(value, model_list))