Example #1
0
def test_event_hostmod_to_hostmod_large(log, hostctrl):
    """Send a large event packet which will be split into two"""
    hm1 = osd.Hostmod(log, HOSTCTRL_ADDR)
    hm2 = osd.Hostmod(log, HOSTCTRL_ADDR)

    hm1.connect()
    assert hm1.is_connected()

    hm2.connect()
    assert hm2.is_connected()

    pkg_sent = osd.Packet()
    pkg_sent.set_header(dest=hm2.diaddr,
                        src=hm1.diaddr,
                        type=osd.Packet.TYPE_EVENT,
                        type_sub=0)
    for i in range(hm1.get_max_event_words(hm2.diaddr) + 1):
        pkg_sent.payload.append(i + 1337)

    hm1.event_send(pkg_sent)

    pkg_received = hm2.event_receive()
    assert pkg_sent == pkg_received

    hm2.disconnect()
    hm1.disconnect()
Example #2
0
def test_event_hostmod_to_hostmod_callback(log, hostctrl):
    """Receive packet with callback"""

    mock_event_handler = Mock()

    hm1 = osd.Hostmod(log, HOSTCTRL_ADDR)
    hm2 = osd.Hostmod(log, HOSTCTRL_ADDR, event_handler=mock_event_handler)

    hm1.connect()
    assert hm1.is_connected()

    hm2.connect()
    assert hm2.is_connected()

    pkg_sent = osd.Packet()
    pkg_sent.set_header(dest=hm2.diaddr,
                        src=hm1.diaddr,
                        type=osd.Packet.TYPE_EVENT,
                        type_sub=0)
    pkg_sent.payload.append(1337)

    hm1.event_send(pkg_sent)

    # XXX: That's a bit fragile: expect the event to be delivered within 0.5 s
    time.sleep(0.5)

    mock_event_handler.assert_called_with(pkg_sent)

    hm2.disconnect()
    hm1.disconnect()
Example #3
0
def test_event_hostmod_to_hostmod(log, hostctrl):
    """Send a small event packet between host modules"""
    hm1 = osd.Hostmod(log, HOSTCTRL_ADDR)
    hm2 = osd.Hostmod(log, HOSTCTRL_ADDR)

    hm1.connect()
    assert hm1.is_connected()

    hm2.connect()
    assert hm2.is_connected()

    pkg_sent = osd.Packet()
    pkg_sent.set_header(dest=hm2.diaddr,
                        src=hm1.diaddr,
                        type=osd.Packet.TYPE_EVENT,
                        type_sub=0)
    pkg_sent.payload.append(1337)
    hm1.event_send(pkg_sent)

    pkg_received = hm2.event_receive()
    assert pkg_sent == pkg_received

    hm2.disconnect()
    hm1.disconnect()
Example #4
0
def test_event_hostmod_to_hostmod_callback_class(log, hostctrl):
    """Receive packet with callback living inside a class"""

    test_finish = False

    # Hostmod 1 (sender)
    hm1 = osd.Hostmod(log, HOSTCTRL_ADDR)
    hm1.connect()
    assert hm1.is_connected()

    # Hostmod 2 (receiver)
    class Receiver:
        def __init__(self, log, host_controller):
            self.hm = osd.Hostmod(log,
                                  host_controller,
                                  event_handler=self.event_handler)
            self.hm.connect()
            assert self.hm.is_connected()

        def event_handler(self, pkg_received):
            nonlocal test_finish
            assert pkg_received == pkg_sent
            test_finish = True

    rcv = Receiver(log, HOSTCTRL_ADDR)

    # packet to send out
    pkg_sent = osd.Packet()
    pkg_sent.set_header(dest=rcv.hm.diaddr,
                        src=hm1.diaddr,
                        type=osd.Packet.TYPE_EVENT,
                        type_sub=0)
    pkg_sent.payload.append(1337)

    # send it out
    hm1.event_send(pkg_sent)

    # wait for packet to be received by callback
    for _ in range(10):
        if test_finish:
            break
        time.sleep(0.1)
    assert test_finish == True

    hm1.disconnect()
Example #5
0
 def __init__(self, log, host_controller):
     self.hm = osd.Hostmod(log,
                           host_controller,
                           event_handler=self.event_handler)
     self.hm.connect()
     assert self.hm.is_connected()