From add09f389bd365c89f74d42dc5e0cda328e842b8 Mon Sep 17 00:00:00 2001 From: Bjarki Arge Andreasen Date: Fri, 15 Sep 2023 14:31:11 +0200 Subject: [PATCH] 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 --- tests/subsys/modem/modem_chat/src/main.c | 47 ++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/tests/subsys/modem/modem_chat/src/main.c b/tests/subsys/modem/modem_chat/src/main.c index 6af24bffaa8..ccd6e785bd9 100644 --- a/tests/subsys/modem/modem_chat/src/main.c +++ b/tests/subsys/modem/modem_chat/src/main.c @@ -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 */ /*************************************************************************************************/