Exemple #1
0
def test_read_clears(mbed):
    """Tests that reading a packet from the MBED then resetting works"""
    # Ensure MBED is empty
    _ = mbed.get_spinn()

    # Send a simulated packet
    mbed.send_sim(spinn_2_to_7(DVSPacket(10, 20, 1), SpiNNMode.SPINN_MODE_128))

    # Check that there is a returned value
    (_, _, packets) = mbed.get_spinn()
    assert packets

    # Read again and check that there is nothing
    (_, _, packets) = mbed.get_spinn()
    assert not packets
Exemple #2
0
def test_many_packets(mbed, board, log, packets):
    """Tests the time taken for many packets to be sent is small"""

    # Clear the MBED and tell it to wait
    mbed.get_spinn()
    mbed.wait()

    # Work out x limits for 20 packets
    x_min = 12
    x_step = 6
    x_max = 100 + (packets) * x_step

    y_max = 90
    y_step = 3
    y_min = y_max - (packets) * y_step

    # Form list of test packets and expected results
    dvs_data = [
        DVSPacket(x, y, y % 2) for x, y in zip(range(x_min, x_max, x_step),
                                               range(y_max, y_min, -y_step))
    ]
    exp_data = [spinn_2_to_7(x, SpiNNMode.SPINN_MODE_128) for x in dvs_data]

    for dvs_pkt in dvs_data:
        board_assert_equal(board.use_dvs(dvs_pkt), RESPONSES["success"])

    # Trigger the MBED to start the speed test
    mbed.trigger()

    # Give period of time to forward to the MBED
    time.sleep(packets * 0.05)

    # Retrieve packets
    (duration, count, rx_data) = mbed.get_spinn()

    # Check results are identical
    assert rx_data
    assert len(rx_data) == len(exp_data)
    assert len(rx_data) == count
    for exp, rxp in zip(rx_data, exp_data):
        assert exp.data == rxp.data

    # Check duration is reasonable - packets times 15ms
    assert duration < len(exp_data) * 15000

    log.info("Test for %d packets took %lfs with %lfs per packet" %
             (len(exp_data), duration / 1000000.0, duration /
              (1000000.0 * packets)))
Exemple #3
0
def test_single_packet(mbed, board, log):
    """Test that DVS packet sent to board is sent to MBED correctly"""

    # Trigger the MBED to ensure state is correct
    mbed.trigger()

    # Ensure board is in correct mode
    board_assert_equal(board.set_mode_spinn(SpiNNMode.SPINN_MODE_128.value),
                       RESPONSES["success"])

    # Send a DVS packet to the board
    dvs_pkt = DVSPacket(10, 30, 1)
    board_assert_equal(board.use_dvs(dvs_pkt), RESPONSES["success"])
    pkt = spinn_2_to_7(dvs_pkt, SpiNNMode.SPINN_MODE_128)

    # Give a brief period of time to forward to the MBED
    time.sleep(0.1)

    # Retrieve packets from MBED
    (_, _, rx_pkt) = mbed.get_spinn()

    # Check results are identical
    assert rx_pkt
    for rxp in rx_pkt:
        board_assert_isinstance(rxp, SpiNNPacket)
    log.info("Got packet data: {}".format([hex(x) for x in rx_pkt[0].data]))
    log.info("Calculated data: {}".format([hex(x) for x in pkt.data]))
    board_assert_equal(pkt.data, rx_pkt[0].data)
Exemple #4
0
def test_sim_many_packets(mbed):
    """Tests that sending many packets, each 10ms apart, gives a duration"""

    # Ensure we are triggered
    mbed.trigger()

    # Construct packets
    pkts = []
    pkts += [spinn_2_to_7(DVSPacket(10, 20, 1), SpiNNMode.SPINN_MODE_128)]
    pkts += [spinn_2_to_7(DVSPacket(43, 19, 1), SpiNNMode.SPINN_MODE_128)]
    pkts += [spinn_2_to_7(DVSPacket(131, 0, 1), SpiNNMode.SPINN_MODE_128)]
    pkts += [spinn_2_to_7(DVSPacket(85, 67, 1), SpiNNMode.SPINN_MODE_128)]
    pkts += [spinn_2_to_7(DVSPacket(127, 127, 1), SpiNNMode.SPINN_MODE_128)]

    for pkt in pkts:
        mbed.send_sim(pkt)
        time.sleep(0.01)

    # Retrieve all packets and check their contents and total duration
    (duration, _, rx_pkts) = mbed.get_spinn()

    assert duration
    # Check duration is +/- 40ms
    assert (len(pkts) - 4) * 10000 <= duration <= (len(pkts) + 4) * 10000

    assert rx_pkts
    for true_pkt, rx_pkt in zip(pkts, rx_pkts):
        assert true_pkt.data == rx_pkt.data
Exemple #5
0
def test_trigger(mbed):
    """Tests that triggering the MBED allows values to be captured"""
    mbed.trigger()

    # Send a simulated packet
    mbed.send_sim(spinn_2_to_7(DVSPacket(10, 20, 1), SpiNNMode.SPINN_MODE_128))

    # Check that packet is returned
    (_, _, packet) = mbed.get_spinn()
    assert packet
Exemple #6
0
def test_wait(mbed):
    """Tests that telling the MBED to wait doesn't log values"""
    mbed.wait()

    # Send a simulated packet
    mbed.send_sim(spinn_2_to_7(DVSPacket(10, 20, 1), SpiNNMode.SPINN_MODE_128))

    # Check that nothing is recorded
    (_, _, packets) = mbed.get_spinn()
    assert not packets
Exemple #7
0
def test_empty_spinn(mbed):
    """Tests that no DVS packets sent to board means no SpiNNaker results"""

    # Note that test is flawed as no bytes returned gives the same result
    # as only a carriage return returned. This merely checks that there is
    # nothing in the buffer waiting to be sent
    (duration, count, packets) = mbed.get_spinn()
    assert duration == 0
    assert count == 0
    assert not packets
Exemple #8
0
def test_wait_trigger(mbed):
    """Tests that triggering after a wait allows capture"""

    # Initial wait command
    mbed.wait()

    # Send a simulated packet
    mbed.send_sim(spinn_2_to_7(DVSPacket(10, 20, 1), SpiNNMode.SPINN_MODE_128))

    # Check that nothing is recorded
    (_, _, packets) = mbed.get_spinn()
    assert not packets

    # Trigger recording again
    mbed.trigger()

    # Send a simulated packet
    mbed.send_sim(spinn_2_to_7(DVSPacket(10, 20, 1), SpiNNMode.SPINN_MODE_128))

    # Check that packet is returned
    (_, _, packet) = mbed.get_spinn()
    assert packet
Exemple #9
0
def test_sim_spinn(mbed, log):
    """Tests that a single SpiNNaker packet is sent back correctly"""

    # Ensure we are triggered
    mbed.trigger()

    # Construct packet
    pkt = spinn_2_to_7(DVSPacket(10, 20, 1), SpiNNMode.SPINN_MODE_128)

    # Send simulated packet
    mbed.send_sim(pkt)

    # Retrieve packet and check
    (_, _, rx_pkt) = mbed.get_spinn()
    assert rx_pkt
    log.info("Got packet %s", rx_pkt[0].data)
    log.info("Expected   %s", pkt.data)
    assert rx_pkt[0].data == pkt.data
Exemple #10
0
def test_sim_duration(mbed):
    """Tests that sending two packets roughly 100ms apart gives a duration"""

    # Ensure we are triggered
    mbed.trigger()

    # Construct packet
    pkt = spinn_2_to_7(DVSPacket(10, 20, 1), SpiNNMode.SPINN_MODE_128)

    # Send simulated packet twice
    mbed.send_sim(pkt)
    time.sleep(0.1)
    mbed.send_sim(pkt)

    # Retrieve packet and check
    (duration, _, _) = mbed.get_spinn()
    assert duration
    # Check duration is +/- 40ms
    assert 60000 <= duration <= 140000