mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
ci: Migrate unit test for tcp_transport to unit test app
This commit is contained in:
parent
4bc762621d
commit
e1f2e656e2
7
components/tcp_transport/.build-test-rules.yml
Normal file
7
components/tcp_transport/.build-test-rules.yml
Normal file
@ -0,0 +1,7 @@
|
||||
# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps
|
||||
|
||||
components/tcp_transport/test_apps:
|
||||
disable_test:
|
||||
- if: IDF_TARGET not in ["esp32", "esp32c3"]
|
||||
temporary: false
|
||||
reason: Not needed to test on all targets (chosen two, one for each architecture)
|
@ -1,4 +0,0 @@
|
||||
idf_component_register(SRC_DIRS "."
|
||||
PRIV_INCLUDE_DIRS "../private_include" "."
|
||||
PRIV_REQUIRES cmock test_utils tcp_transport)
|
||||
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
|
7
components/tcp_transport/test_apps/CMakeLists.txt
Normal file
7
components/tcp_transport/test_apps/CMakeLists.txt
Normal file
@ -0,0 +1,7 @@
|
||||
#This is the project CMakeLists.txt file for the test subproject
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/unit-test-app/components")
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
project(esp_tcp_transport_test)
|
2
components/tcp_transport/test_apps/README.md
Normal file
2
components/tcp_transport/test_apps/README.md
Normal file
@ -0,0 +1,2 @@
|
||||
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-H2 | ESP32-S2 | ESP32-S3 |
|
||||
| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | -------- |
|
5
components/tcp_transport/test_apps/main/CMakeLists.txt
Normal file
5
components/tcp_transport/test_apps/main/CMakeLists.txt
Normal file
@ -0,0 +1,5 @@
|
||||
set(srcs "test_app_main.c" "test_transport_basic.c" "test_transport_connect" "test_transport_fixtures.c")
|
||||
idf_component_register(SRCS ${srcs}
|
||||
PRIV_INCLUDE_DIRS "../../private_include" "."
|
||||
PRIV_REQUIRES cmock test_utils tcp_transport unity
|
||||
WHOLE_ARCHIVE)
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
#ifndef _TCP_TRANSPORT_FIXTURES_H_
|
||||
#define _TCP_TRANSPORT_FIXTURES_H_
|
||||
|
18
components/tcp_transport/test_apps/main/test_app_main.c
Normal file
18
components/tcp_transport/test_apps/main/test_app_main.c
Normal file
@ -0,0 +1,18 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
#include "unity_fixture.h"
|
||||
#include "unity_fixture_extras.h"
|
||||
|
||||
static void run_all_tests(void)
|
||||
{
|
||||
RUN_TEST_GROUP(transport_basic);
|
||||
RUN_TEST_GROUP(transport_connect);
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
UNITY_MAIN_FUNC(run_all_tests);
|
||||
}
|
@ -1,4 +1,10 @@
|
||||
#include "unity.h"
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
#include "unity_fixture.h"
|
||||
#include "memory_checks.h"
|
||||
|
||||
#include "esp_transport.h"
|
||||
#include "esp_transport_tcp.h"
|
||||
@ -7,7 +13,21 @@
|
||||
#include "esp_log.h"
|
||||
|
||||
|
||||
TEST_CASE("tcp_transport: init and deinit transport list", "[tcp_transport][leaks=0]")
|
||||
TEST_GROUP(transport_basic);
|
||||
|
||||
TEST_SETUP(transport_basic)
|
||||
{
|
||||
test_utils_record_free_mem();
|
||||
TEST_ESP_OK(test_utils_set_leak_level(0, ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_GENERAL));
|
||||
}
|
||||
|
||||
TEST_TEAR_DOWN(transport_basic)
|
||||
{
|
||||
test_utils_finish_and_evaluate_leaks(test_utils_get_leak_level(ESP_LEAK_TYPE_WARNING, ESP_COMP_LEAK_ALL),
|
||||
test_utils_get_leak_level(ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_ALL));
|
||||
}
|
||||
|
||||
TEST(transport_basic, transport_list_init_and_destroy)
|
||||
{
|
||||
esp_transport_list_handle_t transport_list = esp_transport_list_init();
|
||||
esp_transport_handle_t tcp = esp_transport_tcp_init();
|
||||
@ -15,13 +35,13 @@ TEST_CASE("tcp_transport: init and deinit transport list", "[tcp_transport][leak
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_transport_list_destroy(transport_list));
|
||||
}
|
||||
|
||||
TEST_CASE("tcp_transport: using ssl transport separately", "[tcp_transport][leaks=0]")
|
||||
TEST(transport_basic, transport_ssl_init_destroy_no_list)
|
||||
{
|
||||
esp_transport_handle_t h = esp_transport_ssl_init();
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_transport_destroy(h));
|
||||
}
|
||||
|
||||
TEST_CASE("tcp_transport: using ws transport separately", "[tcp_transport][leaks=0]")
|
||||
TEST(transport_basic, transport_ws_init_destroy_no_list)
|
||||
{
|
||||
esp_transport_handle_t tcp = esp_transport_tcp_init();
|
||||
esp_transport_handle_t ws = esp_transport_ws_init(tcp);
|
||||
@ -29,7 +49,7 @@ TEST_CASE("tcp_transport: using ws transport separately", "[tcp_transport][leaks
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_transport_destroy(tcp));
|
||||
}
|
||||
|
||||
TEST_CASE("transport: init and deinit multiple transport items", "[tcp_transport][leaks=0]")
|
||||
TEST(transport_basic, transport_list_init_multiple_and_destroy)
|
||||
{
|
||||
esp_transport_list_handle_t transport_list = esp_transport_list_init();
|
||||
esp_transport_handle_t tcp = esp_transport_tcp_init();
|
||||
@ -42,3 +62,11 @@ TEST_CASE("transport: init and deinit multiple transport items", "[tcp_transport
|
||||
esp_transport_list_add(transport_list, wss, "wss");
|
||||
TEST_ASSERT_EQUAL(ESP_OK, esp_transport_list_destroy(transport_list));
|
||||
}
|
||||
|
||||
TEST_GROUP_RUNNER(transport_basic)
|
||||
{
|
||||
RUN_TEST_CASE(transport_basic, transport_list_init_and_destroy);
|
||||
RUN_TEST_CASE(transport_basic, transport_ssl_init_destroy_no_list);
|
||||
RUN_TEST_CASE(transport_basic, transport_ws_init_destroy_no_list);
|
||||
RUN_TEST_CASE(transport_basic, transport_list_init_multiple_and_destroy);
|
||||
}
|
@ -1,4 +1,10 @@
|
||||
#include "unity.h"
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
#include "unity_fixture.h"
|
||||
#include "memory_checks.h"
|
||||
#include "esp_transport.h"
|
||||
#include "esp_transport_tcp.h"
|
||||
#include "esp_transport_ssl.h"
|
||||
@ -8,6 +14,19 @@
|
||||
#include "tcp_transport_fixtures.h"
|
||||
#include "test_utils.h"
|
||||
|
||||
TEST_GROUP(transport_connect);
|
||||
|
||||
TEST_SETUP(transport_connect)
|
||||
{
|
||||
test_utils_record_free_mem();
|
||||
TEST_ESP_OK(test_utils_set_leak_level(0, ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_GENERAL));
|
||||
}
|
||||
|
||||
TEST_TEAR_DOWN(transport_connect)
|
||||
{
|
||||
test_utils_finish_and_evaluate_leaks(test_utils_get_leak_level(ESP_LEAK_TYPE_WARNING, ESP_COMP_LEAK_ALL),
|
||||
test_utils_get_leak_level(ESP_LEAK_TYPE_CRITICAL, ESP_COMP_LEAK_ALL));
|
||||
}
|
||||
|
||||
#define TEST_TRANSPORT_BIND_IFNAME() \
|
||||
struct ifreq ifr; \
|
||||
@ -20,10 +39,10 @@
|
||||
static void tcp_transport_keepalive_test(esp_transport_handle_t transport_under_test, bool async, esp_transport_keep_alive_t *config)
|
||||
{
|
||||
static struct expected_sock_option expected_opts[4] = {
|
||||
{ .level = SOL_SOCKET, .optname = SO_KEEPALIVE, .optval = 1, .opttype = SOCK_OPT_TYPE_BOOL },
|
||||
{ .level = IPPROTO_TCP },
|
||||
{ .level = IPPROTO_TCP },
|
||||
{ .level = IPPROTO_TCP }
|
||||
{ .level = SOL_SOCKET, .optname = SO_KEEPALIVE, .optval = 1, .opttype = SOCK_OPT_TYPE_BOOL },
|
||||
{ .level = IPPROTO_TCP },
|
||||
{ .level = IPPROTO_TCP },
|
||||
{ .level = IPPROTO_TCP }
|
||||
};
|
||||
|
||||
expected_opts[1].optname = TCP_KEEPIDLE;
|
||||
@ -37,7 +56,7 @@ static void tcp_transport_keepalive_test(esp_transport_handle_t transport_under_
|
||||
sizeof(expected_opts) / sizeof(struct expected_sock_option));
|
||||
}
|
||||
|
||||
TEST_CASE("tcp_transport: connect timeout", "[tcp_transport]")
|
||||
TEST(transport_connect, tcp_connect_timeout)
|
||||
{
|
||||
// Init the transport under test
|
||||
esp_transport_list_handle_t transport_list = esp_transport_list_init();
|
||||
@ -49,7 +68,7 @@ TEST_CASE("tcp_transport: connect timeout", "[tcp_transport]")
|
||||
esp_transport_list_destroy(transport_list);
|
||||
}
|
||||
|
||||
TEST_CASE("ssl_transport: connect timeout", "[tcp_transport]")
|
||||
TEST(transport_connect, ssl_connect_timeout)
|
||||
{
|
||||
// Init the transport under test
|
||||
esp_transport_list_handle_t transport_list = esp_transport_list_init();
|
||||
@ -64,7 +83,7 @@ TEST_CASE("ssl_transport: connect timeout", "[tcp_transport]")
|
||||
esp_transport_list_destroy(transport_list);
|
||||
}
|
||||
|
||||
TEST_CASE("tcp_transport: Keep alive test", "[tcp_transport]")
|
||||
TEST(transport_connect, tcp_keep_alive)
|
||||
{
|
||||
// Init the transport under test
|
||||
esp_transport_list_handle_t transport_list = esp_transport_list_init();
|
||||
@ -73,10 +92,11 @@ TEST_CASE("tcp_transport: Keep alive test", "[tcp_transport]")
|
||||
|
||||
// Perform the test
|
||||
esp_transport_keep_alive_t keep_alive_cfg = {
|
||||
.keep_alive_interval = 5,
|
||||
.keep_alive_idle = 4,
|
||||
.keep_alive_enable = true,
|
||||
.keep_alive_count = 3 };
|
||||
.keep_alive_interval = 5,
|
||||
.keep_alive_idle = 4,
|
||||
.keep_alive_enable = true,
|
||||
.keep_alive_count = 3
|
||||
};
|
||||
esp_transport_tcp_set_keep_alive(tcp, &keep_alive_cfg);
|
||||
|
||||
// Bind device interface to loopback
|
||||
@ -92,7 +112,7 @@ TEST_CASE("tcp_transport: Keep alive test", "[tcp_transport]")
|
||||
esp_transport_list_destroy(transport_list);
|
||||
}
|
||||
|
||||
TEST_CASE("ssl_transport: Keep alive test", "[tcp_transport]")
|
||||
TEST(transport_connect, ssl_keep_alive)
|
||||
{
|
||||
// Init the transport under test
|
||||
esp_transport_list_handle_t transport_list = esp_transport_list_init();
|
||||
@ -103,10 +123,11 @@ TEST_CASE("ssl_transport: Keep alive test", "[tcp_transport]")
|
||||
|
||||
// Perform the test
|
||||
esp_transport_keep_alive_t keep_alive_cfg = {
|
||||
.keep_alive_interval = 2,
|
||||
.keep_alive_idle = 3,
|
||||
.keep_alive_enable = true,
|
||||
.keep_alive_count = 4 };
|
||||
.keep_alive_interval = 2,
|
||||
.keep_alive_idle = 3,
|
||||
.keep_alive_enable = true,
|
||||
.keep_alive_count = 4
|
||||
};
|
||||
esp_transport_ssl_set_keep_alive(ssl, &keep_alive_cfg);
|
||||
|
||||
// Bind device interface to loopback
|
||||
@ -122,7 +143,7 @@ TEST_CASE("ssl_transport: Keep alive test", "[tcp_transport]")
|
||||
esp_transport_list_destroy(transport_list);
|
||||
}
|
||||
|
||||
TEST_CASE("ws_transport: Keep alive test", "[tcp_transport]")
|
||||
TEST(transport_connect, ws_keep_alive)
|
||||
{
|
||||
// Init the transport under test
|
||||
esp_transport_list_handle_t transport_list = esp_transport_list_init();
|
||||
@ -133,10 +154,11 @@ TEST_CASE("ws_transport: Keep alive test", "[tcp_transport]")
|
||||
|
||||
// Perform the test
|
||||
esp_transport_keep_alive_t keep_alive_cfg = {
|
||||
.keep_alive_interval = 11,
|
||||
.keep_alive_idle = 22,
|
||||
.keep_alive_enable = true,
|
||||
.keep_alive_count = 33 };
|
||||
.keep_alive_interval = 11,
|
||||
.keep_alive_idle = 22,
|
||||
.keep_alive_enable = true,
|
||||
.keep_alive_count = 33
|
||||
};
|
||||
esp_transport_tcp_set_keep_alive(tcp, &keep_alive_cfg);
|
||||
|
||||
// Bind device interface to loopback
|
||||
@ -153,7 +175,7 @@ TEST_CASE("ws_transport: Keep alive test", "[tcp_transport]")
|
||||
|
||||
// Note: This functionality is tested and kept only for compatibility reasons with IDF <= 4.x
|
||||
// It is strongly encouraged to use transport within lists only
|
||||
TEST_CASE("ssl_transport: Check that parameters (keepalive) are set independently on the list", "[tcp_transport]")
|
||||
TEST(transport_connect, ssl_set_parameter_independently)
|
||||
{
|
||||
// Init the transport under test
|
||||
esp_transport_handle_t ssl = esp_transport_ssl_init();
|
||||
@ -162,10 +184,11 @@ TEST_CASE("ssl_transport: Check that parameters (keepalive) are set independentl
|
||||
|
||||
// Perform the test
|
||||
esp_transport_keep_alive_t keep_alive_cfg = {
|
||||
.keep_alive_interval = 2,
|
||||
.keep_alive_idle = 4,
|
||||
.keep_alive_enable = true,
|
||||
.keep_alive_count = 3 };
|
||||
.keep_alive_interval = 2,
|
||||
.keep_alive_idle = 4,
|
||||
.keep_alive_enable = true,
|
||||
.keep_alive_count = 3
|
||||
};
|
||||
esp_transport_ssl_set_keep_alive(ssl, &keep_alive_cfg);
|
||||
|
||||
// Bind device interface to loopback
|
||||
@ -178,3 +201,13 @@ TEST_CASE("ssl_transport: Check that parameters (keepalive) are set independentl
|
||||
esp_transport_close(ssl);
|
||||
esp_transport_destroy(ssl);
|
||||
}
|
||||
|
||||
TEST_GROUP_RUNNER(transport_connect)
|
||||
{
|
||||
RUN_TEST_CASE(transport_connect, tcp_connect_timeout);
|
||||
RUN_TEST_CASE(transport_connect, ssl_connect_timeout);
|
||||
RUN_TEST_CASE(transport_connect, tcp_keep_alive);
|
||||
RUN_TEST_CASE(transport_connect, ssl_keep_alive);
|
||||
RUN_TEST_CASE(transport_connect, ws_keep_alive);
|
||||
RUN_TEST_CASE(transport_connect, ssl_set_parameter_independently);
|
||||
}
|
@ -1,3 +1,8 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
#include "unity.h"
|
||||
|
||||
#include "esp_transport.h"
|
@ -0,0 +1,12 @@
|
||||
# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
import pytest
|
||||
from pytest_embedded import Dut
|
||||
|
||||
|
||||
@pytest.mark.esp32
|
||||
@pytest.mark.esp32c3
|
||||
@pytest.mark.generic
|
||||
def test_tcp_transport_client(dut: Dut) -> None:
|
||||
dut.expect_unity_test_output()
|
1
components/tcp_transport/test_apps/sdkconfig.ci.default
Normal file
1
components/tcp_transport/test_apps/sdkconfig.ci.default
Normal file
@ -0,0 +1 @@
|
||||
CONFIG_UNITY_ENABLE_FIXTURE=y
|
10
components/tcp_transport/test_apps/sdkconfig.ci.psram
Normal file
10
components/tcp_transport/test_apps/sdkconfig.ci.psram
Normal file
@ -0,0 +1,10 @@
|
||||
CONFIG_UNITY_ENABLE_FIXTURE=y
|
||||
CONFIG_SPIRAM=y
|
||||
CONFIG_ESP_INT_WDT_TIMEOUT_MS=800
|
||||
CONFIG_SPIRAM_OCCUPY_NO_HOST=y
|
||||
CONFIG_ESP_WIFI_RX_IRAM_OPT=n
|
||||
CONFIG_ESP_WIFI_IRAM_OPT=n
|
||||
# Disable encrypted flash reads/writes to save IRAM in this build configuration
|
||||
CONFIG_SPI_FLASH_ENABLE_ENCRYPTED_READ_WRITE=n
|
||||
CONFIG_SPIRAM_ALLOW_NOINIT_SEG_EXTERNAL_MEMORY=y
|
||||
CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY=y
|
Loading…
Reference in New Issue
Block a user