Exemple #1
0
def test_listener_deinit(can=builtin_bus_factory):
    with can() as b:
        extended_matches = [
            Match(0x1FFFCAFE, mask=0xFFFF, extended=True),
            Match(0x0BEEF000, mask=0x1FFFF000, extended=True),
        ]
        standard_matches = [
            Match(0x400, mask=0x7F0),  # should allow 0x40*
            Match(0x70A, mask=0x70F),  # should allow 0x7*A
        ]
        with b.listen(extended_matches, timeout=0.1) as l:
            # mask matching
            mo = Message(id=0x0BEEF000, extended=True, data=b"")
            b.send(mo)
            mi = l.receive()
            assert mi

            # non-matching
            mo = Message(id=0x1FFFFAFF, extended=True, data=b"")
            b.send(mo)
            mi = l.receive()
            assert not mi

        with b.listen(standard_matches, timeout=0.1) as l:
            # non-matching
            mo = RemoteTransmissionRequest(id=0x418, length=0)
            b.send(mo)
            mi = l.receive()
            assert not mi, "ID 0x418 not blocked by masked filter"

            # masked matching
            mo = RemoteTransmissionRequest(id=0x7FA, length=0)
            b.send(mo)
            mi = l.receive()
            assert mi, "ID 0x7FA blocked by masked filter"
Exemple #2
0
def test_mcp_extended_id_masked_filters(can=builtin_bus_factory):
    print("Test MCP Extended ID filters")
    extended_matches = [
        Match(0x1FFFCAFE, mask=0xFFFF, extended=True),
        Match(0x0BEEF000, mask=0x1FFFF000, extended=True),
    ]

    with can() as b, b.listen(extended_matches, timeout=0.1) as l:
        # Extended
        # exact ID matching
        mo = Message(id=0x1FFFCAFE, extended=True, data=b"")
        b.send(mo)
        mi = l.receive()
        assert mi, "Exact extended filter match blocked"

        # mask matching
        mo = Message(id=0x0BEEF000, extended=True, data=b"")
        b.send(mo)
        mi = l.receive()
        assert mi

        # non-matching
        mo = Message(id=0x1FFFFAFF, extended=True, data=b"")
        b.send(mo)
        mi = l.receive()
        assert not mi

        # non-matching
        mo = Message(id=0x00BEEF00, extended=True, data=b"")
        b.send(mo)
        mi = l.receive()
        assert not mi, "ID %x not blocked by filters & masks" % (max_extended_id - 1)
Exemple #3
0
def test_mcp_standard_id_masked_filters(can=builtin_bus_factory):

    print("Test MCP Standard ID masked filters")
    standard_matches = [
        Match(0x400, mask=0x7F0),  # should allow 0x40*
        Match(0x70A, mask=0x70F),  # should allow 0x7*A
    ]

    with can() as b, b.listen(standard_matches, timeout=0.1) as l:
        # masked matching
        mo = RemoteTransmissionRequest(id=0x408, length=0)
        b.send(mo)
        mi = l.receive()
        assert mi, "ID 0x408 not blocked by masked filter"

        # # non-matching
        mo = RemoteTransmissionRequest(id=0x418, length=0)
        b.send(mo)
        mi = l.receive()
        assert not mi, "ID 0x418 not blocked by masked filter"

        # masked matching
        mo = RemoteTransmissionRequest(id=0x7FA, length=0)
        b.send(mo)
        mi = l.receive()
        assert mi, "ID 0x7FA blocked by masked filter"

        # non-matching
        mo = RemoteTransmissionRequest(id=0x7FB, length=0)
        b.send(mo)
        mi = l.receive()
        assert not mi, "ID 0x7FB not blocked by masked filter"
Exemple #4
0
def test_mcp_standard_id_exact_filters(can=builtin_bus_factory):

    print("Test MCP Standard ID filters")
    standard_matches = [
        Match(0x408),
        Match(max_standard_id),
    ]

    with can() as b, b.listen(standard_matches, timeout=0.1) as l:
        # exact ID matching
        mo = RemoteTransmissionRequest(id=0x408, length=0)
        b.send(mo)
        mi = l.receive()
        assert mi

        # # mask matching
        mo = RemoteTransmissionRequest(id=max_standard_id, length=0)
        b.send(mo)
        mi = l.receive()
        assert mi

        # non-matching
        mo = RemoteTransmissionRequest(id=0x409, length=0)
        b.send(mo)
        mi = l.receive()
        assert not mi, "ID 0x409 not blocked by filters & masks"

        # non-matching
        mo = RemoteTransmissionRequest(id=(max_standard_id - 1), length=0)
        b.send(mo)
        mi = l.receive()
        assert not mi, "ID %x not blocked by filters & masks" % (max_standard_id - 1)
Exemple #5
0
def test_filters2(can=builtin_bus_factory):
    matches = [
        Match(0x408),
        Match(0x700, mask=0x7F0),
        Match(0x4081975, extended=True),
        Match(0x888800, mask=0xFFFFF0, extended=True),
    ]
    print("Test filters 2")
    with can() as b, b.listen(matches[0:2], timeout=0.1) as l1, b.listen(
        matches[2:4], timeout=0.1
    ) as l2:
        # exact ID matching
        mo = RemoteTransmissionRequest(id=0x408, length=0)
        b.send(mo)
        mi1 = l1.receive()
        mi2 = l2.receive()
        assert mi1
        assert not mi2

        # mask matching
        mo = RemoteTransmissionRequest(id=0x704, length=0)
        b.send(mo)
        mi1 = l1.receive()
        mi2 = l2.receive()
        assert mi1
        assert not mi2

        # non-matching
        mo = RemoteTransmissionRequest(id=0x409, length=0)
        b.send(mo)
        mi1 = l1.receive()
        mi2 = l2.receive()
        assert not mi1
        assert not mi2

        # Extended
        # exact ID matching
        mo = Message(id=0x4081975, extended=True, data=b"")
        b.send(mo)
        mi1 = l1.receive()
        mi2 = l2.receive()
        assert not mi1
        assert mi2

        # mask matching
        mo = Message(id=0x888804, extended=True, data=b"")
        b.send(mo)
        mi1 = l1.receive()
        mi2 = l2.receive()
        assert not mi1
        assert mi2

        # non-matching
        mo = Message(id=0x4081985, extended=True, data=b"")
        b.send(mo)
        mi1 = l1.receive()
        mi2 = l2.receive()
        assert not mi1
        assert not mi2
Exemple #6
0
def test_filters1(can=builtin_bus_factory):

    matches = [
        Match(0x408),
        Match(0x700, mask=0x7F0),
        Match(0x4081975, extended=True),
        Match(0x888800, mask=0xFFFFF0, extended=True),
    ]

    print("Test filters")
    with can() as b, b.listen(matches, timeout=0.1) as l:
        # exact ID matching
        mo = RemoteTransmissionRequest(id=0x408, length=0)
        b.send(mo)
        mi = l.receive()
        assert mi

        # mask matching
        mo = RemoteTransmissionRequest(id=0x704, length=0)
        b.send(mo)
        mi = l.receive()
        assert mi

        # non-matching
        # 0x409 => 0b 0000 0100 0000 1001
        mo = RemoteTransmissionRequest(id=0x409, length=0)
        b.send(mo)
        mi = l.receive()
        assert not mi, "ID 0x409 not blocked by filters & masks"

        # Extended
        # exact ID matching
        mo = Message(id=0x4081975, extended=True, data=b"")
        b.send(mo)
        mi = l.receive()
        assert mi

        # mask matching
        mo = Message(id=0x888804, extended=True, data=b"")
        b.send(mo)
        mi = l.receive()
        assert mi

        # non-matching
        mo = Message(id=0x4081985, extended=True, data=b"")
        b.send(mo)
        mi = l.receive()
        assert not mi