|
1 | 1 | /*
|
2 |
| - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD |
| 2 | + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD |
3 | 3 | *
|
4 | 4 | * SPDX-License-Identifier: Unlicense OR CC0-1.0
|
5 | 5 | */
|
@@ -247,3 +247,88 @@ TEST_CASE("Test CMUX protocol by injecting payloads", "[esp_modem]")
|
247 | 247 | CHECK(ret == command_result::OK);
|
248 | 248 | }
|
249 | 249 | }
|
| 250 | + |
| 251 | +TEST_CASE("Command and Data mode transitions", "[esp_modem][transitions]") |
| 252 | +{ |
| 253 | + auto term = std::make_unique<LoopbackTerm>(); |
| 254 | + auto loopback = term.get(); |
| 255 | + auto dte = std::make_shared<DTE>(std::move(term)); |
| 256 | + CHECK(term == nullptr); |
| 257 | + |
| 258 | + esp_modem_dce_config_t dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG("APN"); |
| 259 | + esp_netif_t netif{}; |
| 260 | + auto dce = create_SIM7600_dce(&dce_config, dte, &netif); |
| 261 | + CHECK(dce != nullptr); |
| 262 | + |
| 263 | + // UNDEF -> CMD (OK) |
| 264 | + uint8_t resp[] = "DISCONNECTED\n"; |
| 265 | + loopback->inject(&resp[0], sizeof(resp), sizeof(resp), /* 10ms before injecting reply */100, 0); |
| 266 | + loopback->write(nullptr, 0); /* this triggers sending the injected response */ |
| 267 | + CHECK(dce->set_mode(esp_modem::modem_mode::COMMAND_MODE) == true); |
| 268 | + loopback->inject(nullptr, 0, 0, 0, 0); /* reset injection, use synchronous replies now */ |
| 269 | + // CMD -> CMD (Fail) |
| 270 | + CHECK(dce->set_mode(esp_modem::modem_mode::COMMAND_MODE) == false); |
| 271 | + |
| 272 | + // Forcing transition to CMD (via UNDEF) |
| 273 | + // CMD -> UNDEF (OK) |
| 274 | + CHECK(dce->set_mode(esp_modem::modem_mode::UNDEF) == true); |
| 275 | + // UNDEF -> CMD (OK) |
| 276 | + CHECK(dce->set_mode(esp_modem::modem_mode::COMMAND_MODE) == true); |
| 277 | + |
| 278 | + // CMD -> DATA (OK) |
| 279 | + CHECK(dce->set_mode(esp_modem::modem_mode::DATA_MODE) == true); |
| 280 | + // DATA -> CMD (OK) |
| 281 | + CHECK(dce->set_mode(esp_modem::modem_mode::COMMAND_MODE) == true); |
| 282 | +} |
| 283 | + |
| 284 | +TEST_CASE("CMUX mode transitions", "[esp_modem][transitions]") |
| 285 | +{ |
| 286 | + auto term = std::make_unique<LoopbackTerm>(); |
| 287 | + auto dte = std::make_shared<DTE>(std::move(term)); |
| 288 | + CHECK(term == nullptr); |
| 289 | + |
| 290 | + esp_modem_dce_config_t dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG("APN"); |
| 291 | + esp_netif_t netif{}; |
| 292 | + auto dce = create_SIM7600_dce(&dce_config, dte, &netif); |
| 293 | + CHECK(dce != nullptr); |
| 294 | + // UNDEF -> CMUX (OK) |
| 295 | + CHECK(dce->set_mode(esp_modem::modem_mode::CMUX_MODE) == true); |
| 296 | + // CMUX -> DATA (Fail) |
| 297 | + CHECK(dce->set_mode(esp_modem::modem_mode::DATA_MODE) == false); |
| 298 | + // CMUX back -> CMD (OK) |
| 299 | + CHECK(dce->set_mode(esp_modem::modem_mode::COMMAND_MODE) == true); |
| 300 | +} |
| 301 | + |
| 302 | +TEST_CASE("CMUX manual mode transitions", "[esp_modem][transitions]") |
| 303 | +{ |
| 304 | + auto term = std::make_unique<LoopbackTerm>(); |
| 305 | + auto dte = std::make_shared<DTE>(std::move(term)); |
| 306 | + CHECK(term == nullptr); |
| 307 | + |
| 308 | + esp_modem_dce_config_t dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG("APN"); |
| 309 | + esp_netif_t netif{}; |
| 310 | + auto dce = create_SIM7600_dce(&dce_config, dte, &netif); |
| 311 | + CHECK(dce != nullptr); |
| 312 | + |
| 313 | + // Happy flow transitions of Manual CMUX transitions |
| 314 | + CHECK(dce->set_mode(esp_modem::modem_mode::CMUX_MANUAL_MODE) == true); |
| 315 | + CHECK(dce->set_mode(esp_modem::modem_mode::CMUX_MANUAL_EXIT) == true); |
| 316 | + CHECK(dce->set_mode(esp_modem::modem_mode::CMUX_MANUAL_MODE) == true); |
| 317 | + CHECK(dce->set_mode(esp_modem::modem_mode::CMUX_MANUAL_SWAP) == true); |
| 318 | + CHECK(dce->set_mode(esp_modem::modem_mode::CMUX_MANUAL_DATA) == true); |
| 319 | + // Cannot test CMUX_MANUAL_DATA -> CMUX_MANUAL_COMMAND with our mocked terminal for now |
| 320 | + CHECK(dce->set_mode(esp_modem::modem_mode::CMUX_MANUAL_EXIT) == true); |
| 321 | + |
| 322 | + // Check some out of order manual transitions, most of them are allowed, |
| 323 | + // but some fail as modem layers report issues with specific steps |
| 324 | + CHECK(dce->set_mode(esp_modem::modem_mode::CMUX_MANUAL_SWAP) == false); // cannot go directly to SWAP |
| 325 | + CHECK(dce->set_mode(esp_modem::modem_mode::UNDEF) == true); |
| 326 | + CHECK(dce->set_mode(esp_modem::modem_mode::CMUX_MANUAL_SWAP) == true); // can go via UNDEF |
| 327 | + CHECK(dce->set_mode(esp_modem::modem_mode::CMUX_MANUAL_EXIT) == false); // EXIT is allowed, but CMUX terms don't exist |
| 328 | + CHECK(dce->set_mode(esp_modem::modem_mode::UNDEF) == true); |
| 329 | + CHECK(dce->set_mode(esp_modem::modem_mode::CMUX_MANUAL_MODE) == true); // Enter CMUX (via UNDEF) |
| 330 | + CHECK(dce->set_mode(esp_modem::modem_mode::CMUX_MANUAL_DATA) == true); // Go directly to DATA mode |
| 331 | + CHECK(dce->set_mode(esp_modem::modem_mode::CMUX_MANUAL_EXIT) == true); // Exit CMUX |
| 332 | + CHECK(dce->set_mode(esp_modem::modem_mode::UNDEF) == true); // Succeeds from any state |
| 333 | + |
| 334 | +} |
0 commit comments