From e54b240870fd0ea6c25ca92ca0ad5352251ca4ce Mon Sep 17 00:00:00 2001 From: David Cermak Date: Wed, 23 Feb 2022 11:00:05 +0100 Subject: [PATCH] add(esp_modem): Add unit test to check polymorphic delete --- .../esp_modem/test/host_test/CMakeLists.txt | 2 +- .../test/host_test/main/test_modem.cpp | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/components/esp_modem/test/host_test/CMakeLists.txt b/components/esp_modem/test/host_test/CMakeLists.txt index 6ec111a89..8c603a21e 100644 --- a/components/esp_modem/test/host_test/CMakeLists.txt +++ b/components/esp_modem/test/host_test/CMakeLists.txt @@ -12,4 +12,4 @@ project(host_modem_test) 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") -target_link_options(${esp_modem} INTERFACE -fsanitize=address) +target_link_options(${esp_modem} INTERFACE -fsanitize=address -fsanitize=undefined) 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 a50f02b1d..f2305e9e0 100644 --- a/components/esp_modem/test/host_test/main/test_modem.cpp +++ b/components/esp_modem/test/host_test/main/test_modem.cpp @@ -7,12 +7,27 @@ using namespace esp_modem; +TEST_CASE("Test polymorphic delete for custom device/dte", "[esp_modem]") +{ + auto term = std::make_unique(true); + auto dte = std::make_shared(std::move(term)); + CHECK(term == nullptr); + esp_modem_dce_config_t dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG("APN"); + + // Create custom device and DTE manually to check for a potential undefined behaviour + auto device = new GenericModule(std::move(dte), &dce_config); + device->power_down(); + delete device; + auto custom_dte = new DTE(std::make_unique(false)); + custom_dte->command("AT", nullptr, 0); + delete custom_dte; +} + TEST_CASE("DCE AT parser", "[esp_modem]") { auto term = std::make_unique(true); auto dte = std::make_shared(std::move(term)); CHECK(term == nullptr); - esp_modem_dce_config_t dce_config = ESP_MODEM_DCE_DEFAULT_CONFIG("APN"); esp_netif_t netif{}; auto dce = create_BG96_dce(&dce_config, dte, &netif);