modem: pipe: Add explicit timeout to sync APIs
The modem pipe APIs include synchronous calls to open/close, which internally use a fixed timeout of 10 seconds. The timeout should be configurable through the APIs, anywhere from K_NO_WAIT to K_FOREVER. This commit adds timeout parameters to the open/close APIs, and updates in-tree usage of the open/close APIs to explicitly provide the previously implicit timeout of 10 seconds. Signed-off-by: Bjarki Arge Andreasen <bjarki@arge-andreasen.me>
This commit is contained in:
parent
def7f37c83
commit
372c7183ef
13 changed files with 69 additions and 61 deletions
|
@ -108,7 +108,7 @@ static void *test_modem_backend_tty_setup(void)
|
|||
|
||||
tty_pipe = modem_backend_tty_init(&tty_backend, &config);
|
||||
modem_pipe_attach(tty_pipe, modem_pipe_callback_handler, NULL);
|
||||
__ASSERT_NO_MSG(modem_pipe_open(tty_pipe) == 0);
|
||||
__ASSERT_NO_MSG(modem_pipe_open(tty_pipe, K_SECONDS(10)) == 0);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,7 @@ static void test_modem_backend_tty_before(void *f)
|
|||
|
||||
static void test_modem_backend_tty_teardown(void *f)
|
||||
{
|
||||
modem_pipe_close(tty_pipe);
|
||||
modem_pipe_close(tty_pipe, K_SECONDS(10));
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
|
@ -129,12 +129,12 @@ ZTEST(modem_backend_tty_suite, test_close_open)
|
|||
{
|
||||
bool result;
|
||||
|
||||
zassert_ok(modem_pipe_close(tty_pipe), "Failed to close pipe");
|
||||
zassert_ok(modem_pipe_close(tty_pipe), "Pipe should already be closed");
|
||||
zassert_ok(modem_pipe_open(tty_pipe), "Failed to open pipe");
|
||||
zassert_ok(modem_pipe_close(tty_pipe, K_SECONDS(10)), "Failed to close pipe");
|
||||
zassert_ok(modem_pipe_close(tty_pipe, K_SECONDS(10)), "Pipe should already be closed");
|
||||
zassert_ok(modem_pipe_open(tty_pipe, K_SECONDS(10)), "Failed to open pipe");
|
||||
result = atomic_test_bit(&tty_pipe_events, TEST_MODEM_BACKEND_TTY_PIPE_EVENT_TIDLE_BIT);
|
||||
zassert_true(result, "Transmit idle event should be set");
|
||||
zassert_ok(modem_pipe_open(tty_pipe), "Pipe should already be open");
|
||||
zassert_ok(modem_pipe_open(tty_pipe, K_SECONDS(10)), "Pipe should already be open");
|
||||
}
|
||||
|
||||
ZTEST(modem_backend_tty_suite, test_receive_ready_event_not_raised)
|
||||
|
|
|
@ -172,12 +172,12 @@ static void test_modem_backend_uart_before(void *f)
|
|||
prng_reset();
|
||||
ring_buf_reset(&transmit_ring_buf);
|
||||
k_sem_reset(&receive_ready_sem);
|
||||
__ASSERT_NO_MSG(modem_pipe_open(pipe) == 0);
|
||||
__ASSERT_NO_MSG(modem_pipe_open(pipe, K_SECONDS(10)) == 0);
|
||||
}
|
||||
|
||||
static void test_modem_backend_uart_after(void *f)
|
||||
{
|
||||
__ASSERT_NO_MSG(modem_pipe_close(pipe) == 0);
|
||||
__ASSERT_NO_MSG(modem_pipe_close(pipe, K_SECONDS(10)) == 0);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
|
|
|
@ -280,7 +280,7 @@ static void *test_modem_chat_setup(void)
|
|||
};
|
||||
|
||||
mock_pipe = modem_backend_mock_init(&mock, &mock_config);
|
||||
zassert(modem_pipe_open(mock_pipe) == 0, "Failed to open mock pipe");
|
||||
zassert(modem_pipe_open(mock_pipe, K_SECONDS(10)) == 0, "Failed to open mock pipe");
|
||||
zassert(modem_chat_attach(&cmd, mock_pipe) == 0, "Failed to attach pipe mock to modem CMD");
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -283,7 +283,7 @@ static void *test_modem_cmux_setup(void)
|
|||
};
|
||||
|
||||
bus_mock_pipe = modem_backend_mock_init(&bus_mock, &bus_mock_config);
|
||||
__ASSERT_NO_MSG(modem_pipe_open(bus_mock_pipe) == 0);
|
||||
__ASSERT_NO_MSG(modem_pipe_open(bus_mock_pipe, K_SECONDS(10)) == 0);
|
||||
|
||||
/* Connect CMUX */
|
||||
__ASSERT_NO_MSG(modem_cmux_attach(&cmux, bus_mock_pipe) == 0);
|
||||
|
@ -731,9 +731,9 @@ ZTEST(modem_cmux, test_modem_cmux_disconnect_connect)
|
|||
ZTEST(modem_cmux, test_modem_cmux_disconnect_connect_sync)
|
||||
{
|
||||
modem_backend_mock_prime(&bus_mock, &transaction_dlci1_disc);
|
||||
zassert_true(modem_pipe_close(dlci1_pipe) == 0, "Failed to close DLCI1");
|
||||
zassert_true(modem_pipe_close(dlci1_pipe, K_SECONDS(10)) == 0, "Failed to close DLCI1");
|
||||
modem_backend_mock_prime(&bus_mock, &transaction_dlci2_disc);
|
||||
zassert_true(modem_pipe_close(dlci2_pipe) == 0, "Failed to close DLCI2");
|
||||
zassert_true(modem_pipe_close(dlci2_pipe, K_SECONDS(10)) == 0, "Failed to close DLCI2");
|
||||
modem_backend_mock_prime(&bus_mock, &transaction_control_cld);
|
||||
zassert_true(modem_cmux_disconnect(&cmux) == 0, "Failed to disconnect CMUX");
|
||||
zassert_true(modem_cmux_disconnect(&cmux) == -EALREADY,
|
||||
|
@ -745,21 +745,25 @@ ZTEST(modem_cmux, test_modem_cmux_disconnect_connect_sync)
|
|||
"Should already be connected");
|
||||
|
||||
modem_backend_mock_prime(&bus_mock, &transaction_dlci1_sabm);
|
||||
zassert_true(modem_pipe_open(dlci1_pipe) == 0, "Failed to open DLCI1 pipe");
|
||||
zassert_true(modem_pipe_open(dlci1_pipe, K_SECONDS(10)) == 0,
|
||||
"Failed to open DLCI1 pipe");
|
||||
modem_backend_mock_prime(&bus_mock, &transaction_dlci2_sabm);
|
||||
zassert_true(modem_pipe_open(dlci2_pipe) == 0, "Failed to open DLCI2 pipe");
|
||||
zassert_true(modem_pipe_open(dlci2_pipe, K_SECONDS(10)) == 0,
|
||||
"Failed to open DLCI2 pipe");
|
||||
}
|
||||
|
||||
ZTEST(modem_cmux, test_modem_cmux_dlci_close_open_sync)
|
||||
{
|
||||
modem_backend_mock_prime(&bus_mock, &transaction_dlci1_disc);
|
||||
zassert_true(modem_pipe_close(dlci1_pipe) == 0, "Failed to close DLCI1");
|
||||
zassert_true(modem_pipe_close(dlci1_pipe, K_SECONDS(10)) == 0, "Failed to close DLCI1");
|
||||
modem_backend_mock_prime(&bus_mock, &transaction_dlci2_disc);
|
||||
zassert_true(modem_pipe_close(dlci2_pipe) == 0, "Failed to close DLCI2");
|
||||
zassert_true(modem_pipe_close(dlci2_pipe, K_SECONDS(10)) == 0, "Failed to close DLCI2");
|
||||
modem_backend_mock_prime(&bus_mock, &transaction_dlci1_sabm);
|
||||
zassert_true(modem_pipe_open(dlci1_pipe) == 0, "Failed to open DLCI1 pipe");
|
||||
zassert_true(modem_pipe_open(dlci1_pipe, K_SECONDS(10)) == 0,
|
||||
"Failed to open DLCI1 pipe");
|
||||
modem_backend_mock_prime(&bus_mock, &transaction_dlci2_sabm);
|
||||
zassert_true(modem_pipe_open(dlci2_pipe) == 0, "Failed to open DLCI2 pipe");
|
||||
zassert_true(modem_pipe_open(dlci2_pipe, K_SECONDS(10)) == 0,
|
||||
"Failed to open DLCI2 pipe");
|
||||
}
|
||||
|
||||
ZTEST(modem_cmux, test_modem_cmux_prevent_work_while_released)
|
||||
|
|
|
@ -236,7 +236,7 @@ static void cmux_dte_init(void)
|
|||
dlci2_pipe = modem_cmux_dlci_init(&cmux_dte, &dlci2, &dlci2_config);
|
||||
/* Init Backend DTE */
|
||||
bus_mock_pipe = modem_backend_mock_init(&bus_mock_dte, &bus_mock_config);
|
||||
__ASSERT_NO_MSG(modem_pipe_open(bus_mock_pipe) == 0);
|
||||
__ASSERT_NO_MSG(modem_pipe_open(bus_mock_pipe, K_SECONDS(10)) == 0);
|
||||
__ASSERT_NO_MSG(modem_cmux_attach(&cmux_dte, bus_mock_pipe) == 0);
|
||||
modem_pipe_attach(dlci1_pipe, test_dlci1_pipe_cb, NULL);
|
||||
modem_pipe_attach(dlci2_pipe, test_dlci2_pipe_cb, NULL);
|
||||
|
@ -278,7 +278,7 @@ static void cmux_dce_init(void)
|
|||
dlci2_pipe_dce = modem_cmux_dlci_init(&cmux_dce, &dlci2_dce, &dlci2_config);
|
||||
/* Init Backend DCE */
|
||||
bus_mock_pipe_dce = modem_backend_mock_init(&bus_mock_dce, &bus_mock_config);
|
||||
__ASSERT_NO_MSG(modem_pipe_open(bus_mock_pipe_dce) == 0);
|
||||
__ASSERT_NO_MSG(modem_pipe_open(bus_mock_pipe_dce, K_SECONDS(10)) == 0);
|
||||
__ASSERT_NO_MSG(modem_cmux_attach(&cmux_dce, bus_mock_pipe_dce) == 0);
|
||||
modem_pipe_attach(dlci1_pipe_dce, test_dlci1_pipe_cb_dce, NULL);
|
||||
modem_pipe_attach(dlci2_pipe_dce, test_dlci2_pipe_cb_dce, NULL);
|
||||
|
@ -543,8 +543,8 @@ ZTEST(modem_cmux_pair, test_modem_cmux_disconnect_connect_sync)
|
|||
{
|
||||
uint32_t events;
|
||||
|
||||
zassert_true(modem_pipe_close(dlci1_pipe) == 0, "Failed to close DLCI1");
|
||||
zassert_true(modem_pipe_close(dlci2_pipe) == 0, "Failed to close DLCI2");
|
||||
zassert_true(modem_pipe_close(dlci1_pipe, K_SECONDS(10)) == 0, "Failed to close DLCI1");
|
||||
zassert_true(modem_pipe_close(dlci2_pipe, K_SECONDS(10)) == 0, "Failed to close DLCI2");
|
||||
events = k_event_wait_all(&cmux_event_dce,
|
||||
(EVENT_CMUX_DLCI1_CLOSED | EVENT_CMUX_DLCI2_CLOSED), false,
|
||||
K_MSEC(100));
|
||||
|
@ -563,8 +563,8 @@ ZTEST(modem_cmux_pair, test_modem_cmux_disconnect_connect_sync)
|
|||
zassert_true(modem_cmux_connect(&cmux_dte) == -EALREADY, "Should already be connected");
|
||||
zassert_true(modem_cmux_connect(&cmux_dce) == -EALREADY, "Should already be connected");
|
||||
|
||||
zassert_true(modem_pipe_open(dlci1_pipe) == 0, "Failed to open DLCI1 pipe");
|
||||
zassert_true(modem_pipe_open(dlci2_pipe) == 0, "Failed to open DLCI2 pipe");
|
||||
zassert_true(modem_pipe_open(dlci1_pipe, K_SECONDS(10)) == 0, "Failed to open DLCI1 pipe");
|
||||
zassert_true(modem_pipe_open(dlci2_pipe, K_SECONDS(10)) == 0, "Failed to open DLCI2 pipe");
|
||||
events = k_event_wait_all(&cmux_event_dce, (EVENT_CMUX_DLCI1_OPEN | EVENT_CMUX_DLCI2_OPEN),
|
||||
false, K_MSEC(100));
|
||||
zassert_true((events & EVENT_CMUX_DLCI1_OPEN), "DCE DLCI1 not open as expected");
|
||||
|
@ -575,8 +575,8 @@ ZTEST(modem_cmux_pair, test_modem_cmux_dlci_close_open_sync)
|
|||
{
|
||||
uint32_t events;
|
||||
|
||||
zassert_true(modem_pipe_close(dlci1_pipe) == 0, "Failed to close DLCI1");
|
||||
zassert_true(modem_pipe_close(dlci2_pipe) == 0, "Failed to close DLCI2");
|
||||
zassert_true(modem_pipe_close(dlci1_pipe, K_SECONDS(10)) == 0, "Failed to close DLCI1");
|
||||
zassert_true(modem_pipe_close(dlci2_pipe, K_SECONDS(10)) == 0, "Failed to close DLCI2");
|
||||
|
||||
events = k_event_wait_all(&cmux_event_dce,
|
||||
(EVENT_CMUX_DLCI1_CLOSED | EVENT_CMUX_DLCI2_CLOSED), false,
|
||||
|
@ -584,8 +584,8 @@ ZTEST(modem_cmux_pair, test_modem_cmux_dlci_close_open_sync)
|
|||
zassert_true((events & EVENT_CMUX_DLCI1_CLOSED), "DCE DLCI1 not closed as expected");
|
||||
zassert_true((events & EVENT_CMUX_DLCI2_CLOSED), "DCE DLCI2 not closed as expected");
|
||||
|
||||
zassert_true(modem_pipe_open(dlci1_pipe) == 0, "Failed to open DLCI1 pipe");
|
||||
zassert_true(modem_pipe_open(dlci2_pipe) == 0, "Failed to open DLCI2 pipe");
|
||||
zassert_true(modem_pipe_open(dlci1_pipe, K_SECONDS(10)) == 0, "Failed to open DLCI1 pipe");
|
||||
zassert_true(modem_pipe_open(dlci2_pipe, K_SECONDS(10)) == 0, "Failed to open DLCI2 pipe");
|
||||
/* Verify DCE side channels are open also */
|
||||
events = k_event_wait_all(&cmux_event_dce, (EVENT_CMUX_DLCI1_OPEN | EVENT_CMUX_DLCI2_OPEN),
|
||||
false, K_MSEC(100));
|
||||
|
|
|
@ -223,14 +223,14 @@ static void modem_backend_fake_before(void *f)
|
|||
|
||||
static void modem_backend_fake_after(void *f)
|
||||
{
|
||||
__ASSERT(modem_pipe_close(test_pipe) == 0, "Failed to close pipe");
|
||||
__ASSERT(modem_pipe_close(test_pipe, K_SECONDS(10)) == 0, "Failed to close pipe");
|
||||
modem_pipe_release(test_pipe);
|
||||
}
|
||||
|
||||
/* Opening pipe shall raise events OPENED and TRANSMIT_IDLE */
|
||||
static void test_pipe_open(void)
|
||||
{
|
||||
zassert_ok(modem_pipe_open(test_pipe), "Failed to open pipe");
|
||||
zassert_ok(modem_pipe_open(test_pipe, K_SECONDS(10)), "Failed to open pipe");
|
||||
zassert_true(test_backend.open_called, "open was not called");
|
||||
zassert_equal(atomic_get(&test_state),
|
||||
BIT(TEST_MODEM_PIPE_EVENT_OPENED_BIT) |
|
||||
|
@ -241,7 +241,7 @@ static void test_pipe_open(void)
|
|||
/* Re-opening pipe shall have no effect */
|
||||
static void test_pipe_reopen(void)
|
||||
{
|
||||
zassert_ok(modem_pipe_open(test_pipe), "Failed to re-open pipe");
|
||||
zassert_ok(modem_pipe_open(test_pipe, K_SECONDS(10)), "Failed to re-open pipe");
|
||||
zassert_false(test_backend.open_called, "open was called");
|
||||
zassert_equal(atomic_get(&test_state), 0,
|
||||
"Unexpected state %u", atomic_get(&test_state));
|
||||
|
@ -250,7 +250,7 @@ static void test_pipe_reopen(void)
|
|||
/* Closing pipe shall raise event CLOSED */
|
||||
static void test_pipe_close(void)
|
||||
{
|
||||
zassert_ok(modem_pipe_close(test_pipe), "Failed to close pipe");
|
||||
zassert_ok(modem_pipe_close(test_pipe, K_SECONDS(10)), "Failed to close pipe");
|
||||
zassert_true(test_backend.close_called, "close was not called");
|
||||
zassert_equal(atomic_get(&test_state), BIT(TEST_MODEM_PIPE_EVENT_CLOSED_BIT),
|
||||
"Unexpected state %u", atomic_get(&test_state));
|
||||
|
@ -259,7 +259,7 @@ static void test_pipe_close(void)
|
|||
/* Re-closing pipe shall have no effect */
|
||||
static void test_pipe_reclose(void)
|
||||
{
|
||||
zassert_ok(modem_pipe_close(test_pipe), "Failed to re-close pipe");
|
||||
zassert_ok(modem_pipe_close(test_pipe, K_SECONDS(10)), "Failed to re-close pipe");
|
||||
zassert_false(test_backend.close_called, "close was called");
|
||||
zassert_equal(atomic_get(&test_state), 0,
|
||||
"Unexpected state %u", atomic_get(&test_state));
|
||||
|
|
|
@ -276,7 +276,7 @@ static void *test_modem_ppp_setup(void)
|
|||
};
|
||||
|
||||
mock_pipe = modem_backend_mock_init(&mock, &mock_config);
|
||||
zassert_true(modem_pipe_open(mock_pipe) == 0, "Failed to open mock pipe");
|
||||
zassert_true(modem_pipe_open(mock_pipe, K_SECONDS(10)) == 0, "Failed to open mock pipe");
|
||||
modem_ppp_attach(&ppp, mock_pipe);
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue