tests: modem: Add tests for sync script run functions

This commit adds tests to validate the behavior of the
new script run functions.

Signed-off-by: Bjarki Arge Andreasen <bjarkix123@gmail.com>
This commit is contained in:
Bjarki Arge Andreasen 2023-09-15 14:31:11 +02:00 committed by Fabio Baltieri
commit add09f389b

View file

@ -193,6 +193,34 @@ MODEM_CHAT_SCRIPT_CMDS_DEFINE(
MODEM_CHAT_SCRIPT_DEFINE(script_partial, script_partial_cmds, abort_matches, on_script_result, 4);
/*************************************************************************************************/
/* Small echo script and mock transactions */
/*************************************************************************************************/
static const uint8_t at_echo_data[] = {'A', 'T', '\r', '\n'};
static const struct modem_backend_mock_transaction at_echo_transaction = {
.get = at_echo_data,
.get_size = sizeof(at_echo_data),
.put = at_echo_data,
.put_size = sizeof(at_echo_data),
};
static const uint8_t at_echo_error_data[] = {'E', 'R', 'R', 'O', 'R', ' ', '1', '\r', '\n'};
static const struct modem_backend_mock_transaction at_echo_error_transaction = {
.get = at_echo_data,
.get_size = sizeof(at_echo_data),
.put = at_echo_error_data,
.put_size = sizeof(at_echo_error_data),
};
MODEM_CHAT_MATCH_DEFINE(at_match, "AT", "", NULL);
MODEM_CHAT_SCRIPT_CMDS_DEFINE(
script_echo_cmds,
MODEM_CHAT_SCRIPT_CMD_RESP("AT", at_match),
);
MODEM_CHAT_SCRIPT_DEFINE(script_echo, script_echo_cmds, abort_matches, on_script_result, 4);
/*************************************************************************************************/
/* Script responses */
/*************************************************************************************************/
@ -519,6 +547,25 @@ ZTEST(modem_chat, test_script_with_partial_matches)
"Script sent too many requests");
}
ZTEST(modem_chat, test_script_run_sync_complete)
{
modem_backend_mock_prime(&mock, &at_echo_transaction);
zassert_ok(modem_chat_run_script(&cmd, &script_echo), "Failed to run echo script");
}
ZTEST(modem_chat, test_script_run_sync_timeout)
{
zassert_equal(modem_chat_run_script(&cmd, &script_echo), -EAGAIN,
"Failed to run echo script");
}
ZTEST(modem_chat, test_script_run_sync_abort)
{
modem_backend_mock_prime(&mock, &at_echo_error_transaction);
zassert_equal(modem_chat_run_script(&cmd, &script_echo), -EAGAIN,
"Echo script should time out and return -EAGAIN");
}
/*************************************************************************************************/
/* Test suite */
/*************************************************************************************************/