2024-01-30 05:42:22 -05:00
|
|
|
# SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD
|
2022-03-30 05:07:25 -04:00
|
|
|
# SPDX-License-Identifier: Unlicense OR CC0-1.0
|
2021-01-25 21:49:01 -05:00
|
|
|
import http.server
|
2021-11-10 03:24:21 -05:00
|
|
|
import multiprocessing
|
2019-06-10 05:13:24 -04:00
|
|
|
import os
|
|
|
|
import ssl
|
2023-07-18 06:37:33 -04:00
|
|
|
import subprocess
|
2021-03-02 08:58:11 -05:00
|
|
|
import sys
|
2024-07-05 05:40:41 -04:00
|
|
|
from typing import Optional
|
2022-03-30 05:07:25 -04:00
|
|
|
from typing import Tuple
|
2019-06-10 05:13:24 -04:00
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
import pexpect
|
|
|
|
import pytest
|
|
|
|
from pytest_embedded import Dut
|
2019-06-10 05:13:24 -04:00
|
|
|
|
2023-12-06 07:14:44 -05:00
|
|
|
try:
|
|
|
|
from common_test_methods import get_env_config_variable, get_host_ip4_by_dest_ip
|
|
|
|
except ModuleNotFoundError:
|
|
|
|
idf_path = os.environ['IDF_PATH']
|
|
|
|
sys.path.insert(0, idf_path + '/tools/ci/python_packages')
|
|
|
|
from common_test_methods import get_env_config_variable, get_host_ip4_by_dest_ip
|
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
server_cert = '-----BEGIN CERTIFICATE-----\n' \
|
2021-07-12 08:42:06 -04:00
|
|
|
'MIIDWDCCAkACCQCbF4+gVh/MLjANBgkqhkiG9w0BAQsFADBuMQswCQYDVQQGEwJJ\n'\
|
|
|
|
'TjELMAkGA1UECAwCTUgxDDAKBgNVBAcMA1BVTjEMMAoGA1UECgwDRVNQMQwwCgYD\n'\
|
|
|
|
'VQQLDANFU1AxDDAKBgNVBAMMA0VTUDEaMBgGCSqGSIb3DQEJARYLZXNwQGVzcC5j\n'\
|
|
|
|
'b20wHhcNMjEwNzEyMTIzNjI3WhcNNDEwNzA3MT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2021-01-25 21:49:01 -05:00
|
|
|
'-----END PRIVATE KEY-----\n'
|
2019-06-10 05:13:24 -04:00
|
|
|
|
2024-07-05 05:40:41 -04:00
|
|
|
OTA1_ADDRESS = '0x20000'
|
|
|
|
OTA2_ADDRESS = '0x1d0000'
|
2019-06-10 05:13:24 -04:00
|
|
|
|
2024-07-05 05:40:41 -04:00
|
|
|
|
|
|
|
def start_https_server(ota_image_dir: str, server_ip: str, server_port: int, server_file: Optional[str] = None, key_file: Optional[str] = None) -> None:
|
2019-06-10 05:13:24 -04:00
|
|
|
os.chdir(ota_image_dir)
|
|
|
|
|
2021-03-02 08:58:11 -05:00
|
|
|
if server_file is None:
|
|
|
|
server_file = os.path.join(ota_image_dir, 'server_cert.pem')
|
|
|
|
cert_file_handle = open(server_file, 'w+')
|
|
|
|
cert_file_handle.write(server_cert)
|
|
|
|
cert_file_handle.close()
|
2019-06-10 05:13:24 -04:00
|
|
|
|
2021-03-02 08:58:11 -05:00
|
|
|
if key_file is None:
|
|
|
|
key_file = os.path.join(ota_image_dir, 'server_key.pem')
|
|
|
|
key_file_handle = open('server_key.pem', 'w+')
|
|
|
|
key_file_handle.write(server_key)
|
|
|
|
key_file_handle.close()
|
2019-06-10 05:13:24 -04:00
|
|
|
|
2020-05-14 02:39:29 -04:00
|
|
|
httpd = http.server.HTTPServer((server_ip, server_port), http.server.SimpleHTTPRequestHandler)
|
2019-06-10 05:13:24 -04:00
|
|
|
|
2024-04-15 05:22:37 -04:00
|
|
|
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
|
|
|
|
ssl_context.load_cert_chain(certfile=server_file, keyfile=key_file)
|
|
|
|
|
|
|
|
httpd.socket = ssl_context.wrap_socket(httpd.socket, server_side=True)
|
2019-06-10 05:13:24 -04:00
|
|
|
httpd.serve_forever()
|
|
|
|
|
|
|
|
|
2023-07-18 06:37:33 -04:00
|
|
|
def start_tls1_3_server(ota_image_dir: str, server_port: int) -> subprocess.Popen:
|
|
|
|
os.chdir(ota_image_dir)
|
|
|
|
server_file = os.path.join(ota_image_dir, 'server_cert.pem')
|
|
|
|
cert_file_handle = open(server_file, 'w+')
|
|
|
|
cert_file_handle.write(server_cert)
|
|
|
|
cert_file_handle.close()
|
|
|
|
|
|
|
|
key_file = os.path.join(ota_image_dir, 'server_key.pem')
|
|
|
|
key_file_handle = open('server_key.pem', 'w+')
|
|
|
|
key_file_handle.write(server_key)
|
|
|
|
key_file_handle.close()
|
|
|
|
|
|
|
|
chunked_server = subprocess.Popen(['openssl', 's_server', '-tls1_3', '-WWW', '-key', key_file, '-cert', server_file, '-port', str(server_port)])
|
|
|
|
return chunked_server
|
|
|
|
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
def check_sha256(sha256_expected: str, sha256_reported: str) -> None:
|
|
|
|
print('sha256_expected: %s' % (sha256_expected))
|
|
|
|
print('sha256_reported: %s' % (sha256_reported))
|
|
|
|
if sha256_expected not in sha256_reported:
|
2021-04-27 06:56:02 -04:00
|
|
|
raise ValueError('SHA256 mismatch')
|
|
|
|
else:
|
2022-03-30 05:07:25 -04:00
|
|
|
print('SHA256 expected and reported are the same')
|
2021-04-27 06:56:02 -04:00
|
|
|
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
def calc_all_sha256(dut: Dut) -> Tuple[str, str]:
|
2021-04-27 06:56:02 -04:00
|
|
|
bootloader_path = os.path.join(dut.app.binary_path, 'bootloader', 'bootloader.bin')
|
2022-03-30 05:07:25 -04:00
|
|
|
sha256_bootloader = dut.app.get_sha256(bootloader_path)
|
2021-04-27 06:56:02 -04:00
|
|
|
|
|
|
|
app_path = os.path.join(dut.app.binary_path, 'simple_ota.bin')
|
2022-03-30 05:07:25 -04:00
|
|
|
sha256_app = dut.app.get_sha256(app_path)
|
2021-04-27 06:56:02 -04:00
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
return str(sha256_bootloader), str(sha256_app)
|
2021-04-27 06:56:02 -04:00
|
|
|
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
@pytest.mark.esp32
|
|
|
|
@pytest.mark.esp32c3
|
|
|
|
@pytest.mark.esp32s3
|
2022-07-06 12:34:06 -04:00
|
|
|
@pytest.mark.wifi_high_traffic
|
2022-03-30 05:07:25 -04:00
|
|
|
def test_examples_protocol_simple_ota_example(dut: Dut) -> None:
|
2019-06-10 05:13:24 -04:00
|
|
|
"""
|
|
|
|
steps: |
|
2022-07-03 04:22:20 -04:00
|
|
|
1. join AP/Ethernet
|
2019-06-10 05:13:24 -04:00
|
|
|
2. Fetch OTA image over HTTPS
|
|
|
|
3. Reboot with the new OTA image
|
|
|
|
"""
|
2022-07-03 04:22:20 -04:00
|
|
|
sha256_bootloader, sha256_app = calc_all_sha256(dut)
|
|
|
|
# Start server
|
2022-07-06 12:34:06 -04:00
|
|
|
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, '0.0.0.0', 8000))
|
2022-07-03 04:22:20 -04:00
|
|
|
thread1.daemon = True
|
|
|
|
thread1.start()
|
2022-06-21 07:34:40 -04:00
|
|
|
try:
|
2022-07-06 12:34:06 -04:00
|
|
|
# start test
|
2024-07-05 05:40:41 -04:00
|
|
|
dut.expect(f'Loaded app from partition at offset {OTA1_ADDRESS}', timeout=30)
|
2022-07-06 12:34:06 -04:00
|
|
|
check_sha256(sha256_bootloader, str(dut.expect(r'SHA-256 for bootloader:\s+([a-f0-9]){64}')[0]))
|
|
|
|
check_sha256(sha256_app, str(dut.expect(r'SHA-256 for current firmware:\s+([a-f0-9]){64}')[0]))
|
|
|
|
# Parse IP address of STA
|
|
|
|
if dut.app.sdkconfig.get('EXAMPLE_WIFI_SSID_PWD_FROM_STDIN') is True:
|
|
|
|
env_name = 'wifi_high_traffic'
|
|
|
|
dut.expect('Please input ssid password:')
|
|
|
|
ap_ssid = get_env_config_variable(env_name, 'ap_ssid')
|
|
|
|
ap_password = get_env_config_variable(env_name, 'ap_password')
|
|
|
|
dut.write(f'{ap_ssid} {ap_password}')
|
|
|
|
try:
|
2022-07-14 10:55:50 -04:00
|
|
|
ip_address = dut.expect(r'IPv4 address: (\d+\.\d+\.\d+\.\d+)[^\d]', timeout=30)[1].decode()
|
2022-07-06 12:34:06 -04:00
|
|
|
print('Connected to AP/Ethernet with IP: {}'.format(ip_address))
|
|
|
|
except pexpect.exceptions.TIMEOUT:
|
|
|
|
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP/Ethernet')
|
|
|
|
host_ip = get_host_ip4_by_dest_ip(ip_address)
|
|
|
|
|
|
|
|
dut.expect('Starting OTA example task', timeout=30)
|
2022-06-21 07:34:40 -04:00
|
|
|
print('writing to device: {}'.format('https://' + host_ip + ':8000/simple_ota.bin'))
|
|
|
|
dut.write('https://' + host_ip + ':8000/simple_ota.bin')
|
2022-07-06 12:34:06 -04:00
|
|
|
dut.expect('OTA Succeed, Rebooting...', timeout=60)
|
|
|
|
# after reboot
|
2024-07-05 05:40:41 -04:00
|
|
|
dut.expect(f'Loaded app from partition at offset {OTA2_ADDRESS}', timeout=30)
|
2022-07-06 12:34:06 -04:00
|
|
|
dut.expect('OTA example app_main start', timeout=10)
|
2022-06-21 07:34:40 -04:00
|
|
|
finally:
|
2021-11-10 03:24:21 -05:00
|
|
|
thread1.terminate()
|
2019-06-10 05:13:24 -04:00
|
|
|
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
@pytest.mark.esp32
|
2022-07-06 12:34:06 -04:00
|
|
|
@pytest.mark.ethernet_ota
|
2022-03-30 05:07:25 -04:00
|
|
|
@pytest.mark.parametrize('config', ['spiram',], indirect=True)
|
|
|
|
def test_examples_protocol_simple_ota_example_ethernet_with_spiram_config(dut: Dut) -> None:
|
2020-06-10 05:59:34 -04:00
|
|
|
"""
|
|
|
|
steps: |
|
2022-07-03 04:22:20 -04:00
|
|
|
1. join AP/Ethernet
|
2020-06-10 05:59:34 -04:00
|
|
|
2. Fetch OTA image over HTTPS
|
|
|
|
3. Reboot with the new OTA image
|
|
|
|
"""
|
2022-07-03 04:22:20 -04:00
|
|
|
# Start server
|
2022-07-06 12:34:06 -04:00
|
|
|
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, '0.0.0.0', 8000))
|
2022-07-03 04:22:20 -04:00
|
|
|
thread1.daemon = True
|
|
|
|
thread1.start()
|
2022-06-21 07:34:40 -04:00
|
|
|
try:
|
2022-07-06 12:34:06 -04:00
|
|
|
# start test
|
2024-07-05 05:40:41 -04:00
|
|
|
dut.expect(f'Loaded app from partition at offset {OTA1_ADDRESS}', timeout=30)
|
2022-07-06 12:34:06 -04:00
|
|
|
try:
|
2022-07-14 10:55:50 -04:00
|
|
|
ip_address = dut.expect(r'IPv4 address: (\d+\.\d+\.\d+\.\d+)[^\d]', timeout=30)[1].decode()
|
2022-07-06 12:34:06 -04:00
|
|
|
print('Connected to AP/Ethernet with IP: {}'.format(ip_address))
|
|
|
|
except pexpect.exceptions.TIMEOUT:
|
|
|
|
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP/Ethernet')
|
|
|
|
host_ip = get_host_ip4_by_dest_ip(ip_address)
|
|
|
|
|
|
|
|
dut.expect('Starting OTA example task', timeout=30)
|
2022-06-21 07:34:40 -04:00
|
|
|
print('writing to device: {}'.format('https://' + host_ip + ':8000/simple_ota.bin'))
|
|
|
|
dut.write('https://' + host_ip + ':8000/simple_ota.bin')
|
2022-07-06 12:34:06 -04:00
|
|
|
dut.expect('OTA Succeed, Rebooting...', timeout=60)
|
|
|
|
# after reboot
|
2024-07-05 05:40:41 -04:00
|
|
|
dut.expect(f'Loaded app from partition at offset {OTA2_ADDRESS}', timeout=30)
|
2022-07-06 12:34:06 -04:00
|
|
|
dut.expect('OTA example app_main start', timeout=10)
|
2022-06-21 07:34:40 -04:00
|
|
|
finally:
|
2021-11-10 03:24:21 -05:00
|
|
|
thread1.terminate()
|
2020-06-10 05:59:34 -04:00
|
|
|
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
@pytest.mark.esp32
|
|
|
|
@pytest.mark.esp32c3
|
2022-07-06 12:34:06 -04:00
|
|
|
@pytest.mark.flash_encryption_wifi_high_traffic
|
2022-07-08 05:47:59 -04:00
|
|
|
@pytest.mark.nightly_run
|
2022-03-30 05:07:25 -04:00
|
|
|
@pytest.mark.parametrize('config', ['flash_enc_wifi',], indirect=True)
|
|
|
|
@pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
|
|
|
|
def test_examples_protocol_simple_ota_example_with_flash_encryption_wifi(dut: Dut) -> None:
|
2021-03-17 04:11:03 -04:00
|
|
|
"""
|
|
|
|
steps: |
|
2022-07-03 04:22:20 -04:00
|
|
|
1. join AP/Ethernet
|
2021-03-17 04:11:03 -04:00
|
|
|
2. Fetch OTA image over HTTPS
|
|
|
|
3. Reboot with the new OTA image
|
|
|
|
"""
|
2022-07-03 04:22:20 -04:00
|
|
|
# start test
|
|
|
|
# Erase flash
|
|
|
|
dut.serial.erase_flash()
|
|
|
|
dut.serial.flash()
|
|
|
|
# Start server
|
2022-07-06 12:34:06 -04:00
|
|
|
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, '0.0.0.0', 8000))
|
2022-07-03 04:22:20 -04:00
|
|
|
thread1.daemon = True
|
|
|
|
thread1.start()
|
2022-06-21 07:34:40 -04:00
|
|
|
try:
|
2024-07-05 05:40:41 -04:00
|
|
|
dut.expect(f'Loaded app from partition at offset {OTA1_ADDRESS}', timeout=30)
|
2022-07-06 12:34:06 -04:00
|
|
|
dut.expect('Flash encryption mode is DEVELOPMENT', timeout=10)
|
|
|
|
# Parse IP address of STA
|
|
|
|
if dut.app.sdkconfig.get('EXAMPLE_WIFI_SSID_PWD_FROM_STDIN') is True:
|
|
|
|
env_name = 'flash_encryption_wifi_high_traffic'
|
|
|
|
dut.expect('Please input ssid password:')
|
|
|
|
ap_ssid = get_env_config_variable(env_name, 'ap_ssid')
|
|
|
|
ap_password = get_env_config_variable(env_name, 'ap_password')
|
|
|
|
dut.write(f'{ap_ssid} {ap_password}')
|
|
|
|
try:
|
2022-07-14 10:55:50 -04:00
|
|
|
ip_address = dut.expect(r'IPv4 address: (\d+\.\d+\.\d+\.\d+)[^\d]', timeout=30)[1].decode()
|
2022-07-06 12:34:06 -04:00
|
|
|
print('Connected to AP/Ethernet with IP: {}'.format(ip_address))
|
|
|
|
except pexpect.exceptions.TIMEOUT:
|
|
|
|
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP/Ethernet')
|
|
|
|
host_ip = get_host_ip4_by_dest_ip(ip_address)
|
|
|
|
|
|
|
|
dut.expect('Starting OTA example task', timeout=30)
|
2022-06-21 07:34:40 -04:00
|
|
|
print('writing to device: {}'.format('https://' + host_ip + ':8000/simple_ota.bin'))
|
|
|
|
dut.write('https://' + host_ip + ':8000/simple_ota.bin')
|
2022-07-06 12:34:06 -04:00
|
|
|
dut.expect('OTA Succeed, Rebooting...', timeout=60)
|
|
|
|
# after reboot
|
2024-07-05 05:40:41 -04:00
|
|
|
dut.expect(f'Loaded app from partition at offset {OTA2_ADDRESS}', timeout=30)
|
2022-06-21 07:34:40 -04:00
|
|
|
dut.expect('Flash encryption mode is DEVELOPMENT', timeout=10)
|
2022-07-06 12:34:06 -04:00
|
|
|
dut.expect('OTA example app_main start', timeout=10)
|
2022-06-21 07:34:40 -04:00
|
|
|
finally:
|
2021-11-10 03:24:21 -05:00
|
|
|
thread1.terminate()
|
2020-06-30 08:58:37 -04:00
|
|
|
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
@pytest.mark.esp32
|
2022-07-06 12:34:06 -04:00
|
|
|
@pytest.mark.ethernet_ota
|
2022-03-30 05:07:25 -04:00
|
|
|
@pytest.mark.parametrize('config', ['on_update_no_sb_ecdsa',], indirect=True)
|
|
|
|
def test_examples_protocol_simple_ota_example_with_verify_app_signature_on_update_no_secure_boot_ecdsa(dut: Dut) -> None:
|
2021-03-15 11:59:56 -04:00
|
|
|
"""
|
|
|
|
steps: |
|
2022-07-03 04:22:20 -04:00
|
|
|
1. join AP/Ethernet
|
2021-03-15 11:59:56 -04:00
|
|
|
2. Fetch OTA image over HTTPS
|
|
|
|
3. Reboot with the new OTA image
|
|
|
|
"""
|
2022-07-03 04:22:20 -04:00
|
|
|
sha256_bootloader, sha256_app = calc_all_sha256(dut)
|
|
|
|
# Start server
|
2022-07-06 12:34:06 -04:00
|
|
|
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, '0.0.0.0', 8000))
|
2022-07-03 04:22:20 -04:00
|
|
|
thread1.daemon = True
|
|
|
|
thread1.start()
|
|
|
|
try:
|
2022-07-06 12:34:06 -04:00
|
|
|
# start test
|
2024-07-05 05:40:41 -04:00
|
|
|
dut.expect(f'Loaded app from partition at offset {OTA1_ADDRESS}', timeout=30)
|
2022-07-06 12:34:06 -04:00
|
|
|
check_sha256(sha256_bootloader, str(dut.expect(r'SHA-256 for bootloader:\s+([a-f0-9]){64}')[0]))
|
|
|
|
check_sha256(sha256_app, str(dut.expect(r'SHA-256 for current firmware:\s+([a-f0-9]){64}')[0]))
|
|
|
|
try:
|
2022-07-14 10:55:50 -04:00
|
|
|
ip_address = dut.expect(r'IPv4 address: (\d+\.\d+\.\d+\.\d+)[^\d]', timeout=30)[1].decode()
|
2022-07-06 12:34:06 -04:00
|
|
|
print('Connected to AP/Ethernet with IP: {}'.format(ip_address))
|
|
|
|
except pexpect.exceptions.TIMEOUT:
|
|
|
|
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP/Ethernet')
|
|
|
|
host_ip = get_host_ip4_by_dest_ip(ip_address)
|
|
|
|
|
|
|
|
dut.expect('Starting OTA example task', timeout=30)
|
2022-06-21 07:34:40 -04:00
|
|
|
print('writing to device: {}'.format('https://' + host_ip + ':8000/simple_ota.bin'))
|
|
|
|
dut.write('https://' + host_ip + ':8000/simple_ota.bin')
|
2024-07-05 05:40:41 -04:00
|
|
|
dut.expect(f'Writing to partition subtype 17 at offset {OTA2_ADDRESS}', timeout=20)
|
2022-06-21 07:34:40 -04:00
|
|
|
dut.expect('Verifying image signature...', timeout=60)
|
2022-07-06 12:34:06 -04:00
|
|
|
dut.expect('OTA Succeed, Rebooting...', timeout=60)
|
|
|
|
# after reboot
|
2024-07-05 05:40:41 -04:00
|
|
|
dut.expect(f'Loaded app from partition at offset {OTA2_ADDRESS}', timeout=20)
|
2022-07-06 12:34:06 -04:00
|
|
|
dut.expect('OTA example app_main start', timeout=10)
|
2022-06-21 07:34:40 -04:00
|
|
|
finally:
|
2021-11-10 03:24:21 -05:00
|
|
|
thread1.terminate()
|
2021-03-15 11:59:56 -04:00
|
|
|
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
@pytest.mark.esp32
|
2022-07-06 12:34:06 -04:00
|
|
|
@pytest.mark.ethernet_ota
|
2022-03-30 05:07:25 -04:00
|
|
|
@pytest.mark.parametrize('config', ['on_update_no_sb_rsa',], indirect=True)
|
|
|
|
def test_examples_protocol_simple_ota_example_with_verify_app_signature_on_update_no_secure_boot_rsa(dut: Dut) -> None:
|
2021-03-15 11:59:56 -04:00
|
|
|
"""
|
|
|
|
steps: |
|
2022-07-03 04:22:20 -04:00
|
|
|
1. join AP/Ethernet
|
2021-03-15 11:59:56 -04:00
|
|
|
2. Fetch OTA image over HTTPS
|
|
|
|
3. Reboot with the new OTA image
|
|
|
|
"""
|
2022-07-03 04:22:20 -04:00
|
|
|
sha256_bootloader, sha256_app = calc_all_sha256(dut)
|
|
|
|
# Start server
|
2022-07-06 12:34:06 -04:00
|
|
|
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, '0.0.0.0', 8000))
|
2022-07-03 04:22:20 -04:00
|
|
|
thread1.daemon = True
|
|
|
|
thread1.start()
|
|
|
|
try:
|
2022-07-06 12:34:06 -04:00
|
|
|
# start test
|
2024-07-05 05:40:41 -04:00
|
|
|
dut.expect(f'Loaded app from partition at offset {OTA1_ADDRESS}', timeout=30)
|
2022-07-06 12:34:06 -04:00
|
|
|
check_sha256(sha256_bootloader, str(dut.expect(r'SHA-256 for bootloader:\s+([a-f0-9]){64}')[0]))
|
|
|
|
check_sha256(sha256_app, str(dut.expect(r'SHA-256 for current firmware:\s+([a-f0-9]){64}')[0]))
|
|
|
|
try:
|
2022-07-14 10:55:50 -04:00
|
|
|
ip_address = dut.expect(r'IPv4 address: (\d+\.\d+\.\d+\.\d+)[^\d]', timeout=30)[1].decode()
|
2022-07-06 12:34:06 -04:00
|
|
|
print('Connected to AP/Ethernet with IP: {}'.format(ip_address))
|
|
|
|
except pexpect.exceptions.TIMEOUT:
|
|
|
|
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP/Ethernet')
|
|
|
|
host_ip = get_host_ip4_by_dest_ip(ip_address)
|
|
|
|
|
|
|
|
dut.expect('Starting OTA example task', timeout=30)
|
2022-06-21 07:34:40 -04:00
|
|
|
print('writing to device: {}'.format('https://' + host_ip + ':8000/simple_ota.bin'))
|
|
|
|
dut.write('https://' + host_ip + ':8000/simple_ota.bin')
|
2024-07-05 05:40:41 -04:00
|
|
|
dut.expect(f'Writing to partition subtype 17 at offset {OTA2_ADDRESS}', timeout=20)
|
2022-06-21 07:34:40 -04:00
|
|
|
dut.expect('Verifying image signature...', timeout=60)
|
|
|
|
dut.expect('#0 app key digest == #0 trusted key digest', timeout=10)
|
|
|
|
dut.expect('Verifying with RSA-PSS...', timeout=10)
|
|
|
|
dut.expect('Signature verified successfully!', timeout=10)
|
2022-07-06 12:34:06 -04:00
|
|
|
dut.expect('OTA Succeed, Rebooting...', timeout=60)
|
|
|
|
# after reboot
|
2024-07-05 05:40:41 -04:00
|
|
|
dut.expect(f'Loaded app from partition at offset {OTA2_ADDRESS}', timeout=20)
|
2022-07-06 12:34:06 -04:00
|
|
|
dut.expect('OTA example app_main start', timeout=10)
|
2022-06-21 07:34:40 -04:00
|
|
|
finally:
|
2021-11-10 03:24:21 -05:00
|
|
|
thread1.terminate()
|
2021-03-15 11:59:56 -04:00
|
|
|
|
|
|
|
|
2023-07-18 06:37:33 -04:00
|
|
|
@pytest.mark.esp32
|
|
|
|
@pytest.mark.ethernet_ota
|
|
|
|
@pytest.mark.parametrize('config', ['tls1_3',], indirect=True)
|
|
|
|
def test_examples_protocol_simple_ota_example_tls1_3(dut: Dut) -> None:
|
|
|
|
"""
|
|
|
|
steps: |
|
|
|
|
1. join AP/Ethernet
|
|
|
|
2. Fetch OTA image over HTTPS
|
|
|
|
3. Reboot with the new OTA image
|
|
|
|
"""
|
|
|
|
sha256_bootloader, sha256_app = calc_all_sha256(dut)
|
|
|
|
# Start server
|
|
|
|
tls1_3_server = start_tls1_3_server(dut.app.binary_path, 8000)
|
|
|
|
try:
|
|
|
|
# start test
|
2024-07-05 05:40:41 -04:00
|
|
|
dut.expect(f'Loaded app from partition at offset {OTA1_ADDRESS}', timeout=30)
|
2023-07-18 06:37:33 -04:00
|
|
|
check_sha256(sha256_bootloader, str(dut.expect(r'SHA-256 for bootloader:\s+([a-f0-9]){64}')[0]))
|
|
|
|
check_sha256(sha256_app, str(dut.expect(r'SHA-256 for current firmware:\s+([a-f0-9]){64}')[0]))
|
|
|
|
# Parse IP address of STA
|
|
|
|
if dut.app.sdkconfig.get('EXAMPLE_WIFI_SSID_PWD_FROM_STDIN') is True:
|
|
|
|
env_name = 'wifi_high_traffic'
|
|
|
|
dut.expect('Please input ssid password:')
|
|
|
|
ap_ssid = get_env_config_variable(env_name, 'ap_ssid')
|
|
|
|
ap_password = get_env_config_variable(env_name, 'ap_password')
|
|
|
|
dut.write(f'{ap_ssid} {ap_password}')
|
|
|
|
try:
|
|
|
|
ip_address = dut.expect(r'IPv4 address: (\d+\.\d+\.\d+\.\d+)[^\d]', timeout=30)[1].decode()
|
|
|
|
print('Connected to AP/Ethernet with IP: {}'.format(ip_address))
|
|
|
|
except pexpect.exceptions.TIMEOUT:
|
|
|
|
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP/Ethernet')
|
|
|
|
host_ip = get_host_ip4_by_dest_ip(ip_address)
|
|
|
|
|
|
|
|
dut.expect('Starting OTA example task', timeout=30)
|
|
|
|
print('writing to device: {}'.format('https://' + host_ip + ':8000/simple_ota.bin'))
|
|
|
|
dut.write('https://' + host_ip + ':8000/simple_ota.bin')
|
|
|
|
dut.expect('OTA Succeed, Rebooting...', timeout=120)
|
|
|
|
# after reboot
|
2024-07-05 05:40:41 -04:00
|
|
|
dut.expect(f'Loaded app from partition at offset {OTA2_ADDRESS}', timeout=30)
|
2023-07-18 06:37:33 -04:00
|
|
|
dut.expect('OTA example app_main start', timeout=10)
|
|
|
|
finally:
|
|
|
|
tls1_3_server.kill()
|
|
|
|
|
|
|
|
|
2019-06-10 05:13:24 -04:00
|
|
|
if __name__ == '__main__':
|
2021-03-02 08:58:11 -05:00
|
|
|
if sys.argv[2:]: # if two or more arguments provided:
|
2023-08-01 05:17:51 -04:00
|
|
|
# Usage: pytest_simple_ota.py <image_dir> <server_port> [cert_di>]
|
2021-03-02 08:58:11 -05:00
|
|
|
this_dir = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
bin_dir = os.path.join(this_dir, sys.argv[1])
|
|
|
|
port = int(sys.argv[2])
|
|
|
|
cert_dir = bin_dir if not sys.argv[3:] else os.path.join(this_dir, sys.argv[3]) # optional argument
|
|
|
|
print('Starting HTTPS server at "https://:{}"'.format(port))
|
|
|
|
start_https_server(bin_dir, '', port,
|
|
|
|
server_file=os.path.join(cert_dir, 'ca_cert.pem'),
|
|
|
|
key_file=os.path.join(cert_dir, 'ca_key.pem'))
|