Esempio n. 1
0
    def test_calculate3_004(self):
        data = NumberMask(0x1000, 16)
        crcSize = 16
        inputPoly = NumberMask(0x10001, crcSize)
        regInit = 0x0
        xorOut = 0x0
        reverse = False

        crcProc = HwCRC()
        crcProc.setReversed(reverse)
        crcProc.setXorOutValue(xorOut)
        crcProc.setInitCRC(regInit, crcSize)

        crc = crcProc.calculate3(data, inputPoly)

        #         print "values: {} poly:{:X} init:{:X} xorOut:{:08b} rev:{} crc:{:08b} crcmod:{:08b} crcxor:{:08b}".format( data, inputPoly, regInit, xorOut, reverse, crc, crcLib, crc^crcLib )
        self.assertEqual(crc, 0x1000)
Esempio n. 2
0
    def test_calculate3_c16_d80(self):
        data = NumberMask(0x8E843664A9CB222CE7EC, 80)
        crcSize = 16
        inputPoly = NumberMask(0x1ABCD, crcSize)
        regInit = 0x0
        xorOut = 0x0
        reverse = False

        #         masterPoly = inputPoly.masterData()
        #         crc_func = crcmod.mkCrcFun(masterPoly, rev=reverse, initCrc=regInit, xorOut=xorOut)
        #         crcLib  = crc_func( data.toASCII() )
        # #         print "crc: {:X}".format( crcLib )

        crcProc = HwCRC()
        crcProc.setReversed(reverse)
        crcProc.setXorOutValue(xorOut)
        crcProc.setInitCRC(regInit, crcSize)

        crc = crcProc.calculate3(data, inputPoly)

        #         print "values: {} poly:{:X} init:{:X} xorOut:{:08b} rev:{} crc:{:08b} crcmod:{:08b} crcxor:{:08b}".format( data, inputPoly, regInit, xorOut, reverse, crc, crcLib, crc^crcLib )
        #         self.assertEqual( crc, crcLib )
        self.assertEqual(crc, 0xD36F)
Esempio n. 3
0
    def test_CRC_random(self):
        data = NumberMask(random.randint(1, 0xFFFFFFFFFFFFFFFF), 64)
        crcSize = 8
        crcMax = 2**8 - 1
        inputPoly = NumberMask(0x100 | random.randint(1, crcMax), crcSize)
        regInit = random.randint(0, crcMax)
        xorOut = random.randint(0, crcMax)
        reverse = bool(random.randint(0, 1))

        crc_func = HwCRC()
        crc_func.setReversed(reverse)
        crc_func.setRegisterInitValue(regInit)
        crc_func.setXorOutValue(xorOut)
        crcLib = crc_func.calculate3(data, inputPoly)

        crcProc = DivisionCRC()
        crcProc.setReversed(reverse)
        crcProc.setRegisterInitValue(regInit)
        crcProc.setXorOutValue(xorOut)
        crc = crcProc.calculate3(data, inputPoly)

        #         print "values: {} poly:{:X} init:{:X} xorOut:{:08b} rev:{} crc:{:08b} crcmod:{:08b} crcxor:{:08b}".format( data, inputPoly, regInit, xorOut, reverse, crc, crcLib, crc^crcLib )
        #         self.assertEqual( crc, crcLib, "Data: {} 0x{:X} 0x{:X} 0x{:X} {}".format(data, inputPoly, regInit, xorOut, reverse ) )
        self.assertEqual(crc, crcLib)
Esempio n. 4
0
    def test_CRC(self):
        data = NumberMask(0xBF, 8)
        inputPoly = NumberMask(0x130, 8)
        regInit = 0x0
        xorOut = 0x0
        reverse = True

        crcProc = HwCRC()
        crcProc.setReversed(reverse)
        crcProc.setRegisterInitValue(regInit)
        crcProc.setXorOutValue(xorOut)
        crc = crcProc.calculate3(data, inputPoly)

        dcrcProc = DivisionCRC()
        dcrcProc.setReversed(reverse)
        dcrcProc.setRegisterInitValue(regInit)
        dcrcProc.setXorOutValue(xorOut)
        dcrc = dcrcProc.calculate3(data, inputPoly)

        #         crc_func = crcmod.mkCrcFun(inputPoly, rev=reverse, initCrc=regInit, xorOut=xorOut)
        #         crcLib  = crc_func( data.toASCII() )
        #         print "crc: {:X} {:X} {:X} {:X}".format( dcrc, crc, crcLib, inputPoly )

        self.assertEqual(dcrc, crc)
Esempio n. 5
0
    def test_crcmod_c16d64_random(self):
        data = NumberMask(random.randint(1, 0xFFFFFFFFFFFFFFFF), 64)
        crcSize = 16
        crcMax = 2**crcSize - 1
        inputPoly = NumberMask((0x1 << crcSize) | random.randint(1, crcMax),
                               crcSize)
        #         regInit = random.randint(0, crcMax)
        #         xorOut = random.randint(0, crcMax)
        regInit = 0x0
        xorOut = 0x0
        reverse = bool(random.randint(0, 1))

        crc_func = crcmod.mkCrcFun(inputPoly.masterData(),
                                   rev=reverse,
                                   initCrc=regInit,
                                   xorOut=xorOut)
        crcLib = crc_func(data.toASCII())
        #         print "crc: {:X} {:X}".format( crc, crc2 )

        crcProc = HwCRC()
        crcProc.setReversed(reverse)
        crcProc.setXorOutValue(xorOut)

        if reverse:
            data.reorderBytes()
            inputPoly.reverse()
            crcInit = reverse_number(regInit ^ xorOut, crcSize)
            crcProc.setRegisterInitValue(crcInit)
        else:
            crcInit = regInit ^ xorOut
            crcProc.setRegisterInitValue(crcInit)

        crc = crcProc.calculate3(data, inputPoly)

        #         print "values: {} poly:{:X} init:{:X} xorOut:{:08b} rev:{} crc:{:08b} crcmod:{:08b} crcxor:{:08b}".format( data, inputPoly, regInit, xorOut, reverse, crc, crcLib, crc^crcLib )
        self.assertEqual(crc, crcLib)