Exemple #1
0
def test_OkCommunicationProcess_commands_for_each_run_iteration__does_not_send_fifo_read_to_file_writer_if_not_ready_to_read(
):
    board_queues, error_queue = generate_board_and_error_queues(num_boards=4)
    test_bytearray = bytearray(DATA_FRAME_SIZE_WORDS * 4 *
                               DATA_FRAMES_PER_ROUND_ROBIN)
    test_bytearray[:8] = build_header_magic_number_bytes(HEADER_MAGIC_NUMBER)
    fifo = TestingQueue()
    fifo.put_nowait(test_bytearray)
    assert is_queue_eventually_of_size(
        fifo, 1, timeout_seconds=QUEUE_CHECK_TIMEOUT_SECONDS) is True
    queues = {"pipe_outs": {PIPE_OUT_FIFO: fifo}}
    simulator = FrontPanelSimulator(queues)
    simulator.initialize_board()
    simulator.start_acquisition()
    p = OkCommunicationProcess(board_queues, error_queue)
    p.set_board_connection(0, simulator)
    p._is_managed_acquisition_running[0] = True  # pylint:disable=protected-access
    p._time_of_last_fifo_read[0] = datetime.datetime(  # pylint:disable=protected-access
        2020, 2, 13, 11, 43, 10, 123456)
    p._timepoint_of_last_fifo_read[0] = time.perf_counter()  # pylint: disable=protected-access
    invoke_process_run_and_check_errors(p)

    assert (is_queue_eventually_not_empty(
        board_queues[0][2], timeout_seconds=QUEUE_CHECK_TIMEOUT_SECONDS) is
            False)
Exemple #2
0
def test_OkCommunicationProcess_run__processes_stop_acquisition_debug_console_command(
    four_board_comm_process, ):
    ok_process = four_board_comm_process["ok_process"]
    board_queues = four_board_comm_process["board_queues"]
    input_queue = board_queues[0][0]
    response_queue = board_queues[0][1]

    simulator = FrontPanelSimulator({})
    simulator.initialize_board()
    ok_process.set_board_connection(0, simulator)
    simulator.start_acquisition()

    expected_returned_communication = {
        "communication_type": "debug_console",
        "command": "stop_acquisition",
    }
    put_object_into_queue_and_raise_error_if_eventually_still_empty(
        copy.deepcopy(expected_returned_communication), input_queue)
    invoke_process_run_and_check_errors(ok_process)
    expected_spi_communication = {
        "communication_type": "debug_console",
        "command": "is_spi_running",
    }
    put_object_into_queue_and_raise_error_if_eventually_still_empty(
        copy.deepcopy(expected_spi_communication), input_queue)
    invoke_process_run_and_check_errors(ok_process)

    actual = response_queue.get(timeout=QUEUE_CHECK_TIMEOUT_SECONDS)
    assert actual["communication_type"] == expected_returned_communication[
        "communication_type"]
    assert actual["command"] == expected_returned_communication["command"]
    expected_spi_communication["response"] = False
    actual_spi_response = response_queue.get(
        timeout=QUEUE_CHECK_TIMEOUT_SECONDS)
    assert actual_spi_response == expected_spi_communication
Exemple #3
0
def test_OkCommunicationProcess_commands_for_each_run_iteration__sets_default_time_since_last_fifo_read_if_none_while_spi_running(
    mocker, ):
    board_queues, error_queue = generate_board_and_error_queues(num_boards=4)

    p = OkCommunicationProcess(board_queues, error_queue)

    expected_timepoint = 9876
    mocker.patch.object(time, "perf_counter", return_value=expected_timepoint)

    simulator = FrontPanelSimulator({})
    simulator.initialize_board()
    simulator.start_acquisition()
    p.set_board_connection(0, simulator)
    p._is_managed_acquisition_running[0] = True  # pylint:disable=protected-access
    invoke_process_run_and_check_errors(p)

    assert p._time_of_last_fifo_read[0] == datetime.datetime.utcnow()  # pylint:disable=protected-access
    assert p._timepoint_of_last_fifo_read[0] == expected_timepoint  # pylint:disable=protected-access
Exemple #4
0
def test_OkCommunicationProcess_run__processes_read_from_fifo_debug_console_command(
    test_num_words_to_log,
    test_num_cycles_to_read,
    test_description,
    four_board_comm_process,
):
    ok_process = four_board_comm_process["ok_process"]
    board_queues = four_board_comm_process["board_queues"]
    input_queue = board_queues[0][0]
    response_queue = board_queues[0][1]

    test_bytearray = produce_data(test_num_cycles_to_read, 0)
    fifo = TestingQueue()
    put_object_into_queue_and_raise_error_if_eventually_still_empty(
        test_bytearray, fifo)
    queues = {"pipe_outs": {PIPE_OUT_FIFO: fifo}}
    simulator = FrontPanelSimulator(queues)
    simulator.initialize_board()
    ok_process.set_board_connection(0, simulator)
    simulator.start_acquisition()

    expected_returned_communication = {
        "communication_type": "debug_console",
        "command": "read_from_fifo",
        "num_words_to_log": test_num_words_to_log,
    }
    put_object_into_queue_and_raise_error_if_eventually_still_empty(
        copy.deepcopy(expected_returned_communication), input_queue)
    invoke_process_run_and_check_errors(ok_process)

    total_num_words = len(test_bytearray) // 4
    test_words = struct.unpack(f"<{total_num_words}L", test_bytearray)
    formatted_test_words = list()
    num_words_to_log = min(total_num_words, test_num_words_to_log)
    for i in range(num_words_to_log):
        formatted_test_words.append(hex(test_words[i]))
    expected_returned_communication["response"] = formatted_test_words
    actual = response_queue.get(timeout=QUEUE_CHECK_TIMEOUT_SECONDS)
    assert actual == expected_returned_communication
Exemple #5
0
def test_OkCommunicationProcess_commands_for_each_run_iteration__sends_fifo_read_to_file_writer_if_ready_to_read(
):
    board_queues, error_queue = generate_board_and_error_queues(num_boards=4)
    p = OkCommunicationProcess(board_queues, error_queue)
    test_bytearray = produce_data(1, 0)
    fifo = TestingQueue()
    fifo.put_nowait(test_bytearray)
    assert is_queue_eventually_of_size(fifo, 1) is True
    queues = {"pipe_outs": {PIPE_OUT_FIFO: fifo}}
    simulator = FrontPanelSimulator(queues)
    simulator.initialize_board()
    simulator.start_acquisition()
    p.set_board_connection(0, simulator)
    p._is_managed_acquisition_running[0] = True  # pylint:disable=protected-access
    p._time_of_last_fifo_read[0] = datetime.datetime(  # pylint:disable=protected-access
        2020, 2, 13, 11, 43, 10, 123455)
    p._timepoint_of_last_fifo_read[0] = time.perf_counter()  # pylint: disable=protected-access
    invoke_process_run_and_check_errors(p)

    expected_well_idx = 0
    test_value_1 = (
        FIFO_READ_PRODUCER_DATA_OFFSET + FIFO_READ_PRODUCER_WELL_AMPLITUDE *
        (expected_well_idx + 1) * signal.sawtooth(
            0 / FIFO_READ_PRODUCER_SAWTOOTH_PERIOD, width=0.5) * -1)
    expected_first_dict_sent = {
        "is_reference_sensor":
        False,
        "well_index":
        expected_well_idx,
        "data":
        np.array([[0], [int(test_value_1) - RAW_TO_SIGNED_CONVERSION_VALUE]],
                 dtype=np.int32),
    }
    actual = board_queues[0][2].get(timeout=QUEUE_CHECK_TIMEOUT_SECONDS)
    assert actual["is_reference_sensor"] == expected_first_dict_sent[
        "is_reference_sensor"]
    assert actual["well_index"] == expected_first_dict_sent["well_index"]
    np.testing.assert_equal(actual["data"], expected_first_dict_sent["data"])
Exemple #6
0
def test_OkCommunicationProcess_run__processes_stop_managed_acquisition_command(
    four_board_comm_process, ):
    ok_process = four_board_comm_process["ok_process"]
    board_queues = four_board_comm_process["board_queues"]

    simulator = FrontPanelSimulator({})
    simulator.initialize_board()
    simulator.start_acquisition()
    ok_process.set_board_connection(0, simulator)
    ok_process._is_managed_acquisition_running[0] = True  # pylint:disable=protected-access

    input_queue = board_queues[0][0]
    ok_comm_to_main = board_queues[0][1]
    expected_returned_communication = STOP_MANAGED_ACQUISITION_COMMUNICATION
    input_queue.put_nowait(copy.deepcopy(expected_returned_communication))
    confirm_queue_is_eventually_of_size(input_queue, 1)
    invoke_process_run_and_check_errors(ok_process)

    actual = ok_comm_to_main.get(timeout=QUEUE_CHECK_TIMEOUT_SECONDS)
    assert actual == expected_returned_communication

    assert ok_process._is_managed_acquisition_running[0] is False  # pylint:disable=protected-access
    board_connections = ok_process.get_board_connections_list()
    assert board_connections[0].is_spi_running() is False