From b220d1ee5efe7b853ad6361d5f68472aa7b597be Mon Sep 17 00:00:00 2001 From: David Cermak Date: Fri, 1 Dec 2023 10:43:35 +0100 Subject: [PATCH] fix(modem): Added test injecting unexpected replies This test exhibits an issue of getting unexpected data just after completing a command. The DTE rewrites the state to TIMEOUT, but the signal has been already triggered, thus results in an unexpected state. Related to Closes https://github.com/espressif/esp-protocols/issues/426 --- .../esp_modem/test/host_test/main/test_modem.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/components/esp_modem/test/host_test/main/test_modem.cpp b/components/esp_modem/test/host_test/main/test_modem.cpp index 1a27cc59f..d754839e6 100644 --- a/components/esp_modem/test/host_test/main/test_modem.cpp +++ b/components/esp_modem/test/host_test/main/test_modem.cpp @@ -33,6 +33,20 @@ TEST_CASE("DTE command races", "[esp_modem]") // this command should either timeout or finish successfully CHECK((ret == command_result::TIMEOUT || ret == command_result::OK)); } + + // Now we test the same, but with some garbage after the expected data and inject the reply in chunks by 3 bytes + uint8_t resp2[] = {'O', 'K', '\n', '1', '2', '\n'}; + for (int i = 0; i < 1000; ++i) { + loopback->inject(&resp2[0], sizeof(resp2), 3, /* 1ms before injecting reply */0, 0); + auto ret = dce->command("check\n", [&](uint8_t *data, size_t len) { + if (len > 0 && data[0] == 'O') { // expected reply only when it starts with '0' + return command_result::OK; + } + return esp_modem::command_result::TIMEOUT; + }, 1); + // this command should either timeout or finish successfully + CHECK((ret == command_result::TIMEOUT || ret == command_result::OK)); + } } TEST_CASE("Test polymorphic delete for custom device/dte", "[esp_modem]")