mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-10 04:43:33 +00:00
test: format all test scripts
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
import http.server
|
||||
import logging
|
||||
@@ -13,13 +13,15 @@ import pytest
|
||||
from common_test_methods import get_env_config_variable
|
||||
from common_test_methods import get_host_ip4_by_dest_ip
|
||||
from pytest_embedded import Dut
|
||||
from pytest_embedded_idf.utils import idf_parametrize
|
||||
from RangeHTTPServer import RangeRequestHandler
|
||||
|
||||
|
||||
def https_request_handler() -> Callable[...,http.server.BaseHTTPRequestHandler]:
|
||||
def https_request_handler() -> Callable[..., http.server.BaseHTTPRequestHandler]:
|
||||
"""
|
||||
Returns a request handler class that handles broken pipe exception
|
||||
"""
|
||||
|
||||
class RequestHandler(RangeRequestHandler):
|
||||
protocol_version = 'HTTP/1.1'
|
||||
|
||||
@@ -47,7 +49,6 @@ def https_request_handler() -> Callable[...,http.server.BaseHTTPRequestHandler]:
|
||||
|
||||
|
||||
def start_https_server(server_file: str, key_file: str, server_ip: str, server_port: int) -> None:
|
||||
|
||||
requestHandler = https_request_handler()
|
||||
httpd = http.server.HTTPServer((server_ip, server_port), requestHandler)
|
||||
|
||||
@@ -58,12 +59,18 @@ def start_https_server(server_file: str, key_file: str, server_ip: str, server_p
|
||||
httpd.serve_forever()
|
||||
|
||||
|
||||
@pytest.mark.esp32
|
||||
@pytest.mark.ethernet
|
||||
@pytest.mark.parametrize('config', ['cli_ses_tkt',], indirect=True)
|
||||
@pytest.mark.parametrize(
|
||||
'config',
|
||||
[
|
||||
'cli_ses_tkt',
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
@pytest.mark.parametrize('erase_nvs', ['y'], indirect=True)
|
||||
@idf_parametrize('target', ['esp32'], indirect=['target'])
|
||||
def test_examples_protocol_https_request_cli_session_tickets(dut: Dut) -> None:
|
||||
logging.info("Testing for \"esp_tls client session tickets\"")
|
||||
logging.info('Testing for "esp_tls client session tickets"')
|
||||
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut.app.binary_path, 'https_request.bin')
|
||||
@@ -90,38 +97,44 @@ def test_examples_protocol_https_request_cli_session_tickets(dut: Dut) -> None:
|
||||
dut.expect('Start https_request example', timeout=30)
|
||||
print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port)))
|
||||
dut.write('https://' + host_ip + ':' + str(server_port))
|
||||
logging.info("Testing for \"https_request using saved session\"")
|
||||
logging.info('Testing for "https_request using saved session"')
|
||||
|
||||
# Check for connection using already saved client session
|
||||
try:
|
||||
dut.expect('https_request to local server', timeout=30)
|
||||
dut.expect(['Connection established...',
|
||||
'Reading HTTP response...',
|
||||
'HTTP/1.1 200 OK',
|
||||
'connection closed'], expect_all=True)
|
||||
dut.expect(
|
||||
['Connection established...', 'Reading HTTP response...', 'HTTP/1.1 200 OK', 'connection closed'],
|
||||
expect_all=True,
|
||||
)
|
||||
except Exception:
|
||||
logging.info("Failed to connect to local https server\"")
|
||||
logging.info('Failed to connect to local https server"')
|
||||
raise
|
||||
|
||||
try:
|
||||
dut.expect('https_request using saved client session', timeout=20)
|
||||
dut.expect(['Connection established...',
|
||||
'Reading HTTP response...',
|
||||
'HTTP/1.1 200 OK',
|
||||
'connection closed'], expect_all=True)
|
||||
dut.expect(
|
||||
['Connection established...', 'Reading HTTP response...', 'HTTP/1.1 200 OK', 'connection closed'],
|
||||
expect_all=True,
|
||||
)
|
||||
except Exception:
|
||||
logging.info("Failed the test for \"https_request using saved client session\"")
|
||||
logging.info('Failed the test for "https_request using saved client session"')
|
||||
raise
|
||||
|
||||
logging.info("Passed the test for \"https_request using saved client session\"")
|
||||
logging.info('Passed the test for "https_request using saved client session"')
|
||||
finally:
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
@pytest.mark.esp32
|
||||
@pytest.mark.ethernet
|
||||
@pytest.mark.parametrize('config', ['ssldyn',], indirect=True)
|
||||
@pytest.mark.parametrize(
|
||||
'config',
|
||||
[
|
||||
'ssldyn',
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
@pytest.mark.parametrize('erase_nvs', ['y'], indirect=True)
|
||||
@idf_parametrize('target', ['esp32'], indirect=['target'])
|
||||
def test_examples_protocol_https_request_dynamic_buffers(dut: Dut) -> None:
|
||||
# Check for connection using crt bundle with mbedtls dynamic resource enabled
|
||||
# check and log bin size
|
||||
@@ -137,24 +150,23 @@ def test_examples_protocol_https_request_dynamic_buffers(dut: Dut) -> None:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP/Ethernet')
|
||||
|
||||
# only check if one connection is established
|
||||
logging.info("Testing for \"https_request using crt bundle\" with mbedtls dynamic resource enabled")
|
||||
logging.info('Testing for "https_request using crt bundle" with mbedtls dynamic resource enabled')
|
||||
try:
|
||||
dut.expect('https_request using crt bundle', timeout=30)
|
||||
dut.expect(['Connection established...',
|
||||
'Reading HTTP response...',
|
||||
'HTTP/1.1 200 OK',
|
||||
'connection closed'], expect_all=True)
|
||||
dut.expect(
|
||||
['Connection established...', 'Reading HTTP response...', 'HTTP/1.1 200 OK', 'connection closed'],
|
||||
expect_all=True,
|
||||
)
|
||||
except Exception:
|
||||
logging.info("Failed the test for \"https_request using crt bundle\" when mbedtls dynamic resource was enabled")
|
||||
logging.info('Failed the test for "https_request using crt bundle" when mbedtls dynamic resource was enabled')
|
||||
raise
|
||||
logging.info("Passed the test for \"https_request using crt bundle\" when mbedtls dynamic resource was enabled")
|
||||
logging.info('Passed the test for "https_request using crt bundle" when mbedtls dynamic resource was enabled')
|
||||
|
||||
|
||||
@pytest.mark.esp32
|
||||
@pytest.mark.ethernet
|
||||
@pytest.mark.parametrize('erase_nvs', ['y'], indirect=True)
|
||||
@idf_parametrize('target', ['esp32'], indirect=['target'])
|
||||
def test_examples_protocol_https_request(dut: Dut) -> None:
|
||||
|
||||
"""
|
||||
steps: |
|
||||
1. join AP
|
||||
@@ -176,77 +188,84 @@ def test_examples_protocol_https_request(dut: Dut) -> None:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP/Ethernet')
|
||||
|
||||
# Check for connection using crt bundle
|
||||
logging.info("Testing for \"https_request using crt bundle\"")
|
||||
logging.info('Testing for "https_request using crt bundle"')
|
||||
try:
|
||||
dut.expect('https_request using crt bundle', timeout=30)
|
||||
dut.expect(['Certificate validated',
|
||||
'Connection established...',
|
||||
'Reading HTTP response...',
|
||||
'HTTP/1.1 200 OK',
|
||||
'connection closed'], expect_all=True)
|
||||
dut.expect(
|
||||
[
|
||||
'Certificate validated',
|
||||
'Connection established...',
|
||||
'Reading HTTP response...',
|
||||
'HTTP/1.1 200 OK',
|
||||
'connection closed',
|
||||
],
|
||||
expect_all=True,
|
||||
)
|
||||
except Exception:
|
||||
logging.info("Failed the test for \"https_request using crt bundle\"")
|
||||
logging.info('Failed the test for "https_request using crt bundle"')
|
||||
raise
|
||||
logging.info("Passed the test for \"https_request using crt bundle\"")
|
||||
logging.info('Passed the test for "https_request using crt bundle"')
|
||||
|
||||
# Check for connection using cacert_buf
|
||||
logging.info("Testing for \"https_request using cacert_buf\"")
|
||||
logging.info('Testing for "https_request using cacert_buf"')
|
||||
try:
|
||||
dut.expect('https_request using cacert_buf', timeout=20)
|
||||
dut.expect(['Connection established...',
|
||||
'Reading HTTP response...',
|
||||
'HTTP/1.1 200 OK',
|
||||
'connection closed'], expect_all=True)
|
||||
dut.expect(
|
||||
['Connection established...', 'Reading HTTP response...', 'HTTP/1.1 200 OK', 'connection closed'],
|
||||
expect_all=True,
|
||||
)
|
||||
except Exception:
|
||||
logging.info("Passed the test for \"https_request using cacert_buf\"")
|
||||
logging.info('Passed the test for "https_request using cacert_buf"')
|
||||
raise
|
||||
logging.info("Passed the test for \"https_request using cacert_buf\"")
|
||||
logging.info('Passed the test for "https_request using cacert_buf"')
|
||||
|
||||
# Check for connection using global ca_store
|
||||
logging.info("Testing for \"https_request using global ca_store\"")
|
||||
logging.info('Testing for "https_request using global ca_store"')
|
||||
try:
|
||||
dut.expect('https_request using global ca_store', timeout=20)
|
||||
dut.expect(['Connection established...',
|
||||
'Reading HTTP response...',
|
||||
'HTTP/1.1 200 OK',
|
||||
'connection closed'], expect_all=True)
|
||||
dut.expect(
|
||||
['Connection established...', 'Reading HTTP response...', 'HTTP/1.1 200 OK', 'connection closed'],
|
||||
expect_all=True,
|
||||
)
|
||||
except Exception:
|
||||
logging.info("Failed the test for \"https_request using global ca_store\"")
|
||||
logging.info('Failed the test for "https_request using global ca_store"')
|
||||
raise
|
||||
logging.info("Passed the test for \"https_request using global ca_store\"")
|
||||
logging.info('Passed the test for "https_request using global ca_store"')
|
||||
|
||||
# Check for connection using specified server supported ciphersuites
|
||||
logging.info("Testing for \"https_request using server supported ciphersuites\"")
|
||||
logging.info('Testing for "https_request using server supported ciphersuites"')
|
||||
try:
|
||||
dut.expect('https_request using server supported ciphersuites', timeout=20)
|
||||
dut.expect(['Connection established...',
|
||||
'Reading HTTP response...',
|
||||
'HTTP/1.1 200 OK',
|
||||
'connection closed'], expect_all=True)
|
||||
dut.expect(
|
||||
['Connection established...', 'Reading HTTP response...', 'HTTP/1.1 200 OK', 'connection closed'],
|
||||
expect_all=True,
|
||||
)
|
||||
except Exception:
|
||||
logging.info("Failed the test for \"https_request using server supported ciphersuites\"")
|
||||
logging.info('Failed the test for "https_request using server supported ciphersuites"')
|
||||
raise
|
||||
logging.info("Passed the test for \"https_request using server supported ciphersuites\"")
|
||||
logging.info('Passed the test for "https_request using server supported ciphersuites"')
|
||||
|
||||
# Check for connection using specified server unsupported ciphersuites
|
||||
logging.info("Testing for \"https_request using server unsupported ciphersuites\"")
|
||||
logging.info('Testing for "https_request using server unsupported ciphersuites"')
|
||||
try:
|
||||
dut.expect('https_request using server unsupported ciphersuites', timeout=20)
|
||||
dut.expect('Connection failed...', timeout=30)
|
||||
except Exception:
|
||||
logging.info("Failed the test for \"https_request using server unsupported ciphersuites\"")
|
||||
logging.info('Failed the test for "https_request using server unsupported ciphersuites"')
|
||||
raise
|
||||
logging.info("Passed the test for \"https_request using server unsupported ciphersuites\"")
|
||||
logging.info('Passed the test for "https_request using server unsupported ciphersuites"')
|
||||
|
||||
|
||||
@pytest.mark.esp32c2
|
||||
@pytest.mark.wifi_ap
|
||||
@pytest.mark.xtal_26mhz
|
||||
@pytest.mark.parametrize(
|
||||
'config, baud', [
|
||||
'config, baud',
|
||||
[
|
||||
('esp32c2_rom_mbedtls', '74880'),
|
||||
], indirect=True
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
@idf_parametrize('target', ['esp32c2'], indirect=['target'])
|
||||
def test_examples_protocol_https_request_rom_impl(dut: Dut) -> None:
|
||||
# Connect to AP
|
||||
if dut.app.sdkconfig.get('EXAMPLE_WIFI_SSID_PWD_FROM_STDIN') is True:
|
||||
@@ -268,64 +287,69 @@ def test_examples_protocol_https_request_rom_impl(dut: Dut) -> None:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP/Ethernet')
|
||||
|
||||
# Check for connection using crt bundle
|
||||
logging.info("Testing for \"https_request using crt bundle\"")
|
||||
logging.info('Testing for "https_request using crt bundle"')
|
||||
try:
|
||||
dut.expect('https_request using crt bundle', timeout=30)
|
||||
dut.expect(['Certificate validated',
|
||||
'Connection established...',
|
||||
'Reading HTTP response...',
|
||||
'HTTP/1.1 200 OK',
|
||||
'connection closed'], expect_all=True)
|
||||
dut.expect(
|
||||
[
|
||||
'Certificate validated',
|
||||
'Connection established...',
|
||||
'Reading HTTP response...',
|
||||
'HTTP/1.1 200 OK',
|
||||
'connection closed',
|
||||
],
|
||||
expect_all=True,
|
||||
)
|
||||
except Exception:
|
||||
logging.info("Failed the test for \"https_request using crt bundle\"")
|
||||
logging.info('Failed the test for "https_request using crt bundle"')
|
||||
raise
|
||||
logging.info("Passed the test for \"https_request using crt bundle\"")
|
||||
logging.info('Passed the test for "https_request using crt bundle"')
|
||||
|
||||
# Check for connection using cacert_buf
|
||||
logging.info("Testing for \"https_request using cacert_buf\"")
|
||||
logging.info('Testing for "https_request using cacert_buf"')
|
||||
try:
|
||||
dut.expect('https_request using cacert_buf', timeout=20)
|
||||
dut.expect(['Connection established...',
|
||||
'Reading HTTP response...',
|
||||
'HTTP/1.1 200 OK',
|
||||
'connection closed'], expect_all=True)
|
||||
dut.expect(
|
||||
['Connection established...', 'Reading HTTP response...', 'HTTP/1.1 200 OK', 'connection closed'],
|
||||
expect_all=True,
|
||||
)
|
||||
except Exception:
|
||||
logging.info("Passed the test for \"https_request using cacert_buf\"")
|
||||
logging.info('Passed the test for "https_request using cacert_buf"')
|
||||
raise
|
||||
logging.info("Passed the test for \"https_request using cacert_buf\"")
|
||||
logging.info('Passed the test for "https_request using cacert_buf"')
|
||||
|
||||
# Check for connection using global ca_store
|
||||
logging.info("Testing for \"https_request using global ca_store\"")
|
||||
logging.info('Testing for "https_request using global ca_store"')
|
||||
try:
|
||||
dut.expect('https_request using global ca_store', timeout=20)
|
||||
dut.expect(['Connection established...',
|
||||
'Reading HTTP response...',
|
||||
'HTTP/1.1 200 OK',
|
||||
'connection closed'], expect_all=True)
|
||||
dut.expect(
|
||||
['Connection established...', 'Reading HTTP response...', 'HTTP/1.1 200 OK', 'connection closed'],
|
||||
expect_all=True,
|
||||
)
|
||||
except Exception:
|
||||
logging.info("Failed the test for \"https_request using global ca_store\"")
|
||||
logging.info('Failed the test for "https_request using global ca_store"')
|
||||
raise
|
||||
logging.info("Passed the test for \"https_request using global ca_store\"")
|
||||
logging.info('Passed the test for "https_request using global ca_store"')
|
||||
|
||||
# Check for connection using specified server supported ciphersuites
|
||||
logging.info("Testing for \"https_request using server supported ciphersuites\"")
|
||||
logging.info('Testing for "https_request using server supported ciphersuites"')
|
||||
try:
|
||||
dut.expect('https_request using server supported ciphersuites', timeout=20)
|
||||
dut.expect(['Connection established...',
|
||||
'Reading HTTP response...',
|
||||
'HTTP/1.1 200 OK',
|
||||
'connection closed'], expect_all=True)
|
||||
dut.expect(
|
||||
['Connection established...', 'Reading HTTP response...', 'HTTP/1.1 200 OK', 'connection closed'],
|
||||
expect_all=True,
|
||||
)
|
||||
except Exception:
|
||||
logging.info("Failed the test for \"https_request using server supported ciphersuites\"")
|
||||
logging.info('Failed the test for "https_request using server supported ciphersuites"')
|
||||
raise
|
||||
logging.info("Passed the test for \"https_request using server supported ciphersuites\"")
|
||||
logging.info('Passed the test for "https_request using server supported ciphersuites"')
|
||||
|
||||
# Check for connection using specified server unsupported ciphersuites
|
||||
logging.info("Testing for \"https_request using server unsupported ciphersuites\"")
|
||||
logging.info('Testing for "https_request using server unsupported ciphersuites"')
|
||||
try:
|
||||
dut.expect('https_request using server unsupported ciphersuites', timeout=20)
|
||||
dut.expect('Connection failed...', timeout=30)
|
||||
except Exception:
|
||||
logging.info("Failed the test for \"https_request using server unsupported ciphersuites\"")
|
||||
logging.info('Failed the test for "https_request using server unsupported ciphersuites"')
|
||||
raise
|
||||
logging.info("Passed the test for \"https_request using server unsupported ciphersuites\"")
|
||||
logging.info('Passed the test for "https_request using server unsupported ciphersuites"')
|
||||
|
Reference in New Issue
Block a user