def test_spinn_nocrash(board): """Test that sending a DVS packet with no forwarding does not crash board""" pkt = DVSPacket(10, 30, 1) # Send packet board_assert_equal(board.use_dvs(pkt), RESPONSES["success"]) # Echo to check that the board replies board_assert_equal(board.echo("test"), "test")
def test_bad_cmd(board, log): """Tests whether a non-existent command gives an error message""" board._write("bad_cmd") # Log error code resp_msg = board._read() if resp_msg in RESPONSES.values(): log.info("Response received: " + resp_msg) board_assert_equal(resp_msg, RESPONSES["bad_cmd"])
def test_spinn_fwd_received(board): """Tests that sending a DVS packet and receiving some data works""" # Turn on forwarding to check that any packet comes back board_assert_equal(board.forward_spinn(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_spinn() board_assert_isinstance(pkt, SpiNNPacket)
def test_spinn_fwd_rx_received(board): """Tests that sending a DVS packet and receiving some data works""" # Turn on forwarding to check that any packet comes back board_assert_equal(board.set_spinn_rx_fwd(0), RESPONSES["success"]) # Send a test packet test_pkt = motor_2_to_7(100) board_assert_equal(board.use_spinn(test_pkt), RESPONSES["success"]) speed = board.get_received_data() assert speed > 0 assert speed == 100
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)
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)))
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
def test_sim_single_tx(mbed, board, log): """Tests that a single packet is received by the STM""" # Ensure that STM is forwarding received data board_assert_equal(board.set_spinn_rx_fwd(0), RESPONSES["success"]) # Send data to the MBED ready to transmit to SpiNNaker mbed.send_spinn_tx_pkt(motor_2_to_7(100)) # Trigger the transmission and check the result duration = mbed.send_trigger_tx() log.info("Test for single packet took %lfs with %lfs per symbol", duration / 1000000.0, duration / (1000000.0 * 11)) assert duration > 0 # Retrieve data from STM and check it is correct speed = board.get_received_data() assert speed > 0 assert speed == 100
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
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)
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
def test_sim_many_tx(mbed, board, log): """Tests that many packets are received by the STM""" # Ensure that STM is forwarding received data board_assert_equal(board.set_spinn_rx_fwd(0), RESPONSES["success"]) speed_max = 200 speed_step = math.floor(200 / 20) speeds = list(range(0, speed_max, speed_step)) # Send data to the MBED ready to transmit to SpiNNaker for speed in speeds: mbed.send_spinn_tx_pkt(motor_2_to_7(speed)) # Trigger the transmission and check the result duration = mbed.send_trigger_tx() assert duration > 0 log.info("Test for %d packets took %lfs with %lfs per packet", len(speeds), duration / 1000000.0, duration / (1000000.0 * 20)) # Retrieve data from STM and check it is correct for speed in speeds: assert board.get_received_data() == speed
def test_spinn_encode(board, dvs_pkt, log): """Test that board encodes a packet the same as the test system for mode 128""" # Turn on forwarding to check that any packet comes back board_assert_equal(board.forward_spinn(0), RESPONSES["success"]) # Set mode to the mode under test board_assert_equal(board.set_mode_spinn(SpiNNMode.SPINN_MODE_128.value), RESPONSES["success"]) # For each packet, test all modes result = spinn_2_to_7(dvs_pkt, SpiNNMode.SPINN_MODE_128) # Send packet board_assert_equal(board.use_dvs(dvs_pkt), RESPONSES["success"]) # Retrieve response pkt = board.get_spinn() board_assert_isinstance(pkt, SpiNNPacket) # Check data is correct log.info("Got packet data: {}".format([hex(x) for x in pkt.data])) log.info("Calculated data: {}".format([hex(x) for x in result.data])) board_assert_equal(pkt.data, result.data)
def test_spinn_encode_downres(board, pkt_list, exp, mode, log): """Tests that encoding works for two of each mode""" # Turn on forwarding to check that any packet comes back board_assert_equal(board.forward_spinn(0), RESPONSES["success"]) # Set mode to the mode under test board_assert_equal(board.set_mode_spinn(mode.value), RESPONSES["success"]) # For each packet, test all modes result = spinn_2_to_7(exp, mode) # Send packets for dvs_pkt in pkt_list: board_assert_equal(board.use_dvs(dvs_pkt), RESPONSES["success"]) # Retrieve response pkt = board.get_spinn() board_assert_isinstance(pkt, SpiNNPacket) # Check data is correct log.info("Got packet data: {}".format([hex(x) for x in pkt.data])) log.info("Calculated data: {}".format([hex(x) for x in result.data])) board_assert_equal(pkt.data, result.data)
def test_spinn_fwd_reset(board): """Tetss that resetting the forwarding works""" board_assert_equal(board.reset_spinn(), RESPONSES["success"])
def test_res_16(board, pkt_list, exp): """Tests that resolution 16x16 only outputs packets in specific cases""" board_assert_equal(board.set_mode_spinn(SpiNNMode.SPINN_MODE_16.value), RESPONSES["success"]) helper_check_downscale(board, pkt_list, exp)
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)
def test_spinn_set_mode_incorrect(board, mode): board_assert_equal(board.set_mode_spinn(mode), RESPONSES["bad_param"])
def test_spinn_set_mode_correct(board, mode): board_assert_equal(board.set_mode_spinn(mode), RESPONSES["success"])
def test_id(board): """Tests if open controller responds to ID request""" board_assert_equal(board.get_id(), BOARD_ID)
def test_spinn_fwd_temp(board): """Tests that setting temporary forwarding is accepted""" board_assert_equal(board.forward_spinn(1000), RESPONSES["success"])
def test_echo(board, test_str): """Tests echo functionality of board""" board_assert_equal(board.echo(test_str), test_str)
def test_spinn_fwd_rx_permanent_on(board): """Tests that turning forwarding on permanently works""" board_assert_equal(board.set_spinn_rx_fwd(0), RESPONSES["success"])
def test_spinn_fwd_on_reset(board): """Tests that turning on and then resetting forwarding works""" board_assert_equal(board.forward_spinn(0), RESPONSES["success"]) board_assert_equal(board.reset_spinn(), RESPONSES["success"])
def test_dvs_fwd_permanent_on(board): """Tests that turning forwarding on permanently works""" board_assert_equal(board.forward_dvs(0), RESPONSES["success"])