コード例 #1
0
ファイル: test_dvs_forward.py プロジェクト: michael-hart/FYP
def test_dvs_use_pkt(board):
    """Tests that sending simulated packet is sent back"""

    # Turn on forwarding to check that any packet comes back
    board_assert_equal(board.forward_dvs(0), RESPONSES["success"])
    # Send a test packet
    test_pkt = DVSPacket(10, 30, 1)
    board_assert_equal(board.use_dvs(test_pkt), RESPONSES["success"])
    pkt = board.get_dvs()
    board_assert_isinstance(pkt, DVSPacket)
    board_assert_equal(pkt.x, test_pkt.x)
    board_assert_equal(pkt.y, test_pkt.y)
    board_assert_equal(pkt.pol, test_pkt.pol)
コード例 #2
0
ファイル: test_dvs_forward.py プロジェクト: michael-hart/FYP
def test_dvs_packets_received(board):
    """Tests that board receives actual DVS packets"""

    # Set new timeout to allow time for actual DVS to supply packets
    tmp_timeout = board.ser.timeout
    board.ser.timeout = 1

    # Retrieve and check packet
    board_assert_equal(board.forward_dvs(1000), RESPONSES["success"])
    pkt = board.get_dvs()
    board_assert_isinstance(pkt, DVSPacket)
    board_assert_le(pkt.x, 127)
    board_assert_le(pkt.y, 127)
    board_assert_le(pkt.pol, 1)

    # Reset timeout to previous
    board.ser.timeout = tmp_timeout
コード例 #3
0
def test_res_128(board):
    """Test that resolution 128x128 is unchanged"""

    board_assert_equal(board.set_mode_spinn(SpiNNMode.SPINN_MODE_128.value),
                       RESPONSES["success"])

    # Forward all packets to PC
    board_assert_equal(board.forward_dvs(0), RESPONSES["success"])

    # Send several 128x128 DVS Packets
    for param in range(10, 120, 20):
        pkt = DVSPacket(param, param, param % 2)
        board_assert_equal(board.use_dvs(pkt), RESPONSES["success"])
        rx_pkt = board.get_dvs()
        board_assert_isinstance(rx_pkt, DVSPacket)
        board_assert_equal(rx_pkt.x, pkt.x)
        board_assert_equal(rx_pkt.y, pkt.y)
        board_assert_equal(rx_pkt.pol, pkt.pol)
コード例 #4
0
def helper_check_downscale(board, pkt_list, exp):
    """Helper method to be used by remaining tests"""
    # Request one more than expected to be sure that there aren't extras
    request_packets = 1
    if exp is not None:
        request_packets += len(exp)

    # As we are expecting to time out on reads a lot, set the timeout lower
    tmp_timeout = board.ser.timeout
    board.ser.timeout = 0.2

    # Forward all packets to PC
    board_assert_equal(board.forward_dvs(0), RESPONSES["success"])

    response_list = []
    rx_pkt_list = []

    # Send all packets
    for pkt in pkt_list:
        board_assert_equal(board.use_dvs(pkt), RESPONSES["success"])
        # Check for any output from dvs
        rx_pkt = board.get_dvs()
        if rx_pkt:
            rx_pkt_list += [rx_pkt]

    # Compare to expected
    if exp is None:
        assert rx_pkt_list == []
    else:
        assert rx_pkt_list
        for rx_pkt in rx_pkt_list:
            print("{}, {}, {}".format(rx_pkt.x, rx_pkt.y, rx_pkt.pol))
        assert len(rx_pkt_list) == len(exp)
        for pkt, rx_pkt in zip(exp, rx_pkt_list):
            board_assert_isinstance(rx_pkt, DVSPacket)
            board_assert_equal(rx_pkt.x, pkt.x)
            board_assert_equal(rx_pkt.y, pkt.y)
            board_assert_equal(rx_pkt.pol, pkt.pol)

    # Reset board timeout
    board.ser.timeout = tmp_timeout
コード例 #5
0
ファイル: test_dvs_forward.py プロジェクト: michael-hart/FYP
def test_dvs_packets_manykinds(board, log):
    """Tests that board receives DVS packets with various values"""

    # Set new timeout to allow time for actual DVS to supply packets
    tmp_timeout = board.ser.timeout
    board.ser.timeout = 1

    x_rx = set()
    y_rx = set()
    p_rx = set()

    board_assert_equal(board.forward_dvs(0), RESPONSES["success"])

    # Receive 500ms worth of packets
    start_time = time.time()
    while time.time() - start_time < 2:
        # Retrieve and check packet
        pkt = board.get_dvs()
        if not isinstance(pkt, DVSPacket):
            continue

        board_assert_le(pkt.x, 127)
        board_assert_le(pkt.y, 127)
        board_assert_le(pkt.pol, 1)

        # Add values to sets
        x_rx.add(pkt.x)
        y_rx.add(pkt.y)
        p_rx.add(pkt.pol)

    # Check that various results are received
    log.info("DVS packets have counts: x=%d, y=%d, pol=%d",
             len(x_rx), len(y_rx), len(p_rx))
    assert len(x_rx) >= 10
    assert len(y_rx) >= 10
    assert len(p_rx) == 2

    # Reset timeout to previous
    board.ser.timeout = tmp_timeout