fix(modem): Minor fixes per code review

This commit is contained in:
David Cermak
2026-04-14 16:38:46 +02:00
parent 890088762f
commit ac832bb883
4 changed files with 49 additions and 119 deletions
@@ -11,7 +11,3 @@ set(EXTRA_COMPONENT_DIRS
set(COMPONENTS main)
project(host_test_app)
idf_component_get_property(esp_modem esp_modem COMPONENT_LIB)
target_compile_definitions(${esp_modem} PRIVATE "-DCONFIG_COMPILER_CXX_EXCEPTIONS")
target_compile_definitions(${esp_modem} PRIVATE "-DCONFIG_IDF_TARGET_LINUX")
@@ -5,11 +5,10 @@ set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(${COMPONENT_LIB} PRIVATE Threads::Threads)
target_link_libraries(${COMPONENT_LIB} PRIVATE Catch2WithMain)
target_link_libraries(${COMPONENT_LIB} PRIVATE Catch2)
set_target_properties(${COMPONENT_LIB} PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS ON
)
target_compile_definitions(${COMPONENT_LIB} PRIVATE "-DCONFIG_IDF_TARGET_LINUX")
@@ -4,7 +4,6 @@
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#define CATCH_CONFIG_MAIN
#include <memory>
#include <cstdlib>
#include <unistd.h>
@@ -47,7 +46,7 @@ static std::shared_ptr<DTE> create_test_dte()
return create_vfs_dte(&dte_config);
}
TEST_CASE("Basic AT command via socket", "[esp_modem][at]")
TEST_CASE("AT commands via socket", "[esp_modem][at]")
{
auto dte = create_test_dte();
REQUIRE(dte != nullptr);
@@ -57,115 +56,51 @@ TEST_CASE("Basic AT command via socket", "[esp_modem][at]")
auto dce = create_SIM7600_dce(&dce_config, dte, &netif);
REQUIRE(dce != nullptr);
CHECK(dce->set_command_mode() == command_result::OK);
}
TEST_CASE("Get signal quality", "[esp_modem][at]")
{
auto dte = create_test_dte();
REQUIRE(dte != nullptr);
esp_modem_dce_config_t dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG("internet");
esp_netif_t netif{};
auto dce = create_SIM7600_dce(&dce_config, dte, &netif);
REQUIRE(dce != nullptr);
int rssi, ber;
CHECK(dce->get_signal_quality(rssi, ber) == command_result::OK);
CHECK(rssi == 27);
CHECK(ber == 99);
}
TEST_CASE("Get module name", "[esp_modem][at]")
{
auto dte = create_test_dte();
REQUIRE(dte != nullptr);
esp_modem_dce_config_t dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG("internet");
esp_netif_t netif{};
auto dce = create_SIM7600_dce(&dce_config, dte, &netif);
REQUIRE(dce != nullptr);
std::string model;
CHECK(dce->get_module_name(model) == command_result::OK);
CHECK(model == "SimModem-7600");
}
TEST_CASE("Get operator name", "[esp_modem][at]")
{
auto dte = create_test_dte();
REQUIRE(dte != nullptr);
esp_modem_dce_config_t dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG("internet");
esp_netif_t netif{};
auto dce = create_SIM7600_dce(&dce_config, dte, &netif);
REQUIRE(dce != nullptr);
std::string operator_name;
int act = -1;
CHECK(dce->get_operator_name(operator_name, act) == command_result::OK);
CHECK(operator_name == "TestOperator");
CHECK(act == 7);
}
TEST_CASE("Get IMSI", "[esp_modem][at]")
{
auto dte = create_test_dte();
REQUIRE(dte != nullptr);
esp_modem_dce_config_t dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG("internet");
esp_netif_t netif{};
auto dce = create_SIM7600_dce(&dce_config, dte, &netif);
REQUIRE(dce != nullptr);
std::string imsi;
CHECK(dce->get_imsi(imsi) == command_result::OK);
CHECK(imsi == "987654321098765");
}
TEST_CASE("Get IMEI", "[esp_modem][at]")
{
auto dte = create_test_dte();
REQUIRE(dte != nullptr);
esp_modem_dce_config_t dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG("internet");
esp_netif_t netif{};
auto dce = create_SIM7600_dce(&dce_config, dte, &netif);
REQUIRE(dce != nullptr);
std::string imei;
CHECK(dce->get_imei(imei) == command_result::OK);
CHECK(imei == "123456789012345");
}
TEST_CASE("Read PIN status", "[esp_modem][at]")
{
auto dte = create_test_dte();
REQUIRE(dte != nullptr);
esp_modem_dce_config_t dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG("internet");
esp_netif_t netif{};
auto dce = create_SIM7600_dce(&dce_config, dte, &netif);
REQUIRE(dce != nullptr);
bool pin_ok;
CHECK(dce->read_pin(pin_ok) == command_result::OK);
CHECK(pin_ok == true);
}
#define CATCH_CONFIG_RUNNER
extern "C" int app_main(void)
{
int argc = 5;
const char *argv[] = {"host_test_app", "-r", "junit", "-o", "junit.xml", nullptr};
int result = Catch::Session().run(argc, argv);
if (result != 0) {
printf("Test failed with result %d.\n", result);
} else {
printf("All tests passed successfully.\n");
SECTION("set_command_mode") {
CHECK(dce->set_command_mode() == command_result::OK);
}
std::exit(result);
SECTION("get_signal_quality") {
int rssi, ber;
CHECK(dce->get_signal_quality(rssi, ber) == command_result::OK);
CHECK(rssi == 27);
CHECK(ber == 99);
}
SECTION("get_module_name") {
std::string model;
CHECK(dce->get_module_name(model) == command_result::OK);
CHECK(model == "SimModem-7600");
}
SECTION("get_operator_name") {
std::string operator_name;
int act = -1;
CHECK(dce->get_operator_name(operator_name, act) == command_result::OK);
CHECK(operator_name == "TestOperator");
CHECK(act == 7);
}
SECTION("get_imsi") {
std::string imsi;
CHECK(dce->get_imsi(imsi) == command_result::OK);
CHECK(imsi == "987654321098765");
}
SECTION("get_imei") {
std::string imei;
CHECK(dce->get_imei(imei) == command_result::OK);
CHECK(imei == "123456789012345");
}
SECTION("read_pin") {
bool pin_ok;
CHECK(dce->read_pin(pin_ok) == command_result::OK);
CHECK(pin_ok == true);
}
}
int main(int argc, char *argv[])
{
return Catch::Session().run(argc, argv);
}
@@ -1,7 +1,7 @@
#!/bin/bash
#
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Unlicense OR CC0-1.0
# SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
#
# Test harness: starts modem simulator, runs test app, collects results.