Skip to content

Commit ed8bbf2

Browse files
authored
Merge pull request #447 from david-cermak/fix/modem_command_state_consistent_test
fix(modem): Added test injecting unexpected replies
2 parents 671190b + b220d1e commit ed8bbf2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

components/esp_modem/test/host_test/main/test_modem.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@ TEST_CASE("DTE command races", "[esp_modem]")
3333
// this command should either timeout or finish successfully
3434
CHECK((ret == command_result::TIMEOUT || ret == command_result::OK));
3535
}
36+
37+
// Now we test the same, but with some garbage after the expected data and inject the reply in chunks by 3 bytes
38+
uint8_t resp2[] = {'O', 'K', '\n', '1', '2', '\n'};
39+
for (int i = 0; i < 1000; ++i) {
40+
loopback->inject(&resp2[0], sizeof(resp2), 3, /* 1ms before injecting reply */0, 0);
41+
auto ret = dce->command("check\n", [&](uint8_t *data, size_t len) {
42+
if (len > 0 && data[0] == 'O') { // expected reply only when it starts with '0'
43+
return command_result::OK;
44+
}
45+
return esp_modem::command_result::TIMEOUT;
46+
}, 1);
47+
// this command should either timeout or finish successfully
48+
CHECK((ret == command_result::TIMEOUT || ret == command_result::OK));
49+
}
3650
}
3751

3852
TEST_CASE("Test polymorphic delete for custom device/dte", "[esp_modem]")

0 commit comments

Comments
 (0)