mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-10 20:54:24 +00:00
Fix 'address already in use' exception in OTA tests
We will stop the server instance at the end of each test case. This will solve the "address already in use" exception
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import http.server
|
||||
import multiprocessing
|
||||
import os
|
||||
import random
|
||||
import re
|
||||
@@ -6,7 +7,6 @@ import socket
|
||||
import ssl
|
||||
import struct
|
||||
import subprocess
|
||||
from threading import Thread
|
||||
|
||||
import ttfw_idf
|
||||
from RangeHTTPServer import RangeRequestHandler
|
||||
@@ -191,7 +191,7 @@ def test_examples_protocol_advanced_https_ota_example(env, extra_data):
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
thread1 = Thread(target=start_https_server, args=(dut1.app.binary_path, host_ip, server_port))
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut1.app.binary_path, host_ip, server_port))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
dut1.start_app()
|
||||
@@ -202,7 +202,7 @@ def test_examples_protocol_advanced_https_ota_example(env, extra_data):
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except DUT.ExpectTimeout:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
thread1.close()
|
||||
thread1.terminate()
|
||||
dut1.expect('Starting Advanced OTA example', timeout=30)
|
||||
|
||||
print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port) + '/' + bin_name))
|
||||
@@ -210,6 +210,7 @@ def test_examples_protocol_advanced_https_ota_example(env, extra_data):
|
||||
dut1.expect('Loaded app from partition at offset', timeout=60)
|
||||
dut1.expect('Starting Advanced OTA example', timeout=30)
|
||||
dut1.reset()
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag='EXAMPLE_ETH_OTA')
|
||||
@@ -245,7 +246,7 @@ def test_examples_protocol_advanced_https_ota_example_truncated_bin(env, extra_d
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
thread1 = Thread(target=start_https_server, args=(dut1.app.binary_path, host_ip, server_port))
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut1.app.binary_path, host_ip, server_port))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
dut1.start_app()
|
||||
@@ -255,12 +256,14 @@ def test_examples_protocol_advanced_https_ota_example_truncated_bin(env, extra_d
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except DUT.ExpectTimeout:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
thread1.terminate()
|
||||
dut1.expect('Starting Advanced OTA example', timeout=30)
|
||||
|
||||
print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port) + '/' + truncated_bin_name))
|
||||
dut1.write('https://' + host_ip + ':' + str(server_port) + '/' + truncated_bin_name)
|
||||
dut1.expect('Image validation failed, image is corrupted', timeout=30)
|
||||
os.remove(binary_file)
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag='EXAMPLE_ETH_OTA')
|
||||
@@ -295,7 +298,7 @@ def test_examples_protocol_advanced_https_ota_example_truncated_header(env, extr
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
thread1 = Thread(target=start_https_server, args=(dut1.app.binary_path, host_ip, server_port))
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut1.app.binary_path, host_ip, server_port))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
dut1.start_app()
|
||||
@@ -305,12 +308,14 @@ def test_examples_protocol_advanced_https_ota_example_truncated_header(env, extr
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except DUT.ExpectTimeout:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
thread1.terminate()
|
||||
dut1.expect('Starting Advanced OTA example', timeout=30)
|
||||
|
||||
print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port) + '/' + truncated_bin_name))
|
||||
dut1.write('https://' + host_ip + ':' + str(server_port) + '/' + truncated_bin_name)
|
||||
dut1.expect('advanced_https_ota_example: esp_https_ota_read_img_desc failed', timeout=30)
|
||||
os.remove(binary_file)
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag='EXAMPLE_ETH_OTA')
|
||||
@@ -344,7 +349,7 @@ def test_examples_protocol_advanced_https_ota_example_random(env, extra_data):
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
thread1 = Thread(target=start_https_server, args=(dut1.app.binary_path, host_ip, server_port))
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut1.app.binary_path, host_ip, server_port))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
dut1.start_app()
|
||||
@@ -354,12 +359,14 @@ def test_examples_protocol_advanced_https_ota_example_random(env, extra_data):
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except DUT.ExpectTimeout:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
thread1.terminate()
|
||||
dut1.expect('Starting Advanced OTA example', timeout=30)
|
||||
|
||||
print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port) + '/' + random_bin_name))
|
||||
dut1.write('https://' + host_ip + ':' + str(server_port) + '/' + random_bin_name)
|
||||
dut1.expect('esp_ota_ops: OTA image has invalid magic byte', timeout=10)
|
||||
os.remove(binary_file)
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag='EXAMPLE_ETH_OTA')
|
||||
@@ -424,10 +431,10 @@ def test_examples_protocol_advanced_https_ota_example_redirect_url(env, extra_da
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
thread1 = Thread(target=start_https_server, args=(dut1.app.binary_path, host_ip, server_port))
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut1.app.binary_path, host_ip, server_port))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
thread2 = Thread(target=start_redirect_server, args=(dut1.app.binary_path, host_ip, redirection_server_port, server_port))
|
||||
thread2 = multiprocessing.Process(target=start_redirect_server, args=(dut1.app.binary_path, host_ip, redirection_server_port, server_port))
|
||||
thread2.daemon = True
|
||||
thread2.start()
|
||||
dut1.start_app()
|
||||
@@ -437,8 +444,8 @@ def test_examples_protocol_advanced_https_ota_example_redirect_url(env, extra_da
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except DUT.ExpectTimeout:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
thread1.close()
|
||||
thread2.close()
|
||||
thread1.terminate()
|
||||
thread2.terminate()
|
||||
dut1.expect('Starting Advanced OTA example', timeout=30)
|
||||
|
||||
print('writing to device: {}'.format('https://' + host_ip + ':' + str(redirection_server_port) + '/' + bin_name))
|
||||
@@ -446,6 +453,8 @@ def test_examples_protocol_advanced_https_ota_example_redirect_url(env, extra_da
|
||||
dut1.expect('Loaded app from partition at offset', timeout=60)
|
||||
dut1.expect('Starting Advanced OTA example', timeout=30)
|
||||
dut1.reset()
|
||||
thread1.terminate()
|
||||
thread2.terminate()
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_8Mflash_Ethernet')
|
||||
@@ -485,7 +494,7 @@ def test_examples_protocol_advanced_https_ota_example_anti_rollback(env, extra_d
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
thread1 = Thread(target=start_https_server, args=(dut1.app.binary_path, host_ip, server_port))
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut1.app.binary_path, host_ip, server_port))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
dut1.start_app()
|
||||
@@ -496,6 +505,7 @@ def test_examples_protocol_advanced_https_ota_example_anti_rollback(env, extra_d
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except DUT.ExpectTimeout:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
thread1.terminate()
|
||||
dut1.expect('Starting Advanced OTA example', timeout=30)
|
||||
|
||||
# Use originally generated image with secure_version=1
|
||||
@@ -511,7 +521,8 @@ def test_examples_protocol_advanced_https_ota_example_anti_rollback(env, extra_d
|
||||
print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port) + '/' + anti_rollback_bin_name))
|
||||
dut1.write('https://' + host_ip + ':' + str(server_port) + '/' + anti_rollback_bin_name)
|
||||
dut1.expect('New firmware security version is less than eFuse programmed, 0 < 1', timeout=30)
|
||||
os.remove(anti_rollback_bin_name)
|
||||
os.remove(binary_file)
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag='EXAMPLE_ETH_OTA')
|
||||
@@ -537,7 +548,7 @@ def test_examples_protocol_advanced_https_ota_example_partial_request(env, extra
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
thread1 = Thread(target=start_https_server, args=(dut1.app.binary_path, host_ip, server_port))
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut1.app.binary_path, host_ip, server_port))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
dut1.start_app()
|
||||
@@ -548,6 +559,7 @@ def test_examples_protocol_advanced_https_ota_example_partial_request(env, extra
|
||||
except DUT.ExpectTimeout:
|
||||
Utility.console_log('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
raise
|
||||
thread1.terminate()
|
||||
dut1.expect('Starting Advanced OTA example', timeout=30)
|
||||
|
||||
print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port) + '/' + bin_name))
|
||||
@@ -557,6 +569,7 @@ def test_examples_protocol_advanced_https_ota_example_partial_request(env, extra
|
||||
dut1.expect('Loaded app from partition at offset', timeout=60)
|
||||
dut1.expect('Starting Advanced OTA example', timeout=30)
|
||||
dut1.reset()
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI_OTA', nightly_run=True)
|
||||
@@ -580,7 +593,7 @@ def test_examples_protocol_advanced_https_ota_example_nimble_gatts(env, extra_da
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
thread1 = Thread(target=start_https_server, args=(dut1.app.binary_path, host_ip, server_port))
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut1.app.binary_path, host_ip, server_port))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
dut1.start_app()
|
||||
@@ -590,6 +603,7 @@ def test_examples_protocol_advanced_https_ota_example_nimble_gatts(env, extra_da
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except DUT.ExpectTimeout:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
thread1.terminate()
|
||||
|
||||
dut1.expect('Starting Advanced OTA example', timeout=30)
|
||||
print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port) + '/' + bin_name))
|
||||
@@ -600,6 +614,7 @@ def test_examples_protocol_advanced_https_ota_example_nimble_gatts(env, extra_da
|
||||
dut1.expect('Loaded app from partition at offset', timeout=60)
|
||||
dut1.expect('Starting Advanced OTA example', timeout=30)
|
||||
dut1.reset()
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI_OTA', nightly_run=True)
|
||||
@@ -623,7 +638,7 @@ def test_examples_protocol_advanced_https_ota_example_bluedroid_gatts(env, extra
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
thread1 = Thread(target=start_https_server, args=(dut1.app.binary_path, host_ip, server_port))
|
||||
thread1 = multiprocessing.Process(target=start_https_server, args=(dut1.app.binary_path, host_ip, server_port))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
dut1.start_app()
|
||||
@@ -633,6 +648,7 @@ def test_examples_protocol_advanced_https_ota_example_bluedroid_gatts(env, extra
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except DUT.ExpectTimeout:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
thread1.terminate()
|
||||
|
||||
dut1.expect('Starting Advanced OTA example', timeout=30)
|
||||
print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port) + '/' + bin_name))
|
||||
@@ -643,6 +659,7 @@ def test_examples_protocol_advanced_https_ota_example_bluedroid_gatts(env, extra
|
||||
dut1.expect('Loaded app from partition at offset', timeout=60)
|
||||
dut1.expect('Starting Advanced OTA example', timeout=30)
|
||||
dut1.reset()
|
||||
thread1.terminate()
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag='EXAMPLE_ETH_OTA')
|
||||
|
Reference in New Issue
Block a user