From 214627f14b64ae5070a0c79d28708e68edeea372 Mon Sep 17 00:00:00 2001 From: Harshit Malpani Date: Fri, 17 Feb 2023 11:09:14 +0530 Subject: [PATCH 1/4] mbedtls: Keep `CONFIG_MBEDTLS_DYNAMIC_BUFFER` disabled for Linux target --- components/mbedtls/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/mbedtls/Kconfig b/components/mbedtls/Kconfig index 301380576f..7675c0f0a2 100644 --- a/components/mbedtls/Kconfig +++ b/components/mbedtls/Kconfig @@ -102,7 +102,7 @@ menu "mbedTLS" default n select MBEDTLS_ASYMMETRIC_CONTENT_LEN # Dynamic buffer feature is not supported with DTLS - depends on !MBEDTLS_SSL_PROTO_DTLS && !MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH + depends on !IDF_TARGET_LINUX && !MBEDTLS_SSL_PROTO_DTLS && !MBEDTLS_SSL_VARIABLE_BUFFER_LENGTH help Using dynamic TX/RX buffer. After enabling this option, mbedTLS will allocate TX buffer when need to send data and then free it if all data From 34705c0cc44ef335b5c64c716428392c0d794a22 Mon Sep 17 00:00:00 2001 From: Harshit Malpani Date: Mon, 13 Feb 2023 10:23:16 +0530 Subject: [PATCH 2/4] fix esp_http_client_example to build for Linux target. Made `protocol_examples_common` compatible for Linux target --- .../protocol_examples_common/CMakeLists.txt | 2 +- .../common_components/protocol_examples_common/connect.c | 2 +- .../include/example_common_private.h | 2 +- .../include/protocol_examples_common.h | 7 +++++++ examples/protocols/esp_http_client/CMakeLists.txt | 6 +++--- examples/protocols/esp_http_client/main/CMakeLists.txt | 2 +- examples/protocols/linux_stubs/esp_stubs/esp_stubs.c | 5 ----- .../esp_stubs/include/protocol_examples_common.h | 8 -------- 8 files changed, 14 insertions(+), 20 deletions(-) delete mode 100644 examples/protocols/linux_stubs/esp_stubs/include/protocol_examples_common.h diff --git a/examples/common_components/protocol_examples_common/CMakeLists.txt b/examples/common_components/protocol_examples_common/CMakeLists.txt index 2a7352d5fd..4f9ea953cf 100644 --- a/examples/common_components/protocol_examples_common/CMakeLists.txt +++ b/examples/common_components/protocol_examples_common/CMakeLists.txt @@ -4,7 +4,7 @@ if(${target} STREQUAL "linux") # Header only library for linux idf_component_register(INCLUDE_DIRS include - PRIV_REQUIRES tapif_io) + SRCS protocol_examples_utils.c) return() endif() diff --git a/examples/common_components/protocol_examples_common/connect.c b/examples/common_components/protocol_examples_common/connect.c index 8a7e28266b..6debc20813 100644 --- a/examples/common_components/protocol_examples_common/connect.c +++ b/examples/common_components/protocol_examples_common/connect.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ diff --git a/examples/common_components/protocol_examples_common/include/example_common_private.h b/examples/common_components/protocol_examples_common/include/example_common_private.h index 4921e477ea..b85d26d636 100644 --- a/examples/common_components/protocol_examples_common/include/example_common_private.h +++ b/examples/common_components/protocol_examples_common/include/example_common_private.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Unlicense OR CC0-1.0 */ diff --git a/examples/common_components/protocol_examples_common/include/protocol_examples_common.h b/examples/common_components/protocol_examples_common/include/protocol_examples_common.h index 7417c1e635..430cdae7f9 100644 --- a/examples/common_components/protocol_examples_common/include/protocol_examples_common.h +++ b/examples/common_components/protocol_examples_common/include/protocol_examples_common.h @@ -11,15 +11,18 @@ #include "sdkconfig.h" #include "esp_err.h" +#if !CONFIG_IDF_TARGET_LINUX #include "esp_netif.h" #if CONFIG_EXAMPLE_CONNECT_ETHERNET #include "esp_eth.h" #endif +#endif // !CONFIG_IDF_TARGET_LINUX #ifdef __cplusplus extern "C" { #endif +#if !CONFIG_IDF_TARGET_LINUX #if CONFIG_EXAMPLE_CONNECT_WIFI #define EXAMPLE_NETIF_DESC_STA "example_netif_sta" #endif @@ -96,6 +99,10 @@ void example_register_wifi_connect_commands(void); esp_eth_handle_t get_example_eth_handle(void); #endif // CONFIG_EXAMPLE_CONNECT_ETHERNET +#else +static inline esp_err_t example_connect(void) {return ESP_OK;} +#endif // !CONFIG_IDF_TARGET_LINUX + #ifdef __cplusplus } #endif diff --git a/examples/protocols/esp_http_client/CMakeLists.txt b/examples/protocols/esp_http_client/CMakeLists.txt index a30836152e..3316f636e7 100644 --- a/examples/protocols/esp_http_client/CMakeLists.txt +++ b/examples/protocols/esp_http_client/CMakeLists.txt @@ -2,12 +2,12 @@ # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.16) +set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common) + if(${IDF_TARGET} STREQUAL "linux") - set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/freertos/" + list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/freertos/" "$ENV{IDF_PATH}/examples/protocols/linux_stubs/esp_stubs") set(COMPONENTS main) -else() - set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common) endif() include($ENV{IDF_PATH}/tools/cmake/project.cmake) diff --git a/examples/protocols/esp_http_client/main/CMakeLists.txt b/examples/protocols/esp_http_client/main/CMakeLists.txt index 783d70fa84..cc80568867 100644 --- a/examples/protocols/esp_http_client/main/CMakeLists.txt +++ b/examples/protocols/esp_http_client/main/CMakeLists.txt @@ -3,7 +3,7 @@ # (If this was a component, we would set COMPONENT_EMBED_TXTFILES here.) set(requires "") if(${IDF_TARGET} STREQUAL "linux") - list(APPEND requires esp_stubs esp-tls esp_http_client) + list(APPEND requires esp_stubs esp-tls esp_http_client protocol_examples_common) endif() idf_component_register(SRCS "esp_http_client_example.c" INCLUDE_DIRS "." diff --git a/examples/protocols/linux_stubs/esp_stubs/esp_stubs.c b/examples/protocols/linux_stubs/esp_stubs/esp_stubs.c index 33f0cfd0ff..b0edaecd2b 100644 --- a/examples/protocols/linux_stubs/esp_stubs/esp_stubs.c +++ b/examples/protocols/linux_stubs/esp_stubs/esp_stubs.c @@ -19,11 +19,6 @@ esp_err_t esp_netif_init(void) return ESP_OK; } -esp_err_t example_connect(void) -{ - return ESP_OK; -} - esp_err_t nvs_flash_init(void) { return ESP_OK; diff --git a/examples/protocols/linux_stubs/esp_stubs/include/protocol_examples_common.h b/examples/protocols/linux_stubs/esp_stubs/include/protocol_examples_common.h deleted file mode 100644 index 416377a82d..0000000000 --- a/examples/protocols/linux_stubs/esp_stubs/include/protocol_examples_common.h +++ /dev/null @@ -1,8 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Unlicense OR CC0-1.0 - */ -#include "esp_err.h" - -esp_err_t example_connect(void); From af686f2eeda962b1347184d7e25f1e8fa0c497ed Mon Sep 17 00:00:00 2001 From: Harshit Malpani Date: Mon, 13 Feb 2023 14:42:04 +0530 Subject: [PATCH 3/4] tcp_client: fix missing header file --- examples/protocols/sockets/tcp_client/CMakeLists.txt | 9 ++++----- .../protocols/sockets/tcp_client/main/CMakeLists.txt | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/examples/protocols/sockets/tcp_client/CMakeLists.txt b/examples/protocols/sockets/tcp_client/CMakeLists.txt index 0fd7e2e047..86ed08467b 100644 --- a/examples/protocols/sockets/tcp_client/CMakeLists.txt +++ b/examples/protocols/sockets/tcp_client/CMakeLists.txt @@ -1,15 +1,14 @@ # The following lines of boilerplate have to be in your project's # CMakeLists in this exact order for cmake to work correctly cmake_minimum_required(VERSION 3.16) +set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common) if("${IDF_TARGET}" STREQUAL "linux") - set(EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/freertos/" + list(APPEND EXTRA_COMPONENT_DIRS "$ENV{IDF_PATH}/tools/mocks/freertos/" "$ENV{IDF_PATH}/examples/protocols/linux_stubs/esp_stubs") set(COMPONENTS main) - include($ENV{IDF_PATH}/tools/cmake/project.cmake) -else() - set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/common_components/protocol_examples_common) - include($ENV{IDF_PATH}/tools/cmake/project.cmake) endif() +include($ENV{IDF_PATH}/tools/cmake/project.cmake) + project(tcp_client) diff --git a/examples/protocols/sockets/tcp_client/main/CMakeLists.txt b/examples/protocols/sockets/tcp_client/main/CMakeLists.txt index acea8ee344..ce931f8b55 100644 --- a/examples/protocols/sockets/tcp_client/main/CMakeLists.txt +++ b/examples/protocols/sockets/tcp_client/main/CMakeLists.txt @@ -1,5 +1,5 @@ if(${IDF_TARGET} STREQUAL "linux") - set(requires esp_stubs) + set(requires esp_stubs protocol_examples_common) endif() if("${CONFIG_EXAMPLE_IPV4}" STREQUAL y) From ae403c6210f93ff868d56c4bd715c158354fc710 Mon Sep 17 00:00:00 2001 From: Harshit Malpani Date: Fri, 17 Feb 2023 11:39:54 +0530 Subject: [PATCH 4/4] Add test for Linux in pytest_esp_http_client.py --- examples/protocols/.build-test-rules.yml | 4 +- examples/protocols/esp_http_client/README.md | 5 +-- .../esp_http_client/pytest_esp_http_client.py | 41 +++++++++++++++++++ .../esp_http_client/sdkconfig.defaults | 0 .../linux_stubs/esp_stubs/esp_stubs.c | 2 +- 5 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 examples/protocols/esp_http_client/sdkconfig.defaults diff --git a/examples/protocols/.build-test-rules.yml b/examples/protocols/.build-test-rules.yml index c64d4da25d..883a88cd09 100644 --- a/examples/protocols/.build-test-rules.yml +++ b/examples/protocols/.build-test-rules.yml @@ -12,10 +12,12 @@ examples/protocols/coap_server: - if: IDF_TARGET in ["esp32h2"] examples/protocols/esp_http_client: + enable: + - if: INCLUDE_DEFAULT == 1 or IDF_TARGET == "linux" disable: - if: IDF_TARGET in ["esp32h2"] disable_test: - - if: IDF_TARGET != "esp32" + - if: IDF_TARGET not in ["esp32", "linux"] temporary: true reason: only test on esp32 diff --git a/examples/protocols/esp_http_client/README.md b/examples/protocols/esp_http_client/README.md index e4d347def2..220426fdd3 100644 --- a/examples/protocols/esp_http_client/README.md +++ b/examples/protocols/esp_http_client/README.md @@ -1,6 +1,5 @@ -| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-S2 | ESP32-S3 | -| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | - +| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-C6 | ESP32-S2 | ESP32-S3 | Linux | +| ----------------- | ----- | -------- | -------- | -------- | -------- | -------- | ----- | # ESP HTTP Client Example See the README.md file in the upper level 'examples' directory for more information about examples. diff --git a/examples/protocols/esp_http_client/pytest_esp_http_client.py b/examples/protocols/esp_http_client/pytest_esp_http_client.py index ec6d01444f..1fc58d016f 100644 --- a/examples/protocols/esp_http_client/pytest_esp_http_client.py +++ b/examples/protocols/esp_http_client/pytest_esp_http_client.py @@ -98,3 +98,44 @@ def test_examples_protocol_esp_http_client_dynamic_buffer(dut: Dut) -> None: dut.expect(r'HTTP Status = 206, content_length = 10') dut.expect(r'HTTP Status = 206, content_length = 10') dut.expect('Finish http example') + + +@pytest.mark.linux +@pytest.mark.host_test +@pytest.mark.parametrize('config', [ + 'default', 'ssldyn', +], indirect=True) +def test_examples_protocol_esp_http_client_linux(dut: Dut) -> None: + # start test + dut.expect('Connected to AP, begin http example', timeout=120) + dut.expect(r'HTTP GET Status = 200, content_length = (\d)') + dut.expect(r'HTTP POST Status = 200, content_length = (\d)') + dut.expect(r'HTTP PUT Status = 200, content_length = (\d)') + dut.expect(r'HTTP PATCH Status = 200, content_length = (\d)') + dut.expect(r'HTTP DELETE Status = 200, content_length = (\d)') + dut.expect(r'HTTP HEAD Status = 200, content_length = (\d)') + dut.expect(r'HTTP GET Status = 200, content_length = (\d)') + dut.expect(r'HTTP POST Status = 200, content_length = (\d)') + dut.expect(r'HTTP PUT Status = 200, content_length = (\d)') + dut.expect(r'HTTP PATCH Status = 200, content_length = (\d)') + dut.expect(r'HTTP DELETE Status = 200, content_length = (\d)') + dut.expect(r'HTTP HEAD Status = 200, content_length = (\d)') + dut.expect(r'HTTP Basic Auth Status = 200, content_length = (\d)') + dut.expect(r'HTTP Basic Auth redirect Status = 200, content_length = (\d)') + dut.expect(r'HTTP Relative path redirect Status = 200, content_length = (\d)') + dut.expect(r'HTTP Absolute path redirect Status = 200, content_length = (\d)') + dut.expect(r'HTTP Absolute path redirect \(manual\) Status = 200, content_length = (\d)') + dut.expect(r'HTTPS Status = 200, content_length = (\d)') + dut.expect(r'HTTPS Status = 200, content_length = (\d)') + dut.expect(r'HTTP redirect to HTTPS Status = 200, content_length = (\d)') + dut.expect(r'HTTP chunk encoding Status = 200, content_length = (-?\d)') + # content-len for chunked encoding is typically -1, could be a positive length in some cases + dut.expect(r'HTTP Stream reader Status = 200, content_length = (\d)') + dut.expect(r'HTTPS Status = 200, content_length = (\d)') + dut.expect(r'Last esp error code: 0x8001') + dut.expect(r'HTTP GET Status = 200, content_length = (\d)') + dut.expect(r'HTTP POST Status = 200, content_length = (\d)') + dut.expect(r'HTTP Status = 206, content_length = (\d)') + dut.expect(r'HTTP Status = 206, content_length = 10') + dut.expect(r'HTTP Status = 206, content_length = 10') + dut.expect('Finish http example') diff --git a/examples/protocols/esp_http_client/sdkconfig.defaults b/examples/protocols/esp_http_client/sdkconfig.defaults new file mode 100644 index 0000000000..e69de29bb2 diff --git a/examples/protocols/linux_stubs/esp_stubs/esp_stubs.c b/examples/protocols/linux_stubs/esp_stubs/esp_stubs.c index b0edaecd2b..53116fcecf 100644 --- a/examples/protocols/linux_stubs/esp_stubs/esp_stubs.c +++ b/examples/protocols/linux_stubs/esp_stubs/esp_stubs.c @@ -29,7 +29,7 @@ esp_err_t nvs_flash_erase(void) return ESP_OK; } -int main() +int main(void) { app_main();