fix(asio): Add a simple unit test to check the leaks

This commit is contained in:
David Cermak
2026-01-20 11:40:21 +01:00
parent 91fd657742
commit c3b0168868
7 changed files with 112 additions and 11 deletions
+11 -11
View File
@@ -13,20 +13,20 @@ jobs:
name: Build
strategy:
matrix:
idf_ver: ["latest", "release-v5.0", "release-v5.1", "release-v5.2", "release-v5.3", "release-v5.4"]
idf_ver: ["latest", "release-v5.1", "release-v5.2", "release-v5.3", "release-v5.4", "release-v5.5", "release-v6.0"]
idf_target: ["esp32", "esp32s2"]
example: ["asio_chat", "async_request", "socks4", "ssl_client_server", "tcp_echo_server", "udp_echo_server"]
example: ["asio_chat", "async_request", "socks4", "ssl_client_server", "tcp_echo_server", "udp_echo_server", "unit"]
runs-on: ubuntu-22.04
container: espressif/idf:${{ matrix.idf_ver }}
env:
TEST_DIR: components/asio/examples
APP_DIR: ${{ matrix.example == 'unit' && 'components/asio/tests/unit' || format('components/asio/examples/{0}', matrix.example) }}
steps:
- name: Checkout esp-protocols
uses: actions/checkout@v4
with:
submodules: recursive
- name: Build ${{ matrix.example }} with IDF-${{ matrix.idf_ver }} for ${{ matrix.idf_target }}
working-directory: ${{ env.TEST_DIR }}/${{ matrix.example }}
working-directory: ${{ env.APP_DIR }}
env:
IDF_TARGET: ${{ matrix.idf_target }}
shell: bash
@@ -40,7 +40,7 @@ jobs:
- uses: actions/upload-artifact@v4
with:
name: examples_app_bin_${{ matrix.idf_target }}_${{ matrix.idf_ver }}_${{ matrix.example }}
path: ${{ env.TEST_DIR }}/${{ matrix.example }}/artifacts.zip
path: ${{ env.APP_DIR }}/artifacts.zip
if-no-files-found: error
target_tests_asio:
@@ -51,15 +51,15 @@ jobs:
name: Target tests
strategy:
matrix:
idf_ver: ["latest", "release-v5.1", "release-v5.2", "release-v5.3", "release-v5.4"]
idf_ver: ["latest", "release-v5.3", "release-v5.4", "release-v5.5", "release-v6.0"]
idf_target: ["esp32"]
example: ["asio_chat", "tcp_echo_server", "udp_echo_server", "ssl_client_server"]
example: ["asio_chat", "tcp_echo_server", "udp_echo_server", "ssl_client_server", "unit"]
needs: build_asio
runs-on:
- self-hosted
- ESP32-ETHERNET-KIT
env:
TEST_DIR: components/asio/examples
APP_DIR: ${{ matrix.example == 'unit' && 'components/asio/tests/unit' || format('components/asio/examples/{0}', matrix.example) }}
steps:
- name: Clear repository
run: sudo rm -fr $GITHUB_WORKSPACE && mkdir $GITHUB_WORKSPACE
@@ -67,9 +67,9 @@ jobs:
- uses: actions/download-artifact@v4
with:
name: examples_app_bin_${{ matrix.idf_target }}_${{ matrix.idf_ver }}_${{ matrix.example }}
path: ${{ env.TEST_DIR }}/${{ matrix.example }}
path: ${{ env.APP_DIR }}
- name: Run Example Test ${{ matrix.example }} on target
working-directory: ${{ env.TEST_DIR }}/${{ matrix.example }}
working-directory: ${{ env.APP_DIR }}
run: |
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
@@ -91,4 +91,4 @@ jobs:
if: always()
with:
name: examples_results_${{ matrix.idf_target }}_${{ matrix.idf_ver }}_${{ matrix.example }}
path: ${{ env.TEST_DIR }}/${{ matrix.example }}/*.xml
path: ${{ env.APP_DIR }}/*.xml
+15
View File
@@ -0,0 +1,15 @@
# This is the project CMakeLists.txt file for the test subproject
cmake_minimum_required(VERSION 3.16)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
if("${IDF_VERSION_MAJOR}.${IDF_VERSION_MINOR}" VERSION_GREATER_EQUAL "6.0")
set(test_component_dir $ENV{IDF_PATH}/tools/test_apps/components)
else()
set(test_component_dir $ENV{IDF_PATH}/tools/unit-test-app/components)
endif()
set(EXTRA_COMPONENT_DIRS ../..
${test_component_dir})
project(asio_ssl_unit_test)
@@ -0,0 +1,4 @@
idf_component_register(SRCS "test_asio_ssl.cpp"
# REQUIRES test_utils
INCLUDE_DIRS ".")
# PRIV_REQUIRES unity asio)
@@ -0,0 +1,5 @@
dependencies:
idf: ">=5.1"
espressif/asio:
version: "^1.14.1"
override_path: "../../../"
@@ -0,0 +1,65 @@
/*
* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Unlicense OR CC0-1.0
*/
#include "unity.h"
extern "C" // workaround for unity headers (possibly) without C++ guards
{
#include "unity_fixture.h"
}
#include "test_utils.h"
#include "memory_checks.h"
#include "esp_netif.h"
#include "esp_event.h"
#include "asio.hpp"
#include "asio/ssl.hpp"
static void create_stream_and_attempt_handshake()
{
asio::io_context io;
asio::ssl::context ctx(asio::ssl::context::tlsv12_client);
asio::ssl::stream<asio::ip::tcp::socket> stream(io, ctx);
stream.set_verify_mode(asio::ssl::verify_none);
asio::error_code ec;
stream.handshake(asio::ssl::stream_base::client, ec);
}
TEST_GROUP(asio_ssl);
TEST_SETUP(asio_ssl)
{
// call once to allocate all one time inits
create_stream_and_attempt_handshake();
test_utils_record_free_mem();
}
TEST_TEAR_DOWN(asio_ssl)
{
// account for some timer-based lwip allocations
test_utils_finish_and_evaluate_leaks(128, 256);
}
TEST(asio_ssl, ssl_stream_lifecycle_no_leak)
{
test_case_uses_tcpip();
create_stream_and_attempt_handshake();
TEST_ASSERT_TRUE(true);
}
TEST_GROUP_RUNNER(asio_ssl)
{
RUN_TEST_CASE(asio_ssl, ssl_stream_lifecycle_no_leak)
}
extern "C" void app_main(void)
{
esp_netif_init();
esp_event_loop_create_default();
UNITY_MAIN(asio_ssl);
}
@@ -0,0 +1,8 @@
# SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
from pytest_embedded import Dut
def test_asio_ssl_unit(dut: Dut) -> None:
dut.expect_unity_test_output()
@@ -0,0 +1,4 @@
CONFIG_COMPILER_CXX_EXCEPTIONS=y
CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=n
CONFIG_UNITY_ENABLE_FIXTURE=y
CONFIG_ASIO_SSL_SUPPORT=y