예제 #1
0
def test_custom_algorithm():
    crcengine.register_algorithm('mycrc8', 0xFFD5, 8, 0, False, 0, 0xFFbc)
    assert 'mycrc8' in crcengine.algorithms_available()
    params = crcengine.get_algorithm_params('mycrc8')
    assert params['poly'] == 0xD5
    assert params['seed'] == 0
    crcengine.unregister_algorithm('mycrc8')
    assert 'mycrc8' not in crcengine.algorithms_available()
    with pytest.raises(crcengine.AlgorithmNotFoundError):
        crcengine.get_algorithm_params('mycrc8')
예제 #2
0
def test_custom_algorithm():
    crcengine.register_algorithm("mycrc8", 0xFFD5, 8, 0, False, 0, 0xFFBC)
    assert "mycrc8" in crcengine.algorithms_available()
    params = crcengine.get_algorithm_params("mycrc8")
    assert params["poly"] == 0xD5
    assert params["seed"] == 0
    crcengine.unregister_algorithm("mycrc8")
    assert "mycrc8" not in crcengine.algorithms_available()
    with pytest.raises(crcengine.AlgorithmNotFoundError):
        crcengine.get_algorithm_params("mycrc8")
예제 #3
0
def generate_tests():
    """Generate the test files for generated code, normally these are checked
    in so that the introduction of a regression in enumeration of algorithms
    (for example) won't affect the tests run unless they are explicitly
     regenerated"""
    algorithms = crcengine.algorithms_available()
    for alg in algorithms:
        print("Generating code for", alg)
        crcengine.generate_code(alg, join(C_TEST_HOME, "src"))
        crcengine.codegen.generate_test(alg, join(C_TEST_HOME, "test"))
예제 #4
0
def test_available_algorithms():
    assert 'crc32' in crcengine.algorithms_available()
    assert 'crc16-xmodem' in crcengine.algorithms_available()
    assert 'crc-womble' not in crcengine.algorithms_available()
예제 #5
0
    assert crc16_autosar(b'\x00\x00\x00\x00') == 0x84C0
    assert crc16_autosar(b'\xF2\x01\x83') == 0xD374
    assert crc16_autosar(b'\x0F\xAA\x00\x55') == 0x2023
    assert crc16_autosar(b'\x00\xFF\x55\x11') == 0xB8F9
    assert crc16_autosar(b'3"U\xAA\xBB\xCC\xDD\xEE\xFF') == 0xF53F
    assert crc16_autosar(b'\x92\x6B\x55') == 0x0745
    assert crc16_autosar(b'\xFF\xFF\xFF\xFF') == 0x1D0F


def test_available_algorithms():
    assert 'crc32' in crcengine.algorithms_available()
    assert 'crc16-xmodem' in crcengine.algorithms_available()
    assert 'crc-womble' not in crcengine.algorithms_available()


@pytest.mark.parametrize("algorithm_name", crcengine.algorithms_available())
def test_algorithm_checks(algorithm_name):
    """Check the result of every algorithm against its recorded check-word"""
    check_word = crcengine.get_algorithm_params(algorithm_name, True)['check']
    crc_alg = crcengine.new(algorithm_name)
    assert crc_alg(b'123456789') == check_word,\
        'Check CRC mismatch for {}'.format(algorithm_name)


def test_custom_algorithm():
    crcengine.register_algorithm('mycrc8', 0xFFD5, 8, 0, False, 0, 0xFFbc)
    assert 'mycrc8' in crcengine.algorithms_available()
    params = crcengine.get_algorithm_params('mycrc8')
    assert params['poly'] == 0xD5
    assert params['seed'] == 0
    crcengine.unregister_algorithm('mycrc8')
예제 #6
0
def _generate_algorithms():
    algorithms = crcengine.algorithms_available()
    for alg in algorithms:
        print("Generating code for", alg)
        crcengine.generate_code(alg, join(C_TEST_HOME, "src"))
예제 #7
0
import crcengine

if __name__ == '__main__':
    params = crcengine.get_algorithm_params('crc32')
    crcengine.generate_code(params, 'out/')
    crcengine.generate_code('crc16-xmodem', 'out/')
    filename = "out/crc16_xmodem.c"
    print("Created {} with the following content:")
    with open(filename, "r") as f:
        file = f.read()
        print(file)
    available = crcengine.algorithms_available()
    print("\nThe following algorithms are available")
    print(", ".join(available))

    data = b"123456789"
    crc16x = crcengine.new("crc16-xmodem")
    result = crc16x.calculate(data)
    print("\nThe crc16-xmodem of {} is 0x{:x}".format(data.decode("ascii"),
                                                      result))
예제 #8
0
def test_available_algorithms():
    assert "crc32" in crcengine.algorithms_available()
    assert "crc16-xmodem" in crcengine.algorithms_available()
    assert "crc-womble" not in crcengine.algorithms_available()