2022-03-30 05:07:25 -04:00
|
|
|
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD
|
|
|
|
# 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-12-09 09:23:05 -05:00
|
|
|
import os
|
2021-01-25 21:49:01 -05:00
|
|
|
import random
|
2019-12-09 09:23:05 -05:00
|
|
|
import socket
|
|
|
|
import ssl
|
2021-01-25 21:49:01 -05:00
|
|
|
import struct
|
|
|
|
import subprocess
|
2022-03-30 05:07:25 -04:00
|
|
|
from typing import Callable
|
2019-12-09 09:23:05 -05:00
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
import pexpect
|
|
|
|
import pytest
|
|
|
|
from pytest_embedded import Dut
|
2021-02-02 02:56:27 -05:00
|
|
|
from RangeHTTPServer import RangeRequestHandler
|
2019-12-09 09:23:05 -05:00
|
|
|
|
2021-12-08 05:53:25 -05:00
|
|
|
server_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test_certs/server_cert.pem')
|
|
|
|
key_file = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test_certs/server_key.pem')
|
2019-12-09 09:23:05 -05:00
|
|
|
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
def get_my_ip() -> str:
|
2019-12-09 09:23:05 -05:00
|
|
|
s1 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
2021-01-25 21:49:01 -05:00
|
|
|
s1.connect(('8.8.8.8', 80))
|
2022-03-30 05:07:25 -04:00
|
|
|
my_ip = ''
|
2019-12-09 09:23:05 -05:00
|
|
|
my_ip = s1.getsockname()[0]
|
|
|
|
s1.close()
|
|
|
|
return my_ip
|
|
|
|
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
def get_server_status(host_ip: str, port: int) -> bool:
|
2020-02-13 03:13:58 -05:00
|
|
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
|
|
server_status = sock.connect_ex((host_ip, port))
|
|
|
|
sock.close()
|
|
|
|
if server_status == 0:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
def https_request_handler() -> Callable[...,http.server.BaseHTTPRequestHandler]:
|
2020-04-28 11:23:19 -04:00
|
|
|
"""
|
|
|
|
Returns a request handler class that handles broken pipe exception
|
|
|
|
"""
|
2021-02-02 02:56:27 -05:00
|
|
|
class RequestHandler(RangeRequestHandler):
|
2022-03-30 05:07:25 -04:00
|
|
|
def finish(self) -> None:
|
2020-04-28 11:23:19 -04:00
|
|
|
try:
|
|
|
|
if not self.wfile.closed:
|
|
|
|
self.wfile.flush()
|
|
|
|
self.wfile.close()
|
|
|
|
except socket.error:
|
|
|
|
pass
|
|
|
|
self.rfile.close()
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
def handle(self) -> None:
|
2020-04-28 11:23:19 -04:00
|
|
|
try:
|
2021-02-02 02:56:27 -05:00
|
|
|
RangeRequestHandler.handle(self)
|
2020-04-28 11:23:19 -04:00
|
|
|
except socket.error:
|
|
|
|
pass
|
|
|
|
|
|
|
|
return RequestHandler
|
|
|
|
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
def start_https_server(ota_image_dir: str, server_ip: str, server_port: int) -> None:
|
2021-12-08 05:53:25 -05:00
|
|
|
os.chdir(ota_image_dir)
|
2020-04-28 11:23:19 -04:00
|
|
|
requestHandler = https_request_handler()
|
2020-05-14 02:39:29 -04:00
|
|
|
httpd = http.server.HTTPServer((server_ip, server_port), requestHandler)
|
2019-12-09 09:23:05 -05:00
|
|
|
|
|
|
|
httpd.socket = ssl.wrap_socket(httpd.socket,
|
|
|
|
keyfile=key_file,
|
|
|
|
certfile=server_file, server_side=True)
|
|
|
|
httpd.serve_forever()
|
|
|
|
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
def start_chunked_server(ota_image_dir: str, server_port: int) -> subprocess.Popen:
|
2021-12-08 05:53:25 -05:00
|
|
|
os.chdir(ota_image_dir)
|
2021-01-25 21:49:01 -05:00
|
|
|
chunked_server = subprocess.Popen(['openssl', 's_server', '-WWW', '-key', key_file, '-cert', server_file, '-port', str(server_port)])
|
2020-02-13 03:13:58 -05:00
|
|
|
return chunked_server
|
|
|
|
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
def redirect_handler_factory(url: str) -> Callable[...,http.server.BaseHTTPRequestHandler]:
|
2020-02-13 03:13:58 -05:00
|
|
|
"""
|
|
|
|
Returns a request handler class that redirects to supplied `url`
|
|
|
|
"""
|
2020-05-14 02:39:29 -04:00
|
|
|
class RedirectHandler(http.server.SimpleHTTPRequestHandler):
|
2022-03-30 05:07:25 -04:00
|
|
|
def do_GET(self) -> None:
|
2021-01-25 21:49:01 -05:00
|
|
|
print('Sending resp, URL: ' + url)
|
2020-02-13 03:13:58 -05:00
|
|
|
self.send_response(301)
|
|
|
|
self.send_header('Location', url)
|
|
|
|
self.end_headers()
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
def handle(self) -> None:
|
2020-04-28 11:23:19 -04:00
|
|
|
try:
|
2020-05-14 02:39:29 -04:00
|
|
|
http.server.BaseHTTPRequestHandler.handle(self)
|
2020-04-28 11:23:19 -04:00
|
|
|
except socket.error:
|
|
|
|
pass
|
|
|
|
|
2020-02-13 03:13:58 -05:00
|
|
|
return RedirectHandler
|
|
|
|
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
def start_redirect_server(ota_image_dir: str, server_ip: str, server_port: int, redirection_port: int) -> None:
|
2020-01-27 07:03:36 -05:00
|
|
|
os.chdir(ota_image_dir)
|
2021-01-25 21:49:01 -05:00
|
|
|
redirectHandler = redirect_handler_factory('https://' + server_ip + ':' + str(redirection_port) + '/advanced_https_ota.bin')
|
2020-01-27 07:03:36 -05:00
|
|
|
|
2020-05-14 02:39:29 -04:00
|
|
|
httpd = http.server.HTTPServer((server_ip, server_port), redirectHandler)
|
2020-01-27 07:03:36 -05:00
|
|
|
|
2020-02-13 03:13:58 -05:00
|
|
|
httpd.socket = ssl.wrap_socket(httpd.socket,
|
|
|
|
keyfile=key_file,
|
|
|
|
certfile=server_file, server_side=True)
|
|
|
|
httpd.serve_forever()
|
2020-01-27 07:03:36 -05:00
|
|
|
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
@pytest.mark.esp32
|
|
|
|
@pytest.mark.esp32c3
|
|
|
|
@pytest.mark.esp32s2
|
|
|
|
@pytest.mark.esp32s3
|
|
|
|
@pytest.mark.ethernet_ota
|
|
|
|
def test_examples_protocol_advanced_https_ota_example(dut: Dut) -> None:
|
2019-12-09 09:23:05 -05:00
|
|
|
"""
|
|
|
|
This is a positive test case, which downloads complete binary file multiple number of times.
|
|
|
|
Number of iterations can be specified in variable iterations.
|
|
|
|
steps: |
|
|
|
|
1. join AP
|
|
|
|
2. Fetch OTA image over HTTPS
|
|
|
|
3. Reboot with the new OTA image
|
|
|
|
"""
|
|
|
|
# Number of iterations to validate OTA
|
|
|
|
iterations = 3
|
2020-02-13 03:13:58 -05:00
|
|
|
server_port = 8001
|
2021-01-25 21:49:01 -05:00
|
|
|
bin_name = 'advanced_https_ota.bin'
|
2019-12-09 09:23:05 -05:00
|
|
|
# start test
|
|
|
|
host_ip = get_my_ip()
|
2020-02-13 03:13:58 -05:00
|
|
|
if (get_server_status(host_ip, server_port) is False):
|
2022-03-30 05:07:25 -04:00
|
|
|
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, server_port))
|
2020-02-13 03:13:58 -05:00
|
|
|
thread1.daemon = True
|
|
|
|
thread1.start()
|
2019-12-09 09:23:05 -05:00
|
|
|
for i in range(iterations):
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.expect('Loaded app from partition at offset', timeout=30)
|
2019-12-09 09:23:05 -05:00
|
|
|
try:
|
2022-03-30 05:07:25 -04:00
|
|
|
ip_address = dut.expect(r' (sta|eth) ip: ([^,]+),', timeout=30)
|
2021-01-25 21:49:01 -05:00
|
|
|
print('Connected to AP with IP: {}'.format(ip_address))
|
2022-03-30 05:07:25 -04:00
|
|
|
except pexpect.exceptions.TIMEOUT:
|
2021-11-10 03:24:21 -05:00
|
|
|
thread1.terminate()
|
2021-12-17 04:57:14 -05:00
|
|
|
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.expect('Starting Advanced OTA example', timeout=30)
|
2019-12-09 09:23:05 -05:00
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port) + '/' + bin_name))
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.write('https://' + host_ip + ':' + str(server_port) + '/' + bin_name)
|
2021-11-10 03:24:21 -05:00
|
|
|
thread1.terminate()
|
2019-12-09 09:23:05 -05:00
|
|
|
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
@pytest.mark.esp32
|
|
|
|
@pytest.mark.esp32c3
|
|
|
|
@pytest.mark.esp32s2
|
|
|
|
@pytest.mark.esp32s3
|
|
|
|
@pytest.mark.ethernet_ota
|
|
|
|
def test_examples_protocol_advanced_https_ota_example_truncated_bin(dut: Dut) -> None:
|
2019-12-09 09:23:05 -05:00
|
|
|
"""
|
|
|
|
Working of OTA if binary file is truncated is validated in this test case.
|
|
|
|
Application should return with error message in this case.
|
|
|
|
steps: |
|
|
|
|
1. join AP
|
|
|
|
2. Generate truncated binary file
|
|
|
|
3. Fetch OTA image over HTTPS
|
|
|
|
4. Check working of code if bin is truncated
|
|
|
|
"""
|
2020-02-13 03:13:58 -05:00
|
|
|
server_port = 8001
|
2019-12-09 09:23:05 -05:00
|
|
|
# Original binary file generated after compilation
|
2021-01-25 21:49:01 -05:00
|
|
|
bin_name = 'advanced_https_ota.bin'
|
2019-12-09 09:23:05 -05:00
|
|
|
# Truncated binary file to be generated from original binary file
|
2021-01-25 21:49:01 -05:00
|
|
|
truncated_bin_name = 'truncated.bin'
|
2019-12-09 09:23:05 -05:00
|
|
|
# Size of truncated file to be grnerated. This value can range from 288 bytes (Image header size) to size of original binary file
|
|
|
|
# truncated_bin_size is set to 64000 to reduce consumed by the test case
|
|
|
|
truncated_bin_size = 64000
|
2022-03-30 05:07:25 -04:00
|
|
|
binary_file = os.path.join(dut.app.binary_path, bin_name)
|
2021-12-17 04:57:14 -05:00
|
|
|
with open(binary_file, 'rb+') as f:
|
2022-03-30 05:07:25 -04:00
|
|
|
with open(os.path.join(dut.app.binary_path, truncated_bin_name), 'wb+') as fo:
|
2021-12-17 04:57:14 -05:00
|
|
|
fo.write(f.read(truncated_bin_size))
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
binary_file = os.path.join(dut.app.binary_path, truncated_bin_name)
|
2019-12-09 09:23:05 -05:00
|
|
|
# start test
|
|
|
|
host_ip = get_my_ip()
|
2020-02-13 03:13:58 -05:00
|
|
|
if (get_server_status(host_ip, server_port) is False):
|
2022-03-30 05:07:25 -04:00
|
|
|
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, server_port))
|
2020-02-13 03:13:58 -05:00
|
|
|
thread1.daemon = True
|
|
|
|
thread1.start()
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.expect('Loaded app from partition at offset', timeout=30)
|
2019-12-09 09:23:05 -05:00
|
|
|
try:
|
2022-03-30 05:07:25 -04:00
|
|
|
ip_address = dut.expect(r' (sta|eth) ip: ([^,]+),', timeout=30)
|
2021-01-25 21:49:01 -05:00
|
|
|
print('Connected to AP with IP: {}'.format(ip_address))
|
2022-03-30 05:07:25 -04:00
|
|
|
except pexpect.exceptions.TIMEOUT:
|
2021-11-10 03:24:21 -05:00
|
|
|
thread1.terminate()
|
2021-12-17 04:57:14 -05:00
|
|
|
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.expect('Starting Advanced OTA example', timeout=30)
|
2019-12-09 09:23:05 -05:00
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port) + '/' + truncated_bin_name))
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.write('https://' + host_ip + ':' + str(server_port) + '/' + truncated_bin_name)
|
|
|
|
dut.expect('Image validation failed, image is corrupted', timeout=30)
|
2021-12-17 04:57:14 -05:00
|
|
|
try:
|
|
|
|
os.remove(binary_file)
|
|
|
|
except OSError:
|
|
|
|
pass
|
2021-11-10 03:24:21 -05:00
|
|
|
thread1.terminate()
|
2019-12-09 09:23:05 -05:00
|
|
|
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
@pytest.mark.esp32
|
|
|
|
@pytest.mark.esp32c3
|
|
|
|
@pytest.mark.esp32s2
|
|
|
|
@pytest.mark.esp32s3
|
|
|
|
@pytest.mark.ethernet_ota
|
|
|
|
def test_examples_protocol_advanced_https_ota_example_truncated_header(dut: Dut) -> None:
|
2019-12-09 09:23:05 -05:00
|
|
|
"""
|
|
|
|
Working of OTA if headers of binary file are truncated is vaildated in this test case.
|
|
|
|
Application should return with error message in this case.
|
|
|
|
steps: |
|
|
|
|
1. join AP
|
|
|
|
2. Generate binary file with truncated headers
|
|
|
|
3. Fetch OTA image over HTTPS
|
|
|
|
4. Check working of code if headers are not sent completely
|
|
|
|
"""
|
2020-02-13 03:13:58 -05:00
|
|
|
server_port = 8001
|
2019-12-09 09:23:05 -05:00
|
|
|
# Original binary file generated after compilation
|
2021-01-25 21:49:01 -05:00
|
|
|
bin_name = 'advanced_https_ota.bin'
|
2019-12-09 09:23:05 -05:00
|
|
|
# Truncated binary file to be generated from original binary file
|
2021-01-25 21:49:01 -05:00
|
|
|
truncated_bin_name = 'truncated_header.bin'
|
2022-03-30 05:07:25 -04:00
|
|
|
# Size of truncated file to be generated. This value should be less than 288 bytes (Image header size)
|
2019-12-09 09:23:05 -05:00
|
|
|
truncated_bin_size = 180
|
|
|
|
# check and log bin size
|
2022-03-30 05:07:25 -04:00
|
|
|
binary_file = os.path.join(dut.app.binary_path, bin_name)
|
2021-12-17 04:57:14 -05:00
|
|
|
with open(binary_file, 'rb+') as f:
|
2022-03-30 05:07:25 -04:00
|
|
|
with open(os.path.join(dut.app.binary_path, truncated_bin_name), 'wb+') as fo:
|
2021-12-17 04:57:14 -05:00
|
|
|
fo.write(f.read(truncated_bin_size))
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
binary_file = os.path.join(dut.app.binary_path, truncated_bin_name)
|
2019-12-09 09:23:05 -05:00
|
|
|
# start test
|
|
|
|
host_ip = get_my_ip()
|
2020-02-13 03:13:58 -05:00
|
|
|
if (get_server_status(host_ip, server_port) is False):
|
2022-03-30 05:07:25 -04:00
|
|
|
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, server_port))
|
2020-02-13 03:13:58 -05:00
|
|
|
thread1.daemon = True
|
|
|
|
thread1.start()
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.expect('Loaded app from partition at offset', timeout=30)
|
2019-12-09 09:23:05 -05:00
|
|
|
try:
|
2022-03-30 05:07:25 -04:00
|
|
|
ip_address = dut.expect(r' (sta|eth) ip: ([^,]+),', timeout=30)
|
2021-01-25 21:49:01 -05:00
|
|
|
print('Connected to AP with IP: {}'.format(ip_address))
|
2022-03-30 05:07:25 -04:00
|
|
|
except pexpect.exceptions.TIMEOUT:
|
2021-11-10 03:24:21 -05:00
|
|
|
thread1.terminate()
|
2021-12-17 04:57:14 -05:00
|
|
|
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.expect('Starting Advanced OTA example', timeout=30)
|
2019-12-09 09:23:05 -05:00
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port) + '/' + truncated_bin_name))
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.write('https://' + host_ip + ':' + str(server_port) + '/' + truncated_bin_name)
|
|
|
|
dut.expect('advanced_https_ota_example: esp_https_ota_read_img_desc failed', timeout=30)
|
2021-12-17 04:57:14 -05:00
|
|
|
try:
|
|
|
|
os.remove(binary_file)
|
|
|
|
except OSError:
|
|
|
|
pass
|
2021-11-10 03:24:21 -05:00
|
|
|
thread1.terminate()
|
2019-12-09 09:23:05 -05:00
|
|
|
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
@pytest.mark.esp32
|
|
|
|
@pytest.mark.esp32c3
|
|
|
|
@pytest.mark.esp32s2
|
|
|
|
@pytest.mark.esp32s3
|
|
|
|
@pytest.mark.ethernet_ota
|
|
|
|
def test_examples_protocol_advanced_https_ota_example_random(dut: Dut) -> None:
|
2019-12-09 09:23:05 -05:00
|
|
|
"""
|
|
|
|
Working of OTA if random data is added in binary file are validated in this test case.
|
|
|
|
Magic byte verification should fail in this case.
|
|
|
|
steps: |
|
|
|
|
1. join AP
|
|
|
|
2. Generate random binary image
|
|
|
|
3. Fetch OTA image over HTTPS
|
|
|
|
4. Check working of code for random binary file
|
|
|
|
"""
|
2020-02-13 03:13:58 -05:00
|
|
|
server_port = 8001
|
2019-12-09 09:23:05 -05:00
|
|
|
# Random binary file to be generated
|
2021-01-25 21:49:01 -05:00
|
|
|
random_bin_name = 'random.bin'
|
2019-12-09 09:23:05 -05:00
|
|
|
# Size of random binary file. 32000 is choosen, to reduce the time required to run the test-case
|
|
|
|
random_bin_size = 32000
|
|
|
|
# check and log bin size
|
2022-03-30 05:07:25 -04:00
|
|
|
binary_file = os.path.join(dut.app.binary_path, random_bin_name)
|
2021-12-17 04:57:14 -05:00
|
|
|
with open(binary_file, 'wb+') as fo:
|
|
|
|
# First byte of binary file is always set to zero. If first byte is generated randomly,
|
|
|
|
# in some cases it may generate 0xE9 which will result in failure of testcase.
|
|
|
|
fo.write(struct.pack('B', 0))
|
|
|
|
for i in range(random_bin_size - 1):
|
|
|
|
fo.write(struct.pack('B', random.randrange(0,255,1)))
|
|
|
|
|
2019-12-09 09:23:05 -05:00
|
|
|
# start test
|
|
|
|
host_ip = get_my_ip()
|
2020-02-13 03:13:58 -05:00
|
|
|
if (get_server_status(host_ip, server_port) is False):
|
2022-03-30 05:07:25 -04:00
|
|
|
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, server_port))
|
2020-02-13 03:13:58 -05:00
|
|
|
thread1.daemon = True
|
|
|
|
thread1.start()
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.expect('Loaded app from partition at offset', timeout=30)
|
2019-12-09 09:23:05 -05:00
|
|
|
try:
|
2022-03-30 05:07:25 -04:00
|
|
|
ip_address = dut.expect(r' (sta|eth) ip: ([^,]+),', timeout=30)
|
2021-01-25 21:49:01 -05:00
|
|
|
print('Connected to AP with IP: {}'.format(ip_address))
|
2022-03-30 05:07:25 -04:00
|
|
|
except pexpect.exceptions.TIMEOUT:
|
2021-12-17 04:57:14 -05:00
|
|
|
thread1.terminate()
|
2019-12-09 09:23:05 -05:00
|
|
|
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.expect('Starting Advanced OTA example', timeout=30)
|
2021-12-17 04:57:14 -05:00
|
|
|
|
|
|
|
print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port) + '/' + random_bin_name))
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.write('https://' + host_ip + ':' + str(server_port) + '/' + random_bin_name)
|
|
|
|
dut.expect(r'esp_https_ota: Incorrect app descriptor magic', timeout=10)
|
2021-12-17 04:57:14 -05:00
|
|
|
try:
|
|
|
|
os.remove(binary_file)
|
|
|
|
except OSError:
|
|
|
|
pass
|
|
|
|
thread1.terminate()
|
|
|
|
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
@pytest.mark.esp32
|
|
|
|
@pytest.mark.esp32c3
|
|
|
|
@pytest.mark.esp32s2
|
|
|
|
@pytest.mark.esp32s3
|
|
|
|
@pytest.mark.ethernet_ota
|
|
|
|
def test_examples_protocol_advanced_https_ota_example_invalid_chip_id(dut: Dut) -> None:
|
2021-12-17 04:57:14 -05:00
|
|
|
"""
|
|
|
|
Working of OTA if binary file have invalid chip id is validated in this test case.
|
|
|
|
Chip id verification should fail in this case.
|
|
|
|
steps: |
|
|
|
|
1. join AP
|
|
|
|
2. Generate binary image with invalid chip id
|
|
|
|
3. Fetch OTA image over HTTPS
|
|
|
|
4. Check working of code for random binary file
|
|
|
|
"""
|
|
|
|
server_port = 8001
|
|
|
|
bin_name = 'advanced_https_ota.bin'
|
|
|
|
# Random binary file to be generated
|
|
|
|
random_bin_name = 'random.bin'
|
2022-03-30 05:07:25 -04:00
|
|
|
random_binary_file = os.path.join(dut.app.binary_path, random_bin_name)
|
2021-12-17 04:57:14 -05:00
|
|
|
# Size of random binary file. 2000 is choosen, to reduce the time required to run the test-case
|
|
|
|
random_bin_size = 2000
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
binary_file = os.path.join(dut.app.binary_path, bin_name)
|
2021-12-17 04:57:14 -05:00
|
|
|
with open(binary_file, 'rb+') as f:
|
|
|
|
data = list(f.read(random_bin_size))
|
|
|
|
# Changing Chip id
|
|
|
|
data[13] = 0xfe
|
|
|
|
with open(random_binary_file, 'wb+') as fo:
|
|
|
|
fo.write(bytearray(data))
|
|
|
|
|
|
|
|
# start test
|
|
|
|
host_ip = get_my_ip()
|
|
|
|
if (get_server_status(host_ip, server_port) is False):
|
2022-03-30 05:07:25 -04:00
|
|
|
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, server_port))
|
2021-12-17 04:57:14 -05:00
|
|
|
thread1.daemon = True
|
|
|
|
thread1.start()
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.expect('Loaded app from partition at offset', timeout=30)
|
2021-12-17 04:57:14 -05:00
|
|
|
try:
|
2022-03-30 05:07:25 -04:00
|
|
|
ip_address = dut.expect(r' (sta|eth) ip: ([^,]+),', timeout=30)
|
2021-12-17 04:57:14 -05:00
|
|
|
print('Connected to AP with IP: {}'.format(ip_address))
|
2022-03-30 05:07:25 -04:00
|
|
|
except pexpect.exceptions.TIMEOUT:
|
2021-11-10 03:24:21 -05:00
|
|
|
thread1.terminate()
|
2021-12-17 04:57:14 -05:00
|
|
|
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.expect('Starting Advanced OTA example', timeout=30)
|
2019-12-09 09:23:05 -05:00
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port) + '/' + random_bin_name))
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.write('https://' + host_ip + ':' + str(server_port) + '/' + random_bin_name)
|
|
|
|
dut.expect(r'esp_https_ota: Mismatch chip id, expected 0, found \d', timeout=10)
|
2021-12-17 04:57:14 -05:00
|
|
|
try:
|
|
|
|
os.remove(random_binary_file)
|
|
|
|
except OSError:
|
|
|
|
pass
|
2021-11-10 03:24:21 -05:00
|
|
|
thread1.terminate()
|
2020-01-27 07:03:36 -05:00
|
|
|
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
@pytest.mark.esp32
|
|
|
|
@pytest.mark.esp32c3
|
|
|
|
@pytest.mark.esp32s2
|
|
|
|
@pytest.mark.esp32s3
|
|
|
|
@pytest.mark.ethernet_ota
|
|
|
|
def test_examples_protocol_advanced_https_ota_example_chunked(dut: Dut) -> None:
|
2020-01-27 07:03:36 -05:00
|
|
|
"""
|
|
|
|
This is a positive test case, which downloads complete binary file multiple number of times.
|
|
|
|
Number of iterations can be specified in variable iterations.
|
|
|
|
steps: |
|
|
|
|
1. join AP
|
|
|
|
2. Fetch OTA image over HTTPS
|
|
|
|
3. Reboot with the new OTA image
|
|
|
|
"""
|
|
|
|
# File to be downloaded. This file is generated after compilation
|
2021-01-25 21:49:01 -05:00
|
|
|
bin_name = 'advanced_https_ota.bin'
|
2020-01-27 07:03:36 -05:00
|
|
|
# start test
|
|
|
|
host_ip = get_my_ip()
|
2022-03-30 05:07:25 -04:00
|
|
|
chunked_server = start_chunked_server(dut.app.binary_path, 8070)
|
|
|
|
dut.expect('Loaded app from partition at offset', timeout=30)
|
2020-01-27 07:03:36 -05:00
|
|
|
try:
|
2022-03-30 05:07:25 -04:00
|
|
|
ip_address = dut.expect(r' (sta|eth) ip: ([^,]+),', timeout=30)
|
2021-01-25 21:49:01 -05:00
|
|
|
print('Connected to AP with IP: {}'.format(ip_address))
|
2022-03-30 05:07:25 -04:00
|
|
|
except pexpect.exceptions.TIMEOUT:
|
2020-01-27 07:03:36 -05:00
|
|
|
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.expect('Starting Advanced OTA example', timeout=30)
|
2020-01-27 07:03:36 -05:00
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
print('writing to device: {}'.format('https://' + host_ip + ':8070/' + bin_name))
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.write('https://' + host_ip + ':8070/' + bin_name)
|
|
|
|
dut.expect('Loaded app from partition at offset', timeout=60)
|
|
|
|
dut.expect('Starting Advanced OTA example', timeout=30)
|
2020-01-27 07:03:36 -05:00
|
|
|
chunked_server.kill()
|
2019-12-09 09:23:05 -05:00
|
|
|
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
@pytest.mark.esp32
|
|
|
|
@pytest.mark.esp32c3
|
|
|
|
@pytest.mark.esp32s2
|
|
|
|
@pytest.mark.esp32s3
|
|
|
|
@pytest.mark.ethernet_ota
|
|
|
|
def test_examples_protocol_advanced_https_ota_example_redirect_url(dut: Dut) -> None:
|
2020-02-13 03:13:58 -05:00
|
|
|
"""
|
|
|
|
This is a positive test case, which starts a server and a redirection server.
|
|
|
|
Redirection server redirects http_request to different port
|
|
|
|
Number of iterations can be specified in variable iterations.
|
|
|
|
steps: |
|
|
|
|
1. join AP
|
|
|
|
2. Fetch OTA image over HTTPS
|
|
|
|
3. Reboot with the new OTA image
|
|
|
|
"""
|
|
|
|
server_port = 8001
|
2022-03-16 01:28:38 -04:00
|
|
|
# Port to which the request should be redirected
|
2020-02-13 03:13:58 -05:00
|
|
|
redirection_server_port = 8081
|
2022-03-16 01:28:38 -04:00
|
|
|
redirection_server_port1 = 8082
|
2020-02-13 03:13:58 -05:00
|
|
|
# File to be downloaded. This file is generated after compilation
|
2021-01-25 21:49:01 -05:00
|
|
|
bin_name = 'advanced_https_ota.bin'
|
2020-02-13 03:13:58 -05:00
|
|
|
# start test
|
|
|
|
host_ip = get_my_ip()
|
|
|
|
if (get_server_status(host_ip, server_port) is False):
|
2022-03-30 05:07:25 -04:00
|
|
|
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, server_port))
|
2020-02-13 03:13:58 -05:00
|
|
|
thread1.daemon = True
|
|
|
|
thread1.start()
|
2022-03-30 05:07:25 -04:00
|
|
|
thread2 = multiprocessing.Process(target=start_redirect_server, args=(dut.app.binary_path, host_ip, redirection_server_port, redirection_server_port1))
|
2020-02-13 03:13:58 -05:00
|
|
|
thread2.daemon = True
|
|
|
|
thread2.start()
|
2022-03-30 05:07:25 -04:00
|
|
|
thread3 = multiprocessing.Process(target=start_redirect_server, args=(dut.app.binary_path, host_ip, redirection_server_port1, server_port))
|
2022-03-16 01:28:38 -04:00
|
|
|
thread3.daemon = True
|
|
|
|
thread3.start()
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.expect('Loaded app from partition at offset', timeout=30)
|
2020-02-13 03:13:58 -05:00
|
|
|
try:
|
2022-03-30 05:07:25 -04:00
|
|
|
ip_address = dut.expect(r' (sta|eth) ip: ([^,]+),', timeout=30)
|
2021-01-25 21:49:01 -05:00
|
|
|
print('Connected to AP with IP: {}'.format(ip_address))
|
2022-03-30 05:07:25 -04:00
|
|
|
except pexpect.exceptions.TIMEOUT:
|
2021-11-10 03:24:21 -05:00
|
|
|
thread1.terminate()
|
|
|
|
thread2.terminate()
|
2022-03-16 01:28:38 -04:00
|
|
|
thread3.terminate()
|
2021-12-17 04:57:14 -05:00
|
|
|
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.expect('Starting Advanced OTA example', timeout=30)
|
2020-02-13 03:13:58 -05:00
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
print('writing to device: {}'.format('https://' + host_ip + ':' + str(redirection_server_port) + '/' + bin_name))
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.write('https://' + host_ip + ':' + str(redirection_server_port) + '/' + bin_name)
|
|
|
|
dut.expect('Loaded app from partition at offset', timeout=60)
|
|
|
|
dut.expect('Starting Advanced OTA example', timeout=30)
|
2021-11-10 03:24:21 -05:00
|
|
|
thread1.terminate()
|
|
|
|
thread2.terminate()
|
2022-03-16 01:28:38 -04:00
|
|
|
thread3.terminate()
|
2020-02-13 03:13:58 -05:00
|
|
|
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
@pytest.mark.esp32
|
|
|
|
@pytest.mark.esp32c3
|
|
|
|
@pytest.mark.esp32s2
|
|
|
|
@pytest.mark.esp32s3
|
|
|
|
@pytest.mark.ethernet_flash_8m
|
|
|
|
@pytest.mark.parametrize('config', ['anti_rollback',], indirect=True)
|
|
|
|
@pytest.mark.parametrize('skip_autoflash', ['y'], indirect=True)
|
|
|
|
def test_examples_protocol_advanced_https_ota_example_anti_rollback(dut: Dut) -> None:
|
2020-10-23 12:22:51 -04:00
|
|
|
"""
|
|
|
|
Working of OTA when anti_rollback is enabled and security version of new image is less than current one.
|
|
|
|
Application should return with error message in this case.
|
|
|
|
steps: |
|
|
|
|
1. join AP
|
|
|
|
2. Generate binary file with lower security version
|
|
|
|
3. Fetch OTA image over HTTPS
|
|
|
|
4. Check working of anti_rollback feature
|
|
|
|
"""
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.serial.erase_flash()
|
|
|
|
dut.serial.flash()
|
2020-10-23 12:22:51 -04:00
|
|
|
server_port = 8001
|
|
|
|
# Original binary file generated after compilation
|
2021-01-25 21:49:01 -05:00
|
|
|
bin_name = 'advanced_https_ota.bin'
|
2020-10-23 12:22:51 -04:00
|
|
|
# Modified firmware image to lower security version in its header. This is to enable negative test case
|
2021-01-25 21:49:01 -05:00
|
|
|
anti_rollback_bin_name = 'advanced_https_ota_lower_sec_version.bin'
|
2020-10-23 12:22:51 -04:00
|
|
|
# check and log bin size
|
2022-03-30 05:07:25 -04:00
|
|
|
binary_file = os.path.join(dut.app.binary_path, bin_name)
|
2020-10-23 12:22:51 -04:00
|
|
|
file_size = os.path.getsize(binary_file)
|
2021-12-17 04:57:14 -05:00
|
|
|
with open(binary_file, 'rb+') as f:
|
2022-03-30 05:07:25 -04:00
|
|
|
with open(os.path.join(dut.app.binary_path, anti_rollback_bin_name), 'wb+') as fo:
|
2021-12-17 04:57:14 -05:00
|
|
|
fo.write(f.read(file_size))
|
|
|
|
# Change security_version to 0 for negative test case
|
|
|
|
fo.seek(36)
|
|
|
|
fo.write(b'\x00')
|
2022-03-30 05:07:25 -04:00
|
|
|
binary_file = os.path.join(dut.app.binary_path, anti_rollback_bin_name)
|
2020-10-23 12:22:51 -04:00
|
|
|
# start test
|
|
|
|
host_ip = get_my_ip()
|
|
|
|
if (get_server_status(host_ip, server_port) is False):
|
2022-03-30 05:07:25 -04:00
|
|
|
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, server_port))
|
2020-10-23 12:22:51 -04:00
|
|
|
thread1.daemon = True
|
|
|
|
thread1.start()
|
|
|
|
# Positive Case
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.expect('Loaded app from partition at offset', timeout=30)
|
2020-10-23 12:22:51 -04:00
|
|
|
try:
|
2022-03-30 05:07:25 -04:00
|
|
|
ip_address = dut.expect(r' (sta|eth) ip: ([^,]+),', timeout=30)
|
2021-01-25 21:49:01 -05:00
|
|
|
print('Connected to AP with IP: {}'.format(ip_address))
|
2022-03-30 05:07:25 -04:00
|
|
|
except pexpect.exceptions.TIMEOUT:
|
2021-11-10 03:24:21 -05:00
|
|
|
thread1.terminate()
|
2021-12-17 04:57:14 -05:00
|
|
|
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.expect('Starting Advanced OTA example', timeout=30)
|
2020-10-23 12:22:51 -04:00
|
|
|
|
|
|
|
# Use originally generated image with secure_version=1
|
2021-01-25 21:49:01 -05:00
|
|
|
print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port) + '/' + bin_name))
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.write('https://' + host_ip + ':' + str(server_port) + '/' + bin_name)
|
|
|
|
dut.expect('Loaded app from partition at offset', timeout=60)
|
|
|
|
dut.expect(r' (sta|eth) ip: ([^,]+),', timeout=30)
|
|
|
|
dut.expect(r'App is valid, rollback cancelled successfully', timeout=30)
|
2020-10-23 12:22:51 -04:00
|
|
|
|
|
|
|
# Negative Case
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.expect('Starting Advanced OTA example', timeout=30)
|
2020-10-23 12:22:51 -04:00
|
|
|
# Use modified image with secure_version=0
|
2021-01-25 21:49:01 -05:00
|
|
|
print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port) + '/' + anti_rollback_bin_name))
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.write('https://' + host_ip + ':' + str(server_port) + '/' + anti_rollback_bin_name)
|
|
|
|
dut.expect('New firmware security version is less than eFuse programmed, 0 < 1', timeout=30)
|
2021-12-17 04:57:14 -05:00
|
|
|
try:
|
|
|
|
os.remove(binary_file)
|
|
|
|
except OSError:
|
|
|
|
pass
|
2021-11-10 03:24:21 -05:00
|
|
|
thread1.terminate()
|
2020-10-23 12:22:51 -04:00
|
|
|
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
@pytest.mark.esp32
|
|
|
|
@pytest.mark.esp32c3
|
|
|
|
@pytest.mark.esp32s2
|
|
|
|
@pytest.mark.esp32s3
|
|
|
|
@pytest.mark.ethernet_ota
|
|
|
|
@pytest.mark.parametrize('config', ['partial_download',], indirect=True)
|
|
|
|
def test_examples_protocol_advanced_https_ota_example_partial_request(dut: Dut) -> None:
|
2021-02-02 02:56:27 -05:00
|
|
|
"""
|
|
|
|
This is a positive test case, to test OTA workflow with Range HTTP header.
|
|
|
|
steps: |
|
|
|
|
1. join AP
|
|
|
|
2. Fetch OTA image over HTTPS
|
|
|
|
3. Reboot with the new OTA image
|
|
|
|
"""
|
|
|
|
server_port = 8001
|
2021-08-19 02:21:39 -04:00
|
|
|
# Size of partial HTTP request
|
|
|
|
request_size = 16384
|
2021-02-02 02:56:27 -05:00
|
|
|
# File to be downloaded. This file is generated after compilation
|
|
|
|
bin_name = 'advanced_https_ota.bin'
|
2022-03-30 05:07:25 -04:00
|
|
|
binary_file = os.path.join(dut.app.binary_path, bin_name)
|
2021-02-02 02:56:27 -05:00
|
|
|
bin_size = os.path.getsize(binary_file)
|
2021-08-19 02:21:39 -04:00
|
|
|
http_requests = int((bin_size / request_size) - 1)
|
2021-02-02 02:56:27 -05:00
|
|
|
# start test
|
|
|
|
host_ip = get_my_ip()
|
|
|
|
if (get_server_status(host_ip, server_port) is False):
|
2022-03-30 05:07:25 -04:00
|
|
|
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, server_port))
|
2021-02-02 02:56:27 -05:00
|
|
|
thread1.daemon = True
|
|
|
|
thread1.start()
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.expect('Loaded app from partition at offset', timeout=30)
|
2021-02-02 02:56:27 -05:00
|
|
|
try:
|
2022-03-30 05:07:25 -04:00
|
|
|
ip_address = dut.expect(r' (sta|eth) ip: ([^,]+),', timeout=30)
|
2021-02-02 02:56:27 -05:00
|
|
|
print('Connected to AP with IP: {}'.format(ip_address))
|
2022-03-30 05:07:25 -04:00
|
|
|
except pexpect.exceptions.TIMEOUT:
|
|
|
|
print('ENV_TEST_FAILURE: Cannot connect to AP')
|
2021-11-10 03:24:21 -05:00
|
|
|
thread1.terminate()
|
2021-12-17 04:57:14 -05:00
|
|
|
raise
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.expect('Starting Advanced OTA example', timeout=30)
|
2021-02-02 02:56:27 -05:00
|
|
|
|
|
|
|
print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port) + '/' + bin_name))
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.write('https://' + host_ip + ':' + str(server_port) + '/' + bin_name)
|
2021-02-02 02:56:27 -05:00
|
|
|
for _ in range(http_requests):
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.expect('Connection closed', timeout=60)
|
|
|
|
dut.expect('Loaded app from partition at offset', timeout=60)
|
|
|
|
dut.expect('Starting Advanced OTA example', timeout=30)
|
2021-11-10 03:24:21 -05:00
|
|
|
thread1.terminate()
|
2021-02-02 02:56:27 -05:00
|
|
|
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
@pytest.mark.esp32
|
|
|
|
@pytest.mark.esp32c3
|
|
|
|
@pytest.mark.esp32s2
|
|
|
|
@pytest.mark.esp32s3
|
|
|
|
@pytest.mark.wifi_ota
|
|
|
|
@pytest.mark.parametrize('config', ['nimble',], indirect=True)
|
2022-07-01 02:15:50 -04:00
|
|
|
@pytest.mark.xfail(run=False)
|
2022-03-30 05:07:25 -04:00
|
|
|
def test_examples_protocol_advanced_https_ota_example_nimble_gatts(dut: Dut) -> None:
|
2021-03-02 05:30:49 -05:00
|
|
|
"""
|
|
|
|
Run an OTA image update while a BLE GATT Server is running in background. This GATT server will be using NimBLE Host stack.
|
|
|
|
steps: |
|
|
|
|
1. join AP
|
|
|
|
2. Run BLE advertise and then GATT server.
|
|
|
|
3. Fetch OTA image over HTTPS
|
|
|
|
4. Reboot with the new OTA image
|
|
|
|
"""
|
|
|
|
server_port = 8001
|
|
|
|
# File to be downloaded. This file is generated after compilation
|
|
|
|
bin_name = 'advanced_https_ota.bin'
|
|
|
|
# start test
|
|
|
|
host_ip = get_my_ip()
|
|
|
|
if (get_server_status(host_ip, server_port) is False):
|
2022-03-30 05:07:25 -04:00
|
|
|
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, server_port))
|
2021-03-02 05:30:49 -05:00
|
|
|
thread1.daemon = True
|
|
|
|
thread1.start()
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.expect('Loaded app from partition at offset', timeout=30)
|
2021-03-02 05:30:49 -05:00
|
|
|
try:
|
2022-03-30 05:07:25 -04:00
|
|
|
ip_address = dut.expect(r' sta ip: ([^,]+),', timeout=30)
|
2021-03-02 05:30:49 -05:00
|
|
|
print('Connected to AP with IP: {}'.format(ip_address))
|
2022-03-30 05:07:25 -04:00
|
|
|
except pexpect.exceptions.TIMEOUT:
|
2021-11-10 03:24:21 -05:00
|
|
|
thread1.terminate()
|
2021-12-17 04:57:14 -05:00
|
|
|
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
2021-03-02 05:30:49 -05:00
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.expect('Starting Advanced OTA example', timeout=30)
|
2021-03-02 05:30:49 -05:00
|
|
|
print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port) + '/' + bin_name))
|
|
|
|
print('Started GAP advertising.')
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.write('https://' + host_ip + ':' + str(server_port) + '/' + bin_name)
|
|
|
|
dut.expect('Loaded app from partition at offset', timeout=60)
|
|
|
|
dut.expect('Starting Advanced OTA example', timeout=30)
|
2021-11-10 03:24:21 -05:00
|
|
|
thread1.terminate()
|
2021-03-02 05:30:49 -05:00
|
|
|
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
@pytest.mark.esp32
|
|
|
|
@pytest.mark.esp32c3
|
|
|
|
@pytest.mark.esp32s2
|
|
|
|
@pytest.mark.esp32s3
|
|
|
|
@pytest.mark.wifi_ota
|
|
|
|
@pytest.mark.parametrize('config', ['bluedroid',], indirect=True)
|
2022-07-01 02:15:50 -04:00
|
|
|
@pytest.mark.xfail(run=False)
|
2022-03-30 05:07:25 -04:00
|
|
|
def test_examples_protocol_advanced_https_ota_example_bluedroid_gatts(dut: Dut) -> None:
|
2021-03-02 05:30:49 -05:00
|
|
|
"""
|
|
|
|
Run an OTA image update while a BLE GATT Server is running in background. This GATT server will be using Bluedroid Host stack.
|
|
|
|
steps: |
|
|
|
|
1. join AP
|
|
|
|
2. Run BLE advertise and then GATT server.
|
|
|
|
3. Fetch OTA image over HTTPS
|
|
|
|
4. Reboot with the new OTA image
|
|
|
|
"""
|
|
|
|
server_port = 8001
|
|
|
|
# File to be downloaded. This file is generated after compilation
|
|
|
|
bin_name = 'advanced_https_ota.bin'
|
|
|
|
# start test
|
|
|
|
host_ip = get_my_ip()
|
|
|
|
if (get_server_status(host_ip, server_port) is False):
|
2022-03-30 05:07:25 -04:00
|
|
|
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, server_port))
|
2021-03-02 05:30:49 -05:00
|
|
|
thread1.daemon = True
|
|
|
|
thread1.start()
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.expect('Loaded app from partition at offset', timeout=30)
|
2021-03-02 05:30:49 -05:00
|
|
|
try:
|
2022-03-30 05:07:25 -04:00
|
|
|
ip_address = dut.expect(r' sta ip: ([^,]+),', timeout=30)
|
2021-03-02 05:30:49 -05:00
|
|
|
print('Connected to AP with IP: {}'.format(ip_address))
|
2022-03-30 05:07:25 -04:00
|
|
|
except pexpect.exceptions.TIMEOUT:
|
2021-11-10 03:24:21 -05:00
|
|
|
thread1.terminate()
|
2021-12-17 04:57:14 -05:00
|
|
|
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
2021-03-02 05:30:49 -05:00
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.expect('Starting Advanced OTA example', timeout=30)
|
2021-03-02 05:30:49 -05:00
|
|
|
print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port) + '/' + bin_name))
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.expect('Started advertising.', timeout=30)
|
2021-03-02 05:30:49 -05:00
|
|
|
print('Started GAP advertising.')
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.write('https://' + host_ip + ':' + str(server_port) + '/' + bin_name)
|
|
|
|
dut.expect('Loaded app from partition at offset', timeout=60)
|
|
|
|
dut.expect('Starting Advanced OTA example', timeout=30)
|
2021-11-10 03:24:21 -05:00
|
|
|
thread1.terminate()
|
2021-03-02 05:30:49 -05:00
|
|
|
|
|
|
|
|
2022-03-30 05:07:25 -04:00
|
|
|
@pytest.mark.esp32
|
|
|
|
@pytest.mark.esp32c3
|
|
|
|
@pytest.mark.esp32s2
|
|
|
|
@pytest.mark.esp32s3
|
|
|
|
@pytest.mark.ethernet_ota
|
|
|
|
def test_examples_protocol_advanced_https_ota_example_openssl_aligned_bin(dut: Dut) -> None:
|
2021-04-19 03:17:06 -04:00
|
|
|
"""
|
|
|
|
This is a test case for esp_http_client_read with binary size multiple of 289 bytes
|
|
|
|
steps: |
|
|
|
|
1. join AP
|
|
|
|
2. Fetch OTA image over HTTPS
|
|
|
|
3. Reboot with the new OTA image
|
|
|
|
"""
|
|
|
|
# Original binary file generated after compilation
|
|
|
|
bin_name = 'advanced_https_ota.bin'
|
|
|
|
# Binary file aligned to DEFAULT_OTA_BUF_SIZE(289 bytes) boundary
|
|
|
|
aligned_bin_name = 'aligned.bin'
|
|
|
|
# check and log bin size
|
2022-03-30 05:07:25 -04:00
|
|
|
binary_file = os.path.join(dut.app.binary_path, bin_name)
|
2021-04-19 03:17:06 -04:00
|
|
|
# Original binary size
|
|
|
|
bin_size = os.path.getsize(binary_file)
|
|
|
|
# Dummy data required to align binary size to 289 bytes boundary
|
|
|
|
dummy_data_size = 289 - (bin_size % 289)
|
2021-12-17 04:57:14 -05:00
|
|
|
with open(binary_file, 'rb+') as f:
|
2022-03-30 05:07:25 -04:00
|
|
|
with open(os.path.join(dut.app.binary_path, aligned_bin_name), 'wb+') as fo:
|
2021-12-17 04:57:14 -05:00
|
|
|
fo.write(f.read(bin_size))
|
|
|
|
for _ in range(dummy_data_size):
|
|
|
|
fo.write(struct.pack('B', random.randrange(0,255,1)))
|
2021-04-19 03:17:06 -04:00
|
|
|
# start test
|
|
|
|
host_ip = get_my_ip()
|
2022-03-30 05:07:25 -04:00
|
|
|
chunked_server = start_chunked_server(dut.app.binary_path, 8070)
|
|
|
|
dut.expect('Loaded app from partition at offset', timeout=30)
|
2021-04-19 03:17:06 -04:00
|
|
|
try:
|
2022-03-30 05:07:25 -04:00
|
|
|
ip_address = dut.expect(r' (sta|eth) ip: ([^,]+),', timeout=30)
|
2021-04-19 03:17:06 -04:00
|
|
|
print('Connected to AP with IP: {}'.format(ip_address))
|
2022-03-30 05:07:25 -04:00
|
|
|
except pexpect.exceptions.TIMEOUT:
|
2021-04-19 03:17:06 -04:00
|
|
|
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.expect('Starting Advanced OTA example', timeout=30)
|
2021-04-19 03:17:06 -04:00
|
|
|
|
|
|
|
print('writing to device: {}'.format('https://' + host_ip + ':8070/' + aligned_bin_name))
|
2022-03-30 05:07:25 -04:00
|
|
|
dut.write('https://' + host_ip + ':8070/' + aligned_bin_name)
|
|
|
|
dut.expect('Loaded app from partition at offset', timeout=60)
|
|
|
|
dut.expect('Starting Advanced OTA example', timeout=30)
|
2021-04-19 03:17:06 -04:00
|
|
|
chunked_server.kill()
|
2021-12-17 04:57:14 -05:00
|
|
|
try:
|
|
|
|
os.remove(aligned_bin_name)
|
|
|
|
except OSError:
|
|
|
|
pass
|