Merge branch 'ci/fix_failures_in_esp_http_client_example_v5.0' into 'release/v5.0'

CI: fix esp_http_client example failures in CI. Timeout was observed in the... (v5.0)

See merge request espressif/esp-idf!24950
This commit is contained in:
Mahavir Jain
2023-07-24 17:17:23 +08:00
7 changed files with 42 additions and 21 deletions

View File

@@ -135,6 +135,14 @@ example_test_pytest_esp32_ethernet:
- build_pytest_examples_esp32 - build_pytest_examples_esp32
tags: [ esp32, ethernet] tags: [ esp32, ethernet]
pytest_examples_esp32_ethernet_httpbin:
extends:
- .pytest_examples_dir_template
- .rules:test:example_test-esp32-ethernet
needs:
- build_pytest_examples_esp32
tags: [ esp32, httpbin]
example_test_pytest_esp32_8mb_flash: example_test_pytest_esp32_8mb_flash:
extends: extends:
- .pytest_examples_dir_template - .pytest_examples_dir_template

View File

@@ -0,0 +1,7 @@
menu "Example Configuration"
config EXAMPLE_HTTP_ENDPOINT
string "Example HTTP Endpoint"
default "httpbin.org"
help
Target endpoint host-name for the example to use.
endmenu

View File

@@ -44,7 +44,6 @@ extern const char howsmyssl_com_root_cert_pem_end[] asm("_binary_howsmyssl_com
extern const char postman_root_cert_pem_start[] asm("_binary_postman_root_cert_pem_start"); extern const char postman_root_cert_pem_start[] asm("_binary_postman_root_cert_pem_start");
extern const char postman_root_cert_pem_end[] asm("_binary_postman_root_cert_pem_end"); extern const char postman_root_cert_pem_end[] asm("_binary_postman_root_cert_pem_end");
esp_err_t _http_event_handler(esp_http_client_event_t *evt) esp_err_t _http_event_handler(esp_http_client_event_t *evt)
{ {
static char *output_buffer; // Buffer to store response of http request from event handler static char *output_buffer; // Buffer to store response of http request from event handler
@@ -132,7 +131,7 @@ static void http_rest_with_url(void)
* If URL as well as host and path parameters are specified, values of host and path will be considered. * If URL as well as host and path parameters are specified, values of host and path will be considered.
*/ */
esp_http_client_config_t config = { esp_http_client_config_t config = {
.host = "httpbin.org", .host = CONFIG_EXAMPLE_HTTP_ENDPOINT,
.path = "/get", .path = "/get",
.query = "esp", .query = "esp",
.event_handler = _http_event_handler, .event_handler = _http_event_handler,
@@ -154,7 +153,7 @@ static void http_rest_with_url(void)
// POST // POST
const char *post_data = "{\"field1\":\"value1\"}"; const char *post_data = "{\"field1\":\"value1\"}";
esp_http_client_set_url(client, "http://httpbin.org/post"); esp_http_client_set_url(client, "http://"CONFIG_EXAMPLE_HTTP_ENDPOINT"/post");
esp_http_client_set_method(client, HTTP_METHOD_POST); esp_http_client_set_method(client, HTTP_METHOD_POST);
esp_http_client_set_header(client, "Content-Type", "application/json"); esp_http_client_set_header(client, "Content-Type", "application/json");
esp_http_client_set_post_field(client, post_data, strlen(post_data)); esp_http_client_set_post_field(client, post_data, strlen(post_data));
@@ -168,7 +167,7 @@ static void http_rest_with_url(void)
} }
//PUT //PUT
esp_http_client_set_url(client, "http://httpbin.org/put"); esp_http_client_set_url(client, "http://"CONFIG_EXAMPLE_HTTP_ENDPOINT"/put");
esp_http_client_set_method(client, HTTP_METHOD_PUT); esp_http_client_set_method(client, HTTP_METHOD_PUT);
err = esp_http_client_perform(client); err = esp_http_client_perform(client);
if (err == ESP_OK) { if (err == ESP_OK) {
@@ -180,7 +179,7 @@ static void http_rest_with_url(void)
} }
//PATCH //PATCH
esp_http_client_set_url(client, "http://httpbin.org/patch"); esp_http_client_set_url(client, "http://"CONFIG_EXAMPLE_HTTP_ENDPOINT"/patch");
esp_http_client_set_method(client, HTTP_METHOD_PATCH); esp_http_client_set_method(client, HTTP_METHOD_PATCH);
esp_http_client_set_post_field(client, NULL, 0); esp_http_client_set_post_field(client, NULL, 0);
err = esp_http_client_perform(client); err = esp_http_client_perform(client);
@@ -193,7 +192,7 @@ static void http_rest_with_url(void)
} }
//DELETE //DELETE
esp_http_client_set_url(client, "http://httpbin.org/delete"); esp_http_client_set_url(client, "http://"CONFIG_EXAMPLE_HTTP_ENDPOINT"/delete");
esp_http_client_set_method(client, HTTP_METHOD_DELETE); esp_http_client_set_method(client, HTTP_METHOD_DELETE);
err = esp_http_client_perform(client); err = esp_http_client_perform(client);
if (err == ESP_OK) { if (err == ESP_OK) {
@@ -205,7 +204,7 @@ static void http_rest_with_url(void)
} }
//HEAD //HEAD
esp_http_client_set_url(client, "http://httpbin.org/get"); esp_http_client_set_url(client, "http://"CONFIG_EXAMPLE_HTTP_ENDPOINT"/get");
esp_http_client_set_method(client, HTTP_METHOD_HEAD); esp_http_client_set_method(client, HTTP_METHOD_HEAD);
err = esp_http_client_perform(client); err = esp_http_client_perform(client);
if (err == ESP_OK) { if (err == ESP_OK) {
@@ -222,7 +221,7 @@ static void http_rest_with_url(void)
static void http_rest_with_hostname_path(void) static void http_rest_with_hostname_path(void)
{ {
esp_http_client_config_t config = { esp_http_client_config_t config = {
.host = "httpbin.org", .host = CONFIG_EXAMPLE_HTTP_ENDPOINT,
.path = "/get", .path = "/get",
.transport_type = HTTP_TRANSPORT_OVER_TCP, .transport_type = HTTP_TRANSPORT_OVER_TCP,
.event_handler = _http_event_handler, .event_handler = _http_event_handler,
@@ -316,7 +315,7 @@ static void http_auth_basic(void)
* To disable authorization retries, set max_authorization_retries to -1. * To disable authorization retries, set max_authorization_retries to -1.
*/ */
esp_http_client_config_t config = { esp_http_client_config_t config = {
.url = "http://user:passwd@httpbin.org/basic-auth/user/passwd", .url = "http://user:passwd@"CONFIG_EXAMPLE_HTTP_ENDPOINT"/basic-auth/user/passwd",
.event_handler = _http_event_handler, .event_handler = _http_event_handler,
.auth_type = HTTP_AUTH_TYPE_BASIC, .auth_type = HTTP_AUTH_TYPE_BASIC,
.max_authorization_retries = -1, .max_authorization_retries = -1,
@@ -337,7 +336,7 @@ static void http_auth_basic(void)
static void http_auth_basic_redirect(void) static void http_auth_basic_redirect(void)
{ {
esp_http_client_config_t config = { esp_http_client_config_t config = {
.url = "http://user:passwd@httpbin.org/basic-auth/user/passwd", .url = "http://user:passwd@"CONFIG_EXAMPLE_HTTP_ENDPOINT"/basic-auth/user/passwd",
.event_handler = _http_event_handler, .event_handler = _http_event_handler,
}; };
esp_http_client_handle_t client = esp_http_client_init(&config); esp_http_client_handle_t client = esp_http_client_init(&config);
@@ -358,7 +357,7 @@ static void http_auth_basic_redirect(void)
static void http_auth_digest(void) static void http_auth_digest(void)
{ {
esp_http_client_config_t config = { esp_http_client_config_t config = {
.url = "http://user:passwd@httpbin.org/digest-auth/auth/user/passwd/MD5/never", .url = "http://user:passwd@"CONFIG_EXAMPLE_HTTP_ENDPOINT"/digest-auth/auth/user/passwd/MD5/never",
.event_handler = _http_event_handler, .event_handler = _http_event_handler,
}; };
esp_http_client_handle_t client = esp_http_client_init(&config); esp_http_client_handle_t client = esp_http_client_init(&config);
@@ -422,7 +421,7 @@ static void https_with_hostname_path(void)
static void http_relative_redirect(void) static void http_relative_redirect(void)
{ {
esp_http_client_config_t config = { esp_http_client_config_t config = {
.url = "http://httpbin.org/relative-redirect/3", .url = "http://"CONFIG_EXAMPLE_HTTP_ENDPOINT"/relative-redirect/3",
.event_handler = _http_event_handler, .event_handler = _http_event_handler,
}; };
esp_http_client_handle_t client = esp_http_client_init(&config); esp_http_client_handle_t client = esp_http_client_init(&config);
@@ -441,7 +440,7 @@ static void http_relative_redirect(void)
static void http_absolute_redirect(void) static void http_absolute_redirect(void)
{ {
esp_http_client_config_t config = { esp_http_client_config_t config = {
.url = "http://httpbin.org/absolute-redirect/3", .url = "http://"CONFIG_EXAMPLE_HTTP_ENDPOINT"/absolute-redirect/3",
.event_handler = _http_event_handler, .event_handler = _http_event_handler,
}; };
esp_http_client_handle_t client = esp_http_client_init(&config); esp_http_client_handle_t client = esp_http_client_init(&config);
@@ -460,7 +459,7 @@ static void http_absolute_redirect(void)
static void http_absolute_redirect_manual(void) static void http_absolute_redirect_manual(void)
{ {
esp_http_client_config_t config = { esp_http_client_config_t config = {
.url = "http://httpbin.org/absolute-redirect/3", .url = "http://"CONFIG_EXAMPLE_HTTP_ENDPOINT"/absolute-redirect/3",
.event_handler = _http_event_handler, .event_handler = _http_event_handler,
.disable_auto_redirect = true, .disable_auto_redirect = true,
}; };
@@ -480,7 +479,7 @@ static void http_absolute_redirect_manual(void)
static void http_redirect_to_https(void) static void http_redirect_to_https(void)
{ {
esp_http_client_config_t config = { esp_http_client_config_t config = {
.url = "http://httpbin.org/redirect-to?url=https%3A%2F%2Fwww.howsmyssl.com", .url = "http://"CONFIG_EXAMPLE_HTTP_ENDPOINT"/redirect-to?url=https://www.howsmyssl.com",
.event_handler = _http_event_handler, .event_handler = _http_event_handler,
.cert_pem = howsmyssl_com_root_cert_pem_start, .cert_pem = howsmyssl_com_root_cert_pem_start,
}; };
@@ -501,7 +500,7 @@ static void http_redirect_to_https(void)
static void http_download_chunk(void) static void http_download_chunk(void)
{ {
esp_http_client_config_t config = { esp_http_client_config_t config = {
.url = "http://httpbin.org/stream-bytes/8912", .url = "http://"CONFIG_EXAMPLE_HTTP_ENDPOINT"/stream-bytes/8912",
.event_handler = _http_event_handler, .event_handler = _http_event_handler,
}; };
esp_http_client_handle_t client = esp_http_client_init(&config); esp_http_client_handle_t client = esp_http_client_init(&config);
@@ -525,7 +524,7 @@ static void http_perform_as_stream_reader(void)
return; return;
} }
esp_http_client_config_t config = { esp_http_client_config_t config = {
.url = "http://httpbin.org/get", .url = "http://"CONFIG_EXAMPLE_HTTP_ENDPOINT"/get",
}; };
esp_http_client_handle_t client = esp_http_client_init(&config); esp_http_client_handle_t client = esp_http_client_init(&config);
esp_err_t err; esp_err_t err;
@@ -615,7 +614,7 @@ static void http_native_request(void)
char output_buffer[MAX_HTTP_OUTPUT_BUFFER] = {0}; // Buffer to store response of http request char output_buffer[MAX_HTTP_OUTPUT_BUFFER] = {0}; // Buffer to store response of http request
int content_length = 0; int content_length = 0;
esp_http_client_config_t config = { esp_http_client_config_t config = {
.url = "http://httpbin.org/get", .url = "http://"CONFIG_EXAMPLE_HTTP_ENDPOINT"/get",
}; };
esp_http_client_handle_t client = esp_http_client_init(&config); esp_http_client_handle_t client = esp_http_client_init(&config);
@@ -644,7 +643,7 @@ static void http_native_request(void)
// POST Request // POST Request
const char *post_data = "{\"field1\":\"value1\"}"; const char *post_data = "{\"field1\":\"value1\"}";
esp_http_client_set_url(client, "http://httpbin.org/post"); esp_http_client_set_url(client, "http://"CONFIG_EXAMPLE_HTTP_ENDPOINT"/post");
esp_http_client_set_method(client, HTTP_METHOD_POST); esp_http_client_set_method(client, HTTP_METHOD_POST);
esp_http_client_set_header(client, "Content-Type", "application/json"); esp_http_client_set_header(client, "Content-Type", "application/json");
err = esp_http_client_open(client, strlen(post_data)); err = esp_http_client_open(client, strlen(post_data));

View File

@@ -11,7 +11,7 @@ from pytest_embedded import Dut
@pytest.mark.esp32c3 @pytest.mark.esp32c3
@pytest.mark.esp32s2 @pytest.mark.esp32s2
@pytest.mark.esp32s3 @pytest.mark.esp32s3
@pytest.mark.ethernet @pytest.mark.httpbin
def test_examples_protocol_esp_http_client(dut: Dut) -> None: def test_examples_protocol_esp_http_client(dut: Dut) -> None:
""" """
steps: | steps: |
@@ -57,7 +57,11 @@ def test_examples_protocol_esp_http_client(dut: Dut) -> None:
dut.expect('Finish http example') dut.expect('Finish http example')
@pytest.mark.parametrize('config', [pytest.param('ssldyn', marks=[pytest.mark.supported_targets, pytest.mark.ethernet]),], indirect=True) @pytest.mark.supported_targets
@pytest.mark.httpbin
@pytest.mark.parametrize('config', [
'ssldyn',
], indirect=True)
def test_examples_protocol_esp_http_client_dynamic_buffer(dut: Dut) -> None: def test_examples_protocol_esp_http_client_dynamic_buffer(dut: Dut) -> None:
# test mbedtls dynamic resource # test mbedtls dynamic resource
# check and log bin size # check and log bin size

View File

@@ -9,3 +9,4 @@ CONFIG_EXAMPLE_ETH_PHY_ADDR=1
CONFIG_EXAMPLE_CONNECT_IPV6=y CONFIG_EXAMPLE_CONNECT_IPV6=y
CONFIG_ESP_HTTP_CLIENT_ENABLE_BASIC_AUTH=y CONFIG_ESP_HTTP_CLIENT_ENABLE_BASIC_AUTH=y
CONFIG_ESP_HTTP_CLIENT_ENABLE_DIGEST_AUTH=y CONFIG_ESP_HTTP_CLIENT_ENABLE_DIGEST_AUTH=y
CONFIG_EXAMPLE_HTTP_ENDPOINT="httpbin.espressif.cn"

View File

@@ -11,3 +11,4 @@ CONFIG_ESP_HTTP_CLIENT_ENABLE_BASIC_AUTH=y
CONFIG_MBEDTLS_DYNAMIC_BUFFER=y CONFIG_MBEDTLS_DYNAMIC_BUFFER=y
CONFIG_MBEDTLS_DYNAMIC_FREE_PEER_CERT=y CONFIG_MBEDTLS_DYNAMIC_FREE_PEER_CERT=y
CONFIG_MBEDTLS_DYNAMIC_FREE_CONFIG_DATA=y CONFIG_MBEDTLS_DYNAMIC_FREE_CONFIG_DATA=y
CONFIG_EXAMPLE_HTTP_ENDPOINT="httpbin.espressif.cn"

View File

@@ -47,6 +47,7 @@ markers =
ir_transceiver: runners with a pair of IR transmitter and receiver ir_transceiver: runners with a pair of IR transmitter and receiver
flash_encryption_wifi_high_traffic: Flash Encryption runners with wifi high traffic support flash_encryption_wifi_high_traffic: Flash Encryption runners with wifi high traffic support
ethernet: ethernet runner ethernet: ethernet runner
httpbin: runner for tests that need to access the httpbin service
ethernet_flash_8m: ethernet runner with 8mb flash ethernet_flash_8m: ethernet runner with 8mb flash
ethernet_router: both the runner and dut connect to the same router through ethernet NIC ethernet_router: both the runner and dut connect to the same router through ethernet NIC
wifi_ap: a wifi AP in the environment wifi_ap: a wifi AP in the environment