mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'bugfix/fix_ota_example_tests' into 'master'
Fix OTA example test to fix CI failures See merge request espressif/esp-idf!18690
This commit is contained in:
commit
495d35949d
@ -28,15 +28,6 @@ def get_my_ip() -> str:
|
||||
return my_ip
|
||||
|
||||
|
||||
def get_server_status(host_ip: str, port: int) -> bool:
|
||||
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
|
||||
|
||||
|
||||
def https_request_handler() -> Callable[...,http.server.BaseHTTPRequestHandler]:
|
||||
"""
|
||||
Returns a request handler class that handles broken pipe exception
|
||||
@ -123,18 +114,18 @@ def test_examples_protocol_advanced_https_ota_example(dut: Dut) -> None:
|
||||
2. Fetch OTA image over HTTPS
|
||||
3. Reboot with the new OTA image
|
||||
"""
|
||||
try:
|
||||
# Number of iterations to validate OTA
|
||||
iterations = 3
|
||||
server_port = 8001
|
||||
bin_name = 'advanced_https_ota.bin'
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, server_port))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
for i in range(iterations):
|
||||
dut.expect('Loaded app from partition at offset', timeout=30)
|
||||
dut.expect('Loaded app from partition at offset', timeout=60)
|
||||
try:
|
||||
ip_address = dut.expect(r' (sta|eth) ip: ([^,]+),', timeout=30)
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
@ -145,6 +136,7 @@ def test_examples_protocol_advanced_https_ota_example(dut: Dut) -> None:
|
||||
|
||||
print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port) + '/' + bin_name))
|
||||
dut.write('https://' + host_ip + ':' + str(server_port) + '/' + bin_name)
|
||||
finally:
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
@ -163,6 +155,7 @@ def test_examples_protocol_advanced_https_ota_example_truncated_bin(dut: Dut) ->
|
||||
3. Fetch OTA image over HTTPS
|
||||
4. Check working of code if bin is truncated
|
||||
"""
|
||||
try:
|
||||
server_port = 8001
|
||||
# Original binary file generated after compilation
|
||||
bin_name = 'advanced_https_ota.bin'
|
||||
@ -179,7 +172,6 @@ def test_examples_protocol_advanced_https_ota_example_truncated_bin(dut: Dut) ->
|
||||
binary_file = os.path.join(dut.app.binary_path, truncated_bin_name)
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, server_port))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
@ -199,6 +191,7 @@ def test_examples_protocol_advanced_https_ota_example_truncated_bin(dut: Dut) ->
|
||||
os.remove(binary_file)
|
||||
except OSError:
|
||||
pass
|
||||
finally:
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
@ -217,6 +210,7 @@ def test_examples_protocol_advanced_https_ota_example_truncated_header(dut: Dut)
|
||||
3. Fetch OTA image over HTTPS
|
||||
4. Check working of code if headers are not sent completely
|
||||
"""
|
||||
try:
|
||||
server_port = 8001
|
||||
# Original binary file generated after compilation
|
||||
bin_name = 'advanced_https_ota.bin'
|
||||
@ -233,7 +227,6 @@ def test_examples_protocol_advanced_https_ota_example_truncated_header(dut: Dut)
|
||||
binary_file = os.path.join(dut.app.binary_path, truncated_bin_name)
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, server_port))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
@ -253,6 +246,7 @@ def test_examples_protocol_advanced_https_ota_example_truncated_header(dut: Dut)
|
||||
os.remove(binary_file)
|
||||
except OSError:
|
||||
pass
|
||||
finally:
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
@ -271,6 +265,7 @@ def test_examples_protocol_advanced_https_ota_example_random(dut: Dut) -> None:
|
||||
3. Fetch OTA image over HTTPS
|
||||
4. Check working of code for random binary file
|
||||
"""
|
||||
try:
|
||||
server_port = 8001
|
||||
# Random binary file to be generated
|
||||
random_bin_name = 'random.bin'
|
||||
@ -287,7 +282,6 @@ def test_examples_protocol_advanced_https_ota_example_random(dut: Dut) -> None:
|
||||
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, server_port))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
@ -307,6 +301,7 @@ def test_examples_protocol_advanced_https_ota_example_random(dut: Dut) -> None:
|
||||
os.remove(binary_file)
|
||||
except OSError:
|
||||
pass
|
||||
finally:
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
@ -325,6 +320,7 @@ def test_examples_protocol_advanced_https_ota_example_invalid_chip_id(dut: Dut)
|
||||
3. Fetch OTA image over HTTPS
|
||||
4. Check working of code for random binary file
|
||||
"""
|
||||
try:
|
||||
server_port = 8001
|
||||
bin_name = 'advanced_https_ota.bin'
|
||||
# Random binary file to be generated
|
||||
@ -343,7 +339,6 @@ def test_examples_protocol_advanced_https_ota_example_invalid_chip_id(dut: Dut)
|
||||
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, server_port))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
@ -363,6 +358,7 @@ def test_examples_protocol_advanced_https_ota_example_invalid_chip_id(dut: Dut)
|
||||
os.remove(random_binary_file)
|
||||
except OSError:
|
||||
pass
|
||||
finally:
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
@ -385,18 +381,21 @@ def test_examples_protocol_advanced_https_ota_example_chunked(dut: Dut) -> None:
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
chunked_server = start_chunked_server(dut.app.binary_path, 8070)
|
||||
try:
|
||||
dut.expect('Loaded app from partition at offset', timeout=30)
|
||||
try:
|
||||
ip_address = dut.expect(r' (sta|eth) ip: ([^,]+),', timeout=30)
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except pexpect.exceptions.TIMEOUT:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
|
||||
dut.expect('Starting Advanced OTA example', timeout=30)
|
||||
|
||||
print('writing to device: {}'.format('https://' + host_ip + ':8070/' + bin_name))
|
||||
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)
|
||||
finally:
|
||||
chunked_server.kill()
|
||||
|
||||
|
||||
@ -415,6 +414,7 @@ def test_examples_protocol_advanced_https_ota_example_redirect_url(dut: Dut) ->
|
||||
2. Fetch OTA image over HTTPS
|
||||
3. Reboot with the new OTA image
|
||||
"""
|
||||
try:
|
||||
server_port = 8001
|
||||
# Port to which the request should be redirected
|
||||
redirection_server_port = 8081
|
||||
@ -423,7 +423,6 @@ def test_examples_protocol_advanced_https_ota_example_redirect_url(dut: Dut) ->
|
||||
bin_name = 'advanced_https_ota.bin'
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, server_port))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
@ -448,6 +447,7 @@ def test_examples_protocol_advanced_https_ota_example_redirect_url(dut: Dut) ->
|
||||
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)
|
||||
finally:
|
||||
thread1.terminate()
|
||||
thread2.terminate()
|
||||
thread3.terminate()
|
||||
@ -470,6 +470,7 @@ def test_examples_protocol_advanced_https_ota_example_anti_rollback(dut: Dut) ->
|
||||
3. Fetch OTA image over HTTPS
|
||||
4. Check working of anti_rollback feature
|
||||
"""
|
||||
try:
|
||||
dut.serial.erase_flash()
|
||||
dut.serial.flash()
|
||||
server_port = 8001
|
||||
@ -489,7 +490,6 @@ def test_examples_protocol_advanced_https_ota_example_anti_rollback(dut: Dut) ->
|
||||
binary_file = os.path.join(dut.app.binary_path, anti_rollback_bin_name)
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, server_port))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
@ -520,6 +520,7 @@ def test_examples_protocol_advanced_https_ota_example_anti_rollback(dut: Dut) ->
|
||||
os.remove(binary_file)
|
||||
except OSError:
|
||||
pass
|
||||
finally:
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
@ -537,6 +538,7 @@ def test_examples_protocol_advanced_https_ota_example_partial_request(dut: Dut)
|
||||
2. Fetch OTA image over HTTPS
|
||||
3. Reboot with the new OTA image
|
||||
"""
|
||||
try:
|
||||
server_port = 8001
|
||||
# Size of partial HTTP request
|
||||
request_size = 16384
|
||||
@ -547,7 +549,6 @@ def test_examples_protocol_advanced_https_ota_example_partial_request(dut: Dut)
|
||||
http_requests = int((bin_size / request_size) - 1)
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, server_port))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
@ -567,6 +568,7 @@ def test_examples_protocol_advanced_https_ota_example_partial_request(dut: Dut)
|
||||
dut.expect('Connection closed', timeout=60)
|
||||
dut.expect('Loaded app from partition at offset', timeout=60)
|
||||
dut.expect('Starting Advanced OTA example', timeout=30)
|
||||
finally:
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
@ -586,12 +588,12 @@ def test_examples_protocol_advanced_https_ota_example_nimble_gatts(dut: Dut) ->
|
||||
3. Fetch OTA image over HTTPS
|
||||
4. Reboot with the new OTA image
|
||||
"""
|
||||
try:
|
||||
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):
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, server_port))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
@ -610,6 +612,7 @@ def test_examples_protocol_advanced_https_ota_example_nimble_gatts(dut: Dut) ->
|
||||
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)
|
||||
finally:
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
@ -629,12 +632,12 @@ def test_examples_protocol_advanced_https_ota_example_bluedroid_gatts(dut: Dut)
|
||||
3. Fetch OTA image over HTTPS
|
||||
4. Reboot with the new OTA image
|
||||
"""
|
||||
try:
|
||||
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):
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, server_port))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
@ -654,6 +657,7 @@ def test_examples_protocol_advanced_https_ota_example_bluedroid_gatts(dut: Dut)
|
||||
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)
|
||||
finally:
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
@ -688,20 +692,23 @@ def test_examples_protocol_advanced_https_ota_example_openssl_aligned_bin(dut: D
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
chunked_server = start_chunked_server(dut.app.binary_path, 8070)
|
||||
try:
|
||||
dut.expect('Loaded app from partition at offset', timeout=30)
|
||||
try:
|
||||
ip_address = dut.expect(r' (sta|eth) ip: ([^,]+),', timeout=30)
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except pexpect.exceptions.TIMEOUT:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
|
||||
dut.expect('Starting Advanced OTA example', timeout=30)
|
||||
|
||||
print('writing to device: {}'.format('https://' + host_ip + ':8070/' + aligned_bin_name))
|
||||
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)
|
||||
chunked_server.kill()
|
||||
try:
|
||||
os.remove(aligned_bin_name)
|
||||
except OSError:
|
||||
pass
|
||||
finally:
|
||||
chunked_server.kill()
|
||||
|
@ -74,15 +74,6 @@ def get_my_ip() -> str:
|
||||
return my_ip
|
||||
|
||||
|
||||
def get_server_status(host_ip: str, port: int) -> bool:
|
||||
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
|
||||
|
||||
|
||||
def create_file(server_file: str, file_data: str) -> None:
|
||||
with open(server_file, 'w+') as file:
|
||||
file.write(file_data)
|
||||
@ -149,6 +140,7 @@ def test_examples_protocol_native_ota_example(dut: Dut) -> None:
|
||||
2. Fetch OTA image over HTTPS
|
||||
3. Reboot with the new OTA image
|
||||
"""
|
||||
try:
|
||||
server_port = 8002
|
||||
# No. of times working of application to be validated
|
||||
iterations = 3
|
||||
@ -156,7 +148,6 @@ def test_examples_protocol_native_ota_example(dut: Dut) -> None:
|
||||
bin_name = 'native_ota.bin'
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, server_port))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
@ -172,6 +163,7 @@ def test_examples_protocol_native_ota_example(dut: Dut) -> None:
|
||||
|
||||
print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port) + '/' + bin_name))
|
||||
dut.write('https://' + host_ip + ':' + str(server_port) + '/' + bin_name)
|
||||
finally:
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
@ -187,6 +179,7 @@ def test_examples_protocol_native_ota_example_truncated_bin(dut: Dut) -> None:
|
||||
3. Fetch OTA image over HTTPS
|
||||
4. Check working of code if bin is truncated
|
||||
"""
|
||||
try:
|
||||
server_port = 8002
|
||||
# Original binary file generated after compilation
|
||||
bin_name = 'native_ota.bin'
|
||||
@ -205,7 +198,6 @@ def test_examples_protocol_native_ota_example_truncated_bin(dut: Dut) -> None:
|
||||
binary_file = os.path.join(dut.app.binary_path, truncated_bin_name)
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, server_port))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
@ -222,6 +214,7 @@ def test_examples_protocol_native_ota_example_truncated_bin(dut: Dut) -> None:
|
||||
dut.write('https://' + host_ip + ':' + str(server_port) + '/' + truncated_bin_name)
|
||||
dut.expect('native_ota_example: Image validation failed, image is corrupted', timeout=20)
|
||||
os.remove(binary_file)
|
||||
finally:
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
@ -237,6 +230,7 @@ def test_examples_protocol_native_ota_example_truncated_header(dut: Dut) -> None
|
||||
3. Fetch OTA image over HTTPS
|
||||
4. Check working of code if headers are not sent completely
|
||||
"""
|
||||
try:
|
||||
server_port = 8002
|
||||
# Original binary file generated after compilation
|
||||
bin_name = 'native_ota.bin'
|
||||
@ -254,7 +248,6 @@ def test_examples_protocol_native_ota_example_truncated_header(dut: Dut) -> None
|
||||
binary_file = os.path.join(dut.app.binary_path, truncated_bin_name)
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, server_port))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
@ -271,6 +264,7 @@ def test_examples_protocol_native_ota_example_truncated_header(dut: Dut) -> None
|
||||
dut.write('https://' + host_ip + ':' + str(server_port) + '/' + truncated_bin_name)
|
||||
dut.expect('native_ota_example: received package is not fit len', timeout=20)
|
||||
os.remove(binary_file)
|
||||
finally:
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
@ -286,6 +280,7 @@ def test_examples_protocol_native_ota_example_random(dut: Dut) -> None:
|
||||
3. Fetch OTA image over HTTPS
|
||||
4. Check working of code for random binary file
|
||||
"""
|
||||
try:
|
||||
server_port = 8002
|
||||
# Random binary file to be generated
|
||||
random_bin_name = 'random.bin'
|
||||
@ -302,7 +297,6 @@ def test_examples_protocol_native_ota_example_random(dut: Dut) -> None:
|
||||
fo.close()
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, server_port))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
@ -319,6 +313,7 @@ def test_examples_protocol_native_ota_example_random(dut: Dut) -> None:
|
||||
dut.write('https://' + host_ip + ':' + str(server_port) + '/' + random_bin_name)
|
||||
dut.expect('esp_ota_ops: OTA image has invalid magic byte', timeout=20)
|
||||
os.remove(binary_file)
|
||||
finally:
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
@ -338,6 +333,7 @@ def test_examples_protocol_native_ota_example_chunked(dut: Dut) -> None:
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
chunked_server = start_chunked_server(dut.app.binary_path, 8070)
|
||||
try:
|
||||
dut.expect('Loaded app from partition at offset', timeout=30)
|
||||
try:
|
||||
ip_address = dut.expect(r' (sta|eth) ip: ([^,]+),', timeout=30)
|
||||
@ -350,6 +346,7 @@ def test_examples_protocol_native_ota_example_chunked(dut: Dut) -> None:
|
||||
dut.write('https://' + host_ip + ':8070/' + bin_name)
|
||||
dut.expect('Loaded app from partition at offset', timeout=60)
|
||||
dut.expect('Starting OTA example', timeout=30)
|
||||
chunked_server.kill()
|
||||
os.remove(os.path.join(dut.app.binary_path, 'server_cert.pem'))
|
||||
os.remove(os.path.join(dut.app.binary_path, 'server_key.pem'))
|
||||
finally:
|
||||
chunked_server.kill()
|
||||
|
@ -26,13 +26,6 @@ def get_my_ip() -> str:
|
||||
return my_ip
|
||||
|
||||
|
||||
def get_server_status(host_ip: str, port: int) -> bool:
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
server_status = sock.connect_ex((host_ip, port))
|
||||
sock.close()
|
||||
return server_status == 0
|
||||
|
||||
|
||||
def https_request_handler() -> Callable[...,http.server.BaseHTTPRequestHandler]:
|
||||
"""
|
||||
Returns a request handler class that handles broken pipe exception
|
||||
@ -73,10 +66,10 @@ def start_https_server(ota_image_dir: str, server_ip: str, server_port: int) ->
|
||||
@pytest.mark.esp32s3
|
||||
@pytest.mark.ethernet_ota
|
||||
def test_examples_protocol_pre_encrypted_ota_example(dut: Dut) -> None:
|
||||
try:
|
||||
server_port = 8001
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, server_port))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
@ -95,4 +88,5 @@ def test_examples_protocol_pre_encrypted_ota_example(dut: Dut) -> None:
|
||||
dut.expect('Magic Verified', timeout=30)
|
||||
dut.expect('Reading RSA private key', timeout=30)
|
||||
dut.expect('upgrade successful. Rebooting', timeout=30)
|
||||
finally:
|
||||
thread1.terminate()
|
||||
|
@ -72,15 +72,6 @@ def get_my_ip() -> str:
|
||||
return my_ip
|
||||
|
||||
|
||||
def get_server_status(host_ip: str, server_port: int) -> bool:
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
server_status = sock.connect_ex((host_ip, server_port))
|
||||
sock.close()
|
||||
if server_status == 0:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def start_https_server(ota_image_dir: str, server_ip: str, server_port: int, server_file: str = None, key_file: str = None) -> None:
|
||||
os.chdir(ota_image_dir)
|
||||
|
||||
@ -136,10 +127,10 @@ def test_examples_protocol_simple_ota_example(dut: Dut) -> None:
|
||||
2. Fetch OTA image over HTTPS
|
||||
3. Reboot with the new OTA image
|
||||
"""
|
||||
try:
|
||||
sha256_bootloader, sha256_app = calc_all_sha256(dut)
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, 8000) is False):
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, 8000))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
@ -158,6 +149,7 @@ def test_examples_protocol_simple_ota_example(dut: Dut) -> None:
|
||||
dut.write('https://' + host_ip + ':8000/simple_ota.bin')
|
||||
dut.expect('Loaded app from partition at offset 0x110000', timeout=60)
|
||||
dut.expect('Starting OTA example', timeout=30)
|
||||
finally:
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
@ -174,9 +166,9 @@ def test_examples_protocol_simple_ota_example_ethernet_with_spiram_config(dut: D
|
||||
2. Fetch OTA image over HTTPS
|
||||
3. Reboot with the new OTA image
|
||||
"""
|
||||
try:
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, 8000) is False):
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, 8000))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
@ -193,6 +185,7 @@ def test_examples_protocol_simple_ota_example_ethernet_with_spiram_config(dut: D
|
||||
dut.write('https://' + host_ip + ':8000/simple_ota.bin')
|
||||
dut.expect('Loaded app from partition at offset 0x110000', timeout=60)
|
||||
dut.expect('Starting OTA example', timeout=30)
|
||||
finally:
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
@ -210,12 +203,12 @@ def test_examples_protocol_simple_ota_example_with_flash_encryption(dut: Dut) ->
|
||||
2. Fetch OTA image over HTTPS
|
||||
3. Reboot with the new OTA image
|
||||
"""
|
||||
try:
|
||||
# Erase flash
|
||||
dut.serial.erase_flash()
|
||||
dut.serial.flash()
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, 8000) is False):
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, 8000))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
@ -234,6 +227,7 @@ def test_examples_protocol_simple_ota_example_with_flash_encryption(dut: Dut) ->
|
||||
dut.expect('Loaded app from partition at offset 0x120000', timeout=60)
|
||||
dut.expect('Flash encryption mode is DEVELOPMENT', timeout=10)
|
||||
dut.expect('Starting OTA example', timeout=30)
|
||||
finally:
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
@ -249,12 +243,12 @@ def test_examples_protocol_simple_ota_example_with_flash_encryption_wifi(dut: Du
|
||||
2. Fetch OTA image over HTTPS
|
||||
3. Reboot with the new OTA image
|
||||
"""
|
||||
try:
|
||||
# start test
|
||||
# Erase flash
|
||||
dut.serial.erase_flash()
|
||||
dut.serial.flash()
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, 8000) is False):
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, 8000))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
@ -273,6 +267,7 @@ def test_examples_protocol_simple_ota_example_with_flash_encryption_wifi(dut: Du
|
||||
dut.expect('Loaded app from partition at offset 0x120000', timeout=60)
|
||||
dut.expect('Flash encryption mode is DEVELOPMENT', timeout=10)
|
||||
dut.expect('Starting OTA example', timeout=30)
|
||||
finally:
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
@ -289,10 +284,10 @@ def test_examples_protocol_simple_ota_example_with_verify_app_signature_on_updat
|
||||
2. Fetch OTA image over HTTPS
|
||||
3. Reboot with the new OTA image
|
||||
"""
|
||||
try:
|
||||
sha256_bootloader, sha256_app = calc_all_sha256(dut)
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, 8000) is False):
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, 8000))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
@ -315,6 +310,7 @@ def test_examples_protocol_simple_ota_example_with_verify_app_signature_on_updat
|
||||
|
||||
dut.expect('Loaded app from partition at offset 0x120000', timeout=20)
|
||||
dut.expect('Starting OTA example', timeout=30)
|
||||
finally:
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
@ -331,10 +327,10 @@ def test_examples_protocol_simple_ota_example_with_verify_app_signature_on_updat
|
||||
2. Fetch OTA image over HTTPS
|
||||
3. Reboot with the new OTA image
|
||||
"""
|
||||
try:
|
||||
sha256_bootloader, sha256_app = calc_all_sha256(dut)
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, 8000) is False):
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut.app.binary_path, host_ip, 8000))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
@ -360,6 +356,7 @@ def test_examples_protocol_simple_ota_example_with_verify_app_signature_on_updat
|
||||
|
||||
dut.expect('Loaded app from partition at offset 0x120000', timeout=20)
|
||||
dut.expect('Starting OTA example', timeout=30)
|
||||
finally:
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user