forked from espressif/esp-idf
lwip: Migrate unit tests to test_apps
This commit is contained in:
@@ -1,3 +0,0 @@
|
||||
idf_component_register(SRC_DIRS "."
|
||||
PRIV_REQUIRES test_utils)
|
||||
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
|
6
components/lwip/test_apps/.build-test-rules.yml
Normal file
6
components/lwip/test_apps/.build-test-rules.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
# Documentation: .gitlab/ci/README.md#manifest-file-to-control-the-buildtest-apps
|
||||
|
||||
components/lwip/test_apps:
|
||||
disable_test:
|
||||
- if: IDF_TARGET != "esp32"
|
||||
reason: running this test for one target only is enough to be sufficiently confident about no regression in lwip
|
7
components/lwip/test_apps/CMakeLists.txt
Normal file
7
components/lwip/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(lwip_test)
|
2
components/lwip/test_apps/README.md
Normal file
2
components/lwip/test_apps/README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-S2 | ESP32-S3 |
|
||||
| ----------------- | ----- | -------- | -------- | -------- | -------- |
|
4
components/lwip/test_apps/main/CMakeLists.txt
Normal file
4
components/lwip/test_apps/main/CMakeLists.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
idf_component_register(SRCS "lwip_test.c"
|
||||
REQUIRES test_utils
|
||||
INCLUDE_DIRS "."
|
||||
PRIV_REQUIRES unity lwip test_utils)
|
@@ -3,10 +3,19 @@
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <esp_types.h>
|
||||
|
||||
#include "freertos/FreeRTOS.h"
|
||||
#include "freertos/event_groups.h"
|
||||
#include "test_utils.h"
|
||||
#include "unity.h"
|
||||
#include "unity_fixture.h"
|
||||
|
||||
#include "unity_test_utils.h"
|
||||
#include "soc/soc_caps.h"
|
||||
|
||||
#include "lwip/inet.h"
|
||||
#include "lwip/netdb.h"
|
||||
#include "lwip/sockets.h"
|
||||
@@ -18,8 +27,17 @@
|
||||
#define ETH_PING_END_TIMEOUT_MS (ETH_PING_DURATION_MS * 2)
|
||||
#define TEST_ICMP_DESTINATION_DOMAIN_NAME "127.0.0.1"
|
||||
|
||||
#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)
|
||||
//IDF-5047
|
||||
|
||||
TEST_GROUP(lwip);
|
||||
|
||||
TEST_SETUP(lwip)
|
||||
{
|
||||
}
|
||||
|
||||
TEST_TEAR_DOWN(lwip)
|
||||
{
|
||||
}
|
||||
|
||||
static void test_on_ping_success(esp_ping_handle_t hdl, void *args)
|
||||
{
|
||||
uint8_t ttl;
|
||||
@@ -31,7 +49,7 @@ static void test_on_ping_success(esp_ping_handle_t hdl, void *args)
|
||||
esp_ping_get_profile(hdl, ESP_PING_PROF_IPADDR, &target_addr, sizeof(target_addr));
|
||||
esp_ping_get_profile(hdl, ESP_PING_PROF_SIZE, &recv_len, sizeof(recv_len));
|
||||
esp_ping_get_profile(hdl, ESP_PING_PROF_TIMEGAP, &elapsed_time, sizeof(elapsed_time));
|
||||
printf("%d bytes from %s icmp_seq=%d ttl=%d time=%d ms\n",
|
||||
printf("%" PRId32 "bytes from %s icmp_seq=%d ttl=%d time=%" PRId32 " ms\n",
|
||||
recv_len, inet_ntoa(target_addr.u_addr.ip4), seqno, ttl, elapsed_time);
|
||||
}
|
||||
|
||||
@@ -54,13 +72,13 @@ static void test_on_ping_end(esp_ping_handle_t hdl, void *args)
|
||||
esp_ping_get_profile(hdl, ESP_PING_PROF_REQUEST, &transmitted, sizeof(transmitted));
|
||||
esp_ping_get_profile(hdl, ESP_PING_PROF_REPLY, &received, sizeof(received));
|
||||
esp_ping_get_profile(hdl, ESP_PING_PROF_DURATION, &total_time_ms, sizeof(total_time_ms));
|
||||
printf("%d packets transmitted, %d received, time %dms\n", transmitted, received, total_time_ms);
|
||||
printf("%" PRId32 " packets transmitted, %" PRId32 " received, time %" PRId32 "ms\n", transmitted, received, total_time_ms);
|
||||
if (transmitted == received) {
|
||||
xEventGroupSetBits(eth_event_group, ETH_PING_END_BIT);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("localhost ping test", "[lwip]")
|
||||
TEST(lwip, localhost_ping_test)
|
||||
{
|
||||
EventBits_t bits;
|
||||
EventGroupHandle_t eth_event_group = xEventGroupCreate();
|
||||
@@ -112,9 +130,8 @@ TEST_CASE("localhost ping test", "[lwip]")
|
||||
|
||||
vEventGroupDelete(eth_event_group);
|
||||
}
|
||||
#endif //!TEMPORARY_DISABLED_FOR_TARGETS(ESP32C2)
|
||||
|
||||
TEST_CASE("dhcp server init/deinit", "[lwip][leaks=0]")
|
||||
TEST(lwip, dhcp_server_init_deinit)
|
||||
{
|
||||
dhcps_t *dhcps = dhcps_new();
|
||||
TEST_ASSERT_NOT_NULL(dhcps);
|
||||
@@ -124,7 +141,7 @@ TEST_CASE("dhcp server init/deinit", "[lwip][leaks=0]")
|
||||
dhcps_delete(dhcps);
|
||||
}
|
||||
|
||||
TEST_CASE("dhcp server start/stop on localhost", "[lwip]")
|
||||
TEST(lwip, dhcp_server_start_stop_localhost)
|
||||
{
|
||||
test_case_uses_tcpip();
|
||||
dhcps_t *dhcps = dhcps_new();
|
||||
@@ -142,3 +159,15 @@ TEST_CASE("dhcp server start/stop on localhost", "[lwip]")
|
||||
TEST_ASSERT(dhcps_stop(dhcps, netif) == ERR_OK);
|
||||
dhcps_delete(dhcps);
|
||||
}
|
||||
|
||||
TEST_GROUP_RUNNER(lwip)
|
||||
{
|
||||
RUN_TEST_CASE(lwip, localhost_ping_test)
|
||||
RUN_TEST_CASE(lwip, dhcp_server_init_deinit)
|
||||
RUN_TEST_CASE(lwip, dhcp_server_start_stop_localhost)
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
UNITY_MAIN(lwip);
|
||||
}
|
11
components/lwip/test_apps/pytest_lwip.py
Normal file
11
components/lwip/test_apps/pytest_lwip.py
Normal file
@@ -0,0 +1,11 @@
|
||||
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import pytest
|
||||
from pytest_embedded import Dut
|
||||
|
||||
|
||||
@pytest.mark.esp32
|
||||
@pytest.mark.generic
|
||||
def test_lwip(dut: Dut) -> None:
|
||||
dut.expect_unity_test_output()
|
2
components/lwip/test_apps/sdkconfig.defaults
Normal file
2
components/lwip/test_apps/sdkconfig.defaults
Normal file
@@ -0,0 +1,2 @@
|
||||
CONFIG_UNITY_ENABLE_FIXTURE=y
|
||||
CONFIG_UNITY_ENABLE_IDF_TEST_RUNNER=n
|
Reference in New Issue
Block a user