style: format python files with isort and double-quote-string-fixer
This commit is contained in:
@@ -15,21 +15,22 @@
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import re
|
||||
import uuid
|
||||
import subprocess
|
||||
import uuid
|
||||
|
||||
from tiny_test_fw import Utility
|
||||
import ttfw_idf
|
||||
from ble import lib_ble_client
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
# When running on local machine execute the following before running this script
|
||||
# > make app bootloader
|
||||
# > make print_flash_cmd | tail -n 1 > build/download.config
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI_BT")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI_BT')
|
||||
def test_example_app_ble_central(env, extra_data):
|
||||
"""
|
||||
Steps:
|
||||
@@ -37,7 +38,7 @@ def test_example_app_ble_central(env, extra_data):
|
||||
"""
|
||||
|
||||
interface = 'hci0'
|
||||
adv_host_name = "BleCentTestApp"
|
||||
adv_host_name = 'BleCentTestApp'
|
||||
adv_iface_index = 0
|
||||
adv_type = 'peripheral'
|
||||
adv_uuid = '1811'
|
||||
@@ -45,15 +46,15 @@ def test_example_app_ble_central(env, extra_data):
|
||||
subprocess.check_output(['rm','-rf','/var/lib/bluetooth/*'])
|
||||
subprocess.check_output(['hciconfig','hci0','reset'])
|
||||
# Acquire DUT
|
||||
dut = env.get_dut("blecent", "examples/bluetooth/nimble/blecent", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut = env.get_dut('blecent', 'examples/bluetooth/nimble/blecent', dut_class=ttfw_idf.ESP32DUT)
|
||||
|
||||
# Get binary file
|
||||
binary_file = os.path.join(dut.app.binary_path, "blecent.bin")
|
||||
binary_file = os.path.join(dut.app.binary_path, 'blecent.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("blecent_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('blecent_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
|
||||
# Upload binary and start testing
|
||||
Utility.console_log("Starting blecent example test app")
|
||||
Utility.console_log('Starting blecent example test app')
|
||||
dut.start_app()
|
||||
dut.reset()
|
||||
|
||||
@@ -62,16 +63,16 @@ def test_example_app_ble_central(env, extra_data):
|
||||
# Get BLE client module
|
||||
ble_client_obj = lib_ble_client.BLE_Bluez_Client(interface)
|
||||
if not ble_client_obj:
|
||||
raise RuntimeError("Get DBus-Bluez object failed !!")
|
||||
raise RuntimeError('Get DBus-Bluez object failed !!')
|
||||
|
||||
# Discover Bluetooth Adapter and power on
|
||||
is_adapter_set = ble_client_obj.set_adapter()
|
||||
if not is_adapter_set:
|
||||
raise RuntimeError("Adapter Power On failed !!")
|
||||
raise RuntimeError('Adapter Power On failed !!')
|
||||
|
||||
# Write device address to dut
|
||||
dut.expect("BLE Host Task Started", timeout=60)
|
||||
dut.write(device_addr + "\n")
|
||||
dut.expect('BLE Host Task Started', timeout=60)
|
||||
dut.write(device_addr + '\n')
|
||||
|
||||
'''
|
||||
Blecent application run:
|
||||
@@ -87,22 +88,22 @@ def test_example_app_ble_central(env, extra_data):
|
||||
ble_client_obj.disconnect()
|
||||
|
||||
# Check dut responses
|
||||
dut.expect("Connection established", timeout=60)
|
||||
dut.expect('Connection established', timeout=60)
|
||||
|
||||
dut.expect("Service discovery complete; status=0", timeout=60)
|
||||
print("Service discovery passed\n\tService Discovery Status: 0")
|
||||
dut.expect('Service discovery complete; status=0', timeout=60)
|
||||
print('Service discovery passed\n\tService Discovery Status: 0')
|
||||
|
||||
dut.expect("GATT procedure initiated: read;", timeout=60)
|
||||
dut.expect("Read complete; status=0", timeout=60)
|
||||
print("Read passed\n\tSupportedNewAlertCategoryCharacteristic\n\tRead Status: 0")
|
||||
dut.expect('GATT procedure initiated: read;', timeout=60)
|
||||
dut.expect('Read complete; status=0', timeout=60)
|
||||
print('Read passed\n\tSupportedNewAlertCategoryCharacteristic\n\tRead Status: 0')
|
||||
|
||||
dut.expect("GATT procedure initiated: write;", timeout=60)
|
||||
dut.expect("Write complete; status=0", timeout=60)
|
||||
print("Write passed\n\tAlertNotificationControlPointCharacteristic\n\tWrite Status: 0")
|
||||
dut.expect('GATT procedure initiated: write;', timeout=60)
|
||||
dut.expect('Write complete; status=0', timeout=60)
|
||||
print('Write passed\n\tAlertNotificationControlPointCharacteristic\n\tWrite Status: 0')
|
||||
|
||||
dut.expect("GATT procedure initiated: write;", timeout=60)
|
||||
dut.expect("Subscribe complete; status=0", timeout=60)
|
||||
print("Subscribe passed\n\tClientCharacteristicConfigurationDescriptor\n\tSubscribe Status: 0")
|
||||
dut.expect('GATT procedure initiated: write;', timeout=60)
|
||||
dut.expect('Subscribe complete; status=0', timeout=60)
|
||||
print('Subscribe passed\n\tClientCharacteristicConfigurationDescriptor\n\tSubscribe Status: 0')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -15,20 +15,21 @@
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import threading
|
||||
import traceback
|
||||
import subprocess
|
||||
|
||||
try:
|
||||
import Queue
|
||||
except ImportError:
|
||||
import queue as Queue
|
||||
|
||||
from tiny_test_fw import Utility
|
||||
import ttfw_idf
|
||||
from ble import lib_ble_client
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
# When running on local machine execute the following before running this script
|
||||
# > make app bootloader
|
||||
@@ -44,28 +45,28 @@ def blehr_client_task(hr_obj, dut_addr):
|
||||
# Get BLE client module
|
||||
ble_client_obj = lib_ble_client.BLE_Bluez_Client(interface, devname=ble_devname, devaddr=dut_addr)
|
||||
if not ble_client_obj:
|
||||
raise RuntimeError("Failed to get DBus-Bluez object")
|
||||
raise RuntimeError('Failed to get DBus-Bluez object')
|
||||
|
||||
# Discover Bluetooth Adapter and power on
|
||||
is_adapter_set = ble_client_obj.set_adapter()
|
||||
if not is_adapter_set:
|
||||
raise RuntimeError("Adapter Power On failed !!")
|
||||
raise RuntimeError('Adapter Power On failed !!')
|
||||
|
||||
# Connect BLE Device
|
||||
is_connected = ble_client_obj.connect()
|
||||
if not is_connected:
|
||||
# Call disconnect to perform cleanup operations before exiting application
|
||||
ble_client_obj.disconnect()
|
||||
raise RuntimeError("Connection to device " + str(ble_devname) + " failed !!")
|
||||
raise RuntimeError('Connection to device ' + str(ble_devname) + ' failed !!')
|
||||
|
||||
# Read Services
|
||||
services_ret = ble_client_obj.get_services()
|
||||
if services_ret:
|
||||
Utility.console_log("\nServices\n")
|
||||
Utility.console_log('\nServices\n')
|
||||
Utility.console_log(str(services_ret))
|
||||
else:
|
||||
ble_client_obj.disconnect()
|
||||
raise RuntimeError("Failure: Read Services failed")
|
||||
raise RuntimeError('Failure: Read Services failed')
|
||||
|
||||
'''
|
||||
Blehr application run:
|
||||
@@ -75,9 +76,9 @@ def blehr_client_task(hr_obj, dut_addr):
|
||||
'''
|
||||
blehr_ret = ble_client_obj.hr_update_simulation(hr_srv_uuid, hr_char_uuid)
|
||||
if blehr_ret:
|
||||
Utility.console_log("Success: blehr example test passed")
|
||||
Utility.console_log('Success: blehr example test passed')
|
||||
else:
|
||||
raise RuntimeError("Failure: blehr example test failed")
|
||||
raise RuntimeError('Failure: blehr example test failed')
|
||||
|
||||
# Call disconnect to perform cleanup operations before exiting application
|
||||
ble_client_obj.disconnect()
|
||||
@@ -96,7 +97,7 @@ class BleHRThread(threading.Thread):
|
||||
self.exceptions_queue.put(traceback.format_exc(), block=False)
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI_BT")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI_BT')
|
||||
def test_example_app_ble_hr(env, extra_data):
|
||||
"""
|
||||
Steps:
|
||||
@@ -110,20 +111,20 @@ def test_example_app_ble_hr(env, extra_data):
|
||||
subprocess.check_output(['hciconfig','hci0','reset'])
|
||||
|
||||
# Acquire DUT
|
||||
dut = env.get_dut("blehr", "examples/bluetooth/nimble/blehr", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut = env.get_dut('blehr', 'examples/bluetooth/nimble/blehr', dut_class=ttfw_idf.ESP32DUT)
|
||||
|
||||
# Get binary file
|
||||
binary_file = os.path.join(dut.app.binary_path, "blehr.bin")
|
||||
binary_file = os.path.join(dut.app.binary_path, 'blehr.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("blehr_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('blehr_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
|
||||
# Upload binary and start testing
|
||||
Utility.console_log("Starting blehr simple example test app")
|
||||
Utility.console_log('Starting blehr simple example test app')
|
||||
dut.start_app()
|
||||
dut.reset()
|
||||
|
||||
# Get device address from dut
|
||||
dut_addr = dut.expect(re.compile(r"Device Address: ([a-fA-F0-9:]+)"), timeout=30)[0]
|
||||
dut_addr = dut.expect(re.compile(r'Device Address: ([a-fA-F0-9:]+)'), timeout=30)[0]
|
||||
exceptions_queue = Queue.Queue()
|
||||
# Starting a py-client in a separate thread
|
||||
blehr_thread_obj = BleHRThread(dut_addr, exceptions_queue)
|
||||
@@ -137,15 +138,15 @@ def test_example_app_ble_hr(env, extra_data):
|
||||
except Queue.Empty:
|
||||
break
|
||||
else:
|
||||
Utility.console_log("\n" + exception_msg)
|
||||
Utility.console_log('\n' + exception_msg)
|
||||
|
||||
if exception_msg:
|
||||
raise Exception("Thread did not run successfully")
|
||||
raise Exception('Thread did not run successfully')
|
||||
|
||||
# Check dut responses
|
||||
dut.expect("subscribe event; cur_notify=1", timeout=30)
|
||||
dut.expect("subscribe event; cur_notify=0", timeout=30)
|
||||
dut.expect("disconnect;", timeout=30)
|
||||
dut.expect('subscribe event; cur_notify=1', timeout=30)
|
||||
dut.expect('subscribe event; cur_notify=0', timeout=30)
|
||||
dut.expect('disconnect;', timeout=30)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -15,20 +15,21 @@
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import re
|
||||
import traceback
|
||||
import threading
|
||||
import subprocess
|
||||
import threading
|
||||
import traceback
|
||||
|
||||
try:
|
||||
import Queue
|
||||
except ImportError:
|
||||
import queue as Queue
|
||||
|
||||
from tiny_test_fw import Utility
|
||||
import ttfw_idf
|
||||
from ble import lib_ble_client
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
# When running on local machine execute the following before running this script
|
||||
# > make app bootloader
|
||||
@@ -44,45 +45,45 @@ def bleprph_client_task(prph_obj, dut, dut_addr):
|
||||
# Get BLE client module
|
||||
ble_client_obj = lib_ble_client.BLE_Bluez_Client(interface, devname=ble_devname, devaddr=dut_addr)
|
||||
if not ble_client_obj:
|
||||
raise RuntimeError("Failed to get DBus-Bluez object")
|
||||
raise RuntimeError('Failed to get DBus-Bluez object')
|
||||
|
||||
# Discover Bluetooth Adapter and power on
|
||||
is_adapter_set = ble_client_obj.set_adapter()
|
||||
if not is_adapter_set:
|
||||
raise RuntimeError("Adapter Power On failed !!")
|
||||
raise RuntimeError('Adapter Power On failed !!')
|
||||
|
||||
# Connect BLE Device
|
||||
is_connected = ble_client_obj.connect()
|
||||
if not is_connected:
|
||||
# Call disconnect to perform cleanup operations before exiting application
|
||||
ble_client_obj.disconnect()
|
||||
raise RuntimeError("Connection to device " + ble_devname + " failed !!")
|
||||
raise RuntimeError('Connection to device ' + ble_devname + ' failed !!')
|
||||
|
||||
# Check dut responses
|
||||
dut.expect("GAP procedure initiated: advertise;", timeout=30)
|
||||
dut.expect('GAP procedure initiated: advertise;', timeout=30)
|
||||
|
||||
# Read Services
|
||||
services_ret = ble_client_obj.get_services(srv_uuid)
|
||||
if services_ret:
|
||||
Utility.console_log("\nServices\n")
|
||||
Utility.console_log('\nServices\n')
|
||||
Utility.console_log(str(services_ret))
|
||||
else:
|
||||
ble_client_obj.disconnect()
|
||||
raise RuntimeError("Failure: Read Services failed")
|
||||
raise RuntimeError('Failure: Read Services failed')
|
||||
|
||||
# Read Characteristics
|
||||
chars_ret = {}
|
||||
chars_ret = ble_client_obj.read_chars()
|
||||
if chars_ret:
|
||||
Utility.console_log("\nCharacteristics retrieved")
|
||||
Utility.console_log('\nCharacteristics retrieved')
|
||||
for path, props in chars_ret.items():
|
||||
Utility.console_log("\n\tCharacteristic: " + str(path))
|
||||
Utility.console_log("\tCharacteristic UUID: " + str(props[2]))
|
||||
Utility.console_log("\tValue: " + str(props[0]))
|
||||
Utility.console_log("\tProperties: : " + str(props[1]))
|
||||
Utility.console_log('\n\tCharacteristic: ' + str(path))
|
||||
Utility.console_log('\tCharacteristic UUID: ' + str(props[2]))
|
||||
Utility.console_log('\tValue: ' + str(props[0]))
|
||||
Utility.console_log('\tProperties: : ' + str(props[1]))
|
||||
else:
|
||||
ble_client_obj.disconnect()
|
||||
raise RuntimeError("Failure: Read Characteristics failed")
|
||||
raise RuntimeError('Failure: Read Characteristics failed')
|
||||
|
||||
'''
|
||||
Write Characteristics
|
||||
@@ -91,15 +92,15 @@ def bleprph_client_task(prph_obj, dut, dut_addr):
|
||||
chars_ret_on_write = {}
|
||||
chars_ret_on_write = ble_client_obj.write_chars(b'A')
|
||||
if chars_ret_on_write:
|
||||
Utility.console_log("\nCharacteristics after write operation")
|
||||
Utility.console_log('\nCharacteristics after write operation')
|
||||
for path, props in chars_ret_on_write.items():
|
||||
Utility.console_log("\n\tCharacteristic:" + str(path))
|
||||
Utility.console_log("\tCharacteristic UUID: " + str(props[2]))
|
||||
Utility.console_log("\tValue:" + str(props[0]))
|
||||
Utility.console_log("\tProperties: : " + str(props[1]))
|
||||
Utility.console_log('\n\tCharacteristic:' + str(path))
|
||||
Utility.console_log('\tCharacteristic UUID: ' + str(props[2]))
|
||||
Utility.console_log('\tValue:' + str(props[0]))
|
||||
Utility.console_log('\tProperties: : ' + str(props[1]))
|
||||
else:
|
||||
ble_client_obj.disconnect()
|
||||
raise RuntimeError("Failure: Write Characteristics failed")
|
||||
raise RuntimeError('Failure: Write Characteristics failed')
|
||||
|
||||
# Call disconnect to perform cleanup operations before exiting application
|
||||
ble_client_obj.disconnect()
|
||||
@@ -119,7 +120,7 @@ class BlePrphThread(threading.Thread):
|
||||
self.exceptions_queue.put(traceback.format_exc(), block=False)
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI_BT")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI_BT')
|
||||
def test_example_app_ble_peripheral(env, extra_data):
|
||||
"""
|
||||
Steps:
|
||||
@@ -133,20 +134,20 @@ def test_example_app_ble_peripheral(env, extra_data):
|
||||
subprocess.check_output(['hciconfig','hci0','reset'])
|
||||
|
||||
# Acquire DUT
|
||||
dut = env.get_dut("bleprph", "examples/bluetooth/nimble/bleprph", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut = env.get_dut('bleprph', 'examples/bluetooth/nimble/bleprph', dut_class=ttfw_idf.ESP32DUT)
|
||||
|
||||
# Get binary file
|
||||
binary_file = os.path.join(dut.app.binary_path, "bleprph.bin")
|
||||
binary_file = os.path.join(dut.app.binary_path, 'bleprph.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("bleprph_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('bleprph_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
|
||||
# Upload binary and start testing
|
||||
Utility.console_log("Starting bleprph simple example test app")
|
||||
Utility.console_log('Starting bleprph simple example test app')
|
||||
dut.start_app()
|
||||
dut.reset()
|
||||
|
||||
# Get device address from dut
|
||||
dut_addr = dut.expect(re.compile(r"Device Address: ([a-fA-F0-9:]+)"), timeout=30)[0]
|
||||
dut_addr = dut.expect(re.compile(r'Device Address: ([a-fA-F0-9:]+)'), timeout=30)[0]
|
||||
|
||||
exceptions_queue = Queue.Queue()
|
||||
# Starting a py-client in a separate thread
|
||||
@@ -161,14 +162,14 @@ def test_example_app_ble_peripheral(env, extra_data):
|
||||
except Queue.Empty:
|
||||
break
|
||||
else:
|
||||
Utility.console_log("\n" + exception_msg)
|
||||
Utility.console_log('\n' + exception_msg)
|
||||
|
||||
if exception_msg:
|
||||
raise Exception("Thread did not run successfully")
|
||||
raise Exception('Thread did not run successfully')
|
||||
|
||||
# Check dut responses
|
||||
dut.expect("connection established; status=0", timeout=30)
|
||||
dut.expect("disconnect;", timeout=30)
|
||||
dut.expect('connection established; status=0', timeout=30)
|
||||
dut.expect('disconnect;', timeout=30)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import re
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
import re
|
||||
import os
|
||||
import hashlib
|
||||
from __future__ import division, print_function, unicode_literals
|
||||
|
||||
import hashlib
|
||||
import os
|
||||
import re
|
||||
|
||||
from tiny_test_fw import Utility
|
||||
import ttfw_idf
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
|
||||
def verify_elf_sha256_embedding(dut):
|
||||
elf_file = os.path.join(dut.app.binary_path, "blink.elf")
|
||||
elf_file = os.path.join(dut.app.binary_path, 'blink.elf')
|
||||
sha256 = hashlib.sha256()
|
||||
with open(elf_file, "rb") as f:
|
||||
with open(elf_file, 'rb') as f:
|
||||
sha256.update(f.read())
|
||||
sha256_expected = sha256.hexdigest()
|
||||
|
||||
@@ -28,12 +27,12 @@ def verify_elf_sha256_embedding(dut):
|
||||
raise ValueError('ELF file SHA256 mismatch')
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_GENERIC")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_GENERIC')
|
||||
def test_examples_blink(env, extra_data):
|
||||
dut = env.get_dut("blink", "examples/get-started/blink", dut_class=ttfw_idf.ESP32DUT)
|
||||
binary_file = os.path.join(dut.app.binary_path, "blink.bin")
|
||||
dut = env.get_dut('blink', 'examples/get-started/blink', dut_class=ttfw_idf.ESP32DUT)
|
||||
binary_file = os.path.join(dut.app.binary_path, 'blink.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("blink_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('blink_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
|
||||
dut.start_app()
|
||||
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import division, print_function, unicode_literals
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_GENERIC", target=['esp32', 'esp32s2'], ci_target=['esp32'])
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32', 'esp32s2'], ci_target=['esp32'])
|
||||
def test_examples_hello_world(env, extra_data):
|
||||
app_name = 'hello_world'
|
||||
dut = env.get_dut(app_name, "examples/get-started/hello_world")
|
||||
dut = env.get_dut(app_name, 'examples/get-started/hello_world')
|
||||
dut.start_app()
|
||||
res = dut.expect(ttfw_idf.MINIMUM_FREE_HEAP_SIZE_RE)
|
||||
if not res:
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import division, print_function, unicode_literals
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_TWAI1", target=['esp32', 'esp32s2'], ci_target=['esp32'])
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_TWAI1', target=['esp32', 'esp32s2'], ci_target=['esp32'])
|
||||
def test_examples_gpio(env, extra_data):
|
||||
app_name = "gpio"
|
||||
dut = env.get_dut(app_name, "examples/peripherals/gpio/generic_gpio")
|
||||
app_name = 'gpio'
|
||||
dut = env.get_dut(app_name, 'examples/peripherals/gpio/generic_gpio')
|
||||
dut.start_app()
|
||||
res = dut.expect(ttfw_idf.MINIMUM_FREE_HEAP_SIZE_RE)
|
||||
if not res:
|
||||
|
||||
@@ -10,27 +10,27 @@ def test_i2ctools_example(env, extra_data):
|
||||
# Get device under test, flash and start example. "i2ctool" must be defined in EnvConfig
|
||||
dut = env.get_dut('i2ctools', 'examples/peripherals/i2c/i2c_tools', dut_class=ttfw_idf.ESP32DUT)
|
||||
dut.start_app()
|
||||
dut.expect("i2c-tools>", timeout=EXPECT_TIMEOUT)
|
||||
dut.expect('i2c-tools>', timeout=EXPECT_TIMEOUT)
|
||||
# Get i2c address
|
||||
dut.write("i2cdetect")
|
||||
dut.expect("5b", timeout=EXPECT_TIMEOUT)
|
||||
dut.write('i2cdetect')
|
||||
dut.expect('5b', timeout=EXPECT_TIMEOUT)
|
||||
# Get chip ID
|
||||
dut.write("i2cget -c 0x5b -r 0x20 -l 1")
|
||||
dut.expect("0x81", timeout=EXPECT_TIMEOUT)
|
||||
dut.write('i2cget -c 0x5b -r 0x20 -l 1')
|
||||
dut.expect('0x81', timeout=EXPECT_TIMEOUT)
|
||||
# Reset sensor
|
||||
dut.write("i2cset -c 0x5b -r 0xFF 0x11 0xE5 0x72 0x8A")
|
||||
dut.expect("OK", timeout=EXPECT_TIMEOUT)
|
||||
dut.write('i2cset -c 0x5b -r 0xFF 0x11 0xE5 0x72 0x8A')
|
||||
dut.expect('OK', timeout=EXPECT_TIMEOUT)
|
||||
# Get status
|
||||
dut.write("i2cget -c 0x5b -r 0x00 -l 1")
|
||||
dut.expect_any("0x10", timeout=EXPECT_TIMEOUT)
|
||||
dut.write('i2cget -c 0x5b -r 0x00 -l 1')
|
||||
dut.expect_any('0x10', timeout=EXPECT_TIMEOUT)
|
||||
# Change work mode
|
||||
dut.write("i2cset -c 0x5b -r 0xF4")
|
||||
dut.expect("OK", timeout=EXPECT_TIMEOUT)
|
||||
dut.write("i2cset -c 0x5b -r 0x01 0x10")
|
||||
dut.expect("OK", timeout=EXPECT_TIMEOUT)
|
||||
dut.write('i2cset -c 0x5b -r 0xF4')
|
||||
dut.expect('OK', timeout=EXPECT_TIMEOUT)
|
||||
dut.write('i2cset -c 0x5b -r 0x01 0x10')
|
||||
dut.expect('OK', timeout=EXPECT_TIMEOUT)
|
||||
# Get new status
|
||||
dut.write("i2cget -c 0x5b -r 0x00 -l 1")
|
||||
dut.expect_any("0x98", "0x90", timeout=EXPECT_TIMEOUT)
|
||||
dut.write('i2cget -c 0x5b -r 0x00 -l 1')
|
||||
dut.expect_any('0x98', '0x90', timeout=EXPECT_TIMEOUT)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -1,43 +1,44 @@
|
||||
from __future__ import print_function
|
||||
from builtins import range
|
||||
|
||||
import os
|
||||
import wave
|
||||
import struct
|
||||
import wave
|
||||
from builtins import range
|
||||
|
||||
|
||||
def get_wave_array_str(filename, target_bits):
|
||||
wave_read = wave.open(filename, "r")
|
||||
array_str = ""
|
||||
wave_read = wave.open(filename, 'r')
|
||||
array_str = ''
|
||||
nchannels, sampwidth, framerate, nframes, comptype, compname = wave_read.getparams()
|
||||
sampwidth *= 8
|
||||
for i in range(wave_read.getnframes()):
|
||||
val, = struct.unpack("<H", wave_read.readframes(1))
|
||||
val, = struct.unpack('<H', wave_read.readframes(1))
|
||||
scale_val = (1 << target_bits) - 1
|
||||
cur_lim = (1 << sampwidth) - 1
|
||||
# scale current data to 8-bit data
|
||||
val = val * scale_val / cur_lim
|
||||
val = int(val + ((scale_val + 1) // 2)) & scale_val
|
||||
array_str += "0x%x, " % (val)
|
||||
array_str += '0x%x, ' % (val)
|
||||
if (i + 1) % 16 == 0:
|
||||
array_str += "\n"
|
||||
array_str += '\n'
|
||||
return array_str
|
||||
|
||||
|
||||
def gen_wave_table(wav_file_list, target_file_name, scale_bits=8):
|
||||
with open(target_file_name, "w") as audio_table:
|
||||
with open(target_file_name, 'w') as audio_table:
|
||||
print('#include <stdio.h>', file=audio_table)
|
||||
print('const unsigned char audio_table[] = {', file=audio_table)
|
||||
for wav in wav_file_list:
|
||||
print("processing: {}".format(wav))
|
||||
print('processing: {}'.format(wav))
|
||||
print(get_wave_array_str(filename=wav, target_bits=scale_bits), file=audio_table)
|
||||
print('};\n', file=audio_table)
|
||||
print("Done...")
|
||||
print('Done...')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("Generating audio array...")
|
||||
print('Generating audio array...')
|
||||
wav_list = []
|
||||
for filename in os.listdir("./"):
|
||||
if filename.endswith(".wav"):
|
||||
for filename in os.listdir('./'):
|
||||
if filename.endswith('.wav'):
|
||||
wav_list.append(filename)
|
||||
gen_wave_table(wav_file_list=wav_list, target_file_name="audio_example_file.h")
|
||||
gen_wave_table(wav_file_list=wav_list, target_file_name='audio_example_file.h')
|
||||
|
||||
@@ -8,19 +8,19 @@ EXPECT_TIMEOUT = 20
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_RMT_IR_PROTOCOLS')
|
||||
def test_examples_rmt_ir_protocols(env, extra_data):
|
||||
dut = env.get_dut('ir_protocols_example', 'examples/peripherals/rmt/ir_protocols', app_config_name='nec')
|
||||
print("Using binary path: {}".format(dut.app.binary_path))
|
||||
print('Using binary path: {}'.format(dut.app.binary_path))
|
||||
dut.start_app()
|
||||
dut.expect("example: Send command 0x20 to address 0x10", timeout=EXPECT_TIMEOUT)
|
||||
dut.expect("Scan Code --- addr: 0x0010 cmd: 0x0020", timeout=EXPECT_TIMEOUT)
|
||||
dut.expect("Scan Code (repeat) --- addr: 0x0010 cmd: 0x0020", timeout=EXPECT_TIMEOUT)
|
||||
dut.expect('example: Send command 0x20 to address 0x10', timeout=EXPECT_TIMEOUT)
|
||||
dut.expect('Scan Code --- addr: 0x0010 cmd: 0x0020', timeout=EXPECT_TIMEOUT)
|
||||
dut.expect('Scan Code (repeat) --- addr: 0x0010 cmd: 0x0020', timeout=EXPECT_TIMEOUT)
|
||||
env.close_dut(dut.name)
|
||||
|
||||
dut = env.get_dut('ir_protocols_example', 'examples/peripherals/rmt/ir_protocols', app_config_name='rc5')
|
||||
print("Using binary path: {}".format(dut.app.binary_path))
|
||||
print('Using binary path: {}'.format(dut.app.binary_path))
|
||||
dut.start_app()
|
||||
dut.expect("example: Send command 0x20 to address 0x10", timeout=EXPECT_TIMEOUT)
|
||||
dut.expect("Scan Code --- addr: 0x0010 cmd: 0x0020", timeout=EXPECT_TIMEOUT)
|
||||
dut.expect("Scan Code (repeat) --- addr: 0x0010 cmd: 0x0020", timeout=EXPECT_TIMEOUT)
|
||||
dut.expect('example: Send command 0x20 to address 0x10', timeout=EXPECT_TIMEOUT)
|
||||
dut.expect('Scan Code --- addr: 0x0010 cmd: 0x0020', timeout=EXPECT_TIMEOUT)
|
||||
dut.expect('Scan Code (repeat) --- addr: 0x0010 cmd: 0x0020', timeout=EXPECT_TIMEOUT)
|
||||
env.close_dut(dut.name)
|
||||
|
||||
|
||||
|
||||
@@ -12,11 +12,11 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from tiny_test_fw import TinyFW
|
||||
import ttfw_idf
|
||||
from tiny_test_fw import TinyFW
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_SDIO", ignore=True)
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_SDIO', ignore=True)
|
||||
def test_example_sdio_communication(env, extra_data):
|
||||
"""
|
||||
Configurations
|
||||
@@ -36,88 +36,88 @@ def test_example_sdio_communication(env, extra_data):
|
||||
or use sdio test board, which has two wrover modules connect to a same FT3232
|
||||
Assume that first dut is host and second is slave
|
||||
"""
|
||||
dut1 = env.get_dut("sdio_host", "examples/peripherals/sdio/host", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut2 = env.get_dut("sdio_slave", "examples/peripherals/sdio/slave", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('sdio_host', 'examples/peripherals/sdio/host', dut_class=ttfw_idf.ESP32DUT)
|
||||
dut2 = env.get_dut('sdio_slave', 'examples/peripherals/sdio/slave', dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1.start_app()
|
||||
# wait until the master is ready to setup the slave
|
||||
dut1.expect("host ready, start initializing slave...")
|
||||
dut1.expect('host ready, start initializing slave...')
|
||||
|
||||
dut2.start_app()
|
||||
dut1.expect("0a 0d 10 13 16 19 1c 1f 22 25 28 2b 2e 31 34 37")
|
||||
dut1.expect("3a 3d 40 43 46 49 4c 4f 52 55 58 5b 00 00 00 00")
|
||||
dut1.expect("6a 6d 70 73 76 79 7c 7f 82 85 88 8b 8e 91 94 97")
|
||||
dut1.expect("9a 9d a0 a3 a6 a9 ac af b2 b5 b8 bb be c1 c4 c7")
|
||||
dut1.expect('0a 0d 10 13 16 19 1c 1f 22 25 28 2b 2e 31 34 37')
|
||||
dut1.expect('3a 3d 40 43 46 49 4c 4f 52 55 58 5b 00 00 00 00')
|
||||
dut1.expect('6a 6d 70 73 76 79 7c 7f 82 85 88 8b 8e 91 94 97')
|
||||
dut1.expect('9a 9d a0 a3 a6 a9 ac af b2 b5 b8 bb be c1 c4 c7')
|
||||
|
||||
dut2.expect("================ JOB_WRITE_REG ================")
|
||||
dut2.expect("0a 0d 10 13 16 19 1c 1f 22 25 28 2b 2e 31 34 37")
|
||||
dut2.expect("3a 3d 40 43 46 49 4c 4f 52 55 58 5b 00 00 00 00")
|
||||
dut2.expect("6a 6d 70 73 76 79 7c 7f 82 85 88 8b 8e 91 94 97")
|
||||
dut2.expect("9a 9d a0 a3 a6 a9 ac af b2 b5 b8 bb be c1 c4 c7")
|
||||
dut2.expect('================ JOB_WRITE_REG ================')
|
||||
dut2.expect('0a 0d 10 13 16 19 1c 1f 22 25 28 2b 2e 31 34 37')
|
||||
dut2.expect('3a 3d 40 43 46 49 4c 4f 52 55 58 5b 00 00 00 00')
|
||||
dut2.expect('6a 6d 70 73 76 79 7c 7f 82 85 88 8b 8e 91 94 97')
|
||||
dut2.expect('9a 9d a0 a3 a6 a9 ac af b2 b5 b8 bb be c1 c4 c7')
|
||||
|
||||
dut1.expect("host int: 0")
|
||||
dut1.expect("host int: 1")
|
||||
dut1.expect("host int: 2")
|
||||
dut1.expect("host int: 3")
|
||||
dut1.expect("host int: 4")
|
||||
dut1.expect("host int: 5")
|
||||
dut1.expect("host int: 6")
|
||||
dut1.expect("host int: 7")
|
||||
dut1.expect("host int: 0")
|
||||
dut1.expect("host int: 1")
|
||||
dut1.expect("host int: 2")
|
||||
dut1.expect("host int: 3")
|
||||
dut1.expect("host int: 4")
|
||||
dut1.expect("host int: 5")
|
||||
dut1.expect("host int: 6")
|
||||
dut1.expect("host int: 7")
|
||||
dut1.expect('host int: 0')
|
||||
dut1.expect('host int: 1')
|
||||
dut1.expect('host int: 2')
|
||||
dut1.expect('host int: 3')
|
||||
dut1.expect('host int: 4')
|
||||
dut1.expect('host int: 5')
|
||||
dut1.expect('host int: 6')
|
||||
dut1.expect('host int: 7')
|
||||
dut1.expect('host int: 0')
|
||||
dut1.expect('host int: 1')
|
||||
dut1.expect('host int: 2')
|
||||
dut1.expect('host int: 3')
|
||||
dut1.expect('host int: 4')
|
||||
dut1.expect('host int: 5')
|
||||
dut1.expect('host int: 6')
|
||||
dut1.expect('host int: 7')
|
||||
|
||||
dut2.expect("================ JOB_SEND_INT ================")
|
||||
dut2.expect("================ JOB_SEND_INT ================")
|
||||
dut2.expect('================ JOB_SEND_INT ================')
|
||||
dut2.expect('================ JOB_SEND_INT ================')
|
||||
|
||||
dut1.expect("send packet length: 3")
|
||||
dut1.expect("send packet length: 6")
|
||||
dut1.expect("send packet length: 12")
|
||||
dut1.expect("send packet length: 128")
|
||||
dut1.expect("send packet length: 511")
|
||||
dut1.expect("send packet length: 512")
|
||||
dut1.expect('send packet length: 3')
|
||||
dut1.expect('send packet length: 6')
|
||||
dut1.expect('send packet length: 12')
|
||||
dut1.expect('send packet length: 128')
|
||||
dut1.expect('send packet length: 511')
|
||||
dut1.expect('send packet length: 512')
|
||||
|
||||
dut2.expect("recv len: 3")
|
||||
dut2.expect("recv len: 6")
|
||||
dut2.expect("recv len: 12")
|
||||
dut2.expect("recv len: 128")
|
||||
dut2.expect('recv len: 3')
|
||||
dut2.expect('recv len: 6')
|
||||
dut2.expect('recv len: 12')
|
||||
dut2.expect('recv len: 128')
|
||||
# 511
|
||||
dut2.expect("recv len: 128")
|
||||
dut2.expect("recv len: 128")
|
||||
dut2.expect("recv len: 128")
|
||||
dut2.expect("recv len: 127")
|
||||
dut2.expect('recv len: 128')
|
||||
dut2.expect('recv len: 128')
|
||||
dut2.expect('recv len: 128')
|
||||
dut2.expect('recv len: 127')
|
||||
# 512
|
||||
dut2.expect("recv len: 128")
|
||||
dut2.expect("recv len: 128")
|
||||
dut2.expect("recv len: 128")
|
||||
dut2.expect("recv len: 128")
|
||||
dut2.expect('recv len: 128')
|
||||
dut2.expect('recv len: 128')
|
||||
dut2.expect('recv len: 128')
|
||||
dut2.expect('recv len: 128')
|
||||
|
||||
dut1.expect("receive data, size: 3")
|
||||
dut1.expect("receive data, size: 6")
|
||||
dut1.expect("receive data, size: 12")
|
||||
dut1.expect("receive data, size: 128")
|
||||
dut1.expect('receive data, size: 3')
|
||||
dut1.expect('receive data, size: 6')
|
||||
dut1.expect('receive data, size: 12')
|
||||
dut1.expect('receive data, size: 128')
|
||||
|
||||
dut1.expect("receive data, size: 128")
|
||||
dut1.expect("receive data, size: 128")
|
||||
dut1.expect("receive data, size: 128")
|
||||
dut1.expect("receive data, size: 127")
|
||||
dut1.expect('receive data, size: 128')
|
||||
dut1.expect('receive data, size: 128')
|
||||
dut1.expect('receive data, size: 128')
|
||||
dut1.expect('receive data, size: 127')
|
||||
|
||||
dut1.expect("receive data, size: 128")
|
||||
dut1.expect("receive data, size: 128")
|
||||
dut1.expect("receive data, size: 128")
|
||||
dut1.expect("receive data, size: 128")
|
||||
dut1.expect('receive data, size: 128')
|
||||
dut1.expect('receive data, size: 128')
|
||||
dut1.expect('receive data, size: 128')
|
||||
dut1.expect('receive data, size: 128')
|
||||
|
||||
# the last valid line of one round
|
||||
dut1.expect("ce d3 d8 dd e2 e7 ec f1 f6 fb 00 05 0a 0f 14 19")
|
||||
dut1.expect('ce d3 d8 dd e2 e7 ec f1 f6 fb 00 05 0a 0f 14 19')
|
||||
# the first 2 lines of the second round
|
||||
dut1.expect("46 4b 50")
|
||||
dut1.expect("5a 5f 64 69 6e 73")
|
||||
dut1.expect('46 4b 50')
|
||||
dut1.expect('5a 5f 64 69 6e 73')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
TinyFW.set_default_config(env_config_file="EnvConfigTemplate.yml", dut=ttfw_idf.IDFDUT)
|
||||
TinyFW.set_default_config(env_config_file='EnvConfigTemplate.yml', dut=ttfw_idf.IDFDUT)
|
||||
test_example_sdio_communication()
|
||||
|
||||
@@ -4,7 +4,7 @@ from __future__ import print_function
|
||||
import ttfw_idf
|
||||
|
||||
# TWAI Self Test Example constants
|
||||
STR_EXPECT = ("TWAI Alert and Recovery: Driver installed", "TWAI Alert and Recovery: Driver uninstalled")
|
||||
STR_EXPECT = ('TWAI Alert and Recovery: Driver installed', 'TWAI Alert and Recovery: Driver uninstalled')
|
||||
EXPECT_TIMEOUT = 20
|
||||
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@ from threading import Thread
|
||||
import ttfw_idf
|
||||
|
||||
# Define tuple of strings to expect for each DUT.
|
||||
master_expect = ("TWAI Master: Driver installed", "TWAI Master: Driver uninstalled")
|
||||
slave_expect = ("TWAI Slave: Driver installed", "TWAI Slave: Driver uninstalled")
|
||||
listen_only_expect = ("TWAI Listen Only: Driver installed", "TWAI Listen Only: Driver uninstalled")
|
||||
master_expect = ('TWAI Master: Driver installed', 'TWAI Master: Driver uninstalled')
|
||||
slave_expect = ('TWAI Slave: Driver installed', 'TWAI Slave: Driver uninstalled')
|
||||
listen_only_expect = ('TWAI Listen Only: Driver installed', 'TWAI Listen Only: Driver uninstalled')
|
||||
|
||||
|
||||
def dut_thread_callback(**kwargs):
|
||||
@@ -31,11 +31,11 @@ def dut_thread_callback(**kwargs):
|
||||
def test_twai_network_example(env, extra_data):
|
||||
|
||||
# Get device under test. "dut1", "dut2", and "dut3" must be properly defined in EnvConfig
|
||||
dut_master = env.get_dut("dut1", "examples/peripherals/twai/twai_network/twai_network_master",
|
||||
dut_master = env.get_dut('dut1', 'examples/peripherals/twai/twai_network/twai_network_master',
|
||||
dut_class=ttfw_idf.ESP32DUT)
|
||||
dut_slave = env.get_dut("dut2", "examples/peripherals/twai/twai_network/twai_network_slave",
|
||||
dut_slave = env.get_dut('dut2', 'examples/peripherals/twai/twai_network/twai_network_slave',
|
||||
dut_class=ttfw_idf.ESP32DUT)
|
||||
dut_listen_only = env.get_dut("dut3", "examples/peripherals/twai/twai_network/twai_network_listen_only",
|
||||
dut_listen_only = env.get_dut('dut3', 'examples/peripherals/twai/twai_network/twai_network_listen_only',
|
||||
dut_class=ttfw_idf.ESP32DUT)
|
||||
|
||||
# Flash app onto each DUT, each DUT is reset again at the start of each thread
|
||||
@@ -45,14 +45,14 @@ def test_twai_network_example(env, extra_data):
|
||||
|
||||
# Create dict of keyword arguments for each dut
|
||||
results = [[False], [False], [False]]
|
||||
master_kwargs = {"dut": dut_master, "result": results[0], "expected": master_expect}
|
||||
slave_kwargs = {"dut": dut_slave, "result": results[1], "expected": slave_expect}
|
||||
listen_only_kwargs = {"dut": dut_listen_only, "result": results[2], "expected": listen_only_expect}
|
||||
master_kwargs = {'dut': dut_master, 'result': results[0], 'expected': master_expect}
|
||||
slave_kwargs = {'dut': dut_slave, 'result': results[1], 'expected': slave_expect}
|
||||
listen_only_kwargs = {'dut': dut_listen_only, 'result': results[2], 'expected': listen_only_expect}
|
||||
|
||||
# Create thread for each dut
|
||||
dut_master_thread = Thread(target=dut_thread_callback, name="Master Thread", kwargs=master_kwargs)
|
||||
dut_slave_thread = Thread(target=dut_thread_callback, name="Slave Thread", kwargs=slave_kwargs)
|
||||
dut_listen_only_thread = Thread(target=dut_thread_callback, name="Listen Only Thread", kwargs=listen_only_kwargs)
|
||||
dut_master_thread = Thread(target=dut_thread_callback, name='Master Thread', kwargs=master_kwargs)
|
||||
dut_slave_thread = Thread(target=dut_thread_callback, name='Slave Thread', kwargs=slave_kwargs)
|
||||
dut_listen_only_thread = Thread(target=dut_thread_callback, name='Listen Only Thread', kwargs=listen_only_kwargs)
|
||||
|
||||
# Start each thread
|
||||
dut_listen_only_thread.start()
|
||||
@@ -67,7 +67,7 @@ def test_twai_network_example(env, extra_data):
|
||||
# check each thread ran to completion
|
||||
for result in results:
|
||||
if result[0] is not True:
|
||||
raise Exception("One or more threads did not run successfully")
|
||||
raise Exception('One or more threads did not run successfully')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -3,9 +3,8 @@ from __future__ import print_function
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
# TWAI Self Test Example constants
|
||||
STR_EXPECT = ("TWAI Self Test: Driver installed", "TWAI Self Test: Driver uninstalled")
|
||||
STR_EXPECT = ('TWAI Self Test: Driver installed', 'TWAI Self Test: Driver uninstalled')
|
||||
EXPECT_TIMEOUT = 20
|
||||
|
||||
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
import re
|
||||
import os
|
||||
import re
|
||||
import socket
|
||||
from threading import Thread
|
||||
import time
|
||||
from threading import Thread
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
global g_client_response
|
||||
global g_msg_to_client
|
||||
|
||||
g_client_response = b""
|
||||
g_msg_to_client = b" 3XYZ"
|
||||
g_client_response = b''
|
||||
g_msg_to_client = b' 3XYZ'
|
||||
|
||||
|
||||
def get_my_ip():
|
||||
s1 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
s1.connect(("8.8.8.8", 80))
|
||||
s1.connect(('8.8.8.8', 80))
|
||||
my_ip = s1.getsockname()[0]
|
||||
s1.close()
|
||||
return my_ip
|
||||
@@ -23,14 +23,14 @@ def get_my_ip():
|
||||
|
||||
def chat_server_sketch(my_ip):
|
||||
global g_client_response
|
||||
print("Starting the server on {}".format(my_ip))
|
||||
print('Starting the server on {}'.format(my_ip))
|
||||
port = 2222
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.settimeout(600)
|
||||
s.bind((my_ip, port))
|
||||
s.listen(1)
|
||||
q,addr = s.accept()
|
||||
print("connection accepted")
|
||||
print('connection accepted')
|
||||
q.settimeout(30)
|
||||
q.send(g_msg_to_client)
|
||||
data = q.recv(1024)
|
||||
@@ -39,12 +39,12 @@ def chat_server_sketch(my_ip):
|
||||
g_client_response = data
|
||||
else:
|
||||
g_client_response = q.recv(1024)
|
||||
print("received from client {}".format(g_client_response))
|
||||
print('received from client {}'.format(g_client_response))
|
||||
s.close()
|
||||
print("server closed")
|
||||
print('server closed')
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_asio_chat_client(env, extra_data):
|
||||
"""
|
||||
steps: |
|
||||
@@ -57,19 +57,19 @@ def test_examples_protocol_asio_chat_client(env, extra_data):
|
||||
"""
|
||||
global g_client_response
|
||||
global g_msg_to_client
|
||||
test_msg = "ABC"
|
||||
dut1 = env.get_dut("chat_client", "examples/protocols/asio/chat_client", dut_class=ttfw_idf.ESP32DUT)
|
||||
test_msg = 'ABC'
|
||||
dut1 = env.get_dut('chat_client', 'examples/protocols/asio/chat_client', dut_class=ttfw_idf.ESP32DUT)
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, "asio_chat_client.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'asio_chat_client.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("asio_chat_client_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('asio_chat_client_size', '{}KB'.format(bin_size // 1024))
|
||||
# 1. start a tcp server on the host
|
||||
host_ip = get_my_ip()
|
||||
thread1 = Thread(target=chat_server_sketch, args=(host_ip,))
|
||||
thread1.start()
|
||||
# 2. start the dut test and wait till client gets IP address
|
||||
dut1.start_app()
|
||||
dut1.expect(re.compile(r" IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)"), timeout=30)
|
||||
dut1.expect(re.compile(r' IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)'), timeout=30)
|
||||
# 3. send host's IP to the client i.e. the `dut1`
|
||||
dut1.write(host_ip)
|
||||
# 4. client `dut1` should receive a message
|
||||
@@ -82,10 +82,10 @@ def test_examples_protocol_asio_chat_client(env, extra_data):
|
||||
print(g_client_response)
|
||||
# 6. evaluate host_server received this message
|
||||
if (g_client_response[4:7] == test_msg):
|
||||
print("PASS: Received correct message")
|
||||
print('PASS: Received correct message')
|
||||
pass
|
||||
else:
|
||||
print("Failure!")
|
||||
print('Failure!')
|
||||
raise ValueError('Wrong data received from asi tcp server: {} (expected:{})'.format(g_client_response[4:7], test_msg))
|
||||
thread1.join()
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import re
|
||||
import os
|
||||
import re
|
||||
import socket
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_asio_chat_server(env, extra_data):
|
||||
"""
|
||||
steps: |
|
||||
@@ -14,16 +14,16 @@ def test_examples_protocol_asio_chat_server(env, extra_data):
|
||||
3. Test connects to server and sends a test message
|
||||
4. Test evaluates received test message from server
|
||||
"""
|
||||
test_msg = b" 4ABC\n"
|
||||
dut1 = env.get_dut("chat_server", "examples/protocols/asio/chat_server", dut_class=ttfw_idf.ESP32DUT)
|
||||
test_msg = b' 4ABC\n'
|
||||
dut1 = env.get_dut('chat_server', 'examples/protocols/asio/chat_server', dut_class=ttfw_idf.ESP32DUT)
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, "asio_chat_server.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'asio_chat_server.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("asio_chat_server_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('asio_chat_server_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# 1. start test
|
||||
dut1.start_app()
|
||||
# 2. get the server IP address
|
||||
data = dut1.expect(re.compile(r" IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)"), timeout=30)
|
||||
data = dut1.expect(re.compile(r' IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)'), timeout=30)
|
||||
# 3. create tcp client and connect to server
|
||||
cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
cli.settimeout(30)
|
||||
@@ -32,10 +32,10 @@ def test_examples_protocol_asio_chat_server(env, extra_data):
|
||||
data = cli.recv(1024)
|
||||
# 4. check the message received back from the server
|
||||
if (data == test_msg):
|
||||
print("PASS: Received correct message {}".format(data))
|
||||
print('PASS: Received correct message {}'.format(data))
|
||||
pass
|
||||
else:
|
||||
print("Failure!")
|
||||
print('Failure!')
|
||||
raise ValueError('Wrong data received from asi tcp server: {} (expoected:{})'.format(data, test_msg))
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import re
|
||||
import os
|
||||
import re
|
||||
import socket
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_asio_tcp_server(env, extra_data):
|
||||
"""
|
||||
steps: |
|
||||
@@ -15,16 +15,16 @@ def test_examples_protocol_asio_tcp_server(env, extra_data):
|
||||
4. Test evaluates received test message from server
|
||||
5. Test evaluates received test message on server stdout
|
||||
"""
|
||||
test_msg = b"echo message from client to server"
|
||||
dut1 = env.get_dut("tcp_echo_server", "examples/protocols/asio/tcp_echo_server", dut_class=ttfw_idf.ESP32DUT)
|
||||
test_msg = b'echo message from client to server'
|
||||
dut1 = env.get_dut('tcp_echo_server', 'examples/protocols/asio/tcp_echo_server', dut_class=ttfw_idf.ESP32DUT)
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, "asio_tcp_echo_server.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'asio_tcp_echo_server.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("asio_tcp_echo_server_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('asio_tcp_echo_server_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# 1. start test
|
||||
dut1.start_app()
|
||||
# 2. get the server IP address
|
||||
data = dut1.expect(re.compile(r" IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)"), timeout=30)
|
||||
data = dut1.expect(re.compile(r' IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)'), timeout=30)
|
||||
# 3. create tcp client and connect to server
|
||||
cli = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
cli.settimeout(30)
|
||||
@@ -33,10 +33,10 @@ def test_examples_protocol_asio_tcp_server(env, extra_data):
|
||||
data = cli.recv(1024)
|
||||
# 4. check the message received back from the server
|
||||
if (data == test_msg):
|
||||
print("PASS: Received correct message")
|
||||
print('PASS: Received correct message')
|
||||
pass
|
||||
else:
|
||||
print("Failure!")
|
||||
print('Failure!')
|
||||
raise ValueError('Wrong data received from asi tcp server: {} (expected:{})'.format(data, test_msg))
|
||||
# 5. check the client message appears also on server terminal
|
||||
dut1.expect(test_msg.decode())
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import re
|
||||
import os
|
||||
import re
|
||||
import socket
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_asio_udp_server(env, extra_data):
|
||||
"""
|
||||
steps: |
|
||||
@@ -15,16 +15,16 @@ def test_examples_protocol_asio_udp_server(env, extra_data):
|
||||
4. Test evaluates received test message from server
|
||||
5. Test evaluates received test message on server stdout
|
||||
"""
|
||||
test_msg = b"echo message from client to server"
|
||||
dut1 = env.get_dut("udp_echo_server", "examples/protocols/asio/udp_echo_server", dut_class=ttfw_idf.ESP32DUT)
|
||||
test_msg = b'echo message from client to server'
|
||||
dut1 = env.get_dut('udp_echo_server', 'examples/protocols/asio/udp_echo_server', dut_class=ttfw_idf.ESP32DUT)
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, "asio_udp_echo_server.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'asio_udp_echo_server.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("asio_udp_echo_server_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('asio_udp_echo_server_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# 1. start test
|
||||
dut1.start_app()
|
||||
# 2. get the server IP address
|
||||
data = dut1.expect(re.compile(r" IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)"), timeout=30)
|
||||
data = dut1.expect(re.compile(r' IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)'), timeout=30)
|
||||
# 3. create tcp client and connect to server
|
||||
cli = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
cli.settimeout(30)
|
||||
@@ -33,10 +33,10 @@ def test_examples_protocol_asio_udp_server(env, extra_data):
|
||||
data = cli.recv(1024)
|
||||
# 4. check the message received back from the server
|
||||
if (data == test_msg):
|
||||
print("PASS: Received correct message")
|
||||
print('PASS: Received correct message')
|
||||
pass
|
||||
else:
|
||||
print("Failure!")
|
||||
print('Failure!')
|
||||
raise ValueError('Wrong data received from asio udp server: {} (expected:{})'.format(data, test_msg))
|
||||
# 5. check the client message appears also on server terminal
|
||||
dut1.expect(test_msg.decode())
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import re
|
||||
import textwrap
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
|
||||
@@ -1,64 +1,64 @@
|
||||
import re
|
||||
import os
|
||||
import re
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_EthKitV1")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_EthKitV1')
|
||||
def test_examples_protocol_esp_http_client(env, extra_data):
|
||||
"""
|
||||
steps: |
|
||||
1. join AP
|
||||
2. Send HTTP request to httpbin.org
|
||||
"""
|
||||
dut1 = env.get_dut("esp_http_client", "examples/protocols/esp_http_client", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('esp_http_client', 'examples/protocols/esp_http_client', dut_class=ttfw_idf.ESP32DUT)
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, "esp-http-client-example.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'esp-http-client-example.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("esp_http_client_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('esp_http_client_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# start test
|
||||
dut1.start_app()
|
||||
dut1.expect("Connected to AP, begin http example", timeout=30)
|
||||
dut1.expect(re.compile(r"HTTP GET Status = 200, content_length = (\d)"))
|
||||
dut1.expect(re.compile(r"HTTP POST Status = 200, content_length = (\d)"))
|
||||
dut1.expect(re.compile(r"HTTP PUT Status = 200, content_length = (\d)"))
|
||||
dut1.expect(re.compile(r"HTTP PATCH Status = 200, content_length = (\d)"))
|
||||
dut1.expect(re.compile(r"HTTP DELETE Status = 200, content_length = (\d)"))
|
||||
dut1.expect(re.compile(r"HTTP HEAD Status = 200, content_length = (\d)"))
|
||||
dut1.expect(re.compile(r"HTTP Basic Auth Status = 200, content_length = (\d)"))
|
||||
dut1.expect(re.compile(r"HTTP Basic Auth redirect Status = 200, content_length = (\d)"))
|
||||
dut1.expect(re.compile(r"HTTP Digest Auth Status = 200, content_length = (\d)"))
|
||||
dut1.expect(re.compile(r"HTTPS Status = 200, content_length = (\d)"))
|
||||
dut1.expect(re.compile(r"HTTP chunk encoding Status = 200, content_length = (-?\d)"))
|
||||
dut1.expect('Connected to AP, begin http example', timeout=30)
|
||||
dut1.expect(re.compile(r'HTTP GET Status = 200, content_length = (\d)'))
|
||||
dut1.expect(re.compile(r'HTTP POST Status = 200, content_length = (\d)'))
|
||||
dut1.expect(re.compile(r'HTTP PUT Status = 200, content_length = (\d)'))
|
||||
dut1.expect(re.compile(r'HTTP PATCH Status = 200, content_length = (\d)'))
|
||||
dut1.expect(re.compile(r'HTTP DELETE Status = 200, content_length = (\d)'))
|
||||
dut1.expect(re.compile(r'HTTP HEAD Status = 200, content_length = (\d)'))
|
||||
dut1.expect(re.compile(r'HTTP Basic Auth Status = 200, content_length = (\d)'))
|
||||
dut1.expect(re.compile(r'HTTP Basic Auth redirect Status = 200, content_length = (\d)'))
|
||||
dut1.expect(re.compile(r'HTTP Digest Auth Status = 200, content_length = (\d)'))
|
||||
dut1.expect(re.compile(r'HTTPS Status = 200, content_length = (\d)'))
|
||||
dut1.expect(re.compile(r'HTTP chunk encoding Status = 200, content_length = (-?\d)'))
|
||||
# content-len for chunked encoding is typically -1, could be a positive length in some cases
|
||||
dut1.expect(re.compile(r"HTTP Stream reader Status = 200, content_length = (\d)"))
|
||||
dut1.expect(re.compile(r"Last esp error code: 0x8001"))
|
||||
dut1.expect("Finish http example")
|
||||
dut1.expect(re.compile(r'HTTP Stream reader Status = 200, content_length = (\d)'))
|
||||
dut1.expect(re.compile(r'Last esp error code: 0x8001'))
|
||||
dut1.expect('Finish http example')
|
||||
|
||||
# test mbedtls dynamic resource
|
||||
dut1 = env.get_dut("esp_http_client", "examples/protocols/esp_http_client", dut_class=ttfw_idf.ESP32DUT, app_config_name='ssldyn')
|
||||
dut1 = env.get_dut('esp_http_client', 'examples/protocols/esp_http_client', dut_class=ttfw_idf.ESP32DUT, app_config_name='ssldyn')
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, "esp-http-client-example.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'esp-http-client-example.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("esp_http_client_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('esp_http_client_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# start test
|
||||
dut1.start_app()
|
||||
dut1.expect("Connected to AP, begin http example", timeout=30)
|
||||
dut1.expect(re.compile(r"HTTP GET Status = 200, content_length = (\d)"))
|
||||
dut1.expect(re.compile(r"HTTP POST Status = 200, content_length = (\d)"))
|
||||
dut1.expect(re.compile(r"HTTP PUT Status = 200, content_length = (\d)"))
|
||||
dut1.expect(re.compile(r"HTTP PATCH Status = 200, content_length = (\d)"))
|
||||
dut1.expect(re.compile(r"HTTP DELETE Status = 200, content_length = (\d)"))
|
||||
dut1.expect(re.compile(r"HTTP HEAD Status = 200, content_length = (\d)"))
|
||||
dut1.expect(re.compile(r"HTTP Basic Auth Status = 200, content_length = (\d)"))
|
||||
dut1.expect(re.compile(r"HTTP Basic Auth redirect Status = 200, content_length = (\d)"))
|
||||
dut1.expect(re.compile(r"HTTP Digest Auth Status = 200, content_length = (\d)"))
|
||||
dut1.expect(re.compile(r"HTTPS Status = 200, content_length = (\d)"))
|
||||
dut1.expect(re.compile(r"HTTP chunk encoding Status = 200, content_length = (-?\d)"))
|
||||
dut1.expect('Connected to AP, begin http example', timeout=30)
|
||||
dut1.expect(re.compile(r'HTTP GET Status = 200, content_length = (\d)'))
|
||||
dut1.expect(re.compile(r'HTTP POST Status = 200, content_length = (\d)'))
|
||||
dut1.expect(re.compile(r'HTTP PUT Status = 200, content_length = (\d)'))
|
||||
dut1.expect(re.compile(r'HTTP PATCH Status = 200, content_length = (\d)'))
|
||||
dut1.expect(re.compile(r'HTTP DELETE Status = 200, content_length = (\d)'))
|
||||
dut1.expect(re.compile(r'HTTP HEAD Status = 200, content_length = (\d)'))
|
||||
dut1.expect(re.compile(r'HTTP Basic Auth Status = 200, content_length = (\d)'))
|
||||
dut1.expect(re.compile(r'HTTP Basic Auth redirect Status = 200, content_length = (\d)'))
|
||||
dut1.expect(re.compile(r'HTTP Digest Auth Status = 200, content_length = (\d)'))
|
||||
dut1.expect(re.compile(r'HTTPS Status = 200, content_length = (\d)'))
|
||||
dut1.expect(re.compile(r'HTTP chunk encoding Status = 200, content_length = (-?\d)'))
|
||||
# content-len for chunked encoding is typically -1, could be a positive length in some cases
|
||||
dut1.expect(re.compile(r"HTTP Stream reader Status = 200, content_length = (\d)"))
|
||||
dut1.expect(re.compile(r"Last esp error code: 0x8001"))
|
||||
dut1.expect("Finish http example")
|
||||
dut1.expect(re.compile(r'HTTP Stream reader Status = 200, content_length = (\d)'))
|
||||
dut1.expect(re.compile(r'Last esp error code: 0x8001'))
|
||||
dut1.expect('Finish http example')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
|
||||
@@ -16,22 +16,22 @@
|
||||
#
|
||||
|
||||
from __future__ import print_function
|
||||
from future.utils import tobytes
|
||||
from builtins import input
|
||||
import os
|
||||
import sys
|
||||
import struct
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import ssl
|
||||
import struct
|
||||
import sys
|
||||
from builtins import input
|
||||
|
||||
import proto
|
||||
from future.utils import tobytes
|
||||
|
||||
# The tools directory is already in the PATH in environment prepared by install.sh which would allow to import
|
||||
# esp_prov as file but not as complete module.
|
||||
sys.path.insert(0, os.path.join(os.environ['IDF_PATH'], 'tools/esp_prov'))
|
||||
import esp_prov # noqa: E402
|
||||
|
||||
|
||||
# Set this to true to allow exceptions to be thrown
|
||||
config_throw_except = False
|
||||
|
||||
@@ -48,26 +48,26 @@ PROP_FLAG_READONLY = (1 << 0)
|
||||
|
||||
|
||||
def prop_typestr(prop):
|
||||
if prop["type"] == PROP_TYPE_TIMESTAMP:
|
||||
return "TIME(us)"
|
||||
elif prop["type"] == PROP_TYPE_INT32:
|
||||
return "INT32"
|
||||
elif prop["type"] == PROP_TYPE_BOOLEAN:
|
||||
return "BOOLEAN"
|
||||
elif prop["type"] == PROP_TYPE_STRING:
|
||||
return "STRING"
|
||||
return "UNKNOWN"
|
||||
if prop['type'] == PROP_TYPE_TIMESTAMP:
|
||||
return 'TIME(us)'
|
||||
elif prop['type'] == PROP_TYPE_INT32:
|
||||
return 'INT32'
|
||||
elif prop['type'] == PROP_TYPE_BOOLEAN:
|
||||
return 'BOOLEAN'
|
||||
elif prop['type'] == PROP_TYPE_STRING:
|
||||
return 'STRING'
|
||||
return 'UNKNOWN'
|
||||
|
||||
|
||||
def encode_prop_value(prop, value):
|
||||
try:
|
||||
if prop["type"] == PROP_TYPE_TIMESTAMP:
|
||||
if prop['type'] == PROP_TYPE_TIMESTAMP:
|
||||
return struct.pack('q', value)
|
||||
elif prop["type"] == PROP_TYPE_INT32:
|
||||
elif prop['type'] == PROP_TYPE_INT32:
|
||||
return struct.pack('i', value)
|
||||
elif prop["type"] == PROP_TYPE_BOOLEAN:
|
||||
elif prop['type'] == PROP_TYPE_BOOLEAN:
|
||||
return struct.pack('?', value)
|
||||
elif prop["type"] == PROP_TYPE_STRING:
|
||||
elif prop['type'] == PROP_TYPE_STRING:
|
||||
return tobytes(value)
|
||||
return value
|
||||
except struct.error as e:
|
||||
@@ -77,13 +77,13 @@ def encode_prop_value(prop, value):
|
||||
|
||||
def decode_prop_value(prop, value):
|
||||
try:
|
||||
if prop["type"] == PROP_TYPE_TIMESTAMP:
|
||||
if prop['type'] == PROP_TYPE_TIMESTAMP:
|
||||
return struct.unpack('q', value)[0]
|
||||
elif prop["type"] == PROP_TYPE_INT32:
|
||||
elif prop['type'] == PROP_TYPE_INT32:
|
||||
return struct.unpack('i', value)[0]
|
||||
elif prop["type"] == PROP_TYPE_BOOLEAN:
|
||||
elif prop['type'] == PROP_TYPE_BOOLEAN:
|
||||
return struct.unpack('?', value)[0]
|
||||
elif prop["type"] == PROP_TYPE_STRING:
|
||||
elif prop['type'] == PROP_TYPE_STRING:
|
||||
return value.decode('latin-1')
|
||||
return value
|
||||
except struct.error as e:
|
||||
@@ -93,13 +93,13 @@ def decode_prop_value(prop, value):
|
||||
|
||||
def str_to_prop_value(prop, strval):
|
||||
try:
|
||||
if prop["type"] == PROP_TYPE_TIMESTAMP:
|
||||
if prop['type'] == PROP_TYPE_TIMESTAMP:
|
||||
return int(strval)
|
||||
elif prop["type"] == PROP_TYPE_INT32:
|
||||
elif prop['type'] == PROP_TYPE_INT32:
|
||||
return int(strval)
|
||||
elif prop["type"] == PROP_TYPE_BOOLEAN:
|
||||
elif prop['type'] == PROP_TYPE_BOOLEAN:
|
||||
return bool(strval)
|
||||
elif prop["type"] == PROP_TYPE_STRING:
|
||||
elif prop['type'] == PROP_TYPE_STRING:
|
||||
return strval
|
||||
return strval
|
||||
except ValueError as e:
|
||||
@@ -108,7 +108,7 @@ def str_to_prop_value(prop, strval):
|
||||
|
||||
|
||||
def prop_is_readonly(prop):
|
||||
return (prop["flags"] & PROP_FLAG_READONLY) != 0
|
||||
return (prop['flags'] & PROP_FLAG_READONLY) != 0
|
||||
|
||||
|
||||
def on_except(err):
|
||||
@@ -122,8 +122,8 @@ def get_transport(sel_transport, service_name, check_hostname):
|
||||
try:
|
||||
tp = None
|
||||
if (sel_transport == 'http'):
|
||||
example_path = os.environ['IDF_PATH'] + "/examples/protocols/esp_local_ctrl"
|
||||
cert_path = example_path + "/main/certs/rootCA.pem"
|
||||
example_path = os.environ['IDF_PATH'] + '/examples/protocols/esp_local_ctrl'
|
||||
cert_path = example_path + '/main/certs/rootCA.pem'
|
||||
ssl_ctx = ssl.create_default_context(cafile=cert_path)
|
||||
ssl_ctx.check_hostname = check_hostname
|
||||
tp = esp_prov.transport.Transport_HTTP(service_name, ssl_ctx)
|
||||
@@ -156,15 +156,15 @@ def get_all_property_values(tp):
|
||||
response = tp.send_data('esp_local_ctrl/control', message)
|
||||
count = proto.get_prop_count_response(response)
|
||||
if count == 0:
|
||||
raise RuntimeError("No properties found!")
|
||||
raise RuntimeError('No properties found!')
|
||||
indices = [i for i in range(count)]
|
||||
message = proto.get_prop_vals_request(indices)
|
||||
response = tp.send_data('esp_local_ctrl/control', message)
|
||||
props = proto.get_prop_vals_response(response)
|
||||
if len(props) != count:
|
||||
raise RuntimeError("Incorrect count of properties!")
|
||||
raise RuntimeError('Incorrect count of properties!')
|
||||
for p in props:
|
||||
p["value"] = decode_prop_value(p, p["value"])
|
||||
p['value'] = decode_prop_value(p, p['value'])
|
||||
return props
|
||||
except RuntimeError as e:
|
||||
on_except(e)
|
||||
@@ -176,7 +176,7 @@ def set_property_values(tp, props, indices, values, check_readonly=False):
|
||||
if check_readonly:
|
||||
for index in indices:
|
||||
if prop_is_readonly(props[index]):
|
||||
raise RuntimeError("Cannot set value of Read-Only property")
|
||||
raise RuntimeError('Cannot set value of Read-Only property')
|
||||
message = proto.set_prop_vals_request(indices, values)
|
||||
response = tp.send_data('esp_local_ctrl/control', message)
|
||||
return proto.set_prop_vals_response(response)
|
||||
@@ -188,27 +188,27 @@ def set_property_values(tp, props, indices, values, check_readonly=False):
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(add_help=False)
|
||||
|
||||
parser = argparse.ArgumentParser(description="Control an ESP32 running esp_local_ctrl service")
|
||||
parser = argparse.ArgumentParser(description='Control an ESP32 running esp_local_ctrl service')
|
||||
|
||||
parser.add_argument("--version", dest='version', type=str,
|
||||
help="Protocol version", default='')
|
||||
parser.add_argument('--version', dest='version', type=str,
|
||||
help='Protocol version', default='')
|
||||
|
||||
parser.add_argument("--transport", dest='transport', type=str,
|
||||
help="transport i.e http or ble", default='http')
|
||||
parser.add_argument('--transport', dest='transport', type=str,
|
||||
help='transport i.e http or ble', default='http')
|
||||
|
||||
parser.add_argument("--name", dest='service_name', type=str,
|
||||
help="BLE Device Name / HTTP Server hostname or IP", default='')
|
||||
parser.add_argument('--name', dest='service_name', type=str,
|
||||
help='BLE Device Name / HTTP Server hostname or IP', default='')
|
||||
|
||||
parser.add_argument("--dont-check-hostname", action="store_true",
|
||||
parser.add_argument('--dont-check-hostname', action='store_true',
|
||||
# If enabled, the certificate won't be rejected for hostname mismatch.
|
||||
# This option is hidden because it should be used only for testing purposes.
|
||||
help=argparse.SUPPRESS)
|
||||
|
||||
parser.add_argument("-v", "--verbose", dest='verbose', help="increase output verbosity", action="store_true")
|
||||
parser.add_argument('-v', '--verbose', dest='verbose', help='increase output verbosity', action='store_true')
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.version != '':
|
||||
print("==== Esp_Ctrl Version: " + args.version + " ====")
|
||||
print('==== Esp_Ctrl Version: ' + args.version + ' ====')
|
||||
|
||||
if args.service_name == '':
|
||||
args.service_name = 'my_esp_ctrl_device'
|
||||
@@ -217,45 +217,45 @@ if __name__ == '__main__':
|
||||
|
||||
obj_transport = get_transport(args.transport, args.service_name, not args.dont_check_hostname)
|
||||
if obj_transport is None:
|
||||
print("---- Invalid transport ----")
|
||||
print('---- Invalid transport ----')
|
||||
exit(1)
|
||||
|
||||
if args.version != '':
|
||||
print("\n==== Verifying protocol version ====")
|
||||
print('\n==== Verifying protocol version ====')
|
||||
if not version_match(obj_transport, args.version, args.verbose):
|
||||
print("---- Error in protocol version matching ----")
|
||||
print('---- Error in protocol version matching ----')
|
||||
exit(2)
|
||||
print("==== Verified protocol version successfully ====")
|
||||
print('==== Verified protocol version successfully ====')
|
||||
|
||||
while True:
|
||||
properties = get_all_property_values(obj_transport)
|
||||
if len(properties) == 0:
|
||||
print("---- Error in reading property values ----")
|
||||
print('---- Error in reading property values ----')
|
||||
exit(4)
|
||||
|
||||
print("\n==== Available Properties ====")
|
||||
print("{0: >4} {1: <16} {2: <10} {3: <16} {4: <16}".format(
|
||||
"S.N.", "Name", "Type", "Flags", "Value"))
|
||||
print('\n==== Available Properties ====')
|
||||
print('{0: >4} {1: <16} {2: <10} {3: <16} {4: <16}'.format(
|
||||
'S.N.', 'Name', 'Type', 'Flags', 'Value'))
|
||||
for i in range(len(properties)):
|
||||
print("[{0: >2}] {1: <16} {2: <10} {3: <16} {4: <16}".format(
|
||||
i + 1, properties[i]["name"], prop_typestr(properties[i]),
|
||||
["","Read-Only"][prop_is_readonly(properties[i])],
|
||||
str(properties[i]["value"])))
|
||||
print('[{0: >2}] {1: <16} {2: <10} {3: <16} {4: <16}'.format(
|
||||
i + 1, properties[i]['name'], prop_typestr(properties[i]),
|
||||
['','Read-Only'][prop_is_readonly(properties[i])],
|
||||
str(properties[i]['value'])))
|
||||
|
||||
select = 0
|
||||
while True:
|
||||
try:
|
||||
inval = input("\nSelect properties to set (0 to re-read, 'q' to quit) : ")
|
||||
if inval.lower() == 'q':
|
||||
print("Quitting...")
|
||||
print('Quitting...')
|
||||
exit(5)
|
||||
invals = inval.split(',')
|
||||
selections = [int(val) for val in invals]
|
||||
if min(selections) < 0 or max(selections) > len(properties):
|
||||
raise ValueError("Invalid input")
|
||||
raise ValueError('Invalid input')
|
||||
break
|
||||
except ValueError as e:
|
||||
print(str(e) + "! Retry...")
|
||||
print(str(e) + '! Retry...')
|
||||
|
||||
if len(selections) == 1 and selections[0] == 0:
|
||||
continue
|
||||
@@ -264,15 +264,15 @@ if __name__ == '__main__':
|
||||
set_indices = []
|
||||
for select in selections:
|
||||
while True:
|
||||
inval = input("Enter value to set for property (" + properties[select - 1]["name"] + ") : ")
|
||||
inval = input('Enter value to set for property (' + properties[select - 1]['name'] + ') : ')
|
||||
value = encode_prop_value(properties[select - 1],
|
||||
str_to_prop_value(properties[select - 1], inval))
|
||||
if value is None:
|
||||
print("Invalid input! Retry...")
|
||||
print('Invalid input! Retry...')
|
||||
continue
|
||||
break
|
||||
set_values += [value]
|
||||
set_indices += [select - 1]
|
||||
|
||||
if not set_property_values(obj_transport, properties, set_indices, set_values):
|
||||
print("Failed to set values!")
|
||||
print('Failed to set values!')
|
||||
|
||||
@@ -15,9 +15,11 @@
|
||||
|
||||
|
||||
from __future__ import print_function
|
||||
from future.utils import tobytes
|
||||
|
||||
import os
|
||||
|
||||
from future.utils import tobytes
|
||||
|
||||
|
||||
def _load_source(name, path):
|
||||
try:
|
||||
@@ -30,8 +32,8 @@ def _load_source(name, path):
|
||||
|
||||
|
||||
idf_path = os.environ['IDF_PATH']
|
||||
constants_pb2 = _load_source("constants_pb2", idf_path + "/components/protocomm/python/constants_pb2.py")
|
||||
local_ctrl_pb2 = _load_source("esp_local_ctrl_pb2", idf_path + "/components/esp_local_ctrl/python/esp_local_ctrl_pb2.py")
|
||||
constants_pb2 = _load_source('constants_pb2', idf_path + '/components/protocomm/python/constants_pb2.py')
|
||||
local_ctrl_pb2 = _load_source('esp_local_ctrl_pb2', idf_path + '/components/esp_local_ctrl/python/esp_local_ctrl_pb2.py')
|
||||
|
||||
|
||||
def get_prop_count_request():
|
||||
@@ -67,10 +69,10 @@ def get_prop_vals_response(response_data):
|
||||
if (resp.resp_get_prop_vals.status == 0):
|
||||
for prop in resp.resp_get_prop_vals.props:
|
||||
results += [{
|
||||
"name": prop.name,
|
||||
"type": prop.type,
|
||||
"flags": prop.flags,
|
||||
"value": tobytes(prop.value)
|
||||
'name': prop.name,
|
||||
'type': prop.type,
|
||||
'flags': prop.flags,
|
||||
'value': tobytes(prop.value)
|
||||
}]
|
||||
return results
|
||||
|
||||
|
||||
@@ -14,15 +14,14 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
import re
|
||||
import os
|
||||
from __future__ import division, print_function, unicode_literals
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
from tiny_test_fw import Utility
|
||||
import ttfw_idf
|
||||
from idf_http_server_test import test as client
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
# When running on local machine execute the following before running this script
|
||||
# > make app bootloader
|
||||
@@ -36,23 +35,23 @@ from idf_http_server_test import test as client
|
||||
# features to this component.
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_http_server_advanced(env, extra_data):
|
||||
# Acquire DUT
|
||||
dut1 = env.get_dut("http_server", "examples/protocols/http_server/advanced_tests", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('http_server', 'examples/protocols/http_server/advanced_tests', dut_class=ttfw_idf.ESP32DUT)
|
||||
|
||||
# Get binary file
|
||||
binary_file = os.path.join(dut1.app.binary_path, "tests.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'tests.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("http_server_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('http_server_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
|
||||
# Upload binary and start testing
|
||||
Utility.console_log("Starting http_server advanced test app")
|
||||
Utility.console_log('Starting http_server advanced test app')
|
||||
dut1.start_app()
|
||||
|
||||
# Parse IP address of STA
|
||||
Utility.console_log("Waiting to connect with AP")
|
||||
got_ip = dut1.expect(re.compile(r"(?:[\s\S]*)IPv4 address: (\d+.\d+.\d+.\d+)"), timeout=30)[0]
|
||||
Utility.console_log('Waiting to connect with AP')
|
||||
got_ip = dut1.expect(re.compile(r'(?:[\s\S]*)IPv4 address: (\d+.\d+.\d+.\d+)'), timeout=30)[0]
|
||||
|
||||
got_port = dut1.expect(re.compile(r"(?:[\s\S]*)Started HTTP server on port: '(\d+)'"), timeout=15)[0]
|
||||
result = dut1.expect(re.compile(r"(?:[\s\S]*)Max URI handlers: '(\d+)'(?:[\s\S]*)Max Open Sessions: " # noqa: W605
|
||||
@@ -64,18 +63,18 @@ def test_examples_protocol_http_server_advanced(env, extra_data):
|
||||
max_uri_len = int(result[3])
|
||||
max_stack_size = int(result[4])
|
||||
|
||||
Utility.console_log("Got IP : " + got_ip)
|
||||
Utility.console_log("Got Port : " + got_port)
|
||||
Utility.console_log('Got IP : ' + got_ip)
|
||||
Utility.console_log('Got Port : ' + got_port)
|
||||
|
||||
# Run test script
|
||||
# If failed raise appropriate exception
|
||||
failed = False
|
||||
|
||||
Utility.console_log("Sessions and Context Tests...")
|
||||
Utility.console_log('Sessions and Context Tests...')
|
||||
if not client.spillover_session(got_ip, got_port, max_sessions):
|
||||
Utility.console_log("Ignoring failure")
|
||||
Utility.console_log('Ignoring failure')
|
||||
if not client.parallel_sessions_adder(got_ip, got_port, max_sessions):
|
||||
Utility.console_log("Ignoring failure")
|
||||
Utility.console_log('Ignoring failure')
|
||||
if not client.leftover_data_test(got_ip, got_port):
|
||||
failed = True
|
||||
if not client.async_response_test(got_ip, got_port):
|
||||
@@ -90,17 +89,17 @@ def test_examples_protocol_http_server_advanced(env, extra_data):
|
||||
# if not client.packet_size_limit_test(got_ip, got_port, test_size):
|
||||
# Utility.console_log("Ignoring failure")
|
||||
|
||||
Utility.console_log("Getting initial stack usage...")
|
||||
Utility.console_log('Getting initial stack usage...')
|
||||
if not client.get_hello(got_ip, got_port):
|
||||
failed = True
|
||||
|
||||
inital_stack = int(dut1.expect(re.compile(r"(?:[\s\S]*)Free Stack for server task: '(\d+)'"), timeout=15)[0])
|
||||
|
||||
if inital_stack < 0.1 * max_stack_size:
|
||||
Utility.console_log("More than 90% of stack being used on server start")
|
||||
Utility.console_log('More than 90% of stack being used on server start')
|
||||
failed = True
|
||||
|
||||
Utility.console_log("Basic HTTP Client Tests...")
|
||||
Utility.console_log('Basic HTTP Client Tests...')
|
||||
if not client.get_hello(got_ip, got_port):
|
||||
failed = True
|
||||
if not client.post_hello(got_ip, got_port):
|
||||
@@ -122,7 +121,7 @@ def test_examples_protocol_http_server_advanced(env, extra_data):
|
||||
if not client.get_test_headers(got_ip, got_port):
|
||||
failed = True
|
||||
|
||||
Utility.console_log("Error code tests...")
|
||||
Utility.console_log('Error code tests...')
|
||||
if not client.code_500_server_error_test(got_ip, got_port):
|
||||
failed = True
|
||||
if not client.code_501_method_not_impl(got_ip, got_port):
|
||||
@@ -138,20 +137,20 @@ def test_examples_protocol_http_server_advanced(env, extra_data):
|
||||
if not client.code_408_req_timeout(got_ip, got_port):
|
||||
failed = True
|
||||
if not client.code_414_uri_too_long(got_ip, got_port, max_uri_len):
|
||||
Utility.console_log("Ignoring failure")
|
||||
Utility.console_log('Ignoring failure')
|
||||
if not client.code_431_hdr_too_long(got_ip, got_port, max_hdr_len):
|
||||
Utility.console_log("Ignoring failure")
|
||||
Utility.console_log('Ignoring failure')
|
||||
if not client.test_upgrade_not_supported(got_ip, got_port):
|
||||
failed = True
|
||||
|
||||
Utility.console_log("Getting final stack usage...")
|
||||
Utility.console_log('Getting final stack usage...')
|
||||
if not client.get_hello(got_ip, got_port):
|
||||
failed = True
|
||||
|
||||
final_stack = int(dut1.expect(re.compile(r"(?:[\s\S]*)Free Stack for server task: '(\d+)'"), timeout=15)[0])
|
||||
|
||||
if final_stack < 0.05 * max_stack_size:
|
||||
Utility.console_log("More than 95% of stack got used during tests")
|
||||
Utility.console_log('More than 95% of stack got used during tests')
|
||||
failed = True
|
||||
|
||||
if failed:
|
||||
|
||||
@@ -129,20 +129,17 @@
|
||||
# - Simple GET on /hello/restart_results (returns the leak results)
|
||||
|
||||
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from builtins import str
|
||||
from builtins import range
|
||||
from builtins import object
|
||||
import threading
|
||||
import socket
|
||||
import time
|
||||
from __future__ import division, print_function
|
||||
|
||||
import argparse
|
||||
import http.client
|
||||
import sys
|
||||
import string
|
||||
import random
|
||||
|
||||
import socket
|
||||
import string
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
from builtins import object, range, str
|
||||
|
||||
try:
|
||||
import Utility
|
||||
@@ -151,7 +148,7 @@ except ImportError:
|
||||
|
||||
# This environment variable is expected on the host machine
|
||||
# > export TEST_FW_PATH=~/esp/esp-idf/tools/tiny-test-fw
|
||||
test_fw_path = os.getenv("TEST_FW_PATH")
|
||||
test_fw_path = os.getenv('TEST_FW_PATH')
|
||||
if test_fw_path and test_fw_path not in sys.path:
|
||||
sys.path.insert(0, test_fw_path)
|
||||
|
||||
@@ -177,32 +174,32 @@ class Session(object):
|
||||
self.client.sendall(data.encode())
|
||||
except socket.error as err:
|
||||
self.client.close()
|
||||
Utility.console_log("Socket Error in send :", err)
|
||||
Utility.console_log('Socket Error in send :', err)
|
||||
rval = False
|
||||
return rval
|
||||
|
||||
def send_get(self, path, headers=None):
|
||||
request = "GET " + path + " HTTP/1.1\r\nHost: " + self.target
|
||||
request = 'GET ' + path + ' HTTP/1.1\r\nHost: ' + self.target
|
||||
if headers:
|
||||
for field, value in headers.items():
|
||||
request += "\r\n" + field + ": " + value
|
||||
request += "\r\n\r\n"
|
||||
request += '\r\n' + field + ': ' + value
|
||||
request += '\r\n\r\n'
|
||||
return self.send_err_check(request)
|
||||
|
||||
def send_put(self, path, data, headers=None):
|
||||
request = "PUT " + path + " HTTP/1.1\r\nHost: " + self.target
|
||||
request = 'PUT ' + path + ' HTTP/1.1\r\nHost: ' + self.target
|
||||
if headers:
|
||||
for field, value in headers.items():
|
||||
request += "\r\n" + field + ": " + value
|
||||
request += "\r\nContent-Length: " + str(len(data)) + "\r\n\r\n"
|
||||
request += '\r\n' + field + ': ' + value
|
||||
request += '\r\nContent-Length: ' + str(len(data)) + '\r\n\r\n'
|
||||
return self.send_err_check(request, data)
|
||||
|
||||
def send_post(self, path, data, headers=None):
|
||||
request = "POST " + path + " HTTP/1.1\r\nHost: " + self.target
|
||||
request = 'POST ' + path + ' HTTP/1.1\r\nHost: ' + self.target
|
||||
if headers:
|
||||
for field, value in headers.items():
|
||||
request += "\r\n" + field + ": " + value
|
||||
request += "\r\nContent-Length: " + str(len(data)) + "\r\n\r\n"
|
||||
request += '\r\n' + field + ': ' + value
|
||||
request += '\r\nContent-Length: ' + str(len(data)) + '\r\n\r\n'
|
||||
return self.send_err_check(request, data)
|
||||
|
||||
def read_resp_hdrs(self):
|
||||
@@ -246,7 +243,7 @@ class Session(object):
|
||||
return headers
|
||||
except socket.error as err:
|
||||
self.client.close()
|
||||
Utility.console_log("Socket Error in recv :", err)
|
||||
Utility.console_log('Socket Error in recv :', err)
|
||||
return None
|
||||
|
||||
def read_resp_data(self):
|
||||
@@ -275,9 +272,9 @@ class Session(object):
|
||||
rem_len -= len(new_data)
|
||||
chunk_data_buf = ''
|
||||
# Fetch remaining CRLF
|
||||
if self.client.recv(2) != "\r\n":
|
||||
if self.client.recv(2) != '\r\n':
|
||||
# Error in packet
|
||||
Utility.console_log("Error in chunked data")
|
||||
Utility.console_log('Error in chunked data')
|
||||
return None
|
||||
if not chunk_len:
|
||||
# If last chunk
|
||||
@@ -290,7 +287,7 @@ class Session(object):
|
||||
return read_data
|
||||
except socket.error as err:
|
||||
self.client.close()
|
||||
Utility.console_log("Socket Error in recv :", err)
|
||||
Utility.console_log('Socket Error in recv :', err)
|
||||
return None
|
||||
|
||||
def close(self):
|
||||
@@ -299,10 +296,10 @@ class Session(object):
|
||||
|
||||
def test_val(text, expected, received):
|
||||
if expected != received:
|
||||
Utility.console_log(" Fail!")
|
||||
Utility.console_log(" [reason] " + text + ":")
|
||||
Utility.console_log(" expected: " + str(expected))
|
||||
Utility.console_log(" received: " + str(received))
|
||||
Utility.console_log(' Fail!')
|
||||
Utility.console_log(' [reason] ' + text + ':')
|
||||
Utility.console_log(' expected: ' + str(expected))
|
||||
Utility.console_log(' received: ' + str(received))
|
||||
return False
|
||||
return True
|
||||
|
||||
@@ -320,7 +317,7 @@ class adder_thread (threading.Thread):
|
||||
|
||||
# Pipeline 3 requests
|
||||
if (_verbose_):
|
||||
Utility.console_log(" Thread: Using adder start " + str(self.id))
|
||||
Utility.console_log(' Thread: Using adder start ' + str(self.id))
|
||||
|
||||
for _ in range(self.depth):
|
||||
self.session.send_post('/adder', str(self.id))
|
||||
@@ -332,10 +329,10 @@ class adder_thread (threading.Thread):
|
||||
|
||||
def adder_result(self):
|
||||
if len(self.response) != self.depth:
|
||||
Utility.console_log("Error : missing response packets")
|
||||
Utility.console_log('Error : missing response packets')
|
||||
return False
|
||||
for i in range(len(self.response)):
|
||||
if not test_val("Thread" + str(self.id) + " response[" + str(i) + "]",
|
||||
if not test_val('Thread' + str(self.id) + ' response[' + str(i) + ']',
|
||||
str(self.id * (i + 1)), str(self.response[i])):
|
||||
return False
|
||||
return True
|
||||
@@ -348,177 +345,177 @@ def get_hello(dut, port):
|
||||
# GET /hello should return 'Hello World!'
|
||||
Utility.console_log("[test] GET /hello returns 'Hello World!' =>", end=' ')
|
||||
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||
conn.request("GET", "/hello")
|
||||
conn.request('GET', '/hello')
|
||||
resp = conn.getresponse()
|
||||
if not test_val("status_code", 200, resp.status):
|
||||
if not test_val('status_code', 200, resp.status):
|
||||
conn.close()
|
||||
return False
|
||||
if not test_val("data", "Hello World!", resp.read().decode()):
|
||||
if not test_val('data', 'Hello World!', resp.read().decode()):
|
||||
conn.close()
|
||||
return False
|
||||
if not test_val("data", "text/html", resp.getheader('Content-Type')):
|
||||
if not test_val('data', 'text/html', resp.getheader('Content-Type')):
|
||||
conn.close()
|
||||
return False
|
||||
Utility.console_log("Success")
|
||||
Utility.console_log('Success')
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
|
||||
def put_hello(dut, port):
|
||||
# PUT /hello returns 405'
|
||||
Utility.console_log("[test] PUT /hello returns 405 =>", end=' ')
|
||||
Utility.console_log('[test] PUT /hello returns 405 =>', end=' ')
|
||||
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||
conn.request("PUT", "/hello", "Hello")
|
||||
conn.request('PUT', '/hello', 'Hello')
|
||||
resp = conn.getresponse()
|
||||
if not test_val("status_code", 405, resp.status):
|
||||
if not test_val('status_code', 405, resp.status):
|
||||
conn.close()
|
||||
return False
|
||||
Utility.console_log("Success")
|
||||
Utility.console_log('Success')
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
|
||||
def post_hello(dut, port):
|
||||
# POST /hello returns 405'
|
||||
Utility.console_log("[test] POST /hello returns 405 =>", end=' ')
|
||||
Utility.console_log('[test] POST /hello returns 405 =>', end=' ')
|
||||
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||
conn.request("POST", "/hello", "Hello")
|
||||
conn.request('POST', '/hello', 'Hello')
|
||||
resp = conn.getresponse()
|
||||
if not test_val("status_code", 405, resp.status):
|
||||
if not test_val('status_code', 405, resp.status):
|
||||
conn.close()
|
||||
return False
|
||||
Utility.console_log("Success")
|
||||
Utility.console_log('Success')
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
|
||||
def post_echo(dut, port):
|
||||
# POST /echo echoes data'
|
||||
Utility.console_log("[test] POST /echo echoes data =>", end=' ')
|
||||
Utility.console_log('[test] POST /echo echoes data =>', end=' ')
|
||||
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||
conn.request("POST", "/echo", "Hello")
|
||||
conn.request('POST', '/echo', 'Hello')
|
||||
resp = conn.getresponse()
|
||||
if not test_val("status_code", 200, resp.status):
|
||||
if not test_val('status_code', 200, resp.status):
|
||||
conn.close()
|
||||
return False
|
||||
if not test_val("data", "Hello", resp.read().decode()):
|
||||
if not test_val('data', 'Hello', resp.read().decode()):
|
||||
conn.close()
|
||||
return False
|
||||
Utility.console_log("Success")
|
||||
Utility.console_log('Success')
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
|
||||
def put_echo(dut, port):
|
||||
# PUT /echo echoes data'
|
||||
Utility.console_log("[test] PUT /echo echoes data =>", end=' ')
|
||||
Utility.console_log('[test] PUT /echo echoes data =>', end=' ')
|
||||
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||
conn.request("PUT", "/echo", "Hello")
|
||||
conn.request('PUT', '/echo', 'Hello')
|
||||
resp = conn.getresponse()
|
||||
if not test_val("status_code", 200, resp.status):
|
||||
if not test_val('status_code', 200, resp.status):
|
||||
conn.close()
|
||||
return False
|
||||
if not test_val("data", "Hello", resp.read().decode()):
|
||||
if not test_val('data', 'Hello', resp.read().decode()):
|
||||
conn.close()
|
||||
return False
|
||||
Utility.console_log("Success")
|
||||
Utility.console_log('Success')
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
|
||||
def get_echo(dut, port):
|
||||
# GET /echo returns 404'
|
||||
Utility.console_log("[test] GET /echo returns 405 =>", end=' ')
|
||||
Utility.console_log('[test] GET /echo returns 405 =>', end=' ')
|
||||
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||
conn.request("GET", "/echo")
|
||||
conn.request('GET', '/echo')
|
||||
resp = conn.getresponse()
|
||||
if not test_val("status_code", 405, resp.status):
|
||||
if not test_val('status_code', 405, resp.status):
|
||||
conn.close()
|
||||
return False
|
||||
Utility.console_log("Success")
|
||||
Utility.console_log('Success')
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
|
||||
def get_test_headers(dut, port):
|
||||
# GET /test_header returns data of Header2'
|
||||
Utility.console_log("[test] GET /test_header =>", end=' ')
|
||||
Utility.console_log('[test] GET /test_header =>', end=' ')
|
||||
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||
custom_header = {"Header1": "Value1", "Header3": "Value3"}
|
||||
header2_values = ["", " ", "Value2", " Value2", "Value2 ", " Value2 "]
|
||||
custom_header = {'Header1': 'Value1', 'Header3': 'Value3'}
|
||||
header2_values = ['', ' ', 'Value2', ' Value2', 'Value2 ', ' Value2 ']
|
||||
for val in header2_values:
|
||||
custom_header["Header2"] = val
|
||||
conn.request("GET", "/test_header", headers=custom_header)
|
||||
custom_header['Header2'] = val
|
||||
conn.request('GET', '/test_header', headers=custom_header)
|
||||
resp = conn.getresponse()
|
||||
if not test_val("status_code", 200, resp.status):
|
||||
if not test_val('status_code', 200, resp.status):
|
||||
conn.close()
|
||||
return False
|
||||
hdr_val_start_idx = val.find("Value2")
|
||||
hdr_val_start_idx = val.find('Value2')
|
||||
if hdr_val_start_idx == -1:
|
||||
if not test_val("header: Header2", "", resp.read().decode()):
|
||||
if not test_val('header: Header2', '', resp.read().decode()):
|
||||
conn.close()
|
||||
return False
|
||||
else:
|
||||
if not test_val("header: Header2", val[hdr_val_start_idx:], resp.read().decode()):
|
||||
if not test_val('header: Header2', val[hdr_val_start_idx:], resp.read().decode()):
|
||||
conn.close()
|
||||
return False
|
||||
resp.read()
|
||||
Utility.console_log("Success")
|
||||
Utility.console_log('Success')
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
|
||||
def get_hello_type(dut, port):
|
||||
# GET /hello/type_html returns text/html as Content-Type'
|
||||
Utility.console_log("[test] GET /hello/type_html has Content-Type of text/html =>", end=' ')
|
||||
Utility.console_log('[test] GET /hello/type_html has Content-Type of text/html =>', end=' ')
|
||||
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||
conn.request("GET", "/hello/type_html")
|
||||
conn.request('GET', '/hello/type_html')
|
||||
resp = conn.getresponse()
|
||||
if not test_val("status_code", 200, resp.status):
|
||||
if not test_val('status_code', 200, resp.status):
|
||||
conn.close()
|
||||
return False
|
||||
if not test_val("data", "Hello World!", resp.read().decode()):
|
||||
if not test_val('data', 'Hello World!', resp.read().decode()):
|
||||
conn.close()
|
||||
return False
|
||||
if not test_val("data", "text/html", resp.getheader('Content-Type')):
|
||||
if not test_val('data', 'text/html', resp.getheader('Content-Type')):
|
||||
conn.close()
|
||||
return False
|
||||
Utility.console_log("Success")
|
||||
Utility.console_log('Success')
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
|
||||
def get_hello_status(dut, port):
|
||||
# GET /hello/status_500 returns status 500'
|
||||
Utility.console_log("[test] GET /hello/status_500 returns status 500 =>", end=' ')
|
||||
Utility.console_log('[test] GET /hello/status_500 returns status 500 =>', end=' ')
|
||||
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||
conn.request("GET", "/hello/status_500")
|
||||
conn.request('GET', '/hello/status_500')
|
||||
resp = conn.getresponse()
|
||||
if not test_val("status_code", 500, resp.status):
|
||||
if not test_val('status_code', 500, resp.status):
|
||||
conn.close()
|
||||
return False
|
||||
Utility.console_log("Success")
|
||||
Utility.console_log('Success')
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
|
||||
def get_false_uri(dut, port):
|
||||
# GET /false_uri returns status 404'
|
||||
Utility.console_log("[test] GET /false_uri returns status 404 =>", end=' ')
|
||||
Utility.console_log('[test] GET /false_uri returns status 404 =>', end=' ')
|
||||
conn = http.client.HTTPConnection(dut, int(port), timeout=15)
|
||||
conn.request("GET", "/false_uri")
|
||||
conn.request('GET', '/false_uri')
|
||||
resp = conn.getresponse()
|
||||
if not test_val("status_code", 404, resp.status):
|
||||
if not test_val('status_code', 404, resp.status):
|
||||
conn.close()
|
||||
return False
|
||||
Utility.console_log("Success")
|
||||
Utility.console_log('Success')
|
||||
conn.close()
|
||||
return True
|
||||
|
||||
|
||||
def parallel_sessions_adder(dut, port, max_sessions):
|
||||
# POSTs on /adder in parallel sessions
|
||||
Utility.console_log("[test] POST {pipelined} on /adder in " + str(max_sessions) + " sessions =>", end=' ')
|
||||
Utility.console_log('[test] POST {pipelined} on /adder in ' + str(max_sessions) + ' sessions =>', end=' ')
|
||||
t = []
|
||||
# Create all sessions
|
||||
for i in range(max_sessions):
|
||||
@@ -532,90 +529,90 @@ def parallel_sessions_adder(dut, port, max_sessions):
|
||||
|
||||
res = True
|
||||
for i in range(len(t)):
|
||||
if not test_val("Thread" + str(i) + " Failed", t[i].adder_result(), True):
|
||||
if not test_val('Thread' + str(i) + ' Failed', t[i].adder_result(), True):
|
||||
res = False
|
||||
t[i].close()
|
||||
if (res):
|
||||
Utility.console_log("Success")
|
||||
Utility.console_log('Success')
|
||||
return res
|
||||
|
||||
|
||||
def async_response_test(dut, port):
|
||||
# Test that an asynchronous work is executed in the HTTPD's context
|
||||
# This is tested by reading two responses over the same session
|
||||
Utility.console_log("[test] Test HTTPD Work Queue (Async response) =>", end=' ')
|
||||
Utility.console_log('[test] Test HTTPD Work Queue (Async response) =>', end=' ')
|
||||
s = Session(dut, port)
|
||||
|
||||
s.send_get('/async_data')
|
||||
s.read_resp_hdrs()
|
||||
if not test_val("First Response", "Hello World!", s.read_resp_data()):
|
||||
if not test_val('First Response', 'Hello World!', s.read_resp_data()):
|
||||
s.close()
|
||||
return False
|
||||
s.read_resp_hdrs()
|
||||
if not test_val("Second Response", "Hello Double World!", s.read_resp_data()):
|
||||
if not test_val('Second Response', 'Hello Double World!', s.read_resp_data()):
|
||||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
Utility.console_log("Success")
|
||||
Utility.console_log('Success')
|
||||
return True
|
||||
|
||||
|
||||
def leftover_data_test(dut, port):
|
||||
# Leftover data in POST is purged (valid and invalid URIs)
|
||||
Utility.console_log("[test] Leftover data in POST is purged (valid and invalid URIs) =>", end=' ')
|
||||
s = http.client.HTTPConnection(dut + ":" + port, timeout=15)
|
||||
Utility.console_log('[test] Leftover data in POST is purged (valid and invalid URIs) =>', end=' ')
|
||||
s = http.client.HTTPConnection(dut + ':' + port, timeout=15)
|
||||
|
||||
s.request("POST", url='/leftover_data', body="abcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz")
|
||||
s.request('POST', url='/leftover_data', body='abcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz')
|
||||
resp = s.getresponse()
|
||||
if not test_val("Partial data", "abcdefghij", resp.read().decode()):
|
||||
if not test_val('Partial data', 'abcdefghij', resp.read().decode()):
|
||||
s.close()
|
||||
return False
|
||||
|
||||
s.request("GET", url='/hello')
|
||||
s.request('GET', url='/hello')
|
||||
resp = s.getresponse()
|
||||
if not test_val("Hello World Data", "Hello World!", resp.read().decode()):
|
||||
if not test_val('Hello World Data', 'Hello World!', resp.read().decode()):
|
||||
s.close()
|
||||
return False
|
||||
|
||||
s.request("POST", url='/false_uri', body="abcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz")
|
||||
s.request('POST', url='/false_uri', body='abcdefghijklmnopqrstuvwxyz\r\nabcdefghijklmnopqrstuvwxyz')
|
||||
resp = s.getresponse()
|
||||
if not test_val("False URI Status", str(404), str(resp.status)):
|
||||
if not test_val('False URI Status', str(404), str(resp.status)):
|
||||
s.close()
|
||||
return False
|
||||
# socket would have been closed by server due to error
|
||||
s.close()
|
||||
|
||||
s = http.client.HTTPConnection(dut + ":" + port, timeout=15)
|
||||
s.request("GET", url='/hello')
|
||||
s = http.client.HTTPConnection(dut + ':' + port, timeout=15)
|
||||
s.request('GET', url='/hello')
|
||||
resp = s.getresponse()
|
||||
if not test_val("Hello World Data", "Hello World!", resp.read().decode()):
|
||||
if not test_val('Hello World Data', 'Hello World!', resp.read().decode()):
|
||||
s.close()
|
||||
return False
|
||||
|
||||
s.close()
|
||||
Utility.console_log("Success")
|
||||
Utility.console_log('Success')
|
||||
return True
|
||||
|
||||
|
||||
def spillover_session(dut, port, max_sess):
|
||||
# Session max_sess_sessions + 1 is rejected
|
||||
Utility.console_log("[test] Session max_sess_sessions (" + str(max_sess) + ") + 1 is rejected =>", end=' ')
|
||||
Utility.console_log('[test] Session max_sess_sessions (' + str(max_sess) + ') + 1 is rejected =>', end=' ')
|
||||
s = []
|
||||
_verbose_ = True
|
||||
for i in range(max_sess + 1):
|
||||
if (_verbose_):
|
||||
Utility.console_log("Executing " + str(i))
|
||||
Utility.console_log('Executing ' + str(i))
|
||||
try:
|
||||
a = http.client.HTTPConnection(dut + ":" + port, timeout=15)
|
||||
a.request("GET", url='/hello')
|
||||
a = http.client.HTTPConnection(dut + ':' + port, timeout=15)
|
||||
a.request('GET', url='/hello')
|
||||
resp = a.getresponse()
|
||||
if not test_val("Connection " + str(i), "Hello World!", resp.read().decode()):
|
||||
if not test_val('Connection ' + str(i), 'Hello World!', resp.read().decode()):
|
||||
a.close()
|
||||
break
|
||||
s.append(a)
|
||||
except Exception:
|
||||
if (_verbose_):
|
||||
Utility.console_log("Connection " + str(i) + " rejected")
|
||||
Utility.console_log('Connection ' + str(i) + ' rejected')
|
||||
a.close()
|
||||
break
|
||||
|
||||
@@ -624,134 +621,134 @@ def spillover_session(dut, port, max_sess):
|
||||
a.close()
|
||||
|
||||
# Check if number of connections is equal to max_sess
|
||||
Utility.console_log(["Fail","Success"][len(s) == max_sess])
|
||||
Utility.console_log(['Fail','Success'][len(s) == max_sess])
|
||||
return (len(s) == max_sess)
|
||||
|
||||
|
||||
def recv_timeout_test(dut, port):
|
||||
Utility.console_log("[test] Timeout occurs if partial packet sent =>", end=' ')
|
||||
Utility.console_log('[test] Timeout occurs if partial packet sent =>', end=' ')
|
||||
s = Session(dut, port)
|
||||
s.client.sendall(b"GE")
|
||||
s.client.sendall(b'GE')
|
||||
s.read_resp_hdrs()
|
||||
resp = s.read_resp_data()
|
||||
if not test_val("Request Timeout", "Server closed this connection", resp):
|
||||
if not test_val('Request Timeout', 'Server closed this connection', resp):
|
||||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
Utility.console_log("Success")
|
||||
Utility.console_log('Success')
|
||||
return True
|
||||
|
||||
|
||||
def packet_size_limit_test(dut, port, test_size):
|
||||
Utility.console_log("[test] send size limit test =>", end=' ')
|
||||
Utility.console_log('[test] send size limit test =>', end=' ')
|
||||
retry = 5
|
||||
while (retry):
|
||||
retry -= 1
|
||||
Utility.console_log("data size = ", test_size)
|
||||
s = http.client.HTTPConnection(dut + ":" + port, timeout=15)
|
||||
Utility.console_log('data size = ', test_size)
|
||||
s = http.client.HTTPConnection(dut + ':' + port, timeout=15)
|
||||
random_data = ''.join(string.printable[random.randint(0,len(string.printable)) - 1] for _ in list(range(test_size)))
|
||||
path = "/echo"
|
||||
s.request("POST", url=path, body=random_data)
|
||||
path = '/echo'
|
||||
s.request('POST', url=path, body=random_data)
|
||||
resp = s.getresponse()
|
||||
if not test_val("Error", "200", str(resp.status)):
|
||||
if test_val("Error", "500", str(resp.status)):
|
||||
Utility.console_log("Data too large to be allocated")
|
||||
if not test_val('Error', '200', str(resp.status)):
|
||||
if test_val('Error', '500', str(resp.status)):
|
||||
Utility.console_log('Data too large to be allocated')
|
||||
test_size = test_size // 10
|
||||
else:
|
||||
Utility.console_log("Unexpected error")
|
||||
Utility.console_log('Unexpected error')
|
||||
s.close()
|
||||
Utility.console_log("Retry...")
|
||||
Utility.console_log('Retry...')
|
||||
continue
|
||||
resp = resp.read().decode()
|
||||
result = (resp == random_data)
|
||||
if not result:
|
||||
test_val("Data size", str(len(random_data)), str(len(resp)))
|
||||
test_val('Data size', str(len(random_data)), str(len(resp)))
|
||||
s.close()
|
||||
Utility.console_log("Retry...")
|
||||
Utility.console_log('Retry...')
|
||||
continue
|
||||
s.close()
|
||||
Utility.console_log("Success")
|
||||
Utility.console_log('Success')
|
||||
return True
|
||||
Utility.console_log("Failed")
|
||||
Utility.console_log('Failed')
|
||||
return False
|
||||
|
||||
|
||||
def arbitrary_termination_test(dut, port):
|
||||
Utility.console_log("[test] Arbitrary termination test =>", end=' ')
|
||||
Utility.console_log('[test] Arbitrary termination test =>', end=' ')
|
||||
cases = [
|
||||
{
|
||||
"request": "POST /echo HTTP/1.1\r\nHost: " + dut + "\r\nCustom: SomeValue\r\n\r\n",
|
||||
"code": "200",
|
||||
"header": "SomeValue"
|
||||
'request': 'POST /echo HTTP/1.1\r\nHost: ' + dut + '\r\nCustom: SomeValue\r\n\r\n',
|
||||
'code': '200',
|
||||
'header': 'SomeValue'
|
||||
},
|
||||
{
|
||||
"request": "POST /echo HTTP/1.1\nHost: " + dut + "\r\nCustom: SomeValue\r\n\r\n",
|
||||
"code": "200",
|
||||
"header": "SomeValue"
|
||||
'request': 'POST /echo HTTP/1.1\nHost: ' + dut + '\r\nCustom: SomeValue\r\n\r\n',
|
||||
'code': '200',
|
||||
'header': 'SomeValue'
|
||||
},
|
||||
{
|
||||
"request": "POST /echo HTTP/1.1\r\nHost: " + dut + "\nCustom: SomeValue\r\n\r\n",
|
||||
"code": "200",
|
||||
"header": "SomeValue"
|
||||
'request': 'POST /echo HTTP/1.1\r\nHost: ' + dut + '\nCustom: SomeValue\r\n\r\n',
|
||||
'code': '200',
|
||||
'header': 'SomeValue'
|
||||
},
|
||||
{
|
||||
"request": "POST /echo HTTP/1.1\r\nHost: " + dut + "\r\nCustom: SomeValue\n\r\n",
|
||||
"code": "200",
|
||||
"header": "SomeValue"
|
||||
'request': 'POST /echo HTTP/1.1\r\nHost: ' + dut + '\r\nCustom: SomeValue\n\r\n',
|
||||
'code': '200',
|
||||
'header': 'SomeValue'
|
||||
},
|
||||
{
|
||||
"request": "POST /echo HTTP/1.1\r\nHost: " + dut + "\r\nCustom: SomeValue\r\n\n",
|
||||
"code": "200",
|
||||
"header": "SomeValue"
|
||||
'request': 'POST /echo HTTP/1.1\r\nHost: ' + dut + '\r\nCustom: SomeValue\r\n\n',
|
||||
'code': '200',
|
||||
'header': 'SomeValue'
|
||||
},
|
||||
{
|
||||
"request": "POST /echo HTTP/1.1\nHost: " + dut + "\nCustom: SomeValue\n\n",
|
||||
"code": "200",
|
||||
"header": "SomeValue"
|
||||
'request': 'POST /echo HTTP/1.1\nHost: ' + dut + '\nCustom: SomeValue\n\n',
|
||||
'code': '200',
|
||||
'header': 'SomeValue'
|
||||
},
|
||||
{
|
||||
"request": "POST /echo HTTP/1.1\r\nHost: " + dut + "\r\nContent-Length: 5\n\r\nABCDE",
|
||||
"code": "200",
|
||||
"body": "ABCDE"
|
||||
'request': 'POST /echo HTTP/1.1\r\nHost: ' + dut + '\r\nContent-Length: 5\n\r\nABCDE',
|
||||
'code': '200',
|
||||
'body': 'ABCDE'
|
||||
},
|
||||
{
|
||||
"request": "POST /echo HTTP/1.1\r\nHost: " + dut + "\r\nContent-Length: 5\r\n\nABCDE",
|
||||
"code": "200",
|
||||
"body": "ABCDE"
|
||||
'request': 'POST /echo HTTP/1.1\r\nHost: ' + dut + '\r\nContent-Length: 5\r\n\nABCDE',
|
||||
'code': '200',
|
||||
'body': 'ABCDE'
|
||||
},
|
||||
{
|
||||
"request": "POST /echo HTTP/1.1\r\nHost: " + dut + "\r\nContent-Length: 5\n\nABCDE",
|
||||
"code": "200",
|
||||
"body": "ABCDE"
|
||||
'request': 'POST /echo HTTP/1.1\r\nHost: ' + dut + '\r\nContent-Length: 5\n\nABCDE',
|
||||
'code': '200',
|
||||
'body': 'ABCDE'
|
||||
},
|
||||
{
|
||||
"request": "POST /echo HTTP/1.1\r\nHost: " + dut + "\r\nContent-Length: 5\n\n\rABCD",
|
||||
"code": "200",
|
||||
"body": "\rABCD"
|
||||
'request': 'POST /echo HTTP/1.1\r\nHost: ' + dut + '\r\nContent-Length: 5\n\n\rABCD',
|
||||
'code': '200',
|
||||
'body': '\rABCD'
|
||||
},
|
||||
{
|
||||
"request": "POST /echo HTTP/1.1\r\nHost: " + dut + "\r\r\nCustom: SomeValue\r\r\n\r\r\n",
|
||||
"code": "400"
|
||||
'request': 'POST /echo HTTP/1.1\r\nHost: ' + dut + '\r\r\nCustom: SomeValue\r\r\n\r\r\n',
|
||||
'code': '400'
|
||||
},
|
||||
{
|
||||
"request": "POST /echo HTTP/1.1\r\r\nHost: " + dut + "\r\n\r\n",
|
||||
"code": "400"
|
||||
'request': 'POST /echo HTTP/1.1\r\r\nHost: ' + dut + '\r\n\r\n',
|
||||
'code': '400'
|
||||
},
|
||||
{
|
||||
"request": "POST /echo HTTP/1.1\r\n\rHost: " + dut + "\r\n\r\n",
|
||||
"code": "400"
|
||||
'request': 'POST /echo HTTP/1.1\r\n\rHost: ' + dut + '\r\n\r\n',
|
||||
'code': '400'
|
||||
},
|
||||
{
|
||||
"request": "POST /echo HTTP/1.1\r\nHost: " + dut + "\rCustom: SomeValue\r\n",
|
||||
"code": "400"
|
||||
'request': 'POST /echo HTTP/1.1\r\nHost: ' + dut + '\rCustom: SomeValue\r\n',
|
||||
'code': '400'
|
||||
},
|
||||
{
|
||||
"request": "POST /echo HTTP/1.1\r\nHost: " + dut + "\r\nCustom: Some\rValue\r\n",
|
||||
"code": "400"
|
||||
'request': 'POST /echo HTTP/1.1\r\nHost: ' + dut + '\r\nCustom: Some\rValue\r\n',
|
||||
'code': '400'
|
||||
},
|
||||
{
|
||||
"request": "POST /echo HTTP/1.1\r\nHost: " + dut + "\r\nCustom- SomeValue\r\n\r\n",
|
||||
"code": "400"
|
||||
'request': 'POST /echo HTTP/1.1\r\nHost: ' + dut + '\r\nCustom- SomeValue\r\n\r\n',
|
||||
'code': '400'
|
||||
}
|
||||
]
|
||||
for case in cases:
|
||||
@@ -760,159 +757,159 @@ def arbitrary_termination_test(dut, port):
|
||||
resp_hdrs = s.read_resp_hdrs()
|
||||
resp_body = s.read_resp_data()
|
||||
s.close()
|
||||
if not test_val("Response Code", case["code"], s.status):
|
||||
if not test_val('Response Code', case['code'], s.status):
|
||||
return False
|
||||
if "header" in case.keys():
|
||||
if 'header' in case.keys():
|
||||
resp_hdr_val = None
|
||||
if "Custom" in resp_hdrs.keys():
|
||||
resp_hdr_val = resp_hdrs["Custom"]
|
||||
if not test_val("Response Header", case["header"], resp_hdr_val):
|
||||
if 'Custom' in resp_hdrs.keys():
|
||||
resp_hdr_val = resp_hdrs['Custom']
|
||||
if not test_val('Response Header', case['header'], resp_hdr_val):
|
||||
return False
|
||||
if "body" in case.keys():
|
||||
if not test_val("Response Body", case["body"], resp_body):
|
||||
if 'body' in case.keys():
|
||||
if not test_val('Response Body', case['body'], resp_body):
|
||||
return False
|
||||
Utility.console_log("Success")
|
||||
Utility.console_log('Success')
|
||||
return True
|
||||
|
||||
|
||||
def code_500_server_error_test(dut, port):
|
||||
Utility.console_log("[test] 500 Server Error test =>", end=' ')
|
||||
Utility.console_log('[test] 500 Server Error test =>', end=' ')
|
||||
s = Session(dut, port)
|
||||
# Sending a very large content length will cause malloc to fail
|
||||
content_len = 2**30
|
||||
s.client.sendall(("POST /echo HTTP/1.1\r\nHost: " + dut + "\r\nContent-Length: " + str(content_len) + "\r\n\r\nABCD").encode())
|
||||
s.client.sendall(('POST /echo HTTP/1.1\r\nHost: ' + dut + '\r\nContent-Length: ' + str(content_len) + '\r\n\r\nABCD').encode())
|
||||
s.read_resp_hdrs()
|
||||
s.read_resp_data()
|
||||
if not test_val("Server Error", "500", s.status):
|
||||
if not test_val('Server Error', '500', s.status):
|
||||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
Utility.console_log("Success")
|
||||
Utility.console_log('Success')
|
||||
return True
|
||||
|
||||
|
||||
def code_501_method_not_impl(dut, port):
|
||||
Utility.console_log("[test] 501 Method Not Implemented =>", end=' ')
|
||||
Utility.console_log('[test] 501 Method Not Implemented =>', end=' ')
|
||||
s = Session(dut, port)
|
||||
path = "/hello"
|
||||
s.client.sendall(("ABC " + path + " HTTP/1.1\r\nHost: " + dut + "\r\n\r\n").encode())
|
||||
path = '/hello'
|
||||
s.client.sendall(('ABC ' + path + ' HTTP/1.1\r\nHost: ' + dut + '\r\n\r\n').encode())
|
||||
s.read_resp_hdrs()
|
||||
s.read_resp_data()
|
||||
# Presently server sends back 400 Bad Request
|
||||
# if not test_val("Server Error", "501", s.status):
|
||||
# s.close()
|
||||
# return False
|
||||
if not test_val("Server Error", "400", s.status):
|
||||
if not test_val('Server Error', '400', s.status):
|
||||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
Utility.console_log("Success")
|
||||
Utility.console_log('Success')
|
||||
return True
|
||||
|
||||
|
||||
def code_505_version_not_supported(dut, port):
|
||||
Utility.console_log("[test] 505 Version Not Supported =>", end=' ')
|
||||
Utility.console_log('[test] 505 Version Not Supported =>', end=' ')
|
||||
s = Session(dut, port)
|
||||
path = "/hello"
|
||||
s.client.sendall(("GET " + path + " HTTP/2.0\r\nHost: " + dut + "\r\n\r\n").encode())
|
||||
path = '/hello'
|
||||
s.client.sendall(('GET ' + path + ' HTTP/2.0\r\nHost: ' + dut + '\r\n\r\n').encode())
|
||||
s.read_resp_hdrs()
|
||||
s.read_resp_data()
|
||||
if not test_val("Server Error", "505", s.status):
|
||||
if not test_val('Server Error', '505', s.status):
|
||||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
Utility.console_log("Success")
|
||||
Utility.console_log('Success')
|
||||
return True
|
||||
|
||||
|
||||
def code_400_bad_request(dut, port):
|
||||
Utility.console_log("[test] 400 Bad Request =>", end=' ')
|
||||
Utility.console_log('[test] 400 Bad Request =>', end=' ')
|
||||
s = Session(dut, port)
|
||||
path = "/hello"
|
||||
s.client.sendall(("XYZ " + path + " HTTP/1.1\r\nHost: " + dut + "\r\n\r\n").encode())
|
||||
path = '/hello'
|
||||
s.client.sendall(('XYZ ' + path + ' HTTP/1.1\r\nHost: ' + dut + '\r\n\r\n').encode())
|
||||
s.read_resp_hdrs()
|
||||
s.read_resp_data()
|
||||
if not test_val("Client Error", "400", s.status):
|
||||
if not test_val('Client Error', '400', s.status):
|
||||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
Utility.console_log("Success")
|
||||
Utility.console_log('Success')
|
||||
return True
|
||||
|
||||
|
||||
def code_404_not_found(dut, port):
|
||||
Utility.console_log("[test] 404 Not Found =>", end=' ')
|
||||
Utility.console_log('[test] 404 Not Found =>', end=' ')
|
||||
s = Session(dut, port)
|
||||
path = "/dummy"
|
||||
s.client.sendall(("GET " + path + " HTTP/1.1\r\nHost: " + dut + "\r\n\r\n").encode())
|
||||
path = '/dummy'
|
||||
s.client.sendall(('GET ' + path + ' HTTP/1.1\r\nHost: ' + dut + '\r\n\r\n').encode())
|
||||
s.read_resp_hdrs()
|
||||
s.read_resp_data()
|
||||
if not test_val("Client Error", "404", s.status):
|
||||
if not test_val('Client Error', '404', s.status):
|
||||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
Utility.console_log("Success")
|
||||
Utility.console_log('Success')
|
||||
return True
|
||||
|
||||
|
||||
def code_405_method_not_allowed(dut, port):
|
||||
Utility.console_log("[test] 405 Method Not Allowed =>", end=' ')
|
||||
Utility.console_log('[test] 405 Method Not Allowed =>', end=' ')
|
||||
s = Session(dut, port)
|
||||
path = "/hello"
|
||||
s.client.sendall(("POST " + path + " HTTP/1.1\r\nHost: " + dut + "\r\n\r\n").encode())
|
||||
path = '/hello'
|
||||
s.client.sendall(('POST ' + path + ' HTTP/1.1\r\nHost: ' + dut + '\r\n\r\n').encode())
|
||||
s.read_resp_hdrs()
|
||||
s.read_resp_data()
|
||||
if not test_val("Client Error", "405", s.status):
|
||||
if not test_val('Client Error', '405', s.status):
|
||||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
Utility.console_log("Success")
|
||||
Utility.console_log('Success')
|
||||
return True
|
||||
|
||||
|
||||
def code_408_req_timeout(dut, port):
|
||||
Utility.console_log("[test] 408 Request Timeout =>", end=' ')
|
||||
Utility.console_log('[test] 408 Request Timeout =>', end=' ')
|
||||
s = Session(dut, port)
|
||||
s.client.sendall(("POST /echo HTTP/1.1\r\nHost: " + dut + "\r\nContent-Length: 10\r\n\r\nABCD").encode())
|
||||
s.client.sendall(('POST /echo HTTP/1.1\r\nHost: ' + dut + '\r\nContent-Length: 10\r\n\r\nABCD').encode())
|
||||
s.read_resp_hdrs()
|
||||
s.read_resp_data()
|
||||
if not test_val("Client Error", "408", s.status):
|
||||
if not test_val('Client Error', '408', s.status):
|
||||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
Utility.console_log("Success")
|
||||
Utility.console_log('Success')
|
||||
return True
|
||||
|
||||
|
||||
def code_411_length_required(dut, port):
|
||||
Utility.console_log("[test] 411 Length Required =>", end=' ')
|
||||
Utility.console_log('[test] 411 Length Required =>', end=' ')
|
||||
s = Session(dut, port)
|
||||
path = "/echo"
|
||||
s.client.sendall(("POST " + path + " HTTP/1.1\r\nHost: " + dut + "\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\n\r\n").encode())
|
||||
path = '/echo'
|
||||
s.client.sendall(('POST ' + path + ' HTTP/1.1\r\nHost: ' + dut + '\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\n\r\n').encode())
|
||||
s.read_resp_hdrs()
|
||||
s.read_resp_data()
|
||||
# Presently server sends back 400 Bad Request
|
||||
# if not test_val("Client Error", "411", s.status):
|
||||
# s.close()
|
||||
# return False
|
||||
if not test_val("Client Error", "400", s.status):
|
||||
if not test_val('Client Error', '400', s.status):
|
||||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
Utility.console_log("Success")
|
||||
Utility.console_log('Success')
|
||||
return True
|
||||
|
||||
|
||||
def send_getx_uri_len(dut, port, length):
|
||||
s = Session(dut, port)
|
||||
method = "GET "
|
||||
version = " HTTP/1.1\r\n"
|
||||
path = "/" + "x" * (length - len(method) - len(version) - len("/"))
|
||||
method = 'GET '
|
||||
version = ' HTTP/1.1\r\n'
|
||||
path = '/' + 'x' * (length - len(method) - len(version) - len('/'))
|
||||
s.client.sendall(method.encode())
|
||||
time.sleep(1)
|
||||
s.client.sendall(path.encode())
|
||||
time.sleep(1)
|
||||
s.client.sendall((version + "Host: " + dut + "\r\n\r\n").encode())
|
||||
s.client.sendall((version + 'Host: ' + dut + '\r\n\r\n').encode())
|
||||
s.read_resp_hdrs()
|
||||
s.read_resp_data()
|
||||
s.close()
|
||||
@@ -920,59 +917,59 @@ def send_getx_uri_len(dut, port, length):
|
||||
|
||||
|
||||
def code_414_uri_too_long(dut, port, max_uri_len):
|
||||
Utility.console_log("[test] 414 URI Too Long =>", end=' ')
|
||||
Utility.console_log('[test] 414 URI Too Long =>', end=' ')
|
||||
status = send_getx_uri_len(dut, port, max_uri_len)
|
||||
if not test_val("Client Error", "404", status):
|
||||
if not test_val('Client Error', '404', status):
|
||||
return False
|
||||
status = send_getx_uri_len(dut, port, max_uri_len + 1)
|
||||
if not test_val("Client Error", "414", status):
|
||||
if not test_val('Client Error', '414', status):
|
||||
return False
|
||||
Utility.console_log("Success")
|
||||
Utility.console_log('Success')
|
||||
return True
|
||||
|
||||
|
||||
def send_postx_hdr_len(dut, port, length):
|
||||
s = Session(dut, port)
|
||||
path = "/echo"
|
||||
host = "Host: " + dut
|
||||
custom_hdr_field = "\r\nCustom: "
|
||||
custom_hdr_val = "x" * (length - len(host) - len(custom_hdr_field) - len("\r\n\r\n") + len("0"))
|
||||
request = ("POST " + path + " HTTP/1.1\r\n" + host + custom_hdr_field + custom_hdr_val + "\r\n\r\n").encode()
|
||||
path = '/echo'
|
||||
host = 'Host: ' + dut
|
||||
custom_hdr_field = '\r\nCustom: '
|
||||
custom_hdr_val = 'x' * (length - len(host) - len(custom_hdr_field) - len('\r\n\r\n') + len('0'))
|
||||
request = ('POST ' + path + ' HTTP/1.1\r\n' + host + custom_hdr_field + custom_hdr_val + '\r\n\r\n').encode()
|
||||
s.client.sendall(request[:length // 2])
|
||||
time.sleep(1)
|
||||
s.client.sendall(request[length // 2:])
|
||||
hdr = s.read_resp_hdrs()
|
||||
resp = s.read_resp_data()
|
||||
s.close()
|
||||
if hdr and ("Custom" in hdr):
|
||||
return (hdr["Custom"] == custom_hdr_val), resp
|
||||
if hdr and ('Custom' in hdr):
|
||||
return (hdr['Custom'] == custom_hdr_val), resp
|
||||
return False, s.status
|
||||
|
||||
|
||||
def code_431_hdr_too_long(dut, port, max_hdr_len):
|
||||
Utility.console_log("[test] 431 Header Too Long =>", end=' ')
|
||||
Utility.console_log('[test] 431 Header Too Long =>', end=' ')
|
||||
res, status = send_postx_hdr_len(dut, port, max_hdr_len)
|
||||
if not res:
|
||||
return False
|
||||
res, status = send_postx_hdr_len(dut, port, max_hdr_len + 1)
|
||||
if not test_val("Client Error", "431", status):
|
||||
if not test_val('Client Error', '431', status):
|
||||
return False
|
||||
Utility.console_log("Success")
|
||||
Utility.console_log('Success')
|
||||
return True
|
||||
|
||||
|
||||
def test_upgrade_not_supported(dut, port):
|
||||
Utility.console_log("[test] Upgrade Not Supported =>", end=' ')
|
||||
Utility.console_log('[test] Upgrade Not Supported =>', end=' ')
|
||||
s = Session(dut, port)
|
||||
# path = "/hello"
|
||||
s.client.sendall(("OPTIONS * HTTP/1.1\r\nHost:" + dut + "\r\nUpgrade: TLS/1.0\r\nConnection: Upgrade\r\n\r\n").encode())
|
||||
s.client.sendall(('OPTIONS * HTTP/1.1\r\nHost:' + dut + '\r\nUpgrade: TLS/1.0\r\nConnection: Upgrade\r\n\r\n').encode())
|
||||
s.read_resp_hdrs()
|
||||
s.read_resp_data()
|
||||
if not test_val("Client Error", "400", s.status):
|
||||
if not test_val('Client Error', '400', s.status):
|
||||
s.close()
|
||||
return False
|
||||
s.close()
|
||||
Utility.console_log("Success")
|
||||
Utility.console_log('Success')
|
||||
return True
|
||||
|
||||
|
||||
@@ -997,7 +994,7 @@ if __name__ == '__main__':
|
||||
|
||||
_verbose_ = True
|
||||
|
||||
Utility.console_log("### Basic HTTP Client Tests")
|
||||
Utility.console_log('### Basic HTTP Client Tests')
|
||||
get_hello(dut, port)
|
||||
post_hello(dut, port)
|
||||
put_hello(dut, port)
|
||||
@@ -1009,7 +1006,7 @@ if __name__ == '__main__':
|
||||
get_false_uri(dut, port)
|
||||
get_test_headers(dut, port)
|
||||
|
||||
Utility.console_log("### Error code tests")
|
||||
Utility.console_log('### Error code tests')
|
||||
code_500_server_error_test(dut, port)
|
||||
code_501_method_not_impl(dut, port)
|
||||
code_505_version_not_supported(dut, port)
|
||||
@@ -1024,7 +1021,7 @@ if __name__ == '__main__':
|
||||
# Not supported yet (Error on chunked request)
|
||||
# code_411_length_required(dut, port)
|
||||
|
||||
Utility.console_log("### Sessions and Context Tests")
|
||||
Utility.console_log('### Sessions and Context Tests')
|
||||
parallel_sessions_adder(dut, port, max_sessions)
|
||||
leftover_data_test(dut, port)
|
||||
async_response_test(dut, port)
|
||||
|
||||
@@ -14,49 +14,47 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
from builtins import str
|
||||
from builtins import range
|
||||
import re
|
||||
from __future__ import division, print_function, unicode_literals
|
||||
|
||||
import os
|
||||
import random
|
||||
import re
|
||||
from builtins import range, str
|
||||
|
||||
from tiny_test_fw import Utility
|
||||
import ttfw_idf
|
||||
from idf_http_server_test import adder as client
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
# When running on local machine execute the following before running this script
|
||||
# > make app bootloader
|
||||
# > make print_flash_cmd | tail -n 1 > build/download.config
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_http_server_persistence(env, extra_data):
|
||||
# Acquire DUT
|
||||
dut1 = env.get_dut("http_server", "examples/protocols/http_server/persistent_sockets",
|
||||
dut1 = env.get_dut('http_server', 'examples/protocols/http_server/persistent_sockets',
|
||||
dut_class=ttfw_idf.ESP32DUT)
|
||||
|
||||
# Get binary file
|
||||
binary_file = os.path.join(dut1.app.binary_path, "persistent_sockets.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'persistent_sockets.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("http_server_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('http_server_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
|
||||
# Upload binary and start testing
|
||||
Utility.console_log("Starting http_server persistance test app")
|
||||
Utility.console_log('Starting http_server persistance test app')
|
||||
dut1.start_app()
|
||||
|
||||
# Parse IP address of STA
|
||||
Utility.console_log("Waiting to connect with AP")
|
||||
got_ip = dut1.expect(re.compile(r"(?:[\s\S]*)IPv4 address: (\d+.\d+.\d+.\d+)"), timeout=30)[0]
|
||||
Utility.console_log('Waiting to connect with AP')
|
||||
got_ip = dut1.expect(re.compile(r'(?:[\s\S]*)IPv4 address: (\d+.\d+.\d+.\d+)'), timeout=30)[0]
|
||||
got_port = dut1.expect(re.compile(r"(?:[\s\S]*)Starting server on port: '(\d+)'"), timeout=30)[0]
|
||||
|
||||
Utility.console_log("Got IP : " + got_ip)
|
||||
Utility.console_log("Got Port : " + got_port)
|
||||
Utility.console_log('Got IP : ' + got_ip)
|
||||
Utility.console_log('Got Port : ' + got_port)
|
||||
|
||||
# Expected Logs
|
||||
dut1.expect("Registering URI handlers", timeout=30)
|
||||
dut1.expect('Registering URI handlers', timeout=30)
|
||||
|
||||
# Run test script
|
||||
conn = client.start_session(got_ip, got_port)
|
||||
@@ -65,23 +63,23 @@ def test_examples_protocol_http_server_persistence(env, extra_data):
|
||||
|
||||
# Test PUT request and initialize session context
|
||||
num = random.randint(0,100)
|
||||
client.putreq(conn, "/adder", str(num))
|
||||
client.putreq(conn, '/adder', str(num))
|
||||
visitor += 1
|
||||
dut1.expect("/adder visitor count = " + str(visitor), timeout=30)
|
||||
dut1.expect("/adder PUT handler read " + str(num), timeout=30)
|
||||
dut1.expect("PUT allocating new session", timeout=30)
|
||||
dut1.expect('/adder visitor count = ' + str(visitor), timeout=30)
|
||||
dut1.expect('/adder PUT handler read ' + str(num), timeout=30)
|
||||
dut1.expect('PUT allocating new session', timeout=30)
|
||||
|
||||
# Retest PUT request and change session context value
|
||||
num = random.randint(0,100)
|
||||
Utility.console_log("Adding: " + str(num))
|
||||
client.putreq(conn, "/adder", str(num))
|
||||
Utility.console_log('Adding: ' + str(num))
|
||||
client.putreq(conn, '/adder', str(num))
|
||||
visitor += 1
|
||||
adder += num
|
||||
dut1.expect("/adder visitor count = " + str(visitor), timeout=30)
|
||||
dut1.expect("/adder PUT handler read " + str(num), timeout=30)
|
||||
dut1.expect('/adder visitor count = ' + str(visitor), timeout=30)
|
||||
dut1.expect('/adder PUT handler read ' + str(num), timeout=30)
|
||||
try:
|
||||
# Re allocation shouldn't happen
|
||||
dut1.expect("PUT allocating new session", timeout=30)
|
||||
dut1.expect('PUT allocating new session', timeout=30)
|
||||
# Not expected
|
||||
raise RuntimeError
|
||||
except Exception:
|
||||
@@ -91,37 +89,37 @@ def test_examples_protocol_http_server_persistence(env, extra_data):
|
||||
# Test POST request and session persistence
|
||||
random_nums = [random.randint(0,100) for _ in range(100)]
|
||||
for num in random_nums:
|
||||
Utility.console_log("Adding: " + str(num))
|
||||
client.postreq(conn, "/adder", str(num))
|
||||
Utility.console_log('Adding: ' + str(num))
|
||||
client.postreq(conn, '/adder', str(num))
|
||||
visitor += 1
|
||||
adder += num
|
||||
dut1.expect("/adder visitor count = " + str(visitor), timeout=30)
|
||||
dut1.expect("/adder handler read " + str(num), timeout=30)
|
||||
dut1.expect('/adder visitor count = ' + str(visitor), timeout=30)
|
||||
dut1.expect('/adder handler read ' + str(num), timeout=30)
|
||||
|
||||
# Test GET request and session persistence
|
||||
Utility.console_log("Matching final sum: " + str(adder))
|
||||
if client.getreq(conn, "/adder").decode() != str(adder):
|
||||
Utility.console_log('Matching final sum: ' + str(adder))
|
||||
if client.getreq(conn, '/adder').decode() != str(adder):
|
||||
raise RuntimeError
|
||||
visitor += 1
|
||||
dut1.expect("/adder visitor count = " + str(visitor), timeout=30)
|
||||
dut1.expect("/adder GET handler send " + str(adder), timeout=30)
|
||||
dut1.expect('/adder visitor count = ' + str(visitor), timeout=30)
|
||||
dut1.expect('/adder GET handler send ' + str(adder), timeout=30)
|
||||
|
||||
Utility.console_log("Ending session")
|
||||
Utility.console_log('Ending session')
|
||||
# Close connection and check for invocation of context "Free" function
|
||||
client.end_session(conn)
|
||||
dut1.expect("/adder Free Context function called", timeout=30)
|
||||
dut1.expect('/adder Free Context function called', timeout=30)
|
||||
|
||||
Utility.console_log("Validating user context data")
|
||||
Utility.console_log('Validating user context data')
|
||||
# Start another session to check user context data
|
||||
client.start_session(got_ip, got_port)
|
||||
num = random.randint(0,100)
|
||||
client.putreq(conn, "/adder", str(num))
|
||||
client.putreq(conn, '/adder', str(num))
|
||||
visitor += 1
|
||||
dut1.expect("/adder visitor count = " + str(visitor), timeout=30)
|
||||
dut1.expect("/adder PUT handler read " + str(num), timeout=30)
|
||||
dut1.expect("PUT allocating new session", timeout=30)
|
||||
dut1.expect('/adder visitor count = ' + str(visitor), timeout=30)
|
||||
dut1.expect('/adder PUT handler read ' + str(num), timeout=30)
|
||||
dut1.expect('PUT allocating new session', timeout=30)
|
||||
client.end_session(conn)
|
||||
dut1.expect("/adder Free Context function called", timeout=30)
|
||||
dut1.expect('/adder Free Context function called', timeout=30)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -14,22 +14,20 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
from builtins import range
|
||||
import re
|
||||
import os
|
||||
import string
|
||||
import random
|
||||
from __future__ import division, print_function, unicode_literals
|
||||
|
||||
import os
|
||||
import random
|
||||
import re
|
||||
import socket
|
||||
import string
|
||||
import threading
|
||||
import time
|
||||
import socket
|
||||
from builtins import range
|
||||
|
||||
from tiny_test_fw import Utility
|
||||
import ttfw_idf
|
||||
from idf_http_server_test import client
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
|
||||
class http_client_thread(threading.Thread):
|
||||
@@ -64,97 +62,97 @@ class http_client_thread(threading.Thread):
|
||||
# > make print_flash_cmd | tail -n 1 > build/download.config
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_http_server_simple(env, extra_data):
|
||||
# Acquire DUT
|
||||
dut1 = env.get_dut("http_server", "examples/protocols/http_server/simple", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('http_server', 'examples/protocols/http_server/simple', dut_class=ttfw_idf.ESP32DUT)
|
||||
|
||||
# Get binary file
|
||||
binary_file = os.path.join(dut1.app.binary_path, "simple.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'simple.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("http_server_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('http_server_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
|
||||
# Upload binary and start testing
|
||||
Utility.console_log("Starting http_server simple test app")
|
||||
Utility.console_log('Starting http_server simple test app')
|
||||
dut1.start_app()
|
||||
|
||||
# Parse IP address of STA
|
||||
Utility.console_log("Waiting to connect with AP")
|
||||
got_ip = dut1.expect(re.compile(r"(?:[\s\S]*)IPv4 address: (\d+.\d+.\d+.\d+)"), timeout=30)[0]
|
||||
Utility.console_log('Waiting to connect with AP')
|
||||
got_ip = dut1.expect(re.compile(r'(?:[\s\S]*)IPv4 address: (\d+.\d+.\d+.\d+)'), timeout=30)[0]
|
||||
got_port = dut1.expect(re.compile(r"(?:[\s\S]*)Starting server on port: '(\d+)'"), timeout=30)[0]
|
||||
|
||||
Utility.console_log("Got IP : " + got_ip)
|
||||
Utility.console_log("Got Port : " + got_port)
|
||||
Utility.console_log('Got IP : ' + got_ip)
|
||||
Utility.console_log('Got Port : ' + got_port)
|
||||
|
||||
# Expected Logs
|
||||
dut1.expect("Registering URI handlers", timeout=30)
|
||||
dut1.expect('Registering URI handlers', timeout=30)
|
||||
|
||||
# Run test script
|
||||
# If failed raise appropriate exception
|
||||
Utility.console_log("Test /hello GET handler")
|
||||
Utility.console_log('Test /hello GET handler')
|
||||
if not client.test_get_handler(got_ip, got_port):
|
||||
raise RuntimeError
|
||||
|
||||
# Acquire host IP. Need a way to check it
|
||||
dut1.expect(re.compile(r"(?:[\s\S]*)Found header => Host: (\d+.\d+.\d+.\d+)"), timeout=30)[0]
|
||||
dut1.expect(re.compile(r'(?:[\s\S]*)Found header => Host: (\d+.\d+.\d+.\d+)'), timeout=30)[0]
|
||||
|
||||
# Match additional headers sent in the request
|
||||
dut1.expect("Found header => Test-Header-2: Test-Value-2", timeout=30)
|
||||
dut1.expect("Found header => Test-Header-1: Test-Value-1", timeout=30)
|
||||
dut1.expect("Found URL query parameter => query1=value1", timeout=30)
|
||||
dut1.expect("Found URL query parameter => query3=value3", timeout=30)
|
||||
dut1.expect("Found URL query parameter => query2=value2", timeout=30)
|
||||
dut1.expect("Request headers lost", timeout=30)
|
||||
dut1.expect('Found header => Test-Header-2: Test-Value-2', timeout=30)
|
||||
dut1.expect('Found header => Test-Header-1: Test-Value-1', timeout=30)
|
||||
dut1.expect('Found URL query parameter => query1=value1', timeout=30)
|
||||
dut1.expect('Found URL query parameter => query3=value3', timeout=30)
|
||||
dut1.expect('Found URL query parameter => query2=value2', timeout=30)
|
||||
dut1.expect('Request headers lost', timeout=30)
|
||||
|
||||
Utility.console_log("Test /ctrl PUT handler and realtime handler de/registration")
|
||||
Utility.console_log('Test /ctrl PUT handler and realtime handler de/registration')
|
||||
if not client.test_put_handler(got_ip, got_port):
|
||||
raise RuntimeError
|
||||
dut1.expect("Unregistering /hello and /echo URIs", timeout=30)
|
||||
dut1.expect("Registering /hello and /echo URIs", timeout=30)
|
||||
dut1.expect('Unregistering /hello and /echo URIs', timeout=30)
|
||||
dut1.expect('Registering /hello and /echo URIs', timeout=30)
|
||||
|
||||
# Generate random data of 10KB
|
||||
random_data = ''.join(string.printable[random.randint(0,len(string.printable)) - 1] for _ in range(10 * 1024))
|
||||
Utility.console_log("Test /echo POST handler with random data")
|
||||
Utility.console_log('Test /echo POST handler with random data')
|
||||
if not client.test_post_handler(got_ip, got_port, random_data):
|
||||
raise RuntimeError
|
||||
|
||||
query = "http://foobar"
|
||||
Utility.console_log("Test /hello with custom query : " + query)
|
||||
query = 'http://foobar'
|
||||
Utility.console_log('Test /hello with custom query : ' + query)
|
||||
if not client.test_custom_uri_query(got_ip, got_port, query):
|
||||
raise RuntimeError
|
||||
dut1.expect("Found URL query => " + query, timeout=30)
|
||||
dut1.expect('Found URL query => ' + query, timeout=30)
|
||||
|
||||
query = "abcd+1234%20xyz"
|
||||
Utility.console_log("Test /hello with custom query : " + query)
|
||||
query = 'abcd+1234%20xyz'
|
||||
Utility.console_log('Test /hello with custom query : ' + query)
|
||||
if not client.test_custom_uri_query(got_ip, got_port, query):
|
||||
raise RuntimeError
|
||||
dut1.expect("Found URL query => " + query, timeout=30)
|
||||
dut1.expect('Found URL query => ' + query, timeout=30)
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_http_server_lru_purge_enable(env, extra_data):
|
||||
# Acquire DUT
|
||||
dut1 = env.get_dut("http_server", "examples/protocols/http_server/simple", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('http_server', 'examples/protocols/http_server/simple', dut_class=ttfw_idf.ESP32DUT)
|
||||
|
||||
# Get binary file
|
||||
binary_file = os.path.join(dut1.app.binary_path, "simple.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'simple.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("http_server_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('http_server_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
|
||||
# Upload binary and start testing
|
||||
Utility.console_log("Starting http_server simple test app")
|
||||
Utility.console_log('Starting http_server simple test app')
|
||||
dut1.start_app()
|
||||
|
||||
# Parse IP address of STA
|
||||
Utility.console_log("Waiting to connect with AP")
|
||||
got_ip = dut1.expect(re.compile(r"(?:[\s\S]*)IPv4 address: (\d+.\d+.\d+.\d+)"), timeout=30)[0]
|
||||
Utility.console_log('Waiting to connect with AP')
|
||||
got_ip = dut1.expect(re.compile(r'(?:[\s\S]*)IPv4 address: (\d+.\d+.\d+.\d+)'), timeout=30)[0]
|
||||
got_port = dut1.expect(re.compile(r"(?:[\s\S]*)Starting server on port: '(\d+)'"), timeout=30)[0]
|
||||
|
||||
Utility.console_log("Got IP : " + got_ip)
|
||||
Utility.console_log("Got Port : " + got_port)
|
||||
Utility.console_log('Got IP : ' + got_ip)
|
||||
Utility.console_log('Got Port : ' + got_port)
|
||||
|
||||
# Expected Logs
|
||||
dut1.expect("Registering URI handlers", timeout=30)
|
||||
dut1.expect('Registering URI handlers', timeout=30)
|
||||
threads = []
|
||||
# Open 20 sockets, one from each thread
|
||||
for _ in range(20):
|
||||
@@ -163,7 +161,7 @@ def test_examples_protocol_http_server_lru_purge_enable(env, extra_data):
|
||||
thread.start()
|
||||
threads.append(thread)
|
||||
except OSError as err:
|
||||
Utility.console_log("Error: unable to start thread, " + err)
|
||||
Utility.console_log('Error: unable to start thread, ' + err)
|
||||
|
||||
for t in threads:
|
||||
t.join()
|
||||
|
||||
@@ -14,15 +14,14 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
import re
|
||||
from tiny_test_fw import Utility
|
||||
import ttfw_idf
|
||||
import os
|
||||
import websocket
|
||||
from __future__ import division, print_function, unicode_literals
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
import ttfw_idf
|
||||
import websocket
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
OPCODE_TEXT = 0x1
|
||||
OPCODE_BIN = 0x2
|
||||
@@ -37,7 +36,7 @@ class WsClient:
|
||||
self.ws = websocket.WebSocket()
|
||||
|
||||
def __enter__(self):
|
||||
self.ws.connect("ws://{}:{}/ws".format(self.ip, self.port))
|
||||
self.ws.connect('ws://{}:{}/ws'.format(self.ip, self.port))
|
||||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
@@ -46,7 +45,7 @@ class WsClient:
|
||||
def read(self):
|
||||
return self.ws.recv_data(control_frame=True)
|
||||
|
||||
def write(self, data="", opcode=OPCODE_TEXT):
|
||||
def write(self, data='', opcode=OPCODE_TEXT):
|
||||
if opcode == OPCODE_BIN:
|
||||
return self.ws.send_binary(data.encode())
|
||||
if opcode == OPCODE_PING:
|
||||
@@ -54,27 +53,27 @@ class WsClient:
|
||||
return self.ws.send(data)
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_http_ws_echo_server(env, extra_data):
|
||||
# Acquire DUT
|
||||
dut1 = env.get_dut("http_server", "examples/protocols/http_server/ws_echo_server", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('http_server', 'examples/protocols/http_server/ws_echo_server', dut_class=ttfw_idf.ESP32DUT)
|
||||
|
||||
# Get binary file
|
||||
binary_file = os.path.join(dut1.app.binary_path, "ws_echo_server.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'ws_echo_server.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("http_ws_server_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('http_ws_server_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
|
||||
# Upload binary and start testing
|
||||
Utility.console_log("Starting ws-echo-server test app based on http_server")
|
||||
Utility.console_log('Starting ws-echo-server test app based on http_server')
|
||||
dut1.start_app()
|
||||
|
||||
# Parse IP address of STA
|
||||
Utility.console_log("Waiting to connect with AP")
|
||||
got_ip = dut1.expect(re.compile(r"IPv4 address: (\d+.\d+.\d+.\d+)"), timeout=60)[0]
|
||||
Utility.console_log('Waiting to connect with AP')
|
||||
got_ip = dut1.expect(re.compile(r'IPv4 address: (\d+.\d+.\d+.\d+)'), timeout=60)[0]
|
||||
got_port = dut1.expect(re.compile(r"Starting server on port: '(\d+)'"), timeout=60)[0]
|
||||
|
||||
Utility.console_log("Got IP : " + got_ip)
|
||||
Utility.console_log("Got Port : " + got_port)
|
||||
Utility.console_log('Got IP : ' + got_ip)
|
||||
Utility.console_log('Got Port : ' + got_port)
|
||||
|
||||
# Start ws server test
|
||||
with WsClient(got_ip, int(got_port)) as ws:
|
||||
@@ -82,23 +81,23 @@ def test_examples_protocol_http_ws_echo_server(env, extra_data):
|
||||
for expected_opcode in [OPCODE_TEXT, OPCODE_BIN, OPCODE_PING]:
|
||||
ws.write(data=DATA, opcode=expected_opcode)
|
||||
opcode, data = ws.read()
|
||||
Utility.console_log("Testing opcode {}: Received opcode:{}, data:{}".format(expected_opcode, opcode, data))
|
||||
Utility.console_log('Testing opcode {}: Received opcode:{}, data:{}'.format(expected_opcode, opcode, data))
|
||||
data = data.decode()
|
||||
if expected_opcode == OPCODE_PING:
|
||||
dut1.expect("Got a WS PING frame, Replying PONG")
|
||||
dut1.expect('Got a WS PING frame, Replying PONG')
|
||||
if opcode != OPCODE_PONG or data != DATA:
|
||||
raise RuntimeError("Failed to receive correct opcode:{} or data:{}".format(opcode, data))
|
||||
raise RuntimeError('Failed to receive correct opcode:{} or data:{}'.format(opcode, data))
|
||||
continue
|
||||
dut_data = dut1.expect(re.compile(r"Got packet with message: ([A-Za-z0-9_]*)"))[0]
|
||||
dut_opcode = int(dut1.expect(re.compile(r"Packet type: ([0-9]*)"))[0])
|
||||
dut_data = dut1.expect(re.compile(r'Got packet with message: ([A-Za-z0-9_]*)'))[0]
|
||||
dut_opcode = int(dut1.expect(re.compile(r'Packet type: ([0-9]*)'))[0])
|
||||
if opcode != expected_opcode or data != DATA or opcode != dut_opcode or data != dut_data:
|
||||
raise RuntimeError("Failed to receive correct opcode:{} or data:{}".format(opcode, data))
|
||||
ws.write(data="Trigger async", opcode=OPCODE_TEXT)
|
||||
raise RuntimeError('Failed to receive correct opcode:{} or data:{}'.format(opcode, data))
|
||||
ws.write(data='Trigger async', opcode=OPCODE_TEXT)
|
||||
opcode, data = ws.read()
|
||||
Utility.console_log("Testing async send: Received opcode:{}, data:{}".format(opcode, data))
|
||||
Utility.console_log('Testing async send: Received opcode:{}, data:{}'.format(opcode, data))
|
||||
data = data.decode()
|
||||
if opcode != OPCODE_TEXT or data != "Async data":
|
||||
raise RuntimeError("Failed to receive correct opcode:{} or data:{}".format(opcode, data))
|
||||
if opcode != OPCODE_TEXT or data != 'Async data':
|
||||
raise RuntimeError('Failed to receive correct opcode:{} or data:{}'.format(opcode, data))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import os
|
||||
import re
|
||||
|
||||
import ttfw_idf
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_EthKitV1")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_EthKitV1')
|
||||
def test_examples_protocol_https_request(env, extra_data):
|
||||
"""
|
||||
steps: |
|
||||
@@ -13,24 +14,24 @@ def test_examples_protocol_https_request(env, extra_data):
|
||||
certificate verification options
|
||||
3. send http request
|
||||
"""
|
||||
dut1 = env.get_dut("https_request", "examples/protocols/https_request", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('https_request', 'examples/protocols/https_request', dut_class=ttfw_idf.ESP32DUT)
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, "https_request.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'https_request.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("https_request_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('https_request_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# start tes
|
||||
Utility.console_log("Starting https_request simple test app")
|
||||
Utility.console_log('Starting https_request simple test app')
|
||||
dut1.start_app()
|
||||
|
||||
# Check for connection using crt bundle
|
||||
Utility.console_log("Testing for \"https_request using crt bundle\"")
|
||||
try:
|
||||
dut1.expect(re.compile("https_request using crt bundle"), timeout=30)
|
||||
dut1.expect_all("Certificate validated",
|
||||
"Connection established...",
|
||||
"Reading HTTP response...",
|
||||
"HTTP/1.1 200 OK",
|
||||
re.compile("connection closed"))
|
||||
dut1.expect(re.compile('https_request using crt bundle'), timeout=30)
|
||||
dut1.expect_all('Certificate validated',
|
||||
'Connection established...',
|
||||
'Reading HTTP response...',
|
||||
'HTTP/1.1 200 OK',
|
||||
re.compile('connection closed'))
|
||||
except Exception:
|
||||
Utility.console_log("Failed the test for \"https_request using crt bundle\"")
|
||||
raise
|
||||
@@ -39,11 +40,11 @@ def test_examples_protocol_https_request(env, extra_data):
|
||||
# Check for connection using cacert_buf
|
||||
Utility.console_log("Testing for \"https_request using cacert_buf\"")
|
||||
try:
|
||||
dut1.expect(re.compile("https_request using cacert_buf"), timeout=20)
|
||||
dut1.expect_all("Connection established...",
|
||||
"Reading HTTP response...",
|
||||
"HTTP/1.1 200 OK",
|
||||
re.compile("connection closed"))
|
||||
dut1.expect(re.compile('https_request using cacert_buf'), timeout=20)
|
||||
dut1.expect_all('Connection established...',
|
||||
'Reading HTTP response...',
|
||||
'HTTP/1.1 200 OK',
|
||||
re.compile('connection closed'))
|
||||
except Exception:
|
||||
Utility.console_log("Passed the test for \"https_request using cacert_buf\"")
|
||||
raise
|
||||
@@ -52,32 +53,32 @@ def test_examples_protocol_https_request(env, extra_data):
|
||||
# Check for connection using global ca_store
|
||||
Utility.console_log("Testing for \"https_request using global ca_store\"")
|
||||
try:
|
||||
dut1.expect(re.compile("https_request using global ca_store"), timeout=20)
|
||||
dut1.expect_all("Connection established...",
|
||||
"Reading HTTP response...",
|
||||
"HTTP/1.1 200 OK",
|
||||
re.compile("connection closed"))
|
||||
dut1.expect(re.compile('https_request using global ca_store'), timeout=20)
|
||||
dut1.expect_all('Connection established...',
|
||||
'Reading HTTP response...',
|
||||
'HTTP/1.1 200 OK',
|
||||
re.compile('connection closed'))
|
||||
except Exception:
|
||||
Utility.console_log("Failed the test for \"https_request using global ca_store\"")
|
||||
raise
|
||||
Utility.console_log("Passed the test for \"https_request using global ca_store\"")
|
||||
|
||||
# Check for connection using crt bundle with mbedtls dynamic resource enabled
|
||||
dut1 = env.get_dut("https_request", "examples/protocols/https_request", dut_class=ttfw_idf.ESP32DUT, app_config_name='ssldyn')
|
||||
dut1 = env.get_dut('https_request', 'examples/protocols/https_request', dut_class=ttfw_idf.ESP32DUT, app_config_name='ssldyn')
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, "https_request.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'https_request.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("https_request_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('https_request_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# start test
|
||||
dut1.start_app()
|
||||
# only check if one connection is established
|
||||
Utility.console_log("Testing for \"https_request using crt bundle\" with mbedtls dynamic resource enabled")
|
||||
try:
|
||||
dut1.expect(re.compile("https_request using crt bundle"), timeout=30)
|
||||
dut1.expect_all("Connection established...",
|
||||
"Reading HTTP response...",
|
||||
"HTTP/1.1 200 OK",
|
||||
re.compile("connection closed"))
|
||||
dut1.expect(re.compile('https_request using crt bundle'), timeout=30)
|
||||
dut1.expect_all('Connection established...',
|
||||
'Reading HTTP response...',
|
||||
'HTTP/1.1 200 OK',
|
||||
re.compile('connection closed'))
|
||||
except Exception:
|
||||
Utility.console_log("Failed the test for \"https_request using crt bundle\" when mbedtls dynamic resource was enabled")
|
||||
raise
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import os
|
||||
import re
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI", ignore=True)
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI', ignore=True)
|
||||
def test_examples_protocol_https_x509_bundle(env, extra_data):
|
||||
"""
|
||||
steps: |
|
||||
@@ -11,28 +12,28 @@ def test_examples_protocol_https_x509_bundle(env, extra_data):
|
||||
2. connect to multiple URLs
|
||||
3. send http request
|
||||
"""
|
||||
dut1 = env.get_dut("https_x509_bundle", "examples/protocols/https_x509_bundle")
|
||||
dut1 = env.get_dut('https_x509_bundle', 'examples/protocols/https_x509_bundle')
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, "https_x509_bundle.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'https_x509_bundle.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("https_x509_bundle_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('https_x509_bundle_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# start test
|
||||
dut1.start_app()
|
||||
num_URLS = dut1.expect(re.compile(r"Connecting to (\d+) URLs"), timeout=30)
|
||||
dut1.expect(re.compile(r"Connection established to ([\s\S]*)"), timeout=30)
|
||||
dut1.expect("Completed {} connections".format(num_URLS[0]), timeout=60)
|
||||
num_URLS = dut1.expect(re.compile(r'Connecting to (\d+) URLs'), timeout=30)
|
||||
dut1.expect(re.compile(r'Connection established to ([\s\S]*)'), timeout=30)
|
||||
dut1.expect('Completed {} connections'.format(num_URLS[0]), timeout=60)
|
||||
|
||||
# test mbedtls dynamic resource
|
||||
dut1 = env.get_dut("https_x509_bundle", "examples/protocols/https_x509_bundle", app_config_name='ssldyn')
|
||||
dut1 = env.get_dut('https_x509_bundle', 'examples/protocols/https_x509_bundle', app_config_name='ssldyn')
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, "https_x509_bundle.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'https_x509_bundle.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("https_x509_bundle_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('https_x509_bundle_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# start test
|
||||
dut1.start_app()
|
||||
num_URLS = dut1.expect(re.compile(r"Connecting to (\d+) URLs"), timeout=30)
|
||||
dut1.expect(re.compile(r"Connection established to ([\s\S]*)"), timeout=30)
|
||||
dut1.expect("Completed {} connections".format(num_URLS[0]), timeout=60)
|
||||
num_URLS = dut1.expect(re.compile(r'Connecting to (\d+) URLs'), timeout=30)
|
||||
dut1.expect(re.compile(r'Connection established to ([\s\S]*)'), timeout=30)
|
||||
dut1.expect('Completed {} connections'.format(num_URLS[0]), timeout=60)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
import re
|
||||
import ttfw_idf
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import re
|
||||
import os
|
||||
import re
|
||||
import socket
|
||||
import time
|
||||
import struct
|
||||
import subprocess
|
||||
import time
|
||||
from threading import Event, Thread
|
||||
|
||||
import dpkt
|
||||
import dpkt.dns
|
||||
from threading import Thread, Event
|
||||
import subprocess
|
||||
|
||||
from tiny_test_fw import DUT
|
||||
import ttfw_idf
|
||||
from tiny_test_fw import DUT
|
||||
|
||||
stop_mdns_server = Event()
|
||||
esp_answered = Event()
|
||||
@@ -18,7 +18,7 @@ esp_answered = Event()
|
||||
def get_dns_query_for_esp(esp_host):
|
||||
dns = dpkt.dns.DNS(b'\x00\x00\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x01')
|
||||
dns.qd[0].name = esp_host + u'.local'
|
||||
print("Created query for esp host: {} ".format(dns.__repr__()))
|
||||
print('Created query for esp host: {} '.format(dns.__repr__()))
|
||||
return dns.pack()
|
||||
|
||||
|
||||
@@ -32,26 +32,26 @@ def get_dns_answer_to_mdns(tester_host):
|
||||
arr.name = tester_host
|
||||
arr.ip = socket.inet_aton('127.0.0.1')
|
||||
dns. an.append(arr)
|
||||
print("Created answer to mdns query: {} ".format(dns.__repr__()))
|
||||
print('Created answer to mdns query: {} '.format(dns.__repr__()))
|
||||
return dns.pack()
|
||||
|
||||
|
||||
def get_dns_answer_to_mdns_lwip(tester_host, id):
|
||||
dns = dpkt.dns.DNS(b"\x5e\x39\x84\x00\x00\x01\x00\x01\x00\x00\x00\x00\x0a\x64\x61\x76\x69\x64"
|
||||
b"\x2d\x63\x6f\x6d\x70\x05\x6c\x6f\x63\x61\x6c\x00\x00\x01\x00\x01\xc0\x0c"
|
||||
b"\x00\x01\x00\x01\x00\x00\x00\x0a\x00\x04\xc0\xa8\x0a\x6c")
|
||||
dns = dpkt.dns.DNS(b'\x5e\x39\x84\x00\x00\x01\x00\x01\x00\x00\x00\x00\x0a\x64\x61\x76\x69\x64'
|
||||
b'\x2d\x63\x6f\x6d\x70\x05\x6c\x6f\x63\x61\x6c\x00\x00\x01\x00\x01\xc0\x0c'
|
||||
b'\x00\x01\x00\x01\x00\x00\x00\x0a\x00\x04\xc0\xa8\x0a\x6c')
|
||||
dns.qd[0].name = tester_host
|
||||
dns.an[0].name = tester_host
|
||||
dns.an[0].ip = socket.inet_aton('127.0.0.1')
|
||||
dns.an[0].rdata = socket.inet_aton('127.0.0.1')
|
||||
dns.id = id
|
||||
print("Created answer to mdns (lwip) query: {} ".format(dns.__repr__()))
|
||||
print('Created answer to mdns (lwip) query: {} '.format(dns.__repr__()))
|
||||
return dns.pack()
|
||||
|
||||
|
||||
def mdns_server(esp_host):
|
||||
global esp_answered
|
||||
UDP_IP = "0.0.0.0"
|
||||
UDP_IP = '0.0.0.0'
|
||||
UDP_PORT = 5353
|
||||
MCAST_GRP = '224.0.0.251'
|
||||
TESTER_NAME = u'tinytester.local'
|
||||
@@ -60,7 +60,7 @@ def mdns_server(esp_host):
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
|
||||
sock.bind((UDP_IP,UDP_PORT))
|
||||
mreq = struct.pack("4sl", socket.inet_aton(MCAST_GRP), socket.INADDR_ANY)
|
||||
mreq = struct.pack('4sl', socket.inet_aton(MCAST_GRP), socket.INADDR_ANY)
|
||||
sock.setsockopt(socket.IPPROTO_IP, socket.IP_ADD_MEMBERSHIP, mreq)
|
||||
sock.settimeout(30)
|
||||
while not stop_mdns_server.is_set():
|
||||
@@ -72,14 +72,14 @@ def mdns_server(esp_host):
|
||||
dns = dpkt.dns.DNS(data)
|
||||
if len(dns.qd) > 0 and dns.qd[0].type == dpkt.dns.DNS_A:
|
||||
if dns.qd[0].name == TESTER_NAME:
|
||||
print("Received query: {} ".format(dns.__repr__()))
|
||||
print('Received query: {} '.format(dns.__repr__()))
|
||||
sock.sendto(get_dns_answer_to_mdns(TESTER_NAME), (MCAST_GRP,UDP_PORT))
|
||||
elif dns.qd[0].name == TESTER_NAME_LWIP:
|
||||
print("Received query: {} ".format(dns.__repr__()))
|
||||
print('Received query: {} '.format(dns.__repr__()))
|
||||
sock.sendto(get_dns_answer_to_mdns_lwip(TESTER_NAME_LWIP, dns.id), addr)
|
||||
if len(dns.an) > 0 and dns.an[0].type == dpkt.dns.DNS_A:
|
||||
if dns.an[0].name == esp_host + u'.local':
|
||||
print("Received answer to esp32-mdns query: {}".format(dns.__repr__()))
|
||||
print('Received answer to esp32-mdns query: {}'.format(dns.__repr__()))
|
||||
esp_answered.set()
|
||||
except socket.timeout:
|
||||
break
|
||||
@@ -87,7 +87,7 @@ def mdns_server(esp_host):
|
||||
continue
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_mdns(env, extra_data):
|
||||
global stop_mdns_server
|
||||
"""
|
||||
@@ -97,21 +97,21 @@ def test_examples_protocol_mdns(env, extra_data):
|
||||
3. check the mdns name is accessible
|
||||
4. check DUT output if mdns advertized host is resolved
|
||||
"""
|
||||
dut1 = env.get_dut("mdns-test", "examples/protocols/mdns", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('mdns-test', 'examples/protocols/mdns', dut_class=ttfw_idf.ESP32DUT)
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, "mdns-test.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'mdns-test.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("mdns-test_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('mdns-test_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# 1. start mdns application
|
||||
dut1.start_app()
|
||||
# 2. get the dut host name (and IP address)
|
||||
specific_host = dut1.expect(re.compile(r"mdns hostname set to: \[([^\]]+)\]"), timeout=30)
|
||||
specific_host = dut1.expect(re.compile(r'mdns hostname set to: \[([^\]]+)\]'), timeout=30)
|
||||
specific_host = str(specific_host[0])
|
||||
thread1 = Thread(target=mdns_server, args=(specific_host,))
|
||||
thread1.start()
|
||||
try:
|
||||
ip_address = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30)[0]
|
||||
print("Connected to AP with IP: {}".format(ip_address))
|
||||
ip_address = dut1.expect(re.compile(r' sta ip: ([^,]+),'), timeout=30)[0]
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except DUT.ExpectTimeout:
|
||||
stop_mdns_server.set()
|
||||
thread1.join()
|
||||
@@ -121,15 +121,15 @@ def test_examples_protocol_mdns(env, extra_data):
|
||||
if not esp_answered.wait(timeout=30):
|
||||
raise ValueError('Test has failed: did not receive mdns answer within timeout')
|
||||
# 4. check DUT output if mdns advertized host is resolved
|
||||
dut1.expect(re.compile(r"mdns-test: Query A: tinytester.local resolved to: 127.0.0.1"), timeout=30)
|
||||
dut1.expect(re.compile(r"mdns-test: gethostbyname: tinytester-lwip.local resolved to: 127.0.0.1"), timeout=30)
|
||||
dut1.expect(re.compile(r"mdns-test: getaddrinfo: tinytester-lwip.local resolved to: 127.0.0.1"), timeout=30)
|
||||
dut1.expect(re.compile(r'mdns-test: Query A: tinytester.local resolved to: 127.0.0.1'), timeout=30)
|
||||
dut1.expect(re.compile(r'mdns-test: gethostbyname: tinytester-lwip.local resolved to: 127.0.0.1'), timeout=30)
|
||||
dut1.expect(re.compile(r'mdns-test: getaddrinfo: tinytester-lwip.local resolved to: 127.0.0.1'), timeout=30)
|
||||
# 5. check the DUT answers to `dig` command
|
||||
dig_output = subprocess.check_output(['dig', '+short', '-p', '5353', '@224.0.0.251',
|
||||
'{}.local'.format(specific_host)])
|
||||
print('Resolving {} using "dig" succeeded with:\n{}'.format(specific_host, dig_output))
|
||||
if not ip_address.encode('utf-8') in dig_output:
|
||||
raise ValueError("Test has failed: Incorrectly resolved DUT hostname using dig"
|
||||
raise ValueError('Test has failed: Incorrectly resolved DUT hostname using dig'
|
||||
"Output should've contained DUT's IP address:{}".format(ip_address))
|
||||
finally:
|
||||
stop_mdns_server.set()
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
# Need Python 3 string formatting functions
|
||||
from __future__ import print_function
|
||||
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import logging
|
||||
from threading import Thread
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
LOG_LEVEL = logging.DEBUG
|
||||
LOGGER_NAME = "modbus_test"
|
||||
LOGGER_NAME = 'modbus_test'
|
||||
|
||||
# Allowed parameter reads
|
||||
TEST_READ_MIN_COUNT = 10 # Minimum number of correct readings
|
||||
@@ -27,38 +27,38 @@ TEST_SLAVE_ASCII = 'slave_ascii'
|
||||
|
||||
# Define tuple of strings to expect for each DUT.
|
||||
#
|
||||
master_expect = ("MASTER_TEST: Modbus master stack initialized...", "MASTER_TEST: Start modbus test...", "MASTER_TEST: Destroy master...")
|
||||
slave_expect = ("SLAVE_TEST: Modbus slave stack initialized.", "SLAVE_TEST: Start modbus test...", "SLAVE_TEST: Modbus controller destroyed.")
|
||||
master_expect = ('MASTER_TEST: Modbus master stack initialized...', 'MASTER_TEST: Start modbus test...', 'MASTER_TEST: Destroy master...')
|
||||
slave_expect = ('SLAVE_TEST: Modbus slave stack initialized.', 'SLAVE_TEST: Start modbus test...', 'SLAVE_TEST: Modbus controller destroyed.')
|
||||
|
||||
# The dictionary for expected values in listing
|
||||
expect_dict_master_ok = {"START": (),
|
||||
"READ_PAR_OK": (),
|
||||
"ALARM_MSG": (u'7',)}
|
||||
expect_dict_master_ok = {'START': (),
|
||||
'READ_PAR_OK': (),
|
||||
'ALARM_MSG': (u'7',)}
|
||||
|
||||
expect_dict_master_err = {"READ_PAR_ERR": (u'263', u'ESP_ERR_TIMEOUT'),
|
||||
"READ_STK_ERR": (u'107', u'ESP_ERR_TIMEOUT')}
|
||||
expect_dict_master_err = {'READ_PAR_ERR': (u'263', u'ESP_ERR_TIMEOUT'),
|
||||
'READ_STK_ERR': (u'107', u'ESP_ERR_TIMEOUT')}
|
||||
|
||||
# The dictionary for regular expression patterns to check in listing
|
||||
pattern_dict_master_ok = {"START": (r'.*I \([0-9]+\) MASTER_TEST: Start modbus test...'),
|
||||
"READ_PAR_OK": (r'.*I\s\([0-9]+\) MASTER_TEST: Characteristic #[0-9]+ [a-zA-Z0-9_]+'
|
||||
pattern_dict_master_ok = {'START': (r'.*I \([0-9]+\) MASTER_TEST: Start modbus test...'),
|
||||
'READ_PAR_OK': (r'.*I\s\([0-9]+\) MASTER_TEST: Characteristic #[0-9]+ [a-zA-Z0-9_]+'
|
||||
r'\s\([a-zA-Z\%\/]+\) value = [a-zA-Z0-9\.\s]*\(0x[a-zA-Z0-9]+\) read successful.'),
|
||||
"ALARM_MSG": (r'.*I \([0-9]*\) MASTER_TEST: Alarm triggered by cid #([0-9]+).')}
|
||||
'ALARM_MSG': (r'.*I \([0-9]*\) MASTER_TEST: Alarm triggered by cid #([0-9]+).')}
|
||||
|
||||
pattern_dict_master_err = {"READ_PAR_ERR_TOUT": (r'.*E \([0-9]+\) MASTER_TEST: Characteristic #[0-9]+'
|
||||
pattern_dict_master_err = {'READ_PAR_ERR_TOUT': (r'.*E \([0-9]+\) MASTER_TEST: Characteristic #[0-9]+'
|
||||
r'\s\([a-zA-Z0-9_]+\) read fail, err = [0-9]+ \([_A-Z]+\).'),
|
||||
"READ_STK_ERR_TOUT": (r'.*E \([0-9]+\) MB_CONTROLLER_MASTER: [a-zA-Z0-9_]+\([0-9]+\):\s'
|
||||
'READ_STK_ERR_TOUT': (r'.*E \([0-9]+\) MB_CONTROLLER_MASTER: [a-zA-Z0-9_]+\([0-9]+\):\s'
|
||||
r'SERIAL master get parameter failure error=\(0x([a-zA-Z0-9]+)\) \(([_A-Z]+)\).')}
|
||||
|
||||
# The dictionary for expected values in listing
|
||||
expect_dict_slave_ok = {"START": (),
|
||||
"READ_PAR_OK": (),
|
||||
"DESTROY": ()}
|
||||
expect_dict_slave_ok = {'START': (),
|
||||
'READ_PAR_OK': (),
|
||||
'DESTROY': ()}
|
||||
|
||||
# The dictionary for regular expression patterns to check in listing
|
||||
pattern_dict_slave_ok = {"START": (r'.*I \([0-9]+\) SLAVE_TEST: Start modbus test...'),
|
||||
"READ_PAR_OK": (r'.*I\s\([0-9]+\) SLAVE_TEST: [A-Z]+ READ \([a-zA-Z0-9_]+ us\),\s'
|
||||
pattern_dict_slave_ok = {'START': (r'.*I \([0-9]+\) SLAVE_TEST: Start modbus test...'),
|
||||
'READ_PAR_OK': (r'.*I\s\([0-9]+\) SLAVE_TEST: [A-Z]+ READ \([a-zA-Z0-9_]+ us\),\s'
|
||||
r'ADDR:[0-9]+, TYPE:[0-9]+, INST_ADDR:0x[a-zA-Z0-9]+, SIZE:[0-9]+'),
|
||||
"DESTROY": (r'.*I\s\([0-9]+\) SLAVE_TEST: Modbus controller destroyed.')}
|
||||
'DESTROY': (r'.*I\s\([0-9]+\) SLAVE_TEST: Modbus controller destroyed.')}
|
||||
|
||||
logger = logging.getLogger(LOGGER_NAME)
|
||||
|
||||
@@ -89,8 +89,8 @@ class DutTestThread(Thread):
|
||||
|
||||
# Check DUT exceptions
|
||||
dut_exceptions = self.dut.get_exceptions()
|
||||
if "Guru Meditation Error:" in dut_exceptions:
|
||||
raise Exception("%s generated an exception: %s\n" % (str(self.dut), dut_exceptions))
|
||||
if 'Guru Meditation Error:' in dut_exceptions:
|
||||
raise Exception('%s generated an exception: %s\n' % (str(self.dut), dut_exceptions))
|
||||
|
||||
# Mark thread has run to completion without any exceptions
|
||||
self.data = self.dut.stop_capture_raw_data()
|
||||
@@ -102,7 +102,7 @@ def test_filter_output(data=None, start_pattern=None, end_pattern=None):
|
||||
"""
|
||||
start_index = str(data).find(start_pattern)
|
||||
end_index = str(data).find(end_pattern)
|
||||
logger.debug("Listing start index= %d, end=%d" % (start_index, end_index))
|
||||
logger.debug('Listing start index= %d, end=%d' % (start_index, end_index))
|
||||
if start_index == -1 or end_index == -1:
|
||||
return data
|
||||
return data[start_index:end_index + len(end_pattern)]
|
||||
@@ -145,9 +145,9 @@ def test_check_output(data=None, check_dict=None, expect_dict=None):
|
||||
for line in data_lines:
|
||||
group, index = test_expect_re(line, pattern)
|
||||
if index is not None:
|
||||
logger.debug("Found key{%s}=%s, line: \n%s" % (key, group, line))
|
||||
logger.debug('Found key{%s}=%s, line: \n%s' % (key, group, line))
|
||||
if expect_dict[key] == group:
|
||||
logger.debug("The result is correct for the key:%s, expected:%s == returned:%s" % (key, str(expect_dict[key]), str(group)))
|
||||
logger.debug('The result is correct for the key:%s, expected:%s == returned:%s' % (key, str(expect_dict[key]), str(group)))
|
||||
match_count += 1
|
||||
return match_count
|
||||
|
||||
@@ -158,7 +158,7 @@ def test_check_mode(dut=None, mode_str=None, value=None):
|
||||
global logger
|
||||
try:
|
||||
opt = dut.app.get_sdkconfig()[mode_str]
|
||||
logger.info("%s {%s} = %s.\n" % (str(dut), mode_str, opt))
|
||||
logger.info('%s {%s} = %s.\n' % (str(dut), mode_str, opt))
|
||||
return value == opt
|
||||
except Exception:
|
||||
logger.info('ENV_TEST_FAILURE: %s: Cannot find option %s in sdkconfig.' % (str(dut), mode_str))
|
||||
@@ -170,30 +170,30 @@ def test_modbus_communication(env, comm_mode):
|
||||
global logger
|
||||
|
||||
# Get device under test. "dut1 - master", "dut2 - slave" must be properly connected through RS485 interface driver
|
||||
dut_master = env.get_dut("modbus_master", "examples/protocols/modbus/serial/mb_master", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut_slave = env.get_dut("modbus_slave", "examples/protocols/modbus/serial/mb_slave", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut_master = env.get_dut('modbus_master', 'examples/protocols/modbus/serial/mb_master', dut_class=ttfw_idf.ESP32DUT)
|
||||
dut_slave = env.get_dut('modbus_slave', 'examples/protocols/modbus/serial/mb_slave', dut_class=ttfw_idf.ESP32DUT)
|
||||
|
||||
try:
|
||||
logger.debug("Environment vars: %s\r\n" % os.environ)
|
||||
logger.debug("DUT slave sdkconfig: %s\r\n" % dut_slave.app.get_sdkconfig())
|
||||
logger.debug("DUT master sdkconfig: %s\r\n" % dut_master.app.get_sdkconfig())
|
||||
logger.debug('Environment vars: %s\r\n' % os.environ)
|
||||
logger.debug('DUT slave sdkconfig: %s\r\n' % dut_slave.app.get_sdkconfig())
|
||||
logger.debug('DUT master sdkconfig: %s\r\n' % dut_master.app.get_sdkconfig())
|
||||
|
||||
# Check Kconfig configuration options for each built example
|
||||
if test_check_mode(dut_master, "CONFIG_MB_COMM_MODE_ASCII", "y") and test_check_mode(dut_slave, "CONFIG_MB_COMM_MODE_ASCII", "y"):
|
||||
logger.info("ENV_TEST_INFO: Modbus ASCII test mode selected in the configuration. \n")
|
||||
if test_check_mode(dut_master, 'CONFIG_MB_COMM_MODE_ASCII', 'y') and test_check_mode(dut_slave, 'CONFIG_MB_COMM_MODE_ASCII', 'y'):
|
||||
logger.info('ENV_TEST_INFO: Modbus ASCII test mode selected in the configuration. \n')
|
||||
slave_name = TEST_SLAVE_ASCII
|
||||
master_name = TEST_MASTER_ASCII
|
||||
elif test_check_mode(dut_master, "CONFIG_MB_COMM_MODE_RTU", "y") and test_check_mode(dut_slave, "CONFIG_MB_COMM_MODE_RTU", "y"):
|
||||
logger.info("ENV_TEST_INFO: Modbus RTU test mode selected in the configuration. \n")
|
||||
elif test_check_mode(dut_master, 'CONFIG_MB_COMM_MODE_RTU', 'y') and test_check_mode(dut_slave, 'CONFIG_MB_COMM_MODE_RTU', 'y'):
|
||||
logger.info('ENV_TEST_INFO: Modbus RTU test mode selected in the configuration. \n')
|
||||
slave_name = TEST_SLAVE_RTU
|
||||
master_name = TEST_MASTER_RTU
|
||||
else:
|
||||
logger.error("ENV_TEST_FAILURE: Communication mode in master and slave configuration don't match.\n")
|
||||
raise Exception("ENV_TEST_FAILURE: Communication mode in master and slave configuration don't match.\n")
|
||||
# Check if slave address for example application is default one to be able to communicate
|
||||
if not test_check_mode(dut_slave, "CONFIG_MB_SLAVE_ADDR", "1"):
|
||||
logger.error("ENV_TEST_FAILURE: Slave address option is incorrect.\n")
|
||||
raise Exception("ENV_TEST_FAILURE: Slave address option is incorrect.\n")
|
||||
if not test_check_mode(dut_slave, 'CONFIG_MB_SLAVE_ADDR', '1'):
|
||||
logger.error('ENV_TEST_FAILURE: Slave address option is incorrect.\n')
|
||||
raise Exception('ENV_TEST_FAILURE: Slave address option is incorrect.\n')
|
||||
|
||||
# Flash app onto each DUT
|
||||
dut_master.start_app()
|
||||
@@ -212,15 +212,15 @@ def test_modbus_communication(env, comm_mode):
|
||||
dut_master_thread.join(timeout=TEST_THREAD_JOIN_TIMEOUT)
|
||||
|
||||
if dut_slave_thread.isAlive():
|
||||
logger.error("ENV_TEST_FAILURE: The thread %s is not completed successfully after %d seconds.\n" %
|
||||
logger.error('ENV_TEST_FAILURE: The thread %s is not completed successfully after %d seconds.\n' %
|
||||
(dut_slave_thread.tname, TEST_THREAD_JOIN_TIMEOUT))
|
||||
raise Exception("ENV_TEST_FAILURE: The thread %s is not completed successfully after %d seconds.\n" %
|
||||
raise Exception('ENV_TEST_FAILURE: The thread %s is not completed successfully after %d seconds.\n' %
|
||||
(dut_slave_thread.tname, TEST_THREAD_JOIN_TIMEOUT))
|
||||
|
||||
if dut_master_thread.isAlive():
|
||||
logger.error("ENV_TEST_FAILURE: The thread %s is not completed successfully after %d seconds.\n" %
|
||||
logger.error('ENV_TEST_FAILURE: The thread %s is not completed successfully after %d seconds.\n' %
|
||||
(dut_master_thread.tname, TEST_THREAD_JOIN_TIMEOUT))
|
||||
raise Exception("ENV_TEST_FAILURE: The thread %s is not completed successfully after %d seconds.\n" %
|
||||
raise Exception('ENV_TEST_FAILURE: The thread %s is not completed successfully after %d seconds.\n' %
|
||||
(dut_master_thread.tname, TEST_THREAD_JOIN_TIMEOUT))
|
||||
finally:
|
||||
dut_master.close()
|
||||
@@ -228,43 +228,43 @@ def test_modbus_communication(env, comm_mode):
|
||||
|
||||
# Check if test threads completed successfully and captured data
|
||||
if not dut_slave_thread.result or dut_slave_thread.data is None:
|
||||
logger.error("The thread %s was not run successfully." % dut_slave_thread.tname)
|
||||
raise Exception("The thread %s was not run successfully." % dut_slave_thread.tname)
|
||||
logger.error('The thread %s was not run successfully.' % dut_slave_thread.tname)
|
||||
raise Exception('The thread %s was not run successfully.' % dut_slave_thread.tname)
|
||||
|
||||
if not dut_master_thread.result or dut_master_thread.data is None:
|
||||
logger.error("The thread %s was not run successfully." % dut_slave_thread.tname)
|
||||
raise Exception("The thread %s was not run successfully." % dut_master_thread.tname)
|
||||
logger.error('The thread %s was not run successfully.' % dut_slave_thread.tname)
|
||||
raise Exception('The thread %s was not run successfully.' % dut_master_thread.tname)
|
||||
|
||||
# Filter output to get test messages
|
||||
master_output = test_filter_output(dut_master_thread.data, master_expect[0], master_expect[len(master_expect) - 1])
|
||||
if master_output is not None:
|
||||
logger.info("The data for master thread is captured.")
|
||||
logger.info('The data for master thread is captured.')
|
||||
logger.debug(master_output)
|
||||
|
||||
slave_output = test_filter_output(dut_slave_thread.data, slave_expect[0], slave_expect[len(slave_expect) - 1])
|
||||
if slave_output is not None:
|
||||
logger.info("The data for slave thread is captured.")
|
||||
logger.info('The data for slave thread is captured.')
|
||||
logger.debug(slave_output)
|
||||
|
||||
# Check if parameters are read correctly by master
|
||||
match_count = test_check_output(master_output, pattern_dict_master_ok, expect_dict_master_ok)
|
||||
if match_count < TEST_READ_MIN_COUNT:
|
||||
logger.error("There are errors reading parameters from %s, %d" % (dut_master_thread.tname, match_count))
|
||||
raise Exception("There are errors reading parameters from %s, %d" % (dut_master_thread.tname, match_count))
|
||||
logger.info("OK pattern test for %s, match_count=%d." % (dut_master_thread.tname, match_count))
|
||||
logger.error('There are errors reading parameters from %s, %d' % (dut_master_thread.tname, match_count))
|
||||
raise Exception('There are errors reading parameters from %s, %d' % (dut_master_thread.tname, match_count))
|
||||
logger.info('OK pattern test for %s, match_count=%d.' % (dut_master_thread.tname, match_count))
|
||||
|
||||
# If the test completed successfully (alarm triggered) but there are some errors during reading of parameters
|
||||
match_count = test_check_output(master_output, pattern_dict_master_err, expect_dict_master_err)
|
||||
if match_count > TEST_READ_MAX_ERR_COUNT:
|
||||
logger.error("There are errors reading parameters from %s, %d" % (dut_master_thread.tname, match_count))
|
||||
raise Exception("There are errors reading parameters from %s, %d" % (dut_master_thread.tname, match_count))
|
||||
logger.info("ERROR pattern test for %s, match_count=%d." % (dut_master_thread.tname, match_count))
|
||||
logger.error('There are errors reading parameters from %s, %d' % (dut_master_thread.tname, match_count))
|
||||
raise Exception('There are errors reading parameters from %s, %d' % (dut_master_thread.tname, match_count))
|
||||
logger.info('ERROR pattern test for %s, match_count=%d.' % (dut_master_thread.tname, match_count))
|
||||
|
||||
match_count = test_check_output(slave_output, pattern_dict_slave_ok, expect_dict_slave_ok)
|
||||
if match_count < TEST_READ_MIN_COUNT:
|
||||
logger.error("There are errors reading parameters from %s, %d" % (dut_slave_thread.tname, match_count))
|
||||
raise Exception("There are errors reading parameters from %s, %d" % (dut_slave_thread.tname, match_count))
|
||||
logger.info("OK pattern test for %s, match_count=%d." % (dut_slave_thread.tname, match_count))
|
||||
logger.error('There are errors reading parameters from %s, %d' % (dut_slave_thread.tname, match_count))
|
||||
raise Exception('There are errors reading parameters from %s, %d' % (dut_slave_thread.tname, match_count))
|
||||
logger.info('OK pattern test for %s, match_count=%d.' % (dut_slave_thread.tname, match_count))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
@@ -282,7 +282,7 @@ if __name__ == '__main__':
|
||||
fh.setFormatter(formatter)
|
||||
logger.addHandler(fh)
|
||||
logger.addHandler(ch)
|
||||
logger.info("Start script %s." % os.path.basename(__file__))
|
||||
print("Logging file name: %s" % logger.handlers[0].baseFilename)
|
||||
logger.info('Start script %s.' % os.path.basename(__file__))
|
||||
print('Logging file name: %s' % logger.handlers[0].baseFilename)
|
||||
test_modbus_communication()
|
||||
logging.shutdown()
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import logging
|
||||
from threading import Thread
|
||||
|
||||
import ttfw_idf
|
||||
from tiny_test_fw import DUT
|
||||
|
||||
LOG_LEVEL = logging.DEBUG
|
||||
LOGGER_NAME = "modbus_test"
|
||||
LOGGER_NAME = 'modbus_test'
|
||||
|
||||
# Allowed options for the test
|
||||
TEST_READ_MAX_ERR_COUNT = 3 # Maximum allowed read errors during initialization
|
||||
@@ -69,7 +69,7 @@ class DutTestThread(Thread):
|
||||
super(DutTestThread, self).__init__()
|
||||
|
||||
def __enter__(self):
|
||||
logger.debug("Restart %s." % self.tname)
|
||||
logger.debug('Restart %s.' % self.tname)
|
||||
# Reset DUT first
|
||||
self.dut.reset()
|
||||
# Capture output from the DUT
|
||||
@@ -80,7 +80,7 @@ class DutTestThread(Thread):
|
||||
""" The exit method of context manager
|
||||
"""
|
||||
if exc_type is not None or exc_value is not None:
|
||||
logger.info("Thread %s rised an exception type: %s, value: %s" % (self.tname, str(exc_type), str(exc_value)))
|
||||
logger.info('Thread %s rised an exception type: %s, value: %s' % (self.tname, str(exc_type), str(exc_value)))
|
||||
|
||||
def run(self):
|
||||
""" The function implements thread functionality
|
||||
@@ -94,8 +94,8 @@ class DutTestThread(Thread):
|
||||
|
||||
# Check DUT exceptions
|
||||
dut_exceptions = self.dut.get_exceptions()
|
||||
if "Guru Meditation Error:" in dut_exceptions:
|
||||
raise Exception("%s generated an exception: %s\n" % (str(self.dut), dut_exceptions))
|
||||
if 'Guru Meditation Error:' in dut_exceptions:
|
||||
raise Exception('%s generated an exception: %s\n' % (str(self.dut), dut_exceptions))
|
||||
|
||||
# Mark thread has run to completion without any exceptions
|
||||
self.data = self.dut.stop_capture_raw_data(capture_id=self.dut.name)
|
||||
@@ -108,13 +108,13 @@ class DutTestThread(Thread):
|
||||
self.dut.read()
|
||||
result = self.dut.expect(re.compile(message), TEST_EXPECT_STR_TIMEOUT)
|
||||
if int(result[0]) != index:
|
||||
raise Exception("Incorrect index of IP=%d for %s\n" % (int(result[0]), str(self.dut)))
|
||||
message = "IP%s=%s" % (result[0], self.ip_addr)
|
||||
self.dut.write(message, "\r\n", False)
|
||||
logger.debug("Sent message for %s: %s" % (self.tname, message))
|
||||
raise Exception('Incorrect index of IP=%d for %s\n' % (int(result[0]), str(self.dut)))
|
||||
message = 'IP%s=%s' % (result[0], self.ip_addr)
|
||||
self.dut.write(message, '\r\n', False)
|
||||
logger.debug('Sent message for %s: %s' % (self.tname, message))
|
||||
message = r'.*IP\([0-9]+\) = \[([0-9a-zA-Z\.\:]+)\] set from stdin.*'
|
||||
result = self.dut.expect(re.compile(message), TEST_EXPECT_STR_TIMEOUT)
|
||||
logger.debug("Thread %s initialized with slave IP (%s)." % (self.tname, result[0]))
|
||||
logger.debug('Thread %s initialized with slave IP (%s).' % (self.tname, result[0]))
|
||||
|
||||
def test_start(self, timeout_value):
|
||||
""" The method to initialize and handle test stages
|
||||
@@ -122,37 +122,37 @@ class DutTestThread(Thread):
|
||||
def handle_get_ip4(data):
|
||||
""" Handle get_ip v4
|
||||
"""
|
||||
logger.debug("%s[STACK_IPV4]: %s" % (self.tname, str(data)))
|
||||
logger.debug('%s[STACK_IPV4]: %s' % (self.tname, str(data)))
|
||||
self.test_stage = STACK_IPV4
|
||||
|
||||
def handle_get_ip6(data):
|
||||
""" Handle get_ip v6
|
||||
"""
|
||||
logger.debug("%s[STACK_IPV6]: %s" % (self.tname, str(data)))
|
||||
logger.debug('%s[STACK_IPV6]: %s' % (self.tname, str(data)))
|
||||
self.test_stage = STACK_IPV6
|
||||
|
||||
def handle_init(data):
|
||||
""" Handle init
|
||||
"""
|
||||
logger.debug("%s[STACK_INIT]: %s" % (self.tname, str(data)))
|
||||
logger.debug('%s[STACK_INIT]: %s' % (self.tname, str(data)))
|
||||
self.test_stage = STACK_INIT
|
||||
|
||||
def handle_connect(data):
|
||||
""" Handle connect
|
||||
"""
|
||||
logger.debug("%s[STACK_CONNECT]: %s" % (self.tname, str(data)))
|
||||
logger.debug('%s[STACK_CONNECT]: %s' % (self.tname, str(data)))
|
||||
self.test_stage = STACK_CONNECT
|
||||
|
||||
def handle_test_start(data):
|
||||
""" Handle connect
|
||||
"""
|
||||
logger.debug("%s[STACK_START]: %s" % (self.tname, str(data)))
|
||||
logger.debug('%s[STACK_START]: %s' % (self.tname, str(data)))
|
||||
self.test_stage = STACK_START
|
||||
|
||||
def handle_par_ok(data):
|
||||
""" Handle parameter ok
|
||||
"""
|
||||
logger.debug("%s[READ_PAR_OK]: %s" % (self.tname, str(data)))
|
||||
logger.debug('%s[READ_PAR_OK]: %s' % (self.tname, str(data)))
|
||||
if self.test_stage >= STACK_START:
|
||||
self.param_ok_count += 1
|
||||
self.test_stage = STACK_PAR_OK
|
||||
@@ -160,14 +160,14 @@ class DutTestThread(Thread):
|
||||
def handle_par_fail(data):
|
||||
""" Handle parameter fail
|
||||
"""
|
||||
logger.debug("%s[READ_PAR_FAIL]: %s" % (self.tname, str(data)))
|
||||
logger.debug('%s[READ_PAR_FAIL]: %s' % (self.tname, str(data)))
|
||||
self.param_fail_count += 1
|
||||
self.test_stage = STACK_PAR_FAIL
|
||||
|
||||
def handle_destroy(data):
|
||||
""" Handle destroy
|
||||
"""
|
||||
logger.debug("%s[DESTROY]: %s" % (self.tname, str(data)))
|
||||
logger.debug('%s[DESTROY]: %s' % (self.tname, str(data)))
|
||||
self.test_stage = STACK_DESTROY
|
||||
self.test_finish = True
|
||||
|
||||
@@ -183,7 +183,7 @@ class DutTestThread(Thread):
|
||||
(re.compile(self.expected[STACK_DESTROY]), handle_destroy),
|
||||
timeout=timeout_value)
|
||||
except DUT.ExpectTimeout:
|
||||
logger.debug("%s, expect timeout on stage #%d (%s seconds)" % (self.tname, self.test_stage, timeout_value))
|
||||
logger.debug('%s, expect timeout on stage #%d (%s seconds)' % (self.tname, self.test_stage, timeout_value))
|
||||
self.test_finish = True
|
||||
|
||||
|
||||
@@ -193,7 +193,7 @@ def test_check_mode(dut=None, mode_str=None, value=None):
|
||||
global logger
|
||||
try:
|
||||
opt = dut.app.get_sdkconfig()[mode_str]
|
||||
logger.debug("%s {%s} = %s.\n" % (str(dut), mode_str, opt))
|
||||
logger.debug('%s {%s} = %s.\n' % (str(dut), mode_str, opt))
|
||||
return value == opt
|
||||
except Exception:
|
||||
logger.error('ENV_TEST_FAILURE: %s: Cannot find option %s in sdkconfig.' % (str(dut), mode_str))
|
||||
@@ -208,8 +208,8 @@ def test_modbus_communication(env, comm_mode):
|
||||
# Get device under test. Both duts must be able to be connected to WiFi router
|
||||
dut_master = env.get_dut('modbus_tcp_master', os.path.join(rel_project_path, TEST_MASTER_TCP))
|
||||
dut_slave = env.get_dut('modbus_tcp_slave', os.path.join(rel_project_path, TEST_SLAVE_TCP))
|
||||
log_file = os.path.join(env.log_path, "modbus_tcp_test.log")
|
||||
print("Logging file name: %s" % log_file)
|
||||
log_file = os.path.join(env.log_path, 'modbus_tcp_test.log')
|
||||
print('Logging file name: %s' % log_file)
|
||||
|
||||
try:
|
||||
# create file handler which logs even debug messages
|
||||
@@ -229,29 +229,29 @@ def test_modbus_communication(env, comm_mode):
|
||||
logger.addHandler(ch)
|
||||
|
||||
# Check Kconfig configuration options for each built example
|
||||
if (test_check_mode(dut_master, "CONFIG_FMB_COMM_MODE_TCP_EN", "y") and
|
||||
test_check_mode(dut_slave, "CONFIG_FMB_COMM_MODE_TCP_EN", "y")):
|
||||
if (test_check_mode(dut_master, 'CONFIG_FMB_COMM_MODE_TCP_EN', 'y') and
|
||||
test_check_mode(dut_slave, 'CONFIG_FMB_COMM_MODE_TCP_EN', 'y')):
|
||||
slave_name = TEST_SLAVE_TCP
|
||||
master_name = TEST_MASTER_TCP
|
||||
else:
|
||||
logger.error("ENV_TEST_FAILURE: IP resolver mode do not match in the master and slave implementation.\n")
|
||||
raise Exception("ENV_TEST_FAILURE: IP resolver mode do not match in the master and slave implementation.\n")
|
||||
logger.error('ENV_TEST_FAILURE: IP resolver mode do not match in the master and slave implementation.\n')
|
||||
raise Exception('ENV_TEST_FAILURE: IP resolver mode do not match in the master and slave implementation.\n')
|
||||
address = None
|
||||
if test_check_mode(dut_master, "CONFIG_MB_SLAVE_IP_FROM_STDIN", "y"):
|
||||
logger.info("ENV_TEST_INFO: Set slave IP address through STDIN.\n")
|
||||
if test_check_mode(dut_master, 'CONFIG_MB_SLAVE_IP_FROM_STDIN', 'y'):
|
||||
logger.info('ENV_TEST_INFO: Set slave IP address through STDIN.\n')
|
||||
# Flash app onto DUT (Todo: Debug case when the slave flashed before master then expect does not work correctly for no reason
|
||||
dut_slave.start_app()
|
||||
dut_master.start_app()
|
||||
if test_check_mode(dut_master, "CONFIG_EXAMPLE_CONNECT_IPV6", "y"):
|
||||
if test_check_mode(dut_master, 'CONFIG_EXAMPLE_CONNECT_IPV6', 'y'):
|
||||
address = dut_slave.expect(re.compile(pattern_dict_slave[STACK_IPV6]), TEST_EXPECT_STR_TIMEOUT)
|
||||
else:
|
||||
address = dut_slave.expect(re.compile(pattern_dict_slave[STACK_IPV4]), TEST_EXPECT_STR_TIMEOUT)
|
||||
if address is not None:
|
||||
print("Found IP slave address: %s" % address[0])
|
||||
print('Found IP slave address: %s' % address[0])
|
||||
else:
|
||||
raise Exception("ENV_TEST_FAILURE: Slave IP address is not found in the output. Check network settings.\n")
|
||||
raise Exception('ENV_TEST_FAILURE: Slave IP address is not found in the output. Check network settings.\n')
|
||||
else:
|
||||
raise Exception("ENV_TEST_FAILURE: Slave IP resolver is not configured correctly.\n")
|
||||
raise Exception('ENV_TEST_FAILURE: Slave IP resolver is not configured correctly.\n')
|
||||
|
||||
# Create thread for each dut
|
||||
with DutTestThread(dut=dut_master, name=master_name, ip_addr=address[0], expect=pattern_dict_master) as dut_master_thread:
|
||||
@@ -266,21 +266,21 @@ def test_modbus_communication(env, comm_mode):
|
||||
dut_master_thread.join(timeout=TEST_THREAD_JOIN_TIMEOUT)
|
||||
|
||||
if dut_slave_thread.isAlive():
|
||||
logger.error("ENV_TEST_FAILURE: The thread %s is not completed successfully after %d seconds.\n" %
|
||||
logger.error('ENV_TEST_FAILURE: The thread %s is not completed successfully after %d seconds.\n' %
|
||||
(dut_slave_thread.tname, TEST_THREAD_JOIN_TIMEOUT))
|
||||
raise Exception("ENV_TEST_FAILURE: The thread %s is not completed successfully after %d seconds.\n" %
|
||||
raise Exception('ENV_TEST_FAILURE: The thread %s is not completed successfully after %d seconds.\n' %
|
||||
(dut_slave_thread.tname, TEST_THREAD_JOIN_TIMEOUT))
|
||||
|
||||
if dut_master_thread.isAlive():
|
||||
logger.error("TEST_FAILURE: The thread %s is not completed successfully after %d seconds.\n" %
|
||||
logger.error('TEST_FAILURE: The thread %s is not completed successfully after %d seconds.\n' %
|
||||
(dut_master_thread.tname, TEST_THREAD_JOIN_TIMEOUT))
|
||||
raise Exception("TEST_FAILURE: The thread %s is not completed successfully after %d seconds.\n" %
|
||||
raise Exception('TEST_FAILURE: The thread %s is not completed successfully after %d seconds.\n' %
|
||||
(dut_master_thread.tname, TEST_THREAD_JOIN_TIMEOUT))
|
||||
|
||||
logger.info("TEST_INFO: %s error count = %d, %s error count = %d.\n" %
|
||||
logger.info('TEST_INFO: %s error count = %d, %s error count = %d.\n' %
|
||||
(dut_master_thread.tname, dut_master_thread.param_fail_count,
|
||||
dut_slave_thread.tname, dut_slave_thread.param_fail_count))
|
||||
logger.info("TEST_INFO: %s ok count = %d, %s ok count = %d.\n" %
|
||||
logger.info('TEST_INFO: %s ok count = %d, %s ok count = %d.\n' %
|
||||
(dut_master_thread.tname, dut_master_thread.param_ok_count,
|
||||
dut_slave_thread.tname, dut_slave_thread.param_ok_count))
|
||||
|
||||
@@ -288,10 +288,10 @@ def test_modbus_communication(env, comm_mode):
|
||||
(dut_slave_thread.param_fail_count > TEST_READ_MAX_ERR_COUNT) or
|
||||
(dut_slave_thread.param_ok_count == 0) or
|
||||
(dut_master_thread.param_ok_count == 0)):
|
||||
raise Exception("TEST_FAILURE: %s parameter read error(ok) count = %d(%d), %s parameter read error(ok) count = %d(%d).\n" %
|
||||
raise Exception('TEST_FAILURE: %s parameter read error(ok) count = %d(%d), %s parameter read error(ok) count = %d(%d).\n' %
|
||||
(dut_master_thread.tname, dut_master_thread.param_fail_count, dut_master_thread.param_ok_count,
|
||||
dut_slave_thread.tname, dut_slave_thread.param_fail_count, dut_slave_thread.param_ok_count))
|
||||
logger.info("TEST_SUCCESS: The Modbus parameter test is completed successfully.\n")
|
||||
logger.info('TEST_SUCCESS: The Modbus parameter test is completed successfully.\n')
|
||||
|
||||
finally:
|
||||
dut_master.close()
|
||||
|
||||
@@ -1,29 +1,28 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
from builtins import str
|
||||
import re
|
||||
from __future__ import print_function, unicode_literals
|
||||
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
import ssl
|
||||
import sys
|
||||
from builtins import str
|
||||
from threading import Event, Thread
|
||||
|
||||
import paho.mqtt.client as mqtt
|
||||
from threading import Thread, Event
|
||||
|
||||
from tiny_test_fw import DUT
|
||||
import ttfw_idf
|
||||
|
||||
from tiny_test_fw import DUT
|
||||
|
||||
event_client_connected = Event()
|
||||
event_stop_client = Event()
|
||||
event_client_received_correct = Event()
|
||||
event_client_received_binary = Event()
|
||||
message_log = ""
|
||||
message_log = ''
|
||||
|
||||
|
||||
# The callback for when the client receives a CONNACK response from the server.
|
||||
def on_connect(client, userdata, flags, rc):
|
||||
print("Connected with result code " + str(rc))
|
||||
print('Connected with result code ' + str(rc))
|
||||
event_client_connected.set()
|
||||
client.subscribe("/topic/qos0")
|
||||
client.subscribe('/topic/qos0')
|
||||
|
||||
|
||||
def mqtt_client_task(client):
|
||||
@@ -36,33 +35,33 @@ def on_message(client, userdata, msg):
|
||||
global message_log
|
||||
global event_client_received_correct
|
||||
global event_client_received_binary
|
||||
if msg.topic == "/topic/binary":
|
||||
if msg.topic == '/topic/binary':
|
||||
binary = userdata
|
||||
size = os.path.getsize(binary)
|
||||
print("Receiving binary from esp and comparing with {}, size {}...".format(binary, size))
|
||||
with open(binary, "rb") as f:
|
||||
print('Receiving binary from esp and comparing with {}, size {}...'.format(binary, size))
|
||||
with open(binary, 'rb') as f:
|
||||
bin = f.read()
|
||||
if bin == msg.payload[:size]:
|
||||
print("...matches!")
|
||||
print('...matches!')
|
||||
event_client_received_binary.set()
|
||||
return
|
||||
else:
|
||||
recv_binary = binary + ".received"
|
||||
with open(recv_binary, "w") as fw:
|
||||
recv_binary = binary + '.received'
|
||||
with open(recv_binary, 'w') as fw:
|
||||
fw.write(msg.payload)
|
||||
raise ValueError('Received binary (saved as: {}) does not match the original file: {}'.format(recv_binary, binary))
|
||||
payload = msg.payload.decode()
|
||||
if not event_client_received_correct.is_set() and payload == "data":
|
||||
client.subscribe("/topic/binary")
|
||||
client.publish("/topic/qos0", "send binary please")
|
||||
if msg.topic == "/topic/qos0" and payload == "data":
|
||||
if not event_client_received_correct.is_set() and payload == 'data':
|
||||
client.subscribe('/topic/binary')
|
||||
client.publish('/topic/qos0', 'send binary please')
|
||||
if msg.topic == '/topic/qos0' and payload == 'data':
|
||||
event_client_received_correct.set()
|
||||
message_log += "Received data:" + msg.topic + " " + payload + "\n"
|
||||
message_log += 'Received data:' + msg.topic + ' ' + payload + '\n'
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_mqtt_ssl(env, extra_data):
|
||||
broker_url = ""
|
||||
broker_url = ''
|
||||
broker_port = 0
|
||||
"""
|
||||
steps: |
|
||||
@@ -72,15 +71,15 @@ def test_examples_protocol_mqtt_ssl(env, extra_data):
|
||||
4. Test ESP32 client received correct qos0 message
|
||||
5. Test python client receives binary data from running partition and compares it with the binary
|
||||
"""
|
||||
dut1 = env.get_dut("mqtt_ssl", "examples/protocols/mqtt/ssl", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('mqtt_ssl', 'examples/protocols/mqtt/ssl', dut_class=ttfw_idf.ESP32DUT)
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, "mqtt_ssl.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'mqtt_ssl.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("mqtt_ssl_bin_size", "{}KB"
|
||||
ttfw_idf.log_performance('mqtt_ssl_bin_size', '{}KB'
|
||||
.format(bin_size // 1024))
|
||||
# Look for host:port in sdkconfig
|
||||
try:
|
||||
value = re.search(r'\:\/\/([^:]+)\:([0-9]+)', dut1.app.get_sdkconfig()["CONFIG_BROKER_URI"])
|
||||
value = re.search(r'\:\/\/([^:]+)\:([0-9]+)', dut1.app.get_sdkconfig()['CONFIG_BROKER_URI'])
|
||||
broker_url = value.group(1)
|
||||
broker_port = int(value.group(2))
|
||||
except Exception:
|
||||
@@ -97,31 +96,31 @@ def test_examples_protocol_mqtt_ssl(env, extra_data):
|
||||
None,
|
||||
None, cert_reqs=ssl.CERT_NONE, tls_version=ssl.PROTOCOL_TLSv1_2, ciphers=None)
|
||||
client.tls_insecure_set(True)
|
||||
print("Connecting...")
|
||||
print('Connecting...')
|
||||
client.connect(broker_url, broker_port, 60)
|
||||
except Exception:
|
||||
print("ENV_TEST_FAILURE: Unexpected error while connecting to broker {}: {}:".format(broker_url, sys.exc_info()[0]))
|
||||
print('ENV_TEST_FAILURE: Unexpected error while connecting to broker {}: {}:'.format(broker_url, sys.exc_info()[0]))
|
||||
raise
|
||||
# Starting a py-client in a separate thread
|
||||
thread1 = Thread(target=mqtt_client_task, args=(client,))
|
||||
thread1.start()
|
||||
try:
|
||||
print("Connecting py-client to broker {}:{}...".format(broker_url, broker_port))
|
||||
print('Connecting py-client to broker {}:{}...'.format(broker_url, broker_port))
|
||||
if not event_client_connected.wait(timeout=30):
|
||||
raise ValueError("ENV_TEST_FAILURE: Test script cannot connect to broker: {}".format(broker_url))
|
||||
raise ValueError('ENV_TEST_FAILURE: Test script cannot connect to broker: {}'.format(broker_url))
|
||||
dut1.start_app()
|
||||
try:
|
||||
ip_address = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30)
|
||||
print("Connected to AP with IP: {}".format(ip_address))
|
||||
ip_address = dut1.expect(re.compile(r' sta ip: ([^,]+),'), timeout=30)
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except DUT.ExpectTimeout:
|
||||
print('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
raise
|
||||
print("Checking py-client received msg published from esp...")
|
||||
print('Checking py-client received msg published from esp...')
|
||||
if not event_client_received_correct.wait(timeout=30):
|
||||
raise ValueError('Wrong data received, msg log: {}'.format(message_log))
|
||||
print("Checking esp-client received msg published from py-client...")
|
||||
dut1.expect(re.compile(r"DATA=send binary please"), timeout=30)
|
||||
print("Receiving binary data from running partition...")
|
||||
print('Checking esp-client received msg published from py-client...')
|
||||
dut1.expect(re.compile(r'DATA=send binary please'), timeout=30)
|
||||
print('Receiving binary data from running partition...')
|
||||
if not event_client_received_binary.wait(timeout=30):
|
||||
raise ValueError('Binary not received within timeout')
|
||||
finally:
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import re
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
import socket
|
||||
from threading import Thread
|
||||
import struct
|
||||
import sys
|
||||
import time
|
||||
from threading import Thread
|
||||
|
||||
from tiny_test_fw import DUT
|
||||
import ttfw_idf
|
||||
from tiny_test_fw import DUT
|
||||
|
||||
msgid = -1
|
||||
|
||||
|
||||
def get_my_ip():
|
||||
s1 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
s1.connect(("8.8.8.8", 80))
|
||||
s1.connect(('8.8.8.8', 80))
|
||||
my_ip = s1.getsockname()[0]
|
||||
s1.close()
|
||||
return my_ip
|
||||
@@ -22,7 +22,7 @@ def get_my_ip():
|
||||
|
||||
def mqqt_server_sketch(my_ip, port):
|
||||
global msgid
|
||||
print("Starting the server on {}".format(my_ip))
|
||||
print('Starting the server on {}'.format(my_ip))
|
||||
s = None
|
||||
try:
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
@@ -31,29 +31,29 @@ def mqqt_server_sketch(my_ip, port):
|
||||
s.listen(1)
|
||||
q,addr = s.accept()
|
||||
q.settimeout(30)
|
||||
print("connection accepted")
|
||||
print('connection accepted')
|
||||
except Exception:
|
||||
print("Local server on {}:{} listening/accepting failure: {}"
|
||||
"Possibly check permissions or firewall settings"
|
||||
"to accept connections on this address".format(my_ip, port, sys.exc_info()[0]))
|
||||
print('Local server on {}:{} listening/accepting failure: {}'
|
||||
'Possibly check permissions or firewall settings'
|
||||
'to accept connections on this address'.format(my_ip, port, sys.exc_info()[0]))
|
||||
raise
|
||||
data = q.recv(1024)
|
||||
# check if received initial empty message
|
||||
print("received from client {}".format(data))
|
||||
print('received from client {}'.format(data))
|
||||
data = bytearray([0x20, 0x02, 0x00, 0x00])
|
||||
q.send(data)
|
||||
# try to receive qos1
|
||||
data = q.recv(1024)
|
||||
msgid = struct.unpack(">H", data[15:17])[0]
|
||||
print("received from client {}, msgid: {}".format(data, msgid))
|
||||
msgid = struct.unpack('>H', data[15:17])[0]
|
||||
print('received from client {}, msgid: {}'.format(data, msgid))
|
||||
data = bytearray([0x40, 0x02, data[15], data[16]])
|
||||
q.send(data)
|
||||
time.sleep(5)
|
||||
s.close()
|
||||
print("server closed")
|
||||
print('server closed')
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_mqtt_qos1(env, extra_data):
|
||||
global msgid
|
||||
"""
|
||||
@@ -63,11 +63,11 @@ def test_examples_protocol_mqtt_qos1(env, extra_data):
|
||||
3. Test evaluates that qos1 message is queued and removed from queued after ACK received
|
||||
4. Test the broker received the same message id evaluated in step 3
|
||||
"""
|
||||
dut1 = env.get_dut("mqtt_tcp", "examples/protocols/mqtt/tcp", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('mqtt_tcp', 'examples/protocols/mqtt/tcp', dut_class=ttfw_idf.ESP32DUT)
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, "mqtt_tcp.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'mqtt_tcp.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("mqtt_tcp_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('mqtt_tcp_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# 1. start mqtt broker sketch
|
||||
host_ip = get_my_ip()
|
||||
thread1 = Thread(target=mqqt_server_sketch, args=(host_ip,1883))
|
||||
@@ -76,23 +76,23 @@ def test_examples_protocol_mqtt_qos1(env, extra_data):
|
||||
dut1.start_app()
|
||||
# waiting for getting the IP address
|
||||
try:
|
||||
ip_address = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30)
|
||||
print("Connected to AP with IP: {}".format(ip_address))
|
||||
ip_address = dut1.expect(re.compile(r' sta ip: ([^,]+),'), timeout=30)
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except DUT.ExpectTimeout:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
|
||||
print("writing to device: {}".format("mqtt://" + host_ip + "\n"))
|
||||
dut1.write("mqtt://" + host_ip + "\n")
|
||||
print('writing to device: {}'.format('mqtt://' + host_ip + '\n'))
|
||||
dut1.write('mqtt://' + host_ip + '\n')
|
||||
thread1.join()
|
||||
print("Message id received from server: {}".format(msgid))
|
||||
print('Message id received from server: {}'.format(msgid))
|
||||
# 3. check the message id was enqueued and then deleted
|
||||
msgid_enqueued = dut1.expect(re.compile(r"OUTBOX: ENQUEUE msgid=([0-9]+)"), timeout=30)
|
||||
msgid_deleted = dut1.expect(re.compile(r"OUTBOX: DELETED msgid=([0-9]+)"), timeout=30)
|
||||
msgid_enqueued = dut1.expect(re.compile(r'OUTBOX: ENQUEUE msgid=([0-9]+)'), timeout=30)
|
||||
msgid_deleted = dut1.expect(re.compile(r'OUTBOX: DELETED msgid=([0-9]+)'), timeout=30)
|
||||
# 4. check the msgid of received data are the same as that of enqueued and deleted from outbox
|
||||
if (msgid_enqueued[0] == str(msgid) and msgid_deleted[0] == str(msgid)):
|
||||
print("PASS: Received correct msg id")
|
||||
print('PASS: Received correct msg id')
|
||||
else:
|
||||
print("Failure!")
|
||||
print('Failure!')
|
||||
raise ValueError('Mismatch of msgid: received: {}, enqueued {}, deleted {}'.format(msgid, msgid_enqueued, msgid_deleted))
|
||||
|
||||
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
from builtins import str
|
||||
import re
|
||||
import os
|
||||
import sys
|
||||
import paho.mqtt.client as mqtt
|
||||
from threading import Thread, Event
|
||||
from __future__ import print_function, unicode_literals
|
||||
|
||||
from tiny_test_fw import DUT
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
from builtins import str
|
||||
from threading import Event, Thread
|
||||
|
||||
import paho.mqtt.client as mqtt
|
||||
import ttfw_idf
|
||||
from tiny_test_fw import DUT
|
||||
|
||||
event_client_connected = Event()
|
||||
event_stop_client = Event()
|
||||
event_client_received_correct = Event()
|
||||
message_log = ""
|
||||
message_log = ''
|
||||
|
||||
|
||||
# The callback for when the client receives a CONNACK response from the server.
|
||||
def on_connect(client, userdata, flags, rc):
|
||||
print("Connected with result code " + str(rc))
|
||||
print('Connected with result code ' + str(rc))
|
||||
event_client_connected.set()
|
||||
client.subscribe("/topic/qos0")
|
||||
client.subscribe('/topic/qos0')
|
||||
|
||||
|
||||
def mqtt_client_task(client):
|
||||
@@ -32,16 +32,16 @@ def mqtt_client_task(client):
|
||||
def on_message(client, userdata, msg):
|
||||
global message_log
|
||||
payload = msg.payload.decode()
|
||||
if not event_client_received_correct.is_set() and payload == "data":
|
||||
client.publish("/topic/qos0", "data_to_esp32")
|
||||
if msg.topic == "/topic/qos0" and payload == "data":
|
||||
if not event_client_received_correct.is_set() and payload == 'data':
|
||||
client.publish('/topic/qos0', 'data_to_esp32')
|
||||
if msg.topic == '/topic/qos0' and payload == 'data':
|
||||
event_client_received_correct.set()
|
||||
message_log += "Received data:" + msg.topic + " " + payload + "\n"
|
||||
message_log += 'Received data:' + msg.topic + ' ' + payload + '\n'
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_mqtt_ws(env, extra_data):
|
||||
broker_url = ""
|
||||
broker_url = ''
|
||||
broker_port = 0
|
||||
"""
|
||||
steps: |
|
||||
@@ -50,14 +50,14 @@ def test_examples_protocol_mqtt_ws(env, extra_data):
|
||||
3. Test evaluates it received correct qos0 message
|
||||
4. Test ESP32 client received correct qos0 message
|
||||
"""
|
||||
dut1 = env.get_dut("mqtt_websocket", "examples/protocols/mqtt/ws", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('mqtt_websocket', 'examples/protocols/mqtt/ws', dut_class=ttfw_idf.ESP32DUT)
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, "mqtt_websocket.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'mqtt_websocket.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("mqtt_websocket_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('mqtt_websocket_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# Look for host:port in sdkconfig
|
||||
try:
|
||||
value = re.search(r'\:\/\/([^:]+)\:([0-9]+)', dut1.app.get_sdkconfig()["CONFIG_BROKER_URI"])
|
||||
value = re.search(r'\:\/\/([^:]+)\:([0-9]+)', dut1.app.get_sdkconfig()['CONFIG_BROKER_URI'])
|
||||
broker_url = value.group(1)
|
||||
broker_port = int(value.group(2))
|
||||
except Exception:
|
||||
@@ -66,33 +66,33 @@ def test_examples_protocol_mqtt_ws(env, extra_data):
|
||||
client = None
|
||||
# 1. Test connects to a broker
|
||||
try:
|
||||
client = mqtt.Client(transport="websockets")
|
||||
client = mqtt.Client(transport='websockets')
|
||||
client.on_connect = on_connect
|
||||
client.on_message = on_message
|
||||
print("Connecting...")
|
||||
print('Connecting...')
|
||||
client.connect(broker_url, broker_port, 60)
|
||||
except Exception:
|
||||
print("ENV_TEST_FAILURE: Unexpected error while connecting to broker {}: {}:".format(broker_url, sys.exc_info()[0]))
|
||||
print('ENV_TEST_FAILURE: Unexpected error while connecting to broker {}: {}:'.format(broker_url, sys.exc_info()[0]))
|
||||
raise
|
||||
# Starting a py-client in a separate thread
|
||||
thread1 = Thread(target=mqtt_client_task, args=(client,))
|
||||
thread1.start()
|
||||
try:
|
||||
print("Connecting py-client to broker {}:{}...".format(broker_url, broker_port))
|
||||
print('Connecting py-client to broker {}:{}...'.format(broker_url, broker_port))
|
||||
if not event_client_connected.wait(timeout=30):
|
||||
raise ValueError("ENV_TEST_FAILURE: Test script cannot connect to broker: {}".format(broker_url))
|
||||
raise ValueError('ENV_TEST_FAILURE: Test script cannot connect to broker: {}'.format(broker_url))
|
||||
dut1.start_app()
|
||||
try:
|
||||
ip_address = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30)
|
||||
print("Connected to AP with IP: {}".format(ip_address))
|
||||
ip_address = dut1.expect(re.compile(r' sta ip: ([^,]+),'), timeout=30)
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except DUT.ExpectTimeout:
|
||||
print('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
raise
|
||||
print("Checking py-client received msg published from esp...")
|
||||
print('Checking py-client received msg published from esp...')
|
||||
if not event_client_received_correct.wait(timeout=30):
|
||||
raise ValueError('Wrong data received, msg log: {}'.format(message_log))
|
||||
print("Checking esp-client received msg published from py-client...")
|
||||
dut1.expect(re.compile(r"DATA=data_to_esp32"), timeout=30)
|
||||
print('Checking esp-client received msg published from py-client...')
|
||||
dut1.expect(re.compile(r'DATA=data_to_esp32'), timeout=30)
|
||||
finally:
|
||||
event_stop_client.set()
|
||||
thread1.join()
|
||||
|
||||
@@ -1,28 +1,27 @@
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import unicode_literals
|
||||
from builtins import str
|
||||
import re
|
||||
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
import ssl
|
||||
import sys
|
||||
from builtins import str
|
||||
from threading import Event, Thread
|
||||
|
||||
import paho.mqtt.client as mqtt
|
||||
from threading import Thread, Event
|
||||
|
||||
from tiny_test_fw import DUT
|
||||
import ttfw_idf
|
||||
|
||||
from tiny_test_fw import DUT
|
||||
|
||||
event_client_connected = Event()
|
||||
event_stop_client = Event()
|
||||
event_client_received_correct = Event()
|
||||
message_log = ""
|
||||
message_log = ''
|
||||
|
||||
|
||||
# The callback for when the client receives a CONNACK response from the server.
|
||||
def on_connect(client, userdata, flags, rc):
|
||||
print("Connected with result code " + str(rc))
|
||||
print('Connected with result code ' + str(rc))
|
||||
event_client_connected.set()
|
||||
client.subscribe("/topic/qos0")
|
||||
client.subscribe('/topic/qos0')
|
||||
|
||||
|
||||
def mqtt_client_task(client):
|
||||
@@ -34,16 +33,16 @@ def mqtt_client_task(client):
|
||||
def on_message(client, userdata, msg):
|
||||
global message_log
|
||||
payload = msg.payload.decode()
|
||||
if not event_client_received_correct.is_set() and payload == "data":
|
||||
client.publish("/topic/qos0", "data_to_esp32")
|
||||
if msg.topic == "/topic/qos0" and payload == "data":
|
||||
if not event_client_received_correct.is_set() and payload == 'data':
|
||||
client.publish('/topic/qos0', 'data_to_esp32')
|
||||
if msg.topic == '/topic/qos0' and payload == 'data':
|
||||
event_client_received_correct.set()
|
||||
message_log += "Received data:" + msg.topic + " " + payload + "\n"
|
||||
message_log += 'Received data:' + msg.topic + ' ' + payload + '\n'
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_mqtt_wss(env, extra_data):
|
||||
broker_url = ""
|
||||
broker_url = ''
|
||||
broker_port = 0
|
||||
"""
|
||||
steps: |
|
||||
@@ -52,14 +51,14 @@ def test_examples_protocol_mqtt_wss(env, extra_data):
|
||||
3. Test evaluates it received correct qos0 message
|
||||
4. Test ESP32 client received correct qos0 message
|
||||
"""
|
||||
dut1 = env.get_dut("mqtt_websocket_secure", "examples/protocols/mqtt/wss", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('mqtt_websocket_secure', 'examples/protocols/mqtt/wss', dut_class=ttfw_idf.ESP32DUT)
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, "mqtt_websocket_secure.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'mqtt_websocket_secure.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("mqtt_websocket_secure_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('mqtt_websocket_secure_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# Look for host:port in sdkconfig
|
||||
try:
|
||||
value = re.search(r'\:\/\/([^:]+)\:([0-9]+)', dut1.app.get_sdkconfig()["CONFIG_BROKER_URI"])
|
||||
value = re.search(r'\:\/\/([^:]+)\:([0-9]+)', dut1.app.get_sdkconfig()['CONFIG_BROKER_URI'])
|
||||
broker_url = value.group(1)
|
||||
broker_port = int(value.group(2))
|
||||
except Exception:
|
||||
@@ -68,36 +67,36 @@ def test_examples_protocol_mqtt_wss(env, extra_data):
|
||||
client = None
|
||||
# 1. Test connects to a broker
|
||||
try:
|
||||
client = mqtt.Client(transport="websockets")
|
||||
client = mqtt.Client(transport='websockets')
|
||||
client.on_connect = on_connect
|
||||
client.on_message = on_message
|
||||
client.tls_set(None,
|
||||
None,
|
||||
None, cert_reqs=ssl.CERT_NONE, tls_version=ssl.PROTOCOL_TLSv1_2, ciphers=None)
|
||||
print("Connecting...")
|
||||
print('Connecting...')
|
||||
client.connect(broker_url, broker_port, 60)
|
||||
except Exception:
|
||||
print("ENV_TEST_FAILURE: Unexpected error while connecting to broker {}: {}:".format(broker_url, sys.exc_info()[0]))
|
||||
print('ENV_TEST_FAILURE: Unexpected error while connecting to broker {}: {}:'.format(broker_url, sys.exc_info()[0]))
|
||||
raise
|
||||
# Starting a py-client in a separate thread
|
||||
thread1 = Thread(target=mqtt_client_task, args=(client,))
|
||||
thread1.start()
|
||||
try:
|
||||
print("Connecting py-client to broker {}:{}...".format(broker_url, broker_port))
|
||||
print('Connecting py-client to broker {}:{}...'.format(broker_url, broker_port))
|
||||
if not event_client_connected.wait(timeout=30):
|
||||
raise ValueError("ENV_TEST_FAILURE: Test script cannot connect to broker: {}".format(broker_url))
|
||||
raise ValueError('ENV_TEST_FAILURE: Test script cannot connect to broker: {}'.format(broker_url))
|
||||
dut1.start_app()
|
||||
try:
|
||||
ip_address = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30)
|
||||
print("Connected to AP with IP: {}".format(ip_address))
|
||||
ip_address = dut1.expect(re.compile(r' sta ip: ([^,]+),'), timeout=30)
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except DUT.ExpectTimeout:
|
||||
print('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
raise
|
||||
print("Checking py-client received msg published from esp...")
|
||||
print('Checking py-client received msg published from esp...')
|
||||
if not event_client_received_correct.wait(timeout=30):
|
||||
raise ValueError('Wrong data received, msg log: {}'.format(message_log))
|
||||
print("Checking esp-client received msg published from py-client...")
|
||||
dut1.expect(re.compile(r"DATA=data_to_esp32"), timeout=30)
|
||||
print('Checking esp-client received msg published from py-client...')
|
||||
dut1.expect(re.compile(r'DATA=data_to_esp32'), timeout=30)
|
||||
finally:
|
||||
event_stop_client.set()
|
||||
thread1.join()
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
from __future__ import unicode_literals
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
import os
|
||||
import serial
|
||||
import threading
|
||||
import time
|
||||
|
||||
import serial
|
||||
import ttfw_idf
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
|
||||
class SerialThread(object):
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
from __future__ import unicode_literals
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
import datetime
|
||||
import re
|
||||
|
||||
import ttfw_idf
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
|
||||
@@ -6,17 +6,17 @@
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
from builtins import input
|
||||
from __future__ import print_function, unicode_literals
|
||||
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import netifaces
|
||||
import socket
|
||||
from threading import Thread, Event
|
||||
import ttfw_idf
|
||||
import sys
|
||||
from builtins import input
|
||||
from threading import Event, Thread
|
||||
|
||||
import netifaces
|
||||
import ttfw_idf
|
||||
|
||||
# ----------- Config ----------
|
||||
PORT = 3333
|
||||
@@ -26,7 +26,7 @@ INTERFACE = 'eth0'
|
||||
|
||||
def get_my_ip(type):
|
||||
for i in netifaces.ifaddresses(INTERFACE)[type]:
|
||||
return i['addr'].replace("%{}".format(INTERFACE), "")
|
||||
return i['addr'].replace('%{}'.format(INTERFACE), '')
|
||||
|
||||
|
||||
class TcpServer:
|
||||
@@ -44,11 +44,11 @@ class TcpServer:
|
||||
try:
|
||||
self.socket.bind(('', self.port))
|
||||
except socket.error as e:
|
||||
print("Bind failed:{}".format(e))
|
||||
print('Bind failed:{}'.format(e))
|
||||
raise
|
||||
self.socket.listen(1)
|
||||
|
||||
print("Starting server on port={} family_addr={}".format(self.port, self.family_addr))
|
||||
print('Starting server on port={} family_addr={}'.format(self.port, self.family_addr))
|
||||
self.server_thread = Thread(target=self.run_server)
|
||||
self.server_thread.start()
|
||||
return self
|
||||
@@ -68,7 +68,7 @@ class TcpServer:
|
||||
while not self.shutdown.is_set():
|
||||
try:
|
||||
conn, address = self.socket.accept() # accept new connection
|
||||
print("Connection from: {}".format(address))
|
||||
print('Connection from: {}'.format(address))
|
||||
conn.setblocking(1)
|
||||
data = conn.recv(1024)
|
||||
if not data:
|
||||
@@ -79,13 +79,13 @@ class TcpServer:
|
||||
conn.send(reply.encode())
|
||||
conn.close()
|
||||
except socket.error as e:
|
||||
print("Running server failed:{}".format(e))
|
||||
print('Running server failed:{}'.format(e))
|
||||
raise
|
||||
if not self.persist:
|
||||
break
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_socket_tcpclient(env, extra_data):
|
||||
"""
|
||||
steps:
|
||||
@@ -93,39 +93,39 @@ def test_examples_protocol_socket_tcpclient(env, extra_data):
|
||||
2. have the board connect to the server
|
||||
3. send and receive data
|
||||
"""
|
||||
dut1 = env.get_dut("tcp_client", "examples/protocols/sockets/tcp_client", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('tcp_client', 'examples/protocols/sockets/tcp_client', dut_class=ttfw_idf.ESP32DUT)
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, "tcp_client.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'tcp_client.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("tcp_client_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('tcp_client_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
|
||||
# start test
|
||||
dut1.start_app()
|
||||
|
||||
ipv4 = dut1.expect(re.compile(r" IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)"), timeout=30)[0]
|
||||
ipv4 = dut1.expect(re.compile(r' IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)'), timeout=30)[0]
|
||||
ipv6_r = r':'.join((r'[0-9a-fA-F]{4}',) * 8) # expect all 8 octets from IPv6 (assumes it's printed in the long form)
|
||||
ipv6 = dut1.expect(re.compile(r' IPv6 address: ({})'.format(ipv6_r)), timeout=30)[0]
|
||||
print("Connected with IPv4={} and IPv6={}".format(ipv4, ipv6))
|
||||
print('Connected with IPv4={} and IPv6={}'.format(ipv4, ipv6))
|
||||
|
||||
# test IPv4
|
||||
with TcpServer(PORT, socket.AF_INET):
|
||||
server_ip = get_my_ip(netifaces.AF_INET)
|
||||
print("Connect tcp client to server IP={}".format(server_ip))
|
||||
print('Connect tcp client to server IP={}'.format(server_ip))
|
||||
dut1.write(server_ip)
|
||||
dut1.expect(re.compile(r"OK: Message from ESP32"))
|
||||
dut1.expect(re.compile(r'OK: Message from ESP32'))
|
||||
# test IPv6
|
||||
with TcpServer(PORT, socket.AF_INET6):
|
||||
server_ip = get_my_ip(netifaces.AF_INET6)
|
||||
print("Connect tcp client to server IP={}".format(server_ip))
|
||||
print('Connect tcp client to server IP={}'.format(server_ip))
|
||||
dut1.write(server_ip)
|
||||
dut1.expect(re.compile(r"OK: Message from ESP32"))
|
||||
dut1.expect(re.compile(r'OK: Message from ESP32'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if sys.argv[1:] and sys.argv[1].startswith("IPv"): # if additional arguments provided:
|
||||
if sys.argv[1:] and sys.argv[1].startswith('IPv'): # if additional arguments provided:
|
||||
# Usage: example_test.py <IPv4|IPv6>
|
||||
family_addr = socket.AF_INET6 if sys.argv[1] == "IPv6" else socket.AF_INET
|
||||
family_addr = socket.AF_INET6 if sys.argv[1] == 'IPv6' else socket.AF_INET
|
||||
with TcpServer(PORT, family_addr, persist=True) as s:
|
||||
print(input("Press Enter stop the server..."))
|
||||
print(input('Press Enter stop the server...'))
|
||||
else:
|
||||
test_examples_protocol_socket_tcpclient()
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function, unicode_literals
|
||||
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
import socket
|
||||
import ttfw_idf
|
||||
import sys
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
# ----------- Config ----------
|
||||
PORT = 3333
|
||||
@@ -46,28 +46,28 @@ def tcp_client(address, payload):
|
||||
return data.decode()
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_socket_tcpserver(env, extra_data):
|
||||
MESSAGE = "Data to ESP"
|
||||
MESSAGE = 'Data to ESP'
|
||||
"""
|
||||
steps:
|
||||
1. join AP
|
||||
2. have the board connect to the server
|
||||
3. send and receive data
|
||||
"""
|
||||
dut1 = env.get_dut("tcp_client", "examples/protocols/sockets/tcp_server", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('tcp_client', 'examples/protocols/sockets/tcp_server', dut_class=ttfw_idf.ESP32DUT)
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, "tcp_server.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'tcp_server.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("tcp_server_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('tcp_server_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
|
||||
# start test
|
||||
dut1.start_app()
|
||||
|
||||
ipv4 = dut1.expect(re.compile(r" IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)"), timeout=30)[0]
|
||||
ipv4 = dut1.expect(re.compile(r' IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)'), timeout=30)[0]
|
||||
ipv6_r = r':'.join((r'[0-9a-fA-F]{4}',) * 8) # expect all 8 octets from IPv6 (assumes it's printed in the long form)
|
||||
ipv6 = dut1.expect(re.compile(r' IPv6 address: ({})'.format(ipv6_r)), timeout=30)[0]
|
||||
print("Connected with IPv4={} and IPv6={}".format(ipv4, ipv6))
|
||||
print('Connected with IPv4={} and IPv6={}'.format(ipv4, ipv6))
|
||||
|
||||
# test IPv4
|
||||
received = tcp_client(ipv4, MESSAGE)
|
||||
@@ -75,7 +75,7 @@ def test_examples_protocol_socket_tcpserver(env, extra_data):
|
||||
raise
|
||||
dut1.expect(MESSAGE)
|
||||
# test IPv6
|
||||
received = tcp_client("{}%{}".format(ipv6, INTERFACE), MESSAGE)
|
||||
received = tcp_client('{}%{}'.format(ipv6, INTERFACE), MESSAGE)
|
||||
if not received == MESSAGE:
|
||||
raise
|
||||
dut1.expect(MESSAGE)
|
||||
|
||||
@@ -6,17 +6,17 @@
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
from builtins import input
|
||||
from __future__ import print_function, unicode_literals
|
||||
|
||||
import os
|
||||
import re
|
||||
import netifaces
|
||||
import socket
|
||||
from threading import Thread, Event
|
||||
import ttfw_idf
|
||||
import sys
|
||||
from builtins import input
|
||||
from threading import Event, Thread
|
||||
|
||||
import netifaces
|
||||
import ttfw_idf
|
||||
|
||||
# ----------- Config ----------
|
||||
PORT = 3333
|
||||
@@ -26,7 +26,7 @@ INTERFACE = 'eth0'
|
||||
|
||||
def get_my_ip(type):
|
||||
for i in netifaces.ifaddresses(INTERFACE)[type]:
|
||||
return i['addr'].replace("%{}".format(INTERFACE), "")
|
||||
return i['addr'].replace('%{}'.format(INTERFACE), '')
|
||||
|
||||
|
||||
class UdpServer:
|
||||
@@ -44,10 +44,10 @@ class UdpServer:
|
||||
try:
|
||||
self.socket.bind(('', self.port))
|
||||
except socket.error as e:
|
||||
print("Bind failed:{}".format(e))
|
||||
print('Bind failed:{}'.format(e))
|
||||
raise
|
||||
|
||||
print("Starting server on port={} family_addr={}".format(self.port, self.family_addr))
|
||||
print('Starting server on port={} family_addr={}'.format(self.port, self.family_addr))
|
||||
self.server_thread = Thread(target=self.run_server)
|
||||
self.server_thread.start()
|
||||
return self
|
||||
@@ -72,13 +72,13 @@ class UdpServer:
|
||||
reply = 'OK: ' + data
|
||||
self.socket.sendto(reply.encode(), addr)
|
||||
except socket.error as e:
|
||||
print("Running server failed:{}".format(e))
|
||||
print('Running server failed:{}'.format(e))
|
||||
raise
|
||||
if not self.persist:
|
||||
break
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_socket_udpclient(env, extra_data):
|
||||
"""
|
||||
steps:
|
||||
@@ -86,39 +86,39 @@ def test_examples_protocol_socket_udpclient(env, extra_data):
|
||||
2. have the board connect to the server
|
||||
3. send and receive data
|
||||
"""
|
||||
dut1 = env.get_dut("udp_client", "examples/protocols/sockets/udp_client", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('udp_client', 'examples/protocols/sockets/udp_client', dut_class=ttfw_idf.ESP32DUT)
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, "udp_client.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'udp_client.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("udp_client_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('udp_client_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
|
||||
# start test
|
||||
dut1.start_app()
|
||||
|
||||
ipv4 = dut1.expect(re.compile(r" IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)"), timeout=30)[0]
|
||||
ipv4 = dut1.expect(re.compile(r' IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)'), timeout=30)[0]
|
||||
ipv6_r = r':'.join((r'[0-9a-fA-F]{4}',) * 8) # expect all 8 octets from IPv6 (assumes it's printed in the long form)
|
||||
ipv6 = dut1.expect(re.compile(r' IPv6 address: ({})'.format(ipv6_r)), timeout=30)[0]
|
||||
print("Connected with IPv4={} and IPv6={}".format(ipv4, ipv6))
|
||||
print('Connected with IPv4={} and IPv6={}'.format(ipv4, ipv6))
|
||||
|
||||
# test IPv4
|
||||
with UdpServer(PORT, socket.AF_INET):
|
||||
server_ip = get_my_ip(netifaces.AF_INET)
|
||||
print("Connect udp client to server IP={}".format(server_ip))
|
||||
print('Connect udp client to server IP={}'.format(server_ip))
|
||||
dut1.write(server_ip)
|
||||
dut1.expect(re.compile(r"OK: Message from ESP32"))
|
||||
dut1.expect(re.compile(r'OK: Message from ESP32'))
|
||||
# test IPv6
|
||||
with UdpServer(PORT, socket.AF_INET6):
|
||||
server_ip = get_my_ip(netifaces.AF_INET6)
|
||||
print("Connect udp client to server IP={}".format(server_ip))
|
||||
print('Connect udp client to server IP={}'.format(server_ip))
|
||||
dut1.write(server_ip)
|
||||
dut1.expect(re.compile(r"OK: Message from ESP32"))
|
||||
dut1.expect(re.compile(r'OK: Message from ESP32'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if sys.argv[1:] and sys.argv[1].startswith("IPv"): # if additional arguments provided:
|
||||
if sys.argv[1:] and sys.argv[1].startswith('IPv'): # if additional arguments provided:
|
||||
# Usage: example_test.py <IPv4|IPv6>
|
||||
family_addr = socket.AF_INET6 if sys.argv[1] == "IPv6" else socket.AF_INET
|
||||
family_addr = socket.AF_INET6 if sys.argv[1] == 'IPv6' else socket.AF_INET
|
||||
with UdpServer(PORT, family_addr, persist=True) as s:
|
||||
print(input("Press Enter stop the server..."))
|
||||
print(input('Press Enter stop the server...'))
|
||||
else:
|
||||
test_examples_protocol_socket_udpclient()
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
from __future__ import print_function, unicode_literals
|
||||
|
||||
import os
|
||||
import sys
|
||||
import re
|
||||
import socket
|
||||
import ttfw_idf
|
||||
import sys
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
# ----------- Config ----------
|
||||
PORT = 3333
|
||||
@@ -44,28 +44,28 @@ def udp_client(address, payload):
|
||||
return reply.decode()
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_socket_udpserver(env, extra_data):
|
||||
MESSAGE = "Data to ESP"
|
||||
MESSAGE = 'Data to ESP'
|
||||
"""
|
||||
steps:
|
||||
1. join AP
|
||||
2. have the board connect to the server
|
||||
3. send and receive data
|
||||
"""
|
||||
dut1 = env.get_dut("udp_server", "examples/protocols/sockets/udp_server", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('udp_server', 'examples/protocols/sockets/udp_server', dut_class=ttfw_idf.ESP32DUT)
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, "udp_server.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'udp_server.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("udp_server_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('udp_server_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
|
||||
# start test
|
||||
dut1.start_app()
|
||||
|
||||
ipv4 = dut1.expect(re.compile(r" IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)"), timeout=30)[0]
|
||||
ipv4 = dut1.expect(re.compile(r' IPv4 address: ([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)'), timeout=30)[0]
|
||||
ipv6_r = r':'.join((r'[0-9a-fA-F]{4}',) * 8) # expect all 8 octets from IPv6 (assumes it's printed in the long form)
|
||||
ipv6 = dut1.expect(re.compile(r' IPv6 address: ({})'.format(ipv6_r)), timeout=30)[0]
|
||||
print("Connected with IPv4={} and IPv6={}".format(ipv4, ipv6))
|
||||
print('Connected with IPv4={} and IPv6={}'.format(ipv4, ipv6))
|
||||
|
||||
# test IPv4
|
||||
received = udp_client(ipv4, MESSAGE)
|
||||
@@ -73,7 +73,7 @@ def test_examples_protocol_socket_udpserver(env, extra_data):
|
||||
raise
|
||||
dut1.expect(MESSAGE)
|
||||
# test IPv6
|
||||
received = udp_client("{}%{}".format(ipv6, INTERFACE), MESSAGE)
|
||||
received = udp_client('{}%{}'.format(ipv6, INTERFACE), MESSAGE)
|
||||
if not received == MESSAGE:
|
||||
raise
|
||||
dut1.expect(MESSAGE)
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
import re
|
||||
from __future__ import print_function, unicode_literals
|
||||
|
||||
import os
|
||||
import socket
|
||||
import random
|
||||
import re
|
||||
import socket
|
||||
import string
|
||||
from threading import Event, Thread
|
||||
|
||||
import ttfw_idf
|
||||
from SimpleWebSocketServer import SimpleWebSocketServer, WebSocket
|
||||
from tiny_test_fw import Utility
|
||||
from threading import Thread, Event
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
def get_my_ip():
|
||||
@@ -66,15 +67,15 @@ class Websocket(object):
|
||||
|
||||
|
||||
def test_echo(dut):
|
||||
dut.expect("WEBSOCKET_EVENT_CONNECTED")
|
||||
dut.expect('WEBSOCKET_EVENT_CONNECTED')
|
||||
for i in range(0, 10):
|
||||
dut.expect(re.compile(r"Received=hello (\d)"), timeout=30)
|
||||
print("All echos received")
|
||||
dut.expect(re.compile(r'Received=hello (\d)'), timeout=30)
|
||||
print('All echos received')
|
||||
|
||||
|
||||
def test_close(dut):
|
||||
code = dut.expect(re.compile(r"WEBSOCKET: Received closed message with code=(\d*)"), timeout=60)[0]
|
||||
print("Received close frame with code {}".format(code))
|
||||
code = dut.expect(re.compile(r'WEBSOCKET: Received closed message with code=(\d*)'), timeout=60)[0]
|
||||
print('Received close frame with code {}'.format(code))
|
||||
|
||||
|
||||
def test_recv_long_msg(dut, websocket, msg_len, repeats):
|
||||
@@ -86,17 +87,17 @@ def test_recv_long_msg(dut, websocket, msg_len, repeats):
|
||||
recv_msg = ''
|
||||
while len(recv_msg) < msg_len:
|
||||
# Filter out color encoding
|
||||
match = dut.expect(re.compile(r"Received=([a-zA-Z0-9]*).*\n"), timeout=30)[0]
|
||||
match = dut.expect(re.compile(r'Received=([a-zA-Z0-9]*).*\n'), timeout=30)[0]
|
||||
recv_msg += match
|
||||
|
||||
if recv_msg == send_msg:
|
||||
print("Sent message and received message are equal")
|
||||
print('Sent message and received message are equal')
|
||||
else:
|
||||
raise ValueError("DUT received string do not match sent string, \nexpected: {}\nwith length {}\
|
||||
\nreceived: {}\nwith length {}".format(send_msg, len(send_msg), recv_msg, len(recv_msg)))
|
||||
raise ValueError('DUT received string do not match sent string, \nexpected: {}\nwith length {}\
|
||||
\nreceived: {}\nwith length {}'.format(send_msg, len(send_msg), recv_msg, len(recv_msg)))
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_websocket(env, extra_data):
|
||||
"""
|
||||
steps:
|
||||
@@ -104,17 +105,17 @@ def test_examples_protocol_websocket(env, extra_data):
|
||||
2. connect to uri specified in the config
|
||||
3. send and receive data
|
||||
"""
|
||||
dut1 = env.get_dut("websocket", "examples/protocols/websocket", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('websocket', 'examples/protocols/websocket', dut_class=ttfw_idf.ESP32DUT)
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, "websocket-example.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'websocket-example.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("websocket_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('websocket_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
|
||||
try:
|
||||
if "CONFIG_WEBSOCKET_URI_FROM_STDIN" in dut1.app.get_sdkconfig():
|
||||
if 'CONFIG_WEBSOCKET_URI_FROM_STDIN' in dut1.app.get_sdkconfig():
|
||||
uri_from_stdin = True
|
||||
else:
|
||||
uri = dut1.app.get_sdkconfig()["CONFIG_WEBSOCKET_URI"].strip('"')
|
||||
uri = dut1.app.get_sdkconfig()['CONFIG_WEBSOCKET_URI'].strip('"')
|
||||
uri_from_stdin = False
|
||||
|
||||
except Exception:
|
||||
@@ -127,9 +128,9 @@ def test_examples_protocol_websocket(env, extra_data):
|
||||
if uri_from_stdin:
|
||||
server_port = 4455
|
||||
with Websocket(server_port) as ws:
|
||||
uri = "ws://{}:{}".format(get_my_ip(), server_port)
|
||||
print("DUT connecting to {}".format(uri))
|
||||
dut1.expect("Please enter uri of websocket endpoint", timeout=30)
|
||||
uri = 'ws://{}:{}'.format(get_my_ip(), server_port)
|
||||
print('DUT connecting to {}'.format(uri))
|
||||
dut1.expect('Please enter uri of websocket endpoint', timeout=30)
|
||||
dut1.write(uri)
|
||||
test_echo(dut1)
|
||||
# Message length should exceed DUT's buffer size to test fragmentation, default is 1024 byte
|
||||
@@ -137,7 +138,7 @@ def test_examples_protocol_websocket(env, extra_data):
|
||||
test_close(dut1)
|
||||
|
||||
else:
|
||||
print("DUT connecting to {}".format(uri))
|
||||
print('DUT connecting to {}'.format(uri))
|
||||
test_echo(dut1)
|
||||
|
||||
|
||||
|
||||
@@ -15,73 +15,74 @@
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import print_function
|
||||
import re
|
||||
import os
|
||||
|
||||
import ttfw_idf
|
||||
import os
|
||||
import re
|
||||
|
||||
import esp_prov
|
||||
import ttfw_idf
|
||||
|
||||
# Have esp_prov throw exception
|
||||
esp_prov.config_throw_except = True
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI_BT")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI_BT')
|
||||
def test_examples_provisioning_ble(env, extra_data):
|
||||
# Acquire DUT
|
||||
dut1 = env.get_dut("ble_prov", "examples/provisioning/legacy/ble_prov", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('ble_prov', 'examples/provisioning/legacy/ble_prov', dut_class=ttfw_idf.ESP32DUT)
|
||||
|
||||
# Get binary file
|
||||
binary_file = os.path.join(dut1.app.binary_path, "ble_prov.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'ble_prov.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("ble_prov_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('ble_prov_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
|
||||
# Upload binary and start testing
|
||||
dut1.start_app()
|
||||
|
||||
# Parse BLE devname
|
||||
devname = dut1.expect(re.compile(r"Provisioning started with BLE devname : '(PROV_\S\S\S\S\S\S)'"), timeout=60)[0]
|
||||
print("BLE Device Alias for DUT :", devname)
|
||||
print('BLE Device Alias for DUT :', devname)
|
||||
|
||||
# Match additional headers sent in the request
|
||||
dut1.expect("BLE Provisioning started", timeout=30)
|
||||
dut1.expect('BLE Provisioning started', timeout=30)
|
||||
|
||||
print("Starting Provisioning")
|
||||
print('Starting Provisioning')
|
||||
verbose = False
|
||||
protover = "V0.1"
|
||||
protover = 'V0.1'
|
||||
secver = 1
|
||||
pop = "abcd1234"
|
||||
provmode = "ble"
|
||||
ap_ssid = "myssid"
|
||||
ap_password = "mypassword"
|
||||
pop = 'abcd1234'
|
||||
provmode = 'ble'
|
||||
ap_ssid = 'myssid'
|
||||
ap_password = 'mypassword'
|
||||
|
||||
print("Getting security")
|
||||
print('Getting security')
|
||||
security = esp_prov.get_security(secver, pop, verbose)
|
||||
if security is None:
|
||||
raise RuntimeError("Failed to get security")
|
||||
raise RuntimeError('Failed to get security')
|
||||
|
||||
print("Getting transport")
|
||||
print('Getting transport')
|
||||
transport = esp_prov.get_transport(provmode, devname)
|
||||
if transport is None:
|
||||
raise RuntimeError("Failed to get transport")
|
||||
raise RuntimeError('Failed to get transport')
|
||||
|
||||
print("Verifying protocol version")
|
||||
print('Verifying protocol version')
|
||||
if not esp_prov.version_match(transport, protover):
|
||||
raise RuntimeError("Mismatch in protocol version")
|
||||
raise RuntimeError('Mismatch in protocol version')
|
||||
|
||||
print("Starting Session")
|
||||
print('Starting Session')
|
||||
if not esp_prov.establish_session(transport, security):
|
||||
raise RuntimeError("Failed to start session")
|
||||
raise RuntimeError('Failed to start session')
|
||||
|
||||
print("Sending Wifi credential to DUT")
|
||||
print('Sending Wifi credential to DUT')
|
||||
if not esp_prov.send_wifi_config(transport, security, ap_ssid, ap_password):
|
||||
raise RuntimeError("Failed to send Wi-Fi config")
|
||||
raise RuntimeError('Failed to send Wi-Fi config')
|
||||
|
||||
print("Applying config")
|
||||
print('Applying config')
|
||||
if not esp_prov.apply_wifi_config(transport, security):
|
||||
raise RuntimeError("Failed to send apply config")
|
||||
raise RuntimeError('Failed to send apply config')
|
||||
|
||||
if not esp_prov.wait_wifi_connected(transport, security):
|
||||
raise RuntimeError("Provisioning failed")
|
||||
raise RuntimeError('Provisioning failed')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -2,12 +2,14 @@
|
||||
# source: custom_config.proto
|
||||
|
||||
import sys
|
||||
|
||||
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
|
||||
from google.protobuf.internal import enum_type_wrapper
|
||||
from google.protobuf import descriptor as _descriptor
|
||||
from google.protobuf import message as _message
|
||||
from google.protobuf import reflection as _reflection
|
||||
from google.protobuf import symbol_database as _symbol_database
|
||||
from google.protobuf.internal import enum_type_wrapper
|
||||
|
||||
# @@protoc_insertion_point(imports)
|
||||
|
||||
_sym_db = _symbol_database.Default()
|
||||
@@ -61,7 +63,7 @@ _CUSTOMCONFIGREQUEST = _descriptor.Descriptor(
|
||||
_descriptor.FieldDescriptor(
|
||||
name='info', full_name='CustomConfigRequest.info', index=0,
|
||||
number=1, type=9, cpp_type=9, label=1,
|
||||
has_default_value=False, default_value=_b("").decode('utf-8'),
|
||||
has_default_value=False, default_value=_b('').decode('utf-8'),
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
|
||||
@@ -15,88 +15,89 @@
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import print_function
|
||||
import re
|
||||
import os
|
||||
|
||||
import ttfw_idf
|
||||
import os
|
||||
import re
|
||||
|
||||
import esp_prov
|
||||
import ttfw_idf
|
||||
import wifi_tools
|
||||
|
||||
# Have esp_prov throw exception
|
||||
esp_prov.config_throw_except = True
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI_BT")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI_BT')
|
||||
def test_examples_provisioning_softap(env, extra_data):
|
||||
# Acquire DUT
|
||||
dut1 = env.get_dut("softap_prov", "examples/provisioning/legacy/softap_prov", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('softap_prov', 'examples/provisioning/legacy/softap_prov', dut_class=ttfw_idf.ESP32DUT)
|
||||
|
||||
# Get binary file
|
||||
binary_file = os.path.join(dut1.app.binary_path, "softap_prov.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'softap_prov.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("softap_prov_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('softap_prov_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
|
||||
# Upload binary and start testing
|
||||
dut1.start_app()
|
||||
|
||||
# Parse IP address of STA
|
||||
dut1.expect("Starting WiFi SoftAP provisioning", timeout=60)
|
||||
dut1.expect('Starting WiFi SoftAP provisioning', timeout=60)
|
||||
[ssid, password] = dut1.expect(re.compile(r"SoftAP Provisioning started with SSID '(\S+)', Password '(\S+)'"), timeout=30)
|
||||
|
||||
iface = wifi_tools.get_wiface_name()
|
||||
if iface is None:
|
||||
raise RuntimeError("Failed to get Wi-Fi interface on host")
|
||||
print("Interface name : " + iface)
|
||||
print("SoftAP SSID : " + ssid)
|
||||
print("SoftAP Password : " + password)
|
||||
raise RuntimeError('Failed to get Wi-Fi interface on host')
|
||||
print('Interface name : ' + iface)
|
||||
print('SoftAP SSID : ' + ssid)
|
||||
print('SoftAP Password : ' + password)
|
||||
|
||||
try:
|
||||
ctrl = wifi_tools.wpa_cli(iface, reset_on_exit=True)
|
||||
print("Connecting to DUT SoftAP...")
|
||||
print('Connecting to DUT SoftAP...')
|
||||
ip = ctrl.connect(ssid, password)
|
||||
got_ip = dut1.expect(re.compile(r"DHCP server assigned IP to a station, IP is: (\d+.\d+.\d+.\d+)"), timeout=60)[0]
|
||||
got_ip = dut1.expect(re.compile(r'DHCP server assigned IP to a station, IP is: (\d+.\d+.\d+.\d+)'), timeout=60)[0]
|
||||
if ip != got_ip:
|
||||
raise RuntimeError("SoftAP connected to another host! " + ip + "!=" + got_ip)
|
||||
print("Connected to DUT SoftAP")
|
||||
raise RuntimeError('SoftAP connected to another host! ' + ip + '!=' + got_ip)
|
||||
print('Connected to DUT SoftAP')
|
||||
|
||||
print("Starting Provisioning")
|
||||
print('Starting Provisioning')
|
||||
verbose = False
|
||||
protover = "V0.1"
|
||||
protover = 'V0.1'
|
||||
secver = 1
|
||||
pop = "abcd1234"
|
||||
provmode = "softap"
|
||||
ap_ssid = "myssid"
|
||||
ap_password = "mypassword"
|
||||
softap_endpoint = ip.split('.')[0] + "." + ip.split('.')[1] + "." + ip.split('.')[2] + ".1:80"
|
||||
pop = 'abcd1234'
|
||||
provmode = 'softap'
|
||||
ap_ssid = 'myssid'
|
||||
ap_password = 'mypassword'
|
||||
softap_endpoint = ip.split('.')[0] + '.' + ip.split('.')[1] + '.' + ip.split('.')[2] + '.1:80'
|
||||
|
||||
print("Getting security")
|
||||
print('Getting security')
|
||||
security = esp_prov.get_security(secver, pop, verbose)
|
||||
if security is None:
|
||||
raise RuntimeError("Failed to get security")
|
||||
raise RuntimeError('Failed to get security')
|
||||
|
||||
print("Getting transport")
|
||||
print('Getting transport')
|
||||
transport = esp_prov.get_transport(provmode, softap_endpoint)
|
||||
if transport is None:
|
||||
raise RuntimeError("Failed to get transport")
|
||||
raise RuntimeError('Failed to get transport')
|
||||
|
||||
print("Verifying protocol version")
|
||||
print('Verifying protocol version')
|
||||
if not esp_prov.version_match(transport, protover):
|
||||
raise RuntimeError("Mismatch in protocol version")
|
||||
raise RuntimeError('Mismatch in protocol version')
|
||||
|
||||
print("Starting Session")
|
||||
print('Starting Session')
|
||||
if not esp_prov.establish_session(transport, security):
|
||||
raise RuntimeError("Failed to start session")
|
||||
raise RuntimeError('Failed to start session')
|
||||
|
||||
print("Sending Wifi credential to DUT")
|
||||
print('Sending Wifi credential to DUT')
|
||||
if not esp_prov.send_wifi_config(transport, security, ap_ssid, ap_password):
|
||||
raise RuntimeError("Failed to send Wi-Fi config")
|
||||
raise RuntimeError('Failed to send Wi-Fi config')
|
||||
|
||||
print("Applying config")
|
||||
print('Applying config')
|
||||
if not esp_prov.apply_wifi_config(transport, security):
|
||||
raise RuntimeError("Failed to send apply config")
|
||||
raise RuntimeError('Failed to send apply config')
|
||||
|
||||
if not esp_prov.wait_wifi_connected(transport, security):
|
||||
raise RuntimeError("Provisioning failed")
|
||||
raise RuntimeError('Provisioning failed')
|
||||
finally:
|
||||
ctrl.reset()
|
||||
|
||||
|
||||
@@ -15,84 +15,85 @@
|
||||
# limitations under the License.
|
||||
|
||||
from __future__ import print_function
|
||||
import re
|
||||
import os
|
||||
|
||||
import ttfw_idf
|
||||
import os
|
||||
import re
|
||||
|
||||
import esp_prov
|
||||
import ttfw_idf
|
||||
|
||||
# Have esp_prov throw exception
|
||||
esp_prov.config_throw_except = True
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI_BT")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI_BT')
|
||||
def test_examples_wifi_prov_mgr(env, extra_data):
|
||||
# Acquire DUT
|
||||
dut1 = env.get_dut("wifi_prov_mgr", "examples/provisioning/wifi_prov_mgr", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('wifi_prov_mgr', 'examples/provisioning/wifi_prov_mgr', dut_class=ttfw_idf.ESP32DUT)
|
||||
|
||||
# Get binary file
|
||||
binary_file = os.path.join(dut1.app.binary_path, "wifi_prov_mgr.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'wifi_prov_mgr.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("wifi_prov_mgr_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('wifi_prov_mgr_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
|
||||
# Upload binary and start testing
|
||||
dut1.start_app()
|
||||
|
||||
# Check if BT memory is released before provisioning starts
|
||||
dut1.expect("wifi_prov_scheme_ble: BT memory released", timeout=60)
|
||||
dut1.expect('wifi_prov_scheme_ble: BT memory released', timeout=60)
|
||||
|
||||
# Parse BLE devname
|
||||
devname = dut1.expect(re.compile(r"Provisioning started with service name : (PROV_\S\S\S\S\S\S)"), timeout=30)[0]
|
||||
print("BLE Device Alias for DUT :", devname)
|
||||
devname = dut1.expect(re.compile(r'Provisioning started with service name : (PROV_\S\S\S\S\S\S)'), timeout=30)[0]
|
||||
print('BLE Device Alias for DUT :', devname)
|
||||
|
||||
print("Starting Provisioning")
|
||||
print('Starting Provisioning')
|
||||
verbose = False
|
||||
protover = "v1.1"
|
||||
protover = 'v1.1'
|
||||
secver = 1
|
||||
pop = "abcd1234"
|
||||
provmode = "ble"
|
||||
ap_ssid = "myssid"
|
||||
ap_password = "mypassword"
|
||||
pop = 'abcd1234'
|
||||
provmode = 'ble'
|
||||
ap_ssid = 'myssid'
|
||||
ap_password = 'mypassword'
|
||||
|
||||
print("Getting security")
|
||||
print('Getting security')
|
||||
security = esp_prov.get_security(secver, pop, verbose)
|
||||
if security is None:
|
||||
raise RuntimeError("Failed to get security")
|
||||
raise RuntimeError('Failed to get security')
|
||||
|
||||
print("Getting transport")
|
||||
print('Getting transport')
|
||||
transport = esp_prov.get_transport(provmode, devname)
|
||||
if transport is None:
|
||||
raise RuntimeError("Failed to get transport")
|
||||
raise RuntimeError('Failed to get transport')
|
||||
|
||||
print("Verifying protocol version")
|
||||
print('Verifying protocol version')
|
||||
if not esp_prov.version_match(transport, protover):
|
||||
raise RuntimeError("Mismatch in protocol version")
|
||||
raise RuntimeError('Mismatch in protocol version')
|
||||
|
||||
print("Verifying scan list capability")
|
||||
print('Verifying scan list capability')
|
||||
if not esp_prov.has_capability(transport, 'wifi_scan'):
|
||||
raise RuntimeError("Capability not present")
|
||||
raise RuntimeError('Capability not present')
|
||||
|
||||
print("Starting Session")
|
||||
print('Starting Session')
|
||||
if not esp_prov.establish_session(transport, security):
|
||||
raise RuntimeError("Failed to start session")
|
||||
raise RuntimeError('Failed to start session')
|
||||
|
||||
print("Sending Custom Data")
|
||||
if not esp_prov.custom_data(transport, security, "My Custom Data"):
|
||||
raise RuntimeError("Failed to send custom data")
|
||||
print('Sending Custom Data')
|
||||
if not esp_prov.custom_data(transport, security, 'My Custom Data'):
|
||||
raise RuntimeError('Failed to send custom data')
|
||||
|
||||
print("Sending Wifi credential to DUT")
|
||||
print('Sending Wifi credential to DUT')
|
||||
if not esp_prov.send_wifi_config(transport, security, ap_ssid, ap_password):
|
||||
raise RuntimeError("Failed to send Wi-Fi config")
|
||||
raise RuntimeError('Failed to send Wi-Fi config')
|
||||
|
||||
print("Applying config")
|
||||
print('Applying config')
|
||||
if not esp_prov.apply_wifi_config(transport, security):
|
||||
raise RuntimeError("Failed to send apply config")
|
||||
raise RuntimeError('Failed to send apply config')
|
||||
|
||||
if not esp_prov.wait_wifi_connected(transport, security):
|
||||
raise RuntimeError("Provisioning failed")
|
||||
raise RuntimeError('Provisioning failed')
|
||||
|
||||
# Check if BTDM memory is released after provisioning finishes
|
||||
dut1.expect("wifi_prov_scheme_ble: BTDM memory released", timeout=30)
|
||||
dut1.expect('wifi_prov_scheme_ble: BTDM memory released', timeout=30)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import binascii
|
||||
from io import BytesIO
|
||||
from collections import namedtuple
|
||||
import os
|
||||
import sys
|
||||
from collections import namedtuple
|
||||
from io import BytesIO
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
try:
|
||||
import espsecure
|
||||
except ImportError:
|
||||
idf_path = os.getenv("IDF_PATH")
|
||||
idf_path = os.getenv('IDF_PATH')
|
||||
if not idf_path or not os.path.exists(idf_path):
|
||||
raise
|
||||
sys.path.insert(0, os.path.join(idf_path, "components", "esptool_py", "esptool"))
|
||||
sys.path.insert(0, os.path.join(idf_path, 'components', 'esptool_py', 'esptool'))
|
||||
import espsecure
|
||||
|
||||
|
||||
@@ -30,7 +32,7 @@ def test_examples_security_flash_encryption(env, extra_data):
|
||||
dut.start_app()
|
||||
|
||||
# calculate the expected ciphertext
|
||||
flash_addr = dut.app.partition_table["storage"]["offset"]
|
||||
flash_addr = dut.app.partition_table['storage']['offset']
|
||||
plain_hex_str = '00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f'
|
||||
plain_data = binascii.unhexlify(plain_hex_str.replace(' ', ''))
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
from tiny_test_fw import Utility
|
||||
import random
|
||||
import re
|
||||
import time
|
||||
|
||||
import ttfw_idf
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_GENERIC')
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from tiny_test_fw import Utility
|
||||
import ttfw_idf
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
try:
|
||||
from itertools import izip_longest as zip_longest
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from tiny_test_fw import Utility
|
||||
import ttfw_idf
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
try:
|
||||
from itertools import izip_longest as zip_longest
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import re
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
@@ -12,23 +13,23 @@ def test_examples_parttool(env, extra_data):
|
||||
dut.start_app(False)
|
||||
|
||||
# Verify factory firmware
|
||||
dut.expect("Partitions Tool Example")
|
||||
dut.expect("Example end")
|
||||
dut.expect('Partitions Tool Example')
|
||||
dut.expect('Example end')
|
||||
|
||||
# Close connection to DUT
|
||||
dut.receive_thread.exit()
|
||||
dut.port_inst.close()
|
||||
|
||||
# Run the example python script
|
||||
script_path = os.path.join(os.getenv("IDF_PATH"), "examples", "storage", "parttool", "parttool_example.py")
|
||||
script_path = os.path.join(os.getenv('IDF_PATH'), 'examples', 'storage', 'parttool', 'parttool_example.py')
|
||||
|
||||
binary_path = ""
|
||||
binary_path = ''
|
||||
for flash_file in dut.app.flash_files:
|
||||
if "parttool.bin" in flash_file[1]:
|
||||
if 'parttool.bin' in flash_file[1]:
|
||||
binary_path = flash_file[1]
|
||||
break
|
||||
|
||||
subprocess.check_call([sys.executable, script_path, "--binary", binary_path, "--port", dut.port])
|
||||
subprocess.check_call([sys.executable, script_path, '--binary', binary_path, '--port', dut.port])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -16,16 +16,16 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
PARTITION_TABLE_DIR = os.path.join("components", "partition_table", "")
|
||||
PARTITION_TABLE_DIR = os.path.join('components', 'partition_table', '')
|
||||
|
||||
|
||||
def assert_file_same(file1, file2, err):
|
||||
with open(file1, "rb") as f1:
|
||||
with open(file2, "rb") as f2:
|
||||
with open(file1, 'rb') as f1:
|
||||
with open(file2, 'rb') as f2:
|
||||
f1 = f1.read()
|
||||
f2 = f2.read()
|
||||
|
||||
@@ -39,17 +39,17 @@ def assert_file_same(file1, file2, err):
|
||||
|
||||
|
||||
def main():
|
||||
COMPONENTS_PATH = os.path.expandvars(os.path.join("$IDF_PATH", "components"))
|
||||
PARTTOOL_DIR = os.path.join(COMPONENTS_PATH, "partition_table")
|
||||
COMPONENTS_PATH = os.path.expandvars(os.path.join('$IDF_PATH', 'components'))
|
||||
PARTTOOL_DIR = os.path.join(COMPONENTS_PATH, 'partition_table')
|
||||
|
||||
sys.path.append(PARTTOOL_DIR)
|
||||
from parttool import PartitionName, PartitionType, ParttoolTarget
|
||||
from gen_empty_partition import generate_blanked_file
|
||||
from parttool import PartitionName, PartitionType, ParttoolTarget
|
||||
|
||||
parser = argparse.ArgumentParser("ESP-IDF Partitions Tool Example")
|
||||
parser = argparse.ArgumentParser('ESP-IDF Partitions Tool Example')
|
||||
|
||||
parser.add_argument("--port", "-p", help="port where the device to perform operations on is connected")
|
||||
parser.add_argument("--binary", "-b", help="path to built example binary", default=os.path.join("build", "parttool.bin"))
|
||||
parser.add_argument('--port', '-p', help='port where the device to perform operations on is connected')
|
||||
parser.add_argument('--binary', '-b', help='path to built example binary', default=os.path.join('build', 'parttool.bin'))
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
@@ -57,47 +57,47 @@ def main():
|
||||
|
||||
# Read app partition and save the contents to a file. The app partition is identified
|
||||
# using type-subtype combination
|
||||
print("Checking if device app binary matches built binary")
|
||||
factory = PartitionType("app", "factory")
|
||||
target.read_partition(factory, "app.bin")
|
||||
assert_file_same(args.binary, "app.bin", "Device app binary does not match built binary")
|
||||
print('Checking if device app binary matches built binary')
|
||||
factory = PartitionType('app', 'factory')
|
||||
target.read_partition(factory, 'app.bin')
|
||||
assert_file_same(args.binary, 'app.bin', 'Device app binary does not match built binary')
|
||||
|
||||
# Retrieve info on data storage partition, this time identifying it by name.
|
||||
storage = PartitionName("storage")
|
||||
storage = PartitionName('storage')
|
||||
storage_info = target.get_partition_info(storage)
|
||||
print("Found data partition at offset 0x{:x} with size 0x{:x}".format(storage_info.offset, storage_info.size))
|
||||
print('Found data partition at offset 0x{:x} with size 0x{:x}'.format(storage_info.offset, storage_info.size))
|
||||
|
||||
# Create a file whose contents will be written to the storage partition
|
||||
with open("write.bin", "wb") as f:
|
||||
with open('write.bin', 'wb') as f:
|
||||
# Create a file to write to the data partition with randomly generated content
|
||||
f.write(os.urandom(storage_info.size))
|
||||
|
||||
# Write the contents of the created file to storage partition
|
||||
print("Writing to data partition")
|
||||
target.write_partition(storage, "write.bin")
|
||||
print('Writing to data partition')
|
||||
target.write_partition(storage, 'write.bin')
|
||||
|
||||
# Read back the contents of the storage partition
|
||||
print("Reading data partition")
|
||||
target.read_partition(storage, "read.bin")
|
||||
print('Reading data partition')
|
||||
target.read_partition(storage, 'read.bin')
|
||||
|
||||
assert_file_same("write.bin", "read.bin", "Read contents of storage partition does not match source file contents")
|
||||
assert_file_same('write.bin', 'read.bin', 'Read contents of storage partition does not match source file contents')
|
||||
|
||||
# Erase contents of the storage partition
|
||||
print("Erasing data partition")
|
||||
print('Erasing data partition')
|
||||
target.erase_partition(storage)
|
||||
|
||||
# Read back the erased data partition
|
||||
print("Reading data partition")
|
||||
target.read_partition(storage, "read.bin")
|
||||
print('Reading data partition')
|
||||
target.read_partition(storage, 'read.bin')
|
||||
|
||||
# Generate a file of all 0xFF
|
||||
generate_blanked_file(storage_info.size, "blank.bin")
|
||||
generate_blanked_file(storage_info.size, 'blank.bin')
|
||||
|
||||
assert_file_same("blank.bin", "read.bin", "Contents of storage partition not fully erased")
|
||||
assert_file_same('blank.bin', 'read.bin', 'Contents of storage partition not fully erased')
|
||||
|
||||
# Example end and cleanup
|
||||
print("\nPartition tool operations performed successfully!")
|
||||
clean_files = ["app.bin", "read.bin", "blank.bin", "write.bin"]
|
||||
print('\nPartition tool operations performed successfully!')
|
||||
clean_files = ['app.bin', 'read.bin', 'blank.bin', 'write.bin']
|
||||
for clean_file in clean_files:
|
||||
os.unlink(clean_file)
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from tiny_test_fw import Utility
|
||||
import ttfw_idf
|
||||
import re
|
||||
|
||||
import ttfw_idf
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag='UT_T1_SDMODE')
|
||||
def test_examples_sd_card(env, extra_data):
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from io import open
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
from io import open
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
try:
|
||||
@@ -11,7 +12,7 @@ except ImportError:
|
||||
from itertools import zip_longest
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="test_jtag_arm")
|
||||
@ttfw_idf.idf_example_test(env_tag='test_jtag_arm')
|
||||
def test_examples_semihost_vfs(env, extra_data):
|
||||
|
||||
rel_project_path = os.path.join('examples', 'storage', 'semihost_vfs')
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import re
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from __future__ import print_function
|
||||
import os
|
||||
|
||||
import hashlib
|
||||
import os
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import re
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
import re
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="test_jtag_arm")
|
||||
@ttfw_idf.idf_example_test(env_tag='test_jtag_arm')
|
||||
def test_examples_app_trace_to_host(env, extra_data):
|
||||
rel_project_path = os.path.join('examples', 'system', 'app_trace_to_host')
|
||||
dut = env.get_dut('app_trace_to_host', rel_project_path)
|
||||
@@ -22,7 +24,7 @@ def test_examples_app_trace_to_host(env, extra_data):
|
||||
re.compile(r'example: Collected \d+ samples in 20 ms.'),
|
||||
timeout=20)
|
||||
|
||||
ocd.apptrace_start("file://adc.log 0 9000 5 0 0")
|
||||
ocd.apptrace_start('file://adc.log 0 9000 5 0 0')
|
||||
ocd.apptrace_wait_stop(tmo=30)
|
||||
|
||||
with ttfw_idf.CustomProcess(' '.join([os.path.join(idf_path, 'tools/esp_app_trace/logtrace_proc.py'),
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
import re
|
||||
|
||||
import ttfw_idf
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_GENERIC')
|
||||
|
||||
@@ -6,15 +6,15 @@ import ttfw_idf
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_GENERIC')
|
||||
def test_examples_system_console(env, extra_data):
|
||||
dut = env.get_dut('console_example', 'examples/system/console', app_config_name='history')
|
||||
print("Using binary path: {}".format(dut.app.binary_path))
|
||||
print('Using binary path: {}'.format(dut.app.binary_path))
|
||||
dut.start_app()
|
||||
dut.expect("Command history enabled")
|
||||
dut.expect('Command history enabled')
|
||||
env.close_dut(dut.name)
|
||||
|
||||
dut = env.get_dut('console_example', 'examples/system/console', app_config_name='nohistory')
|
||||
print("Using binary path: {}".format(dut.app.binary_path))
|
||||
print('Using binary path: {}'.format(dut.app.binary_path))
|
||||
dut.start_app()
|
||||
dut.expect("Command history disabled")
|
||||
dut.expect('Command history disabled')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import re
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import re
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
|
||||
@@ -5,80 +5,80 @@ import ttfw_idf
|
||||
# Timer events
|
||||
TIMER_EVENT_LIMIT = 3
|
||||
|
||||
TIMER_EXPIRY_HANDLING = "TIMER_EVENTS:TIMER_EVENT_EXPIRY: timer_expiry_handler, executed {} out of " + str(TIMER_EVENT_LIMIT) + " times"
|
||||
TIMER_EXPIRY_HANDLING = 'TIMER_EVENTS:TIMER_EVENT_EXPIRY: timer_expiry_handler, executed {} out of ' + str(TIMER_EVENT_LIMIT) + ' times'
|
||||
|
||||
# Task events
|
||||
TASK_ITERATION_LIMIT = 5
|
||||
TASK_UNREGISTRATION_LIMIT = 3
|
||||
|
||||
TASK_ITERATION_POST = "TASK_EVENTS:TASK_ITERATION_EVENT: posting to default loop, {} out of " + str(TASK_ITERATION_LIMIT)
|
||||
TASK_ITERATION_HANDLING = "TASK_EVENTS:TASK_ITERATION_EVENT: task_iteration_handler, executed {} times"
|
||||
TASK_ITERATION_POST = 'TASK_EVENTS:TASK_ITERATION_EVENT: posting to default loop, {} out of ' + str(TASK_ITERATION_LIMIT)
|
||||
TASK_ITERATION_HANDLING = 'TASK_EVENTS:TASK_ITERATION_EVENT: task_iteration_handler, executed {} times'
|
||||
|
||||
|
||||
def _test_timer_events(dut):
|
||||
dut.start_app()
|
||||
|
||||
print("Checking timer events posting and handling")
|
||||
print('Checking timer events posting and handling')
|
||||
|
||||
dut.expect("setting up")
|
||||
dut.expect("starting event sources")
|
||||
dut.expect('setting up')
|
||||
dut.expect('starting event sources')
|
||||
|
||||
print("Finished setup")
|
||||
print('Finished setup')
|
||||
|
||||
dut.expect("TIMER_EVENTS:TIMER_EVENT_STARTED: posting to default loop")
|
||||
print("Posted timer started event")
|
||||
dut.expect("TIMER_EVENTS:TIMER_EVENT_STARTED: timer_started_handler, instance 0")
|
||||
dut.expect("TIMER_EVENTS:TIMER_EVENT_STARTED: timer_started_handler, instance 1")
|
||||
dut.expect("TIMER_EVENTS:TIMER_EVENT_STARTED: timer_started_handler_2")
|
||||
dut.expect("TIMER_EVENTS:TIMER_EVENT_STARTED: timer_any_handler")
|
||||
dut.expect("TIMER_EVENTS:TIMER_EVENT_STARTED: all_event_handler")
|
||||
print("Handled timer started event")
|
||||
dut.expect('TIMER_EVENTS:TIMER_EVENT_STARTED: posting to default loop')
|
||||
print('Posted timer started event')
|
||||
dut.expect('TIMER_EVENTS:TIMER_EVENT_STARTED: timer_started_handler, instance 0')
|
||||
dut.expect('TIMER_EVENTS:TIMER_EVENT_STARTED: timer_started_handler, instance 1')
|
||||
dut.expect('TIMER_EVENTS:TIMER_EVENT_STARTED: timer_started_handler_2')
|
||||
dut.expect('TIMER_EVENTS:TIMER_EVENT_STARTED: timer_any_handler')
|
||||
dut.expect('TIMER_EVENTS:TIMER_EVENT_STARTED: all_event_handler')
|
||||
print('Handled timer started event')
|
||||
|
||||
for expiries in range(1, TIMER_EVENT_LIMIT + 1):
|
||||
dut.expect("TIMER_EVENTS:TIMER_EVENT_EXPIRY: posting to default loop")
|
||||
print("Posted timer expiry event {} out of {}".format(expiries, TIMER_EVENT_LIMIT))
|
||||
dut.expect('TIMER_EVENTS:TIMER_EVENT_EXPIRY: posting to default loop')
|
||||
print('Posted timer expiry event {} out of {}'.format(expiries, TIMER_EVENT_LIMIT))
|
||||
|
||||
if expiries >= TIMER_EVENT_LIMIT:
|
||||
dut.expect("TIMER_EVENTS:TIMER_EVENT_STOPPED: posting to default loop")
|
||||
print("Posted timer stopped event")
|
||||
dut.expect('TIMER_EVENTS:TIMER_EVENT_STOPPED: posting to default loop')
|
||||
print('Posted timer stopped event')
|
||||
|
||||
dut.expect(TIMER_EXPIRY_HANDLING.format(expiries))
|
||||
dut.expect("TIMER_EVENTS:TIMER_EVENT_EXPIRY: timer_any_handler")
|
||||
dut.expect("TIMER_EVENTS:TIMER_EVENT_EXPIRY: all_event_handler")
|
||||
dut.expect('TIMER_EVENTS:TIMER_EVENT_EXPIRY: timer_any_handler')
|
||||
dut.expect('TIMER_EVENTS:TIMER_EVENT_EXPIRY: all_event_handler')
|
||||
|
||||
print("Handled timer expiry event {} out of {}".format(expiries, TIMER_EVENT_LIMIT))
|
||||
print('Handled timer expiry event {} out of {}'.format(expiries, TIMER_EVENT_LIMIT))
|
||||
|
||||
dut.expect("TIMER_EVENTS:TIMER_EVENT_STOPPED: timer_stopped_handler")
|
||||
dut.expect("TIMER_EVENTS:TIMER_EVENT_STOPPED: deleted timer event source")
|
||||
print("Handled timer stopped event")
|
||||
dut.expect('TIMER_EVENTS:TIMER_EVENT_STOPPED: timer_stopped_handler')
|
||||
dut.expect('TIMER_EVENTS:TIMER_EVENT_STOPPED: deleted timer event source')
|
||||
print('Handled timer stopped event')
|
||||
|
||||
|
||||
def _test_iteration_events(dut):
|
||||
dut.start_app()
|
||||
|
||||
print("Checking iteration events posting and handling")
|
||||
dut.expect("setting up")
|
||||
dut.expect("starting event sources")
|
||||
print("Finished setup")
|
||||
print('Checking iteration events posting and handling')
|
||||
dut.expect('setting up')
|
||||
dut.expect('starting event sources')
|
||||
print('Finished setup')
|
||||
|
||||
for iteration in range(1, TASK_ITERATION_LIMIT + 1):
|
||||
dut.expect(TASK_ITERATION_POST.format(iteration))
|
||||
print("Posted iteration {} out of {}".format(iteration, TASK_ITERATION_LIMIT))
|
||||
print('Posted iteration {} out of {}'.format(iteration, TASK_ITERATION_LIMIT))
|
||||
|
||||
if iteration < TASK_UNREGISTRATION_LIMIT:
|
||||
dut.expect(TASK_ITERATION_HANDLING.format(iteration))
|
||||
dut.expect("TASK_EVENTS:TASK_ITERATION_EVENT: all_event_handler")
|
||||
dut.expect('TASK_EVENTS:TASK_ITERATION_EVENT: all_event_handler')
|
||||
elif iteration == TASK_UNREGISTRATION_LIMIT:
|
||||
dut.expect("TASK_EVENTS:TASK_ITERATION_EVENT: unregistering task_iteration_handler")
|
||||
dut.expect("TASK_EVENTS:TASK_ITERATION_EVENT: all_event_handler")
|
||||
print("Unregistered handler at iteration {} out of {}".format(iteration, TASK_ITERATION_LIMIT))
|
||||
dut.expect('TASK_EVENTS:TASK_ITERATION_EVENT: unregistering task_iteration_handler')
|
||||
dut.expect('TASK_EVENTS:TASK_ITERATION_EVENT: all_event_handler')
|
||||
print('Unregistered handler at iteration {} out of {}'.format(iteration, TASK_ITERATION_LIMIT))
|
||||
else:
|
||||
dut.expect("TASK_EVENTS:TASK_ITERATION_EVENT: all_event_handler")
|
||||
dut.expect('TASK_EVENTS:TASK_ITERATION_EVENT: all_event_handler')
|
||||
|
||||
print("Handled iteration {} out of {}".format(iteration, TASK_ITERATION_LIMIT))
|
||||
print('Handled iteration {} out of {}'.format(iteration, TASK_ITERATION_LIMIT))
|
||||
|
||||
dut.expect("TASK_EVENTS:TASK_ITERATION_EVENT: deleting task event source")
|
||||
print("Deleted task event source")
|
||||
dut.expect('TASK_EVENTS:TASK_ITERATION_EVENT: deleting task event source')
|
||||
print('Deleted task event source')
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_GENERIC')
|
||||
|
||||
@@ -4,8 +4,8 @@ import ttfw_idf
|
||||
|
||||
TASK_ITERATION_LIMIT = 10
|
||||
|
||||
TASK_ITERATION_POSTING = "posting TASK_EVENTS:TASK_ITERATION_EVENT to {}, iteration {} out of " + str(TASK_ITERATION_LIMIT)
|
||||
TASK_ITERATION_HANDLING = "handling TASK_EVENTS:TASK_ITERATION_EVENT from {}, iteration {}"
|
||||
TASK_ITERATION_POSTING = 'posting TASK_EVENTS:TASK_ITERATION_EVENT to {}, iteration {} out of ' + str(TASK_ITERATION_LIMIT)
|
||||
TASK_ITERATION_HANDLING = 'handling TASK_EVENTS:TASK_ITERATION_EVENT from {}, iteration {}'
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_GENERIC')
|
||||
@@ -14,26 +14,26 @@ def test_user_event_loops_example(env, extra_data):
|
||||
|
||||
dut.start_app()
|
||||
|
||||
dut.expect("setting up")
|
||||
dut.expect("starting event source")
|
||||
dut.expect("starting application task")
|
||||
print("Finished setup")
|
||||
dut.expect('setting up')
|
||||
dut.expect('starting event source')
|
||||
dut.expect('starting application task')
|
||||
print('Finished setup')
|
||||
|
||||
for iteration in range(1, TASK_ITERATION_LIMIT + 1):
|
||||
loop = None
|
||||
|
||||
if (iteration % 2 == 0):
|
||||
loop = "loop_with_task"
|
||||
loop = 'loop_with_task'
|
||||
else:
|
||||
loop = "loop_without_task"
|
||||
loop = 'loop_without_task'
|
||||
|
||||
dut.expect(TASK_ITERATION_POSTING.format(loop, iteration))
|
||||
print("Posted iteration {} to {}".format(iteration, loop))
|
||||
print('Posted iteration {} to {}'.format(iteration, loop))
|
||||
dut.expect(TASK_ITERATION_HANDLING.format(loop, iteration))
|
||||
print("Handled iteration {} from {}".format(iteration, loop))
|
||||
print('Handled iteration {} from {}'.format(iteration, loop))
|
||||
|
||||
dut.expect("deleting task event source")
|
||||
print("Deleted task event source")
|
||||
dut.expect('deleting task event source')
|
||||
print('Deleted task event source')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import re
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
@@ -3,7 +3,7 @@ from __future__ import print_function
|
||||
import ttfw_idf
|
||||
|
||||
STATS_TASK_ITERS = 3
|
||||
STATS_TASK_EXPECT = "Real time stats obtained"
|
||||
STATS_TASK_EXPECT = 'Real time stats obtained'
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_GENERIC')
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import os
|
||||
import time
|
||||
|
||||
from ttfw_idf import Utility
|
||||
import ttfw_idf
|
||||
from ttfw_idf import Utility
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="test_jtag_arm")
|
||||
@ttfw_idf.idf_example_test(env_tag='test_jtag_arm')
|
||||
def test_examples_gcov(env, extra_data):
|
||||
|
||||
rel_project_path = os.path.join('examples', 'system', 'gcov')
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import re
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import re
|
||||
import time
|
||||
|
||||
|
||||
@@ -1,71 +1,71 @@
|
||||
import re
|
||||
import os
|
||||
import struct
|
||||
import socket
|
||||
import http.server
|
||||
from threading import Thread
|
||||
import ssl
|
||||
|
||||
from tiny_test_fw import DUT
|
||||
import ttfw_idf
|
||||
import os
|
||||
import random
|
||||
import re
|
||||
import socket
|
||||
import ssl
|
||||
import struct
|
||||
import subprocess
|
||||
from threading import Thread
|
||||
|
||||
server_cert = "-----BEGIN CERTIFICATE-----\n" \
|
||||
"MIIDXTCCAkWgAwIBAgIJAP4LF7E72HakMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV\n"\
|
||||
"BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX\n"\
|
||||
"aWRnaXRzIFB0eSBMdGQwHhcNMTkwNjA3MDk1OTE2WhcNMjAwNjA2MDk1OTE2WjBF\n"\
|
||||
"MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50\n"\
|
||||
"ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB\n"\
|
||||
"CgKCAQEAlzfCyv3mIv7TlLkObxunKfCdrJ/zgdANrsx0RBtpEPhV560hWJ0fEin0\n"\
|
||||
"nIOMpJSiF9E6QsPdr6Q+eogH4XnOMU9JE+iG743N1dPfGEzJvRlyct/Ck8SswKPC\n"\
|
||||
"9+VXsnOdZmUw9y/xtANbURA/TspvPzz3Avv382ffffrJGh7ooOmaZSCZFlSYHLZA\n"\
|
||||
"w/XlRr0sSRbLpFGY0gXjaAV8iHHiPDYLy4kZOepjV9U51xi+IGsL4w75zuMgsHyF\n"\
|
||||
"3nJeGYHgtGVBrkL0ZKG5udY0wcBjysjubDJC4iSlNiq2HD3fhs7j6CZddV2v845M\n"\
|
||||
"lVKNxP0kO4Uj4D8r+5USWC8JKfAwxQIDAQABo1AwTjAdBgNVHQ4EFgQU6OE7ssfY\n"\
|
||||
"IIPTDThiUoofUpsD5NwwHwYDVR0jBBgwFoAU6OE7ssfYIIPTDThiUoofUpsD5Nww\n"\
|
||||
"DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAXIlHS/FJWfmcinUAxyBd\n"\
|
||||
"/xd5Lu8ykeru6oaUCci+Vk9lyoMMES7lQ+b/00d5x7AcTawkTil9EWpBTPTOTraA\n"\
|
||||
"lzJMQhNKmSLk0iIoTtAJtSZgUSpIIozqK6lenxQQDsHbXKU6h+u9H6KZE8YcjsFl\n"\
|
||||
"6vL7sw9BVotw/VxfgjQ5OSGLgoLrdVT0z5C2qOuwOgz1c7jNiJhtMdwN+cOtnJp2\n"\
|
||||
"fuBgEYyE3eeuWogvkWoDcIA8r17Ixzkpq2oJsdvZcHZPIZShPKW2SHUsl98KDemu\n"\
|
||||
"y0pQyExmQUbwKE4vbFb9XuWCcL9XaOHQytyszt2DeD67AipvoBwVU7/LBOvqnsmy\n"\
|
||||
"hA==\n"\
|
||||
"-----END CERTIFICATE-----\n"
|
||||
import ttfw_idf
|
||||
from tiny_test_fw import DUT
|
||||
|
||||
server_key = "-----BEGIN PRIVATE KEY-----\n"\
|
||||
"MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCXN8LK/eYi/tOU\n"\
|
||||
"uQ5vG6cp8J2sn/OB0A2uzHREG2kQ+FXnrSFYnR8SKfScg4yklKIX0TpCw92vpD56\n"\
|
||||
"iAfhec4xT0kT6Ibvjc3V098YTMm9GXJy38KTxKzAo8L35Veyc51mZTD3L/G0A1tR\n"\
|
||||
"ED9Oym8/PPcC+/fzZ999+skaHuig6ZplIJkWVJgctkDD9eVGvSxJFsukUZjSBeNo\n"\
|
||||
"BXyIceI8NgvLiRk56mNX1TnXGL4gawvjDvnO4yCwfIXecl4ZgeC0ZUGuQvRkobm5\n"\
|
||||
"1jTBwGPKyO5sMkLiJKU2KrYcPd+GzuPoJl11Xa/zjkyVUo3E/SQ7hSPgPyv7lRJY\n"\
|
||||
"Lwkp8DDFAgMBAAECggEAfBhAfQE7mUByNbxgAgI5fot9eaqR1Nf+QpJ6X2H3KPwC\n"\
|
||||
"02sa0HOwieFwYfj6tB1doBoNq7i89mTc+QUlIn4pHgIowHO0OGawomeKz5BEhjCZ\n"\
|
||||
"4XeLYGSoODary2+kNkf2xY8JTfFEcyvGBpJEwc4S2VyYgRRx+IgnumTSH+N5mIKZ\n"\
|
||||
"SXWNdZIuHEmkwod+rPRXs6/r+PH0eVW6WfpINEbr4zVAGXJx2zXQwd2cuV1GTJWh\n"\
|
||||
"cPVOXLu+XJ9im9B370cYN6GqUnR3fui13urYbnWnEf3syvoH/zuZkyrVChauoFf8\n"\
|
||||
"8EGb74/HhXK7Q2s8NRakx2c7OxQifCbcy03liUMmyQKBgQDFAob5B/66N4Q2cq/N\n"\
|
||||
"MWPf98kYBYoLaeEOhEJhLQlKk0pIFCTmtpmUbpoEes2kCUbH7RwczpYko8tlKyoB\n"\
|
||||
"6Fn6RY4zQQ64KZJI6kQVsjkYpcP/ihnOY6rbds+3yyv+4uPX7Eh9sYZwZMggE19M\n"\
|
||||
"CkFHkwAjiwqhiiSlUxe20sWmowKBgQDEfx4lxuFzA1PBPeZKGVBTxYPQf+DSLCre\n"\
|
||||
"ZFg3ZmrxbCjRq1O7Lra4FXWD3dmRq7NDk79JofoW50yD8wD7I0B7opdDfXD2idO8\n"\
|
||||
"0dBnWUKDr2CAXyoLEINce9kJPbx4kFBQRN9PiGF7VkDQxeQ3kfS8CvcErpTKCOdy\n"\
|
||||
"5wOwBTwJdwKBgDiTFTeGeDv5nVoVbS67tDao7XKchJvqd9q3WGiXikeELJyuTDqE\n"\
|
||||
"zW22pTwMF+m3UEAxcxVCrhMvhkUzNAkANHaOatuFHzj7lyqhO5QPbh4J3FMR0X9X\n"\
|
||||
"V8VWRSg+jA/SECP9koOl6zlzd5Tee0tW1pA7QpryXscs6IEhb3ns5R2JAoGAIkzO\n"\
|
||||
"RmnhEOKTzDex611f2D+yMsMfy5BKK2f4vjLymBH5TiBKDXKqEpgsW0huoi8Gq9Uu\n"\
|
||||
"nvvXXAgkIyRYF36f0vUe0nkjLuYAQAWgC2pZYgNLJR13iVbol0xHJoXQUHtgiaJ8\n"\
|
||||
"GLYFzjHQPqFMpSalQe3oELko39uOC1CoJCHFySECgYBeycUnRBikCO2n8DNhY4Eg\n"\
|
||||
"9Y3oxcssRt6ea5BZwgW2eAYi7/XqKkmxoSoOykUt3MJx9+EkkrL17bxFSpkj1tvL\n"\
|
||||
"qvxn7egtsKjjgGNAxwXC4MwCvhveyUQQxtQb8AqGrGqo4jEEN0L15cnP38i2x1Uo\n"\
|
||||
"muhfskWf4MABV0yTUaKcGg==\n"\
|
||||
"-----END PRIVATE KEY-----\n"
|
||||
server_cert = '-----BEGIN CERTIFICATE-----\n' \
|
||||
'MIIDXTCCAkWgAwIBAgIJAP4LF7E72HakMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV\n'\
|
||||
'BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX\n'\
|
||||
'aWRnaXRzIFB0eSBMdGQwHhcNMTkwNjA3MDk1OTE2WhcNMjAwNjA2MDk1OTE2WjBF\n'\
|
||||
'MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50\n'\
|
||||
'ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB\n'\
|
||||
'CgKCAQEAlzfCyv3mIv7TlLkObxunKfCdrJ/zgdANrsx0RBtpEPhV560hWJ0fEin0\n'\
|
||||
'nIOMpJSiF9E6QsPdr6Q+eogH4XnOMU9JE+iG743N1dPfGEzJvRlyct/Ck8SswKPC\n'\
|
||||
'9+VXsnOdZmUw9y/xtANbURA/TspvPzz3Avv382ffffrJGh7ooOmaZSCZFlSYHLZA\n'\
|
||||
'w/XlRr0sSRbLpFGY0gXjaAV8iHHiPDYLy4kZOepjV9U51xi+IGsL4w75zuMgsHyF\n'\
|
||||
'3nJeGYHgtGVBrkL0ZKG5udY0wcBjysjubDJC4iSlNiq2HD3fhs7j6CZddV2v845M\n'\
|
||||
'lVKNxP0kO4Uj4D8r+5USWC8JKfAwxQIDAQABo1AwTjAdBgNVHQ4EFgQU6OE7ssfY\n'\
|
||||
'IIPTDThiUoofUpsD5NwwHwYDVR0jBBgwFoAU6OE7ssfYIIPTDThiUoofUpsD5Nww\n'\
|
||||
'DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAXIlHS/FJWfmcinUAxyBd\n'\
|
||||
'/xd5Lu8ykeru6oaUCci+Vk9lyoMMES7lQ+b/00d5x7AcTawkTil9EWpBTPTOTraA\n'\
|
||||
'lzJMQhNKmSLk0iIoTtAJtSZgUSpIIozqK6lenxQQDsHbXKU6h+u9H6KZE8YcjsFl\n'\
|
||||
'6vL7sw9BVotw/VxfgjQ5OSGLgoLrdVT0z5C2qOuwOgz1c7jNiJhtMdwN+cOtnJp2\n'\
|
||||
'fuBgEYyE3eeuWogvkWoDcIA8r17Ixzkpq2oJsdvZcHZPIZShPKW2SHUsl98KDemu\n'\
|
||||
'y0pQyExmQUbwKE4vbFb9XuWCcL9XaOHQytyszt2DeD67AipvoBwVU7/LBOvqnsmy\n'\
|
||||
'hA==\n'\
|
||||
'-----END CERTIFICATE-----\n'
|
||||
|
||||
server_key = '-----BEGIN PRIVATE KEY-----\n'\
|
||||
'MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCXN8LK/eYi/tOU\n'\
|
||||
'uQ5vG6cp8J2sn/OB0A2uzHREG2kQ+FXnrSFYnR8SKfScg4yklKIX0TpCw92vpD56\n'\
|
||||
'iAfhec4xT0kT6Ibvjc3V098YTMm9GXJy38KTxKzAo8L35Veyc51mZTD3L/G0A1tR\n'\
|
||||
'ED9Oym8/PPcC+/fzZ999+skaHuig6ZplIJkWVJgctkDD9eVGvSxJFsukUZjSBeNo\n'\
|
||||
'BXyIceI8NgvLiRk56mNX1TnXGL4gawvjDvnO4yCwfIXecl4ZgeC0ZUGuQvRkobm5\n'\
|
||||
'1jTBwGPKyO5sMkLiJKU2KrYcPd+GzuPoJl11Xa/zjkyVUo3E/SQ7hSPgPyv7lRJY\n'\
|
||||
'Lwkp8DDFAgMBAAECggEAfBhAfQE7mUByNbxgAgI5fot9eaqR1Nf+QpJ6X2H3KPwC\n'\
|
||||
'02sa0HOwieFwYfj6tB1doBoNq7i89mTc+QUlIn4pHgIowHO0OGawomeKz5BEhjCZ\n'\
|
||||
'4XeLYGSoODary2+kNkf2xY8JTfFEcyvGBpJEwc4S2VyYgRRx+IgnumTSH+N5mIKZ\n'\
|
||||
'SXWNdZIuHEmkwod+rPRXs6/r+PH0eVW6WfpINEbr4zVAGXJx2zXQwd2cuV1GTJWh\n'\
|
||||
'cPVOXLu+XJ9im9B370cYN6GqUnR3fui13urYbnWnEf3syvoH/zuZkyrVChauoFf8\n'\
|
||||
'8EGb74/HhXK7Q2s8NRakx2c7OxQifCbcy03liUMmyQKBgQDFAob5B/66N4Q2cq/N\n'\
|
||||
'MWPf98kYBYoLaeEOhEJhLQlKk0pIFCTmtpmUbpoEes2kCUbH7RwczpYko8tlKyoB\n'\
|
||||
'6Fn6RY4zQQ64KZJI6kQVsjkYpcP/ihnOY6rbds+3yyv+4uPX7Eh9sYZwZMggE19M\n'\
|
||||
'CkFHkwAjiwqhiiSlUxe20sWmowKBgQDEfx4lxuFzA1PBPeZKGVBTxYPQf+DSLCre\n'\
|
||||
'ZFg3ZmrxbCjRq1O7Lra4FXWD3dmRq7NDk79JofoW50yD8wD7I0B7opdDfXD2idO8\n'\
|
||||
'0dBnWUKDr2CAXyoLEINce9kJPbx4kFBQRN9PiGF7VkDQxeQ3kfS8CvcErpTKCOdy\n'\
|
||||
'5wOwBTwJdwKBgDiTFTeGeDv5nVoVbS67tDao7XKchJvqd9q3WGiXikeELJyuTDqE\n'\
|
||||
'zW22pTwMF+m3UEAxcxVCrhMvhkUzNAkANHaOatuFHzj7lyqhO5QPbh4J3FMR0X9X\n'\
|
||||
'V8VWRSg+jA/SECP9koOl6zlzd5Tee0tW1pA7QpryXscs6IEhb3ns5R2JAoGAIkzO\n'\
|
||||
'RmnhEOKTzDex611f2D+yMsMfy5BKK2f4vjLymBH5TiBKDXKqEpgsW0huoi8Gq9Uu\n'\
|
||||
'nvvXXAgkIyRYF36f0vUe0nkjLuYAQAWgC2pZYgNLJR13iVbol0xHJoXQUHtgiaJ8\n'\
|
||||
'GLYFzjHQPqFMpSalQe3oELko39uOC1CoJCHFySECgYBeycUnRBikCO2n8DNhY4Eg\n'\
|
||||
'9Y3oxcssRt6ea5BZwgW2eAYi7/XqKkmxoSoOykUt3MJx9+EkkrL17bxFSpkj1tvL\n'\
|
||||
'qvxn7egtsKjjgGNAxwXC4MwCvhveyUQQxtQb8AqGrGqo4jEEN0L15cnP38i2x1Uo\n'\
|
||||
'muhfskWf4MABV0yTUaKcGg==\n'\
|
||||
'-----END PRIVATE KEY-----\n'
|
||||
|
||||
|
||||
def get_my_ip():
|
||||
s1 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
s1.connect(("8.8.8.8", 80))
|
||||
s1.connect(('8.8.8.8', 80))
|
||||
my_ip = s1.getsockname()[0]
|
||||
s1.close()
|
||||
return my_ip
|
||||
@@ -81,16 +81,16 @@ def get_server_status(host_ip, port):
|
||||
|
||||
|
||||
def create_file(server_file, file_data):
|
||||
with open(server_file, "w+") as file:
|
||||
with open(server_file, 'w+') as file:
|
||||
file.write(file_data)
|
||||
|
||||
|
||||
def get_ca_cert(ota_image_dir):
|
||||
os.chdir(ota_image_dir)
|
||||
server_file = os.path.join(ota_image_dir, "server_cert.pem")
|
||||
server_file = os.path.join(ota_image_dir, 'server_cert.pem')
|
||||
create_file(server_file, server_cert)
|
||||
|
||||
key_file = os.path.join(ota_image_dir, "server_key.pem")
|
||||
key_file = os.path.join(ota_image_dir, 'server_key.pem')
|
||||
create_file(key_file, server_key)
|
||||
return server_file, key_file
|
||||
|
||||
@@ -131,7 +131,7 @@ def start_https_server(ota_image_dir, server_ip, server_port):
|
||||
|
||||
def start_chunked_server(ota_image_dir, server_port):
|
||||
server_file, key_file = get_ca_cert(ota_image_dir)
|
||||
chunked_server = subprocess.Popen(["openssl", "s_server", "-WWW", "-key", key_file, "-cert", server_file, "-port", str(server_port)])
|
||||
chunked_server = subprocess.Popen(['openssl', 's_server', '-WWW', '-key', key_file, '-cert', server_file, '-port', str(server_port)])
|
||||
return chunked_server
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ def redirect_handler_factory(url):
|
||||
"""
|
||||
class RedirectHandler(http.server.SimpleHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
print("Sending resp, URL: " + url)
|
||||
print('Sending resp, URL: ' + url)
|
||||
self.send_response(301)
|
||||
self.send_header('Location', url)
|
||||
self.end_headers()
|
||||
@@ -158,7 +158,7 @@ def redirect_handler_factory(url):
|
||||
def start_redirect_server(ota_image_dir, server_ip, server_port, redirection_port):
|
||||
os.chdir(ota_image_dir)
|
||||
server_file, key_file = get_ca_cert(ota_image_dir)
|
||||
redirectHandler = redirect_handler_factory("https://" + server_ip + ":" + str(redirection_port) + "/advanced_https_ota.bin")
|
||||
redirectHandler = redirect_handler_factory('https://' + server_ip + ':' + str(redirection_port) + '/advanced_https_ota.bin')
|
||||
|
||||
httpd = http.server.HTTPServer((server_ip, server_port), redirectHandler)
|
||||
|
||||
@@ -168,7 +168,7 @@ def start_redirect_server(ota_image_dir, server_ip, server_port, redirection_por
|
||||
httpd.serve_forever()
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_advanced_https_ota_example(env, extra_data):
|
||||
"""
|
||||
This is a positive test case, which downloads complete binary file multiple number of times.
|
||||
@@ -178,16 +178,16 @@ def test_examples_protocol_advanced_https_ota_example(env, extra_data):
|
||||
2. Fetch OTA image over HTTPS
|
||||
3. Reboot with the new OTA image
|
||||
"""
|
||||
dut1 = env.get_dut("advanced_https_ota_example", "examples/system/ota/advanced_https_ota", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('advanced_https_ota_example', 'examples/system/ota/advanced_https_ota', dut_class=ttfw_idf.ESP32DUT)
|
||||
# Number of iterations to validate OTA
|
||||
iterations = 3
|
||||
server_port = 8001
|
||||
# File to be downloaded. This file is generated after compilation
|
||||
bin_name = "advanced_https_ota.bin"
|
||||
bin_name = 'advanced_https_ota.bin'
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, bin_name)
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("advanced_https_ota_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('advanced_https_ota_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
@@ -196,23 +196,23 @@ def test_examples_protocol_advanced_https_ota_example(env, extra_data):
|
||||
thread1.start()
|
||||
dut1.start_app()
|
||||
for i in range(iterations):
|
||||
dut1.expect("Loaded app from partition at offset", timeout=30)
|
||||
dut1.expect('Loaded app from partition at offset', timeout=30)
|
||||
try:
|
||||
ip_address = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30)
|
||||
print("Connected to AP with IP: {}".format(ip_address))
|
||||
ip_address = dut1.expect(re.compile(r' sta ip: ([^,]+),'), timeout=30)
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except DUT.ExpectTimeout:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
thread1.close()
|
||||
dut1.expect("Starting Advanced OTA example", timeout=30)
|
||||
dut1.expect('Starting Advanced OTA example', timeout=30)
|
||||
|
||||
print("writing to device: {}".format("https://" + host_ip + ":" + str(server_port) + "/" + bin_name))
|
||||
dut1.write("https://" + host_ip + ":" + str(server_port) + "/" + bin_name)
|
||||
dut1.expect("Loaded app from partition at offset", timeout=60)
|
||||
dut1.expect("Starting Advanced OTA example", timeout=30)
|
||||
print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port) + '/' + bin_name))
|
||||
dut1.write('https://' + host_ip + ':' + str(server_port) + '/' + bin_name)
|
||||
dut1.expect('Loaded app from partition at offset', timeout=60)
|
||||
dut1.expect('Starting Advanced OTA example', timeout=30)
|
||||
dut1.reset()
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_advanced_https_ota_example_truncated_bin(env, extra_data):
|
||||
"""
|
||||
Working of OTA if binary file is truncated is validated in this test case.
|
||||
@@ -223,25 +223,25 @@ def test_examples_protocol_advanced_https_ota_example_truncated_bin(env, extra_d
|
||||
3. Fetch OTA image over HTTPS
|
||||
4. Check working of code if bin is truncated
|
||||
"""
|
||||
dut1 = env.get_dut("advanced_https_ota_example", "examples/system/ota/advanced_https_ota", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('advanced_https_ota_example', 'examples/system/ota/advanced_https_ota', dut_class=ttfw_idf.ESP32DUT)
|
||||
server_port = 8001
|
||||
# Original binary file generated after compilation
|
||||
bin_name = "advanced_https_ota.bin"
|
||||
bin_name = 'advanced_https_ota.bin'
|
||||
# Truncated binary file to be generated from original binary file
|
||||
truncated_bin_name = "truncated.bin"
|
||||
truncated_bin_name = 'truncated.bin'
|
||||
# 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
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, bin_name)
|
||||
f = open(binary_file, "rb+")
|
||||
fo = open(os.path.join(dut1.app.binary_path, truncated_bin_name), "wb+")
|
||||
f = open(binary_file, 'rb+')
|
||||
fo = open(os.path.join(dut1.app.binary_path, truncated_bin_name), 'wb+')
|
||||
fo.write(f.read(truncated_bin_size))
|
||||
fo.close()
|
||||
f.close()
|
||||
binary_file = os.path.join(dut1.app.binary_path, truncated_bin_name)
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("advanced_https_ota_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('advanced_https_ota_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
@@ -249,21 +249,21 @@ def test_examples_protocol_advanced_https_ota_example_truncated_bin(env, extra_d
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
dut1.start_app()
|
||||
dut1.expect("Loaded app from partition at offset", timeout=30)
|
||||
dut1.expect('Loaded app from partition at offset', timeout=30)
|
||||
try:
|
||||
ip_address = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30)
|
||||
print("Connected to AP with IP: {}".format(ip_address))
|
||||
ip_address = dut1.expect(re.compile(r' sta ip: ([^,]+),'), timeout=30)
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except DUT.ExpectTimeout:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
dut1.expect("Starting Advanced OTA example", timeout=30)
|
||||
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)
|
||||
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)
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_advanced_https_ota_example_truncated_header(env, extra_data):
|
||||
"""
|
||||
Working of OTA if headers of binary file are truncated is vaildated in this test case.
|
||||
@@ -274,24 +274,24 @@ def test_examples_protocol_advanced_https_ota_example_truncated_header(env, extr
|
||||
3. Fetch OTA image over HTTPS
|
||||
4. Check working of code if headers are not sent completely
|
||||
"""
|
||||
dut1 = env.get_dut("advanced_https_ota_example", "examples/system/ota/advanced_https_ota", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('advanced_https_ota_example', 'examples/system/ota/advanced_https_ota', dut_class=ttfw_idf.ESP32DUT)
|
||||
server_port = 8001
|
||||
# Original binary file generated after compilation
|
||||
bin_name = "advanced_https_ota.bin"
|
||||
bin_name = 'advanced_https_ota.bin'
|
||||
# Truncated binary file to be generated from original binary file
|
||||
truncated_bin_name = "truncated_header.bin"
|
||||
truncated_bin_name = 'truncated_header.bin'
|
||||
# Size of truncated file to be grnerated. This value should be less than 288 bytes (Image header size)
|
||||
truncated_bin_size = 180
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, bin_name)
|
||||
f = open(binary_file, "rb+")
|
||||
fo = open(os.path.join(dut1.app.binary_path, truncated_bin_name), "wb+")
|
||||
f = open(binary_file, 'rb+')
|
||||
fo = open(os.path.join(dut1.app.binary_path, truncated_bin_name), 'wb+')
|
||||
fo.write(f.read(truncated_bin_size))
|
||||
fo.close()
|
||||
f.close()
|
||||
binary_file = os.path.join(dut1.app.binary_path, truncated_bin_name)
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("advanced_https_ota_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('advanced_https_ota_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
@@ -299,21 +299,21 @@ def test_examples_protocol_advanced_https_ota_example_truncated_header(env, extr
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
dut1.start_app()
|
||||
dut1.expect("Loaded app from partition at offset", timeout=30)
|
||||
dut1.expect('Loaded app from partition at offset', timeout=30)
|
||||
try:
|
||||
ip_address = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30)
|
||||
print("Connected to AP with IP: {}".format(ip_address))
|
||||
ip_address = dut1.expect(re.compile(r' sta ip: ([^,]+),'), timeout=30)
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except DUT.ExpectTimeout:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
dut1.expect("Starting Advanced OTA example", timeout=30)
|
||||
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)
|
||||
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)
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_advanced_https_ota_example_random(env, extra_data):
|
||||
"""
|
||||
Working of OTA if random data is added in binary file are validated in this test case.
|
||||
@@ -324,23 +324,23 @@ def test_examples_protocol_advanced_https_ota_example_random(env, extra_data):
|
||||
3. Fetch OTA image over HTTPS
|
||||
4. Check working of code for random binary file
|
||||
"""
|
||||
dut1 = env.get_dut("advanced_https_ota_example", "examples/system/ota/advanced_https_ota", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('advanced_https_ota_example', 'examples/system/ota/advanced_https_ota', dut_class=ttfw_idf.ESP32DUT)
|
||||
server_port = 8001
|
||||
# Random binary file to be generated
|
||||
random_bin_name = "random.bin"
|
||||
random_bin_name = 'random.bin'
|
||||
# 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
|
||||
binary_file = os.path.join(dut1.app.binary_path, random_bin_name)
|
||||
fo = open(binary_file, "wb+")
|
||||
fo = open(binary_file, 'wb+')
|
||||
# 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))
|
||||
fo.write(struct.pack('B', 0))
|
||||
for i in range(random_bin_size - 1):
|
||||
fo.write(struct.pack("B", random.randrange(0,255,1)))
|
||||
fo.write(struct.pack('B', random.randrange(0,255,1)))
|
||||
fo.close()
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("advanced_https_ota_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('advanced_https_ota_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
@@ -348,21 +348,21 @@ def test_examples_protocol_advanced_https_ota_example_random(env, extra_data):
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
dut1.start_app()
|
||||
dut1.expect("Loaded app from partition at offset", timeout=30)
|
||||
dut1.expect('Loaded app from partition at offset', timeout=30)
|
||||
try:
|
||||
ip_address = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30)
|
||||
print("Connected to AP with IP: {}".format(ip_address))
|
||||
ip_address = dut1.expect(re.compile(r' sta ip: ([^,]+),'), timeout=30)
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except DUT.ExpectTimeout:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
dut1.expect("Starting Advanced OTA example", timeout=30)
|
||||
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)
|
||||
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)
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_advanced_https_ota_example_chunked(env, extra_data):
|
||||
"""
|
||||
This is a positive test case, which downloads complete binary file multiple number of times.
|
||||
@@ -372,35 +372,35 @@ def test_examples_protocol_advanced_https_ota_example_chunked(env, extra_data):
|
||||
2. Fetch OTA image over HTTPS
|
||||
3. Reboot with the new OTA image
|
||||
"""
|
||||
dut1 = env.get_dut("advanced_https_ota_example", "examples/system/ota/advanced_https_ota", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('advanced_https_ota_example', 'examples/system/ota/advanced_https_ota', dut_class=ttfw_idf.ESP32DUT)
|
||||
# File to be downloaded. This file is generated after compilation
|
||||
bin_name = "advanced_https_ota.bin"
|
||||
bin_name = 'advanced_https_ota.bin'
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, bin_name)
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("advanced_https_ota_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('advanced_https_ota_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
chunked_server = start_chunked_server(dut1.app.binary_path, 8070)
|
||||
dut1.start_app()
|
||||
dut1.expect("Loaded app from partition at offset", timeout=30)
|
||||
dut1.expect('Loaded app from partition at offset', timeout=30)
|
||||
try:
|
||||
ip_address = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30)
|
||||
print("Connected to AP with IP: {}".format(ip_address))
|
||||
ip_address = dut1.expect(re.compile(r' sta ip: ([^,]+),'), timeout=30)
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except DUT.ExpectTimeout:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
dut1.expect("Starting Advanced OTA example", timeout=30)
|
||||
dut1.expect('Starting Advanced OTA example', timeout=30)
|
||||
|
||||
print("writing to device: {}".format("https://" + host_ip + ":8070/" + bin_name))
|
||||
dut1.write("https://" + host_ip + ":8070/" + bin_name)
|
||||
dut1.expect("Loaded app from partition at offset", timeout=60)
|
||||
dut1.expect("Starting Advanced OTA example", timeout=30)
|
||||
print('writing to device: {}'.format('https://' + host_ip + ':8070/' + bin_name))
|
||||
dut1.write('https://' + host_ip + ':8070/' + bin_name)
|
||||
dut1.expect('Loaded app from partition at offset', timeout=60)
|
||||
dut1.expect('Starting Advanced OTA example', timeout=30)
|
||||
chunked_server.kill()
|
||||
os.remove(os.path.join(dut1.app.binary_path, "server_cert.pem"))
|
||||
os.remove(os.path.join(dut1.app.binary_path, "server_key.pem"))
|
||||
os.remove(os.path.join(dut1.app.binary_path, 'server_cert.pem'))
|
||||
os.remove(os.path.join(dut1.app.binary_path, 'server_key.pem'))
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_advanced_https_ota_example_redirect_url(env, extra_data):
|
||||
"""
|
||||
This is a positive test case, which starts a server and a redirection server.
|
||||
@@ -411,16 +411,16 @@ def test_examples_protocol_advanced_https_ota_example_redirect_url(env, extra_da
|
||||
2. Fetch OTA image over HTTPS
|
||||
3. Reboot with the new OTA image
|
||||
"""
|
||||
dut1 = env.get_dut("advanced_https_ota_example", "examples/system/ota/advanced_https_ota", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('advanced_https_ota_example', 'examples/system/ota/advanced_https_ota', dut_class=ttfw_idf.ESP32DUT)
|
||||
server_port = 8001
|
||||
# Port to which the request should be redirecetd
|
||||
redirection_server_port = 8081
|
||||
# File to be downloaded. This file is generated after compilation
|
||||
bin_name = "advanced_https_ota.bin"
|
||||
bin_name = 'advanced_https_ota.bin'
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, bin_name)
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("advanced_https_ota_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('advanced_https_ota_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
@@ -431,24 +431,24 @@ def test_examples_protocol_advanced_https_ota_example_redirect_url(env, extra_da
|
||||
thread2.daemon = True
|
||||
thread2.start()
|
||||
dut1.start_app()
|
||||
dut1.expect("Loaded app from partition at offset", timeout=30)
|
||||
dut1.expect('Loaded app from partition at offset', timeout=30)
|
||||
try:
|
||||
ip_address = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30)
|
||||
print("Connected to AP with IP: {}".format(ip_address))
|
||||
ip_address = dut1.expect(re.compile(r' sta ip: ([^,]+),'), timeout=30)
|
||||
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()
|
||||
dut1.expect("Starting Advanced OTA example", timeout=30)
|
||||
dut1.expect('Starting Advanced OTA example', timeout=30)
|
||||
|
||||
print("writing to device: {}".format("https://" + host_ip + ":" + str(redirection_server_port) + "/" + bin_name))
|
||||
dut1.write("https://" + host_ip + ":" + str(redirection_server_port) + "/" + bin_name)
|
||||
dut1.expect("Loaded app from partition at offset", timeout=60)
|
||||
dut1.expect("Starting Advanced OTA example", timeout=30)
|
||||
print('writing to device: {}'.format('https://' + host_ip + ':' + str(redirection_server_port) + '/' + bin_name))
|
||||
dut1.write('https://' + host_ip + ':' + str(redirection_server_port) + '/' + bin_name)
|
||||
dut1.expect('Loaded app from partition at offset', timeout=60)
|
||||
dut1.expect('Starting Advanced OTA example', timeout=30)
|
||||
dut1.reset()
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_8Mflash_Ethernet")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_8Mflash_Ethernet')
|
||||
def test_examples_protocol_advanced_https_ota_example_anti_rollback(env, extra_data):
|
||||
"""
|
||||
Working of OTA when anti_rollback is enabled and security version of new image is less than current one.
|
||||
@@ -459,17 +459,17 @@ def test_examples_protocol_advanced_https_ota_example_anti_rollback(env, extra_d
|
||||
3. Fetch OTA image over HTTPS
|
||||
4. Check working of anti_rollback feature
|
||||
"""
|
||||
dut1 = env.get_dut("advanced_https_ota_example", "examples/system/ota/advanced_https_ota", dut_class=ttfw_idf.ESP32DUT, app_config_name='anti_rollback')
|
||||
dut1 = env.get_dut('advanced_https_ota_example', 'examples/system/ota/advanced_https_ota', dut_class=ttfw_idf.ESP32DUT, app_config_name='anti_rollback')
|
||||
server_port = 8001
|
||||
# Original binary file generated after compilation
|
||||
bin_name = "advanced_https_ota.bin"
|
||||
bin_name = 'advanced_https_ota.bin'
|
||||
# Modified firmware image to lower security version in its header. This is to enable negative test case
|
||||
anti_rollback_bin_name = "advanced_https_ota_lower_sec_version.bin"
|
||||
anti_rollback_bin_name = 'advanced_https_ota_lower_sec_version.bin'
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, bin_name)
|
||||
file_size = os.path.getsize(binary_file)
|
||||
f = open(binary_file, "rb+")
|
||||
fo = open(os.path.join(dut1.app.binary_path, anti_rollback_bin_name), "wb+")
|
||||
f = open(binary_file, 'rb+')
|
||||
fo = open(os.path.join(dut1.app.binary_path, anti_rollback_bin_name), 'wb+')
|
||||
fo.write(f.read(file_size))
|
||||
# Change security_version to 0 for negative test case
|
||||
fo.seek(36)
|
||||
@@ -478,7 +478,7 @@ def test_examples_protocol_advanced_https_ota_example_anti_rollback(env, extra_d
|
||||
f.close()
|
||||
binary_file = os.path.join(dut1.app.binary_path, anti_rollback_bin_name)
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("advanced_https_ota_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('advanced_https_ota_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
@@ -487,27 +487,27 @@ def test_examples_protocol_advanced_https_ota_example_anti_rollback(env, extra_d
|
||||
thread1.start()
|
||||
dut1.start_app()
|
||||
# Positive Case
|
||||
dut1.expect("Loaded app from partition at offset", timeout=30)
|
||||
dut1.expect('Loaded app from partition at offset', timeout=30)
|
||||
try:
|
||||
ip_address = dut1.expect(re.compile(r" eth ip: ([^,]+),"), timeout=30)
|
||||
print("Connected to AP with IP: {}".format(ip_address))
|
||||
ip_address = dut1.expect(re.compile(r' eth ip: ([^,]+),'), timeout=30)
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except DUT.ExpectTimeout:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
dut1.expect("Starting Advanced OTA example", timeout=30)
|
||||
dut1.expect('Starting Advanced OTA example', timeout=30)
|
||||
|
||||
# Use originally generated image with secure_version=1
|
||||
print("writing to device: {}".format("https://" + host_ip + ":" + str(server_port) + "/" + bin_name))
|
||||
dut1.write("https://" + host_ip + ":" + str(server_port) + "/" + bin_name)
|
||||
dut1.expect("Loaded app from partition at offset", timeout=60)
|
||||
dut1.expect(re.compile(r" eth ip: ([^,]+),"), timeout=30)
|
||||
dut1.expect("App is valid, rollback cancelled successfully", 30)
|
||||
print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port) + '/' + bin_name))
|
||||
dut1.write('https://' + host_ip + ':' + str(server_port) + '/' + bin_name)
|
||||
dut1.expect('Loaded app from partition at offset', timeout=60)
|
||||
dut1.expect(re.compile(r' eth ip: ([^,]+),'), timeout=30)
|
||||
dut1.expect('App is valid, rollback cancelled successfully', 30)
|
||||
|
||||
# Negative Case
|
||||
dut1.expect("Starting Advanced OTA example", timeout=30)
|
||||
dut1.expect('Starting Advanced OTA example', timeout=30)
|
||||
# Use modified image with secure_version=0
|
||||
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)
|
||||
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)
|
||||
|
||||
|
||||
|
||||
@@ -1,71 +1,71 @@
|
||||
import re
|
||||
import os
|
||||
import struct
|
||||
import socket
|
||||
import http.server
|
||||
from threading import Thread
|
||||
import ssl
|
||||
|
||||
from tiny_test_fw import DUT
|
||||
import ttfw_idf
|
||||
import os
|
||||
import random
|
||||
import re
|
||||
import socket
|
||||
import ssl
|
||||
import struct
|
||||
import subprocess
|
||||
from threading import Thread
|
||||
|
||||
server_cert = "-----BEGIN CERTIFICATE-----\n" \
|
||||
"MIIDXTCCAkWgAwIBAgIJAP4LF7E72HakMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV\n"\
|
||||
"BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX\n"\
|
||||
"aWRnaXRzIFB0eSBMdGQwHhcNMTkwNjA3MDk1OTE2WhcNMjAwNjA2MDk1OTE2WjBF\n"\
|
||||
"MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50\n"\
|
||||
"ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB\n"\
|
||||
"CgKCAQEAlzfCyv3mIv7TlLkObxunKfCdrJ/zgdANrsx0RBtpEPhV560hWJ0fEin0\n"\
|
||||
"nIOMpJSiF9E6QsPdr6Q+eogH4XnOMU9JE+iG743N1dPfGEzJvRlyct/Ck8SswKPC\n"\
|
||||
"9+VXsnOdZmUw9y/xtANbURA/TspvPzz3Avv382ffffrJGh7ooOmaZSCZFlSYHLZA\n"\
|
||||
"w/XlRr0sSRbLpFGY0gXjaAV8iHHiPDYLy4kZOepjV9U51xi+IGsL4w75zuMgsHyF\n"\
|
||||
"3nJeGYHgtGVBrkL0ZKG5udY0wcBjysjubDJC4iSlNiq2HD3fhs7j6CZddV2v845M\n"\
|
||||
"lVKNxP0kO4Uj4D8r+5USWC8JKfAwxQIDAQABo1AwTjAdBgNVHQ4EFgQU6OE7ssfY\n"\
|
||||
"IIPTDThiUoofUpsD5NwwHwYDVR0jBBgwFoAU6OE7ssfYIIPTDThiUoofUpsD5Nww\n"\
|
||||
"DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAXIlHS/FJWfmcinUAxyBd\n"\
|
||||
"/xd5Lu8ykeru6oaUCci+Vk9lyoMMES7lQ+b/00d5x7AcTawkTil9EWpBTPTOTraA\n"\
|
||||
"lzJMQhNKmSLk0iIoTtAJtSZgUSpIIozqK6lenxQQDsHbXKU6h+u9H6KZE8YcjsFl\n"\
|
||||
"6vL7sw9BVotw/VxfgjQ5OSGLgoLrdVT0z5C2qOuwOgz1c7jNiJhtMdwN+cOtnJp2\n"\
|
||||
"fuBgEYyE3eeuWogvkWoDcIA8r17Ixzkpq2oJsdvZcHZPIZShPKW2SHUsl98KDemu\n"\
|
||||
"y0pQyExmQUbwKE4vbFb9XuWCcL9XaOHQytyszt2DeD67AipvoBwVU7/LBOvqnsmy\n"\
|
||||
"hA==\n"\
|
||||
"-----END CERTIFICATE-----\n"
|
||||
import ttfw_idf
|
||||
from tiny_test_fw import DUT
|
||||
|
||||
server_key = "-----BEGIN PRIVATE KEY-----\n"\
|
||||
"MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCXN8LK/eYi/tOU\n"\
|
||||
"uQ5vG6cp8J2sn/OB0A2uzHREG2kQ+FXnrSFYnR8SKfScg4yklKIX0TpCw92vpD56\n"\
|
||||
"iAfhec4xT0kT6Ibvjc3V098YTMm9GXJy38KTxKzAo8L35Veyc51mZTD3L/G0A1tR\n"\
|
||||
"ED9Oym8/PPcC+/fzZ999+skaHuig6ZplIJkWVJgctkDD9eVGvSxJFsukUZjSBeNo\n"\
|
||||
"BXyIceI8NgvLiRk56mNX1TnXGL4gawvjDvnO4yCwfIXecl4ZgeC0ZUGuQvRkobm5\n"\
|
||||
"1jTBwGPKyO5sMkLiJKU2KrYcPd+GzuPoJl11Xa/zjkyVUo3E/SQ7hSPgPyv7lRJY\n"\
|
||||
"Lwkp8DDFAgMBAAECggEAfBhAfQE7mUByNbxgAgI5fot9eaqR1Nf+QpJ6X2H3KPwC\n"\
|
||||
"02sa0HOwieFwYfj6tB1doBoNq7i89mTc+QUlIn4pHgIowHO0OGawomeKz5BEhjCZ\n"\
|
||||
"4XeLYGSoODary2+kNkf2xY8JTfFEcyvGBpJEwc4S2VyYgRRx+IgnumTSH+N5mIKZ\n"\
|
||||
"SXWNdZIuHEmkwod+rPRXs6/r+PH0eVW6WfpINEbr4zVAGXJx2zXQwd2cuV1GTJWh\n"\
|
||||
"cPVOXLu+XJ9im9B370cYN6GqUnR3fui13urYbnWnEf3syvoH/zuZkyrVChauoFf8\n"\
|
||||
"8EGb74/HhXK7Q2s8NRakx2c7OxQifCbcy03liUMmyQKBgQDFAob5B/66N4Q2cq/N\n"\
|
||||
"MWPf98kYBYoLaeEOhEJhLQlKk0pIFCTmtpmUbpoEes2kCUbH7RwczpYko8tlKyoB\n"\
|
||||
"6Fn6RY4zQQ64KZJI6kQVsjkYpcP/ihnOY6rbds+3yyv+4uPX7Eh9sYZwZMggE19M\n"\
|
||||
"CkFHkwAjiwqhiiSlUxe20sWmowKBgQDEfx4lxuFzA1PBPeZKGVBTxYPQf+DSLCre\n"\
|
||||
"ZFg3ZmrxbCjRq1O7Lra4FXWD3dmRq7NDk79JofoW50yD8wD7I0B7opdDfXD2idO8\n"\
|
||||
"0dBnWUKDr2CAXyoLEINce9kJPbx4kFBQRN9PiGF7VkDQxeQ3kfS8CvcErpTKCOdy\n"\
|
||||
"5wOwBTwJdwKBgDiTFTeGeDv5nVoVbS67tDao7XKchJvqd9q3WGiXikeELJyuTDqE\n"\
|
||||
"zW22pTwMF+m3UEAxcxVCrhMvhkUzNAkANHaOatuFHzj7lyqhO5QPbh4J3FMR0X9X\n"\
|
||||
"V8VWRSg+jA/SECP9koOl6zlzd5Tee0tW1pA7QpryXscs6IEhb3ns5R2JAoGAIkzO\n"\
|
||||
"RmnhEOKTzDex611f2D+yMsMfy5BKK2f4vjLymBH5TiBKDXKqEpgsW0huoi8Gq9Uu\n"\
|
||||
"nvvXXAgkIyRYF36f0vUe0nkjLuYAQAWgC2pZYgNLJR13iVbol0xHJoXQUHtgiaJ8\n"\
|
||||
"GLYFzjHQPqFMpSalQe3oELko39uOC1CoJCHFySECgYBeycUnRBikCO2n8DNhY4Eg\n"\
|
||||
"9Y3oxcssRt6ea5BZwgW2eAYi7/XqKkmxoSoOykUt3MJx9+EkkrL17bxFSpkj1tvL\n"\
|
||||
"qvxn7egtsKjjgGNAxwXC4MwCvhveyUQQxtQb8AqGrGqo4jEEN0L15cnP38i2x1Uo\n"\
|
||||
"muhfskWf4MABV0yTUaKcGg==\n"\
|
||||
"-----END PRIVATE KEY-----\n"
|
||||
server_cert = '-----BEGIN CERTIFICATE-----\n' \
|
||||
'MIIDXTCCAkWgAwIBAgIJAP4LF7E72HakMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV\n'\
|
||||
'BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX\n'\
|
||||
'aWRnaXRzIFB0eSBMdGQwHhcNMTkwNjA3MDk1OTE2WhcNMjAwNjA2MDk1OTE2WjBF\n'\
|
||||
'MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50\n'\
|
||||
'ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB\n'\
|
||||
'CgKCAQEAlzfCyv3mIv7TlLkObxunKfCdrJ/zgdANrsx0RBtpEPhV560hWJ0fEin0\n'\
|
||||
'nIOMpJSiF9E6QsPdr6Q+eogH4XnOMU9JE+iG743N1dPfGEzJvRlyct/Ck8SswKPC\n'\
|
||||
'9+VXsnOdZmUw9y/xtANbURA/TspvPzz3Avv382ffffrJGh7ooOmaZSCZFlSYHLZA\n'\
|
||||
'w/XlRr0sSRbLpFGY0gXjaAV8iHHiPDYLy4kZOepjV9U51xi+IGsL4w75zuMgsHyF\n'\
|
||||
'3nJeGYHgtGVBrkL0ZKG5udY0wcBjysjubDJC4iSlNiq2HD3fhs7j6CZddV2v845M\n'\
|
||||
'lVKNxP0kO4Uj4D8r+5USWC8JKfAwxQIDAQABo1AwTjAdBgNVHQ4EFgQU6OE7ssfY\n'\
|
||||
'IIPTDThiUoofUpsD5NwwHwYDVR0jBBgwFoAU6OE7ssfYIIPTDThiUoofUpsD5Nww\n'\
|
||||
'DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAXIlHS/FJWfmcinUAxyBd\n'\
|
||||
'/xd5Lu8ykeru6oaUCci+Vk9lyoMMES7lQ+b/00d5x7AcTawkTil9EWpBTPTOTraA\n'\
|
||||
'lzJMQhNKmSLk0iIoTtAJtSZgUSpIIozqK6lenxQQDsHbXKU6h+u9H6KZE8YcjsFl\n'\
|
||||
'6vL7sw9BVotw/VxfgjQ5OSGLgoLrdVT0z5C2qOuwOgz1c7jNiJhtMdwN+cOtnJp2\n'\
|
||||
'fuBgEYyE3eeuWogvkWoDcIA8r17Ixzkpq2oJsdvZcHZPIZShPKW2SHUsl98KDemu\n'\
|
||||
'y0pQyExmQUbwKE4vbFb9XuWCcL9XaOHQytyszt2DeD67AipvoBwVU7/LBOvqnsmy\n'\
|
||||
'hA==\n'\
|
||||
'-----END CERTIFICATE-----\n'
|
||||
|
||||
server_key = '-----BEGIN PRIVATE KEY-----\n'\
|
||||
'MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCXN8LK/eYi/tOU\n'\
|
||||
'uQ5vG6cp8J2sn/OB0A2uzHREG2kQ+FXnrSFYnR8SKfScg4yklKIX0TpCw92vpD56\n'\
|
||||
'iAfhec4xT0kT6Ibvjc3V098YTMm9GXJy38KTxKzAo8L35Veyc51mZTD3L/G0A1tR\n'\
|
||||
'ED9Oym8/PPcC+/fzZ999+skaHuig6ZplIJkWVJgctkDD9eVGvSxJFsukUZjSBeNo\n'\
|
||||
'BXyIceI8NgvLiRk56mNX1TnXGL4gawvjDvnO4yCwfIXecl4ZgeC0ZUGuQvRkobm5\n'\
|
||||
'1jTBwGPKyO5sMkLiJKU2KrYcPd+GzuPoJl11Xa/zjkyVUo3E/SQ7hSPgPyv7lRJY\n'\
|
||||
'Lwkp8DDFAgMBAAECggEAfBhAfQE7mUByNbxgAgI5fot9eaqR1Nf+QpJ6X2H3KPwC\n'\
|
||||
'02sa0HOwieFwYfj6tB1doBoNq7i89mTc+QUlIn4pHgIowHO0OGawomeKz5BEhjCZ\n'\
|
||||
'4XeLYGSoODary2+kNkf2xY8JTfFEcyvGBpJEwc4S2VyYgRRx+IgnumTSH+N5mIKZ\n'\
|
||||
'SXWNdZIuHEmkwod+rPRXs6/r+PH0eVW6WfpINEbr4zVAGXJx2zXQwd2cuV1GTJWh\n'\
|
||||
'cPVOXLu+XJ9im9B370cYN6GqUnR3fui13urYbnWnEf3syvoH/zuZkyrVChauoFf8\n'\
|
||||
'8EGb74/HhXK7Q2s8NRakx2c7OxQifCbcy03liUMmyQKBgQDFAob5B/66N4Q2cq/N\n'\
|
||||
'MWPf98kYBYoLaeEOhEJhLQlKk0pIFCTmtpmUbpoEes2kCUbH7RwczpYko8tlKyoB\n'\
|
||||
'6Fn6RY4zQQ64KZJI6kQVsjkYpcP/ihnOY6rbds+3yyv+4uPX7Eh9sYZwZMggE19M\n'\
|
||||
'CkFHkwAjiwqhiiSlUxe20sWmowKBgQDEfx4lxuFzA1PBPeZKGVBTxYPQf+DSLCre\n'\
|
||||
'ZFg3ZmrxbCjRq1O7Lra4FXWD3dmRq7NDk79JofoW50yD8wD7I0B7opdDfXD2idO8\n'\
|
||||
'0dBnWUKDr2CAXyoLEINce9kJPbx4kFBQRN9PiGF7VkDQxeQ3kfS8CvcErpTKCOdy\n'\
|
||||
'5wOwBTwJdwKBgDiTFTeGeDv5nVoVbS67tDao7XKchJvqd9q3WGiXikeELJyuTDqE\n'\
|
||||
'zW22pTwMF+m3UEAxcxVCrhMvhkUzNAkANHaOatuFHzj7lyqhO5QPbh4J3FMR0X9X\n'\
|
||||
'V8VWRSg+jA/SECP9koOl6zlzd5Tee0tW1pA7QpryXscs6IEhb3ns5R2JAoGAIkzO\n'\
|
||||
'RmnhEOKTzDex611f2D+yMsMfy5BKK2f4vjLymBH5TiBKDXKqEpgsW0huoi8Gq9Uu\n'\
|
||||
'nvvXXAgkIyRYF36f0vUe0nkjLuYAQAWgC2pZYgNLJR13iVbol0xHJoXQUHtgiaJ8\n'\
|
||||
'GLYFzjHQPqFMpSalQe3oELko39uOC1CoJCHFySECgYBeycUnRBikCO2n8DNhY4Eg\n'\
|
||||
'9Y3oxcssRt6ea5BZwgW2eAYi7/XqKkmxoSoOykUt3MJx9+EkkrL17bxFSpkj1tvL\n'\
|
||||
'qvxn7egtsKjjgGNAxwXC4MwCvhveyUQQxtQb8AqGrGqo4jEEN0L15cnP38i2x1Uo\n'\
|
||||
'muhfskWf4MABV0yTUaKcGg==\n'\
|
||||
'-----END PRIVATE KEY-----\n'
|
||||
|
||||
|
||||
def get_my_ip():
|
||||
s1 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
s1.connect(("8.8.8.8", 80))
|
||||
s1.connect(('8.8.8.8', 80))
|
||||
my_ip = s1.getsockname()[0]
|
||||
s1.close()
|
||||
return my_ip
|
||||
@@ -81,16 +81,16 @@ def get_server_status(host_ip, port):
|
||||
|
||||
|
||||
def create_file(server_file, file_data):
|
||||
with open(server_file, "w+") as file:
|
||||
with open(server_file, 'w+') as file:
|
||||
file.write(file_data)
|
||||
|
||||
|
||||
def get_ca_cert(ota_image_dir):
|
||||
os.chdir(ota_image_dir)
|
||||
server_file = os.path.join(ota_image_dir, "server_cert.pem")
|
||||
server_file = os.path.join(ota_image_dir, 'server_cert.pem')
|
||||
create_file(server_file, server_cert)
|
||||
|
||||
key_file = os.path.join(ota_image_dir, "server_key.pem")
|
||||
key_file = os.path.join(ota_image_dir, 'server_key.pem')
|
||||
create_file(key_file, server_key)
|
||||
return server_file, key_file
|
||||
|
||||
@@ -131,11 +131,11 @@ def start_https_server(ota_image_dir, server_ip, server_port):
|
||||
|
||||
def start_chunked_server(ota_image_dir, server_port):
|
||||
server_file, key_file = get_ca_cert(ota_image_dir)
|
||||
chunked_server = subprocess.Popen(["openssl", "s_server", "-WWW", "-key", key_file, "-cert", server_file, "-port", str(server_port)])
|
||||
chunked_server = subprocess.Popen(['openssl', 's_server', '-WWW', '-key', key_file, '-cert', server_file, '-port', str(server_port)])
|
||||
return chunked_server
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_native_ota_example(env, extra_data):
|
||||
"""
|
||||
This is a positive test case, which downloads complete binary file multiple number of times.
|
||||
@@ -145,16 +145,16 @@ def test_examples_protocol_native_ota_example(env, extra_data):
|
||||
2. Fetch OTA image over HTTPS
|
||||
3. Reboot with the new OTA image
|
||||
"""
|
||||
dut1 = env.get_dut("native_ota_example", "examples/system/ota/native_ota_example", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('native_ota_example', 'examples/system/ota/native_ota_example', dut_class=ttfw_idf.ESP32DUT)
|
||||
server_port = 8002
|
||||
# No. of times working of application to be validated
|
||||
iterations = 3
|
||||
# File to be downloaded. This file is generated after compilation
|
||||
bin_name = "native_ota.bin"
|
||||
bin_name = 'native_ota.bin'
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, bin_name)
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("native_ota_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('native_ota_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
@@ -163,23 +163,23 @@ def test_examples_protocol_native_ota_example(env, extra_data):
|
||||
thread1.start()
|
||||
dut1.start_app()
|
||||
for i in range(iterations):
|
||||
dut1.expect("Loaded app from partition at offset", timeout=30)
|
||||
dut1.expect('Loaded app from partition at offset', timeout=30)
|
||||
try:
|
||||
ip_address = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30)
|
||||
print("Connected to AP with IP: {}".format(ip_address))
|
||||
ip_address = dut1.expect(re.compile(r' sta ip: ([^,]+),'), timeout=30)
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except DUT.ExpectTimeout:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
thread1.close()
|
||||
dut1.expect("Starting OTA example", timeout=30)
|
||||
dut1.expect('Starting OTA example', timeout=30)
|
||||
|
||||
print("writing to device: {}".format("https://" + host_ip + ":" + str(server_port) + "/" + bin_name))
|
||||
dut1.write("https://" + host_ip + ":" + str(server_port) + "/" + bin_name)
|
||||
dut1.expect("Loaded app from partition at offset", timeout=60)
|
||||
dut1.expect("Starting OTA example", timeout=30)
|
||||
print('writing to device: {}'.format('https://' + host_ip + ':' + str(server_port) + '/' + bin_name))
|
||||
dut1.write('https://' + host_ip + ':' + str(server_port) + '/' + bin_name)
|
||||
dut1.expect('Loaded app from partition at offset', timeout=60)
|
||||
dut1.expect('Starting OTA example', timeout=30)
|
||||
dut1.reset()
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_native_ota_example_truncated_bin(env, extra_data):
|
||||
"""
|
||||
Working of OTA if binary file is truncated is validated in this test case.
|
||||
@@ -190,25 +190,25 @@ def test_examples_protocol_native_ota_example_truncated_bin(env, extra_data):
|
||||
3. Fetch OTA image over HTTPS
|
||||
4. Check working of code if bin is truncated
|
||||
"""
|
||||
dut1 = env.get_dut("native_ota_example", "examples/system/ota/native_ota_example", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('native_ota_example', 'examples/system/ota/native_ota_example', dut_class=ttfw_idf.ESP32DUT)
|
||||
server_port = 8002
|
||||
# Original binary file generated after compilation
|
||||
bin_name = "native_ota.bin"
|
||||
bin_name = 'native_ota.bin'
|
||||
# Truncated binary file to be generated from original binary file
|
||||
truncated_bin_name = "truncated.bin"
|
||||
truncated_bin_name = 'truncated.bin'
|
||||
# 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
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, bin_name)
|
||||
f = open(binary_file, "rb+")
|
||||
fo = open(os.path.join(dut1.app.binary_path, truncated_bin_name), "wb+")
|
||||
f = open(binary_file, 'rb+')
|
||||
fo = open(os.path.join(dut1.app.binary_path, truncated_bin_name), 'wb+')
|
||||
fo.write(f.read(truncated_bin_size))
|
||||
fo.close()
|
||||
f.close()
|
||||
binary_file = os.path.join(dut1.app.binary_path, truncated_bin_name)
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("native_ota_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('native_ota_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
@@ -216,21 +216,21 @@ def test_examples_protocol_native_ota_example_truncated_bin(env, extra_data):
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
dut1.start_app()
|
||||
dut1.expect("Loaded app from partition at offset", timeout=30)
|
||||
dut1.expect('Loaded app from partition at offset', timeout=30)
|
||||
try:
|
||||
ip_address = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=60)
|
||||
print("Connected to AP with IP: {}".format(ip_address))
|
||||
ip_address = dut1.expect(re.compile(r' sta ip: ([^,]+),'), timeout=60)
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except DUT.ExpectTimeout:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
dut1.expect("Starting OTA example", timeout=30)
|
||||
dut1.expect('Starting 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("native_ota_example: Image validation failed, image is corrupted", timeout=20)
|
||||
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('native_ota_example: Image validation failed, image is corrupted', timeout=20)
|
||||
os.remove(binary_file)
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_native_ota_example_truncated_header(env, extra_data):
|
||||
"""
|
||||
Working of OTA if headers of binary file are truncated is vaildated in this test case.
|
||||
@@ -241,24 +241,24 @@ def test_examples_protocol_native_ota_example_truncated_header(env, extra_data):
|
||||
3. Fetch OTA image over HTTPS
|
||||
4. Check working of code if headers are not sent completely
|
||||
"""
|
||||
dut1 = env.get_dut("native_ota_example", "examples/system/ota/native_ota_example", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('native_ota_example', 'examples/system/ota/native_ota_example', dut_class=ttfw_idf.ESP32DUT)
|
||||
server_port = 8002
|
||||
# Original binary file generated after compilation
|
||||
bin_name = "native_ota.bin"
|
||||
bin_name = 'native_ota.bin'
|
||||
# Truncated binary file to be generated from original binary file
|
||||
truncated_bin_name = "truncated_header.bin"
|
||||
truncated_bin_name = 'truncated_header.bin'
|
||||
# Size of truncated file to be grnerated. This value should be less than 288 bytes (Image header size)
|
||||
truncated_bin_size = 180
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, bin_name)
|
||||
f = open(binary_file, "rb+")
|
||||
fo = open(os.path.join(dut1.app.binary_path, truncated_bin_name), "wb+")
|
||||
f = open(binary_file, 'rb+')
|
||||
fo = open(os.path.join(dut1.app.binary_path, truncated_bin_name), 'wb+')
|
||||
fo.write(f.read(truncated_bin_size))
|
||||
fo.close()
|
||||
f.close()
|
||||
binary_file = os.path.join(dut1.app.binary_path, truncated_bin_name)
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("native_ota_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('native_ota_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
@@ -266,21 +266,21 @@ def test_examples_protocol_native_ota_example_truncated_header(env, extra_data):
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
dut1.start_app()
|
||||
dut1.expect("Loaded app from partition at offset", timeout=30)
|
||||
dut1.expect('Loaded app from partition at offset', timeout=30)
|
||||
try:
|
||||
ip_address = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=60)
|
||||
print("Connected to AP with IP: {}".format(ip_address))
|
||||
ip_address = dut1.expect(re.compile(r' sta ip: ([^,]+),'), timeout=60)
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except DUT.ExpectTimeout:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
dut1.expect("Starting OTA example", timeout=30)
|
||||
dut1.expect('Starting 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("native_ota_example: received package is not fit len", timeout=20)
|
||||
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('native_ota_example: received package is not fit len', timeout=20)
|
||||
os.remove(binary_file)
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_native_ota_example_random(env, extra_data):
|
||||
"""
|
||||
Working of OTA if random data is added in binary file are validated in this test case.
|
||||
@@ -291,23 +291,23 @@ def test_examples_protocol_native_ota_example_random(env, extra_data):
|
||||
3. Fetch OTA image over HTTPS
|
||||
4. Check working of code for random binary file
|
||||
"""
|
||||
dut1 = env.get_dut("native_ota_example", "examples/system/ota/native_ota_example", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('native_ota_example', 'examples/system/ota/native_ota_example', dut_class=ttfw_idf.ESP32DUT)
|
||||
server_port = 8002
|
||||
# Random binary file to be generated
|
||||
random_bin_name = "random.bin"
|
||||
random_bin_name = 'random.bin'
|
||||
# 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
|
||||
binary_file = os.path.join(dut1.app.binary_path, random_bin_name)
|
||||
fo = open(binary_file, "wb+")
|
||||
fo = open(binary_file, 'wb+')
|
||||
# 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))
|
||||
fo.write(struct.pack('B', 0))
|
||||
for i in range(random_bin_size - 1):
|
||||
fo.write(struct.pack("B", random.randrange(0,255,1)))
|
||||
fo.write(struct.pack('B', random.randrange(0,255,1)))
|
||||
fo.close()
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("native_ota_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('native_ota_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
if (get_server_status(host_ip, server_port) is False):
|
||||
@@ -315,21 +315,21 @@ def test_examples_protocol_native_ota_example_random(env, extra_data):
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
dut1.start_app()
|
||||
dut1.expect("Loaded app from partition at offset", timeout=30)
|
||||
dut1.expect('Loaded app from partition at offset', timeout=30)
|
||||
try:
|
||||
ip_address = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=60)
|
||||
print("Connected to AP with IP: {}".format(ip_address))
|
||||
ip_address = dut1.expect(re.compile(r' sta ip: ([^,]+),'), timeout=60)
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except DUT.ExpectTimeout:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
dut1.expect("Starting OTA example", timeout=30)
|
||||
dut1.expect('Starting 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=20)
|
||||
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=20)
|
||||
os.remove(binary_file)
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_native_ota_example_chunked(env, extra_data):
|
||||
"""
|
||||
This is a positive test case, which downloads complete binary file multiple number of times.
|
||||
@@ -339,32 +339,32 @@ def test_examples_protocol_native_ota_example_chunked(env, extra_data):
|
||||
2. Fetch OTA image over HTTPS
|
||||
3. Reboot with the new OTA image
|
||||
"""
|
||||
dut1 = env.get_dut("native_ota_example", "examples/system/ota/native_ota_example", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('native_ota_example', 'examples/system/ota/native_ota_example', dut_class=ttfw_idf.ESP32DUT)
|
||||
# File to be downloaded. This file is generated after compilation
|
||||
bin_name = "native_ota.bin"
|
||||
bin_name = 'native_ota.bin'
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, bin_name)
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("native_ota_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('native_ota_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
chunked_server = start_chunked_server(dut1.app.binary_path, 8070)
|
||||
dut1.start_app()
|
||||
dut1.expect("Loaded app from partition at offset", timeout=30)
|
||||
dut1.expect('Loaded app from partition at offset', timeout=30)
|
||||
try:
|
||||
ip_address = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30)
|
||||
print("Connected to AP with IP: {}".format(ip_address))
|
||||
ip_address = dut1.expect(re.compile(r' sta ip: ([^,]+),'), timeout=30)
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except DUT.ExpectTimeout:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
|
||||
dut1.expect("Starting OTA example", timeout=30)
|
||||
print("writing to device: {}".format("https://" + host_ip + ":8070/" + bin_name))
|
||||
dut1.write("https://" + host_ip + ":8070/" + bin_name)
|
||||
dut1.expect("Loaded app from partition at offset", timeout=60)
|
||||
dut1.expect("Starting OTA example", timeout=30)
|
||||
dut1.expect('Starting OTA example', timeout=30)
|
||||
print('writing to device: {}'.format('https://' + host_ip + ':8070/' + bin_name))
|
||||
dut1.write('https://' + host_ip + ':8070/' + bin_name)
|
||||
dut1.expect('Loaded app from partition at offset', timeout=60)
|
||||
dut1.expect('Starting OTA example', timeout=30)
|
||||
chunked_server.kill()
|
||||
os.remove(os.path.join(dut1.app.binary_path, "server_cert.pem"))
|
||||
os.remove(os.path.join(dut1.app.binary_path, "server_key.pem"))
|
||||
os.remove(os.path.join(dut1.app.binary_path, 'server_cert.pem'))
|
||||
os.remove(os.path.join(dut1.app.binary_path, 'server_key.pem'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
@@ -12,22 +13,22 @@ def test_otatool_example(env, extra_data):
|
||||
|
||||
# Verify factory firmware
|
||||
dut.start_app()
|
||||
dut.expect("OTA Tool Example")
|
||||
dut.expect("Example end")
|
||||
dut.expect('OTA Tool Example')
|
||||
dut.expect('Example end')
|
||||
|
||||
# Close connection to DUT
|
||||
dut.receive_thread.exit()
|
||||
dut.port_inst.close()
|
||||
|
||||
script_path = os.path.join(os.getenv("IDF_PATH"), "examples", "system", "ota", "otatool", "otatool_example.py")
|
||||
binary_path = ""
|
||||
script_path = os.path.join(os.getenv('IDF_PATH'), 'examples', 'system', 'ota', 'otatool', 'otatool_example.py')
|
||||
binary_path = ''
|
||||
|
||||
for flash_file in dut.app.flash_files:
|
||||
if "otatool.bin" in flash_file[1]:
|
||||
if 'otatool.bin' in flash_file[1]:
|
||||
binary_path = flash_file[1]
|
||||
break
|
||||
|
||||
subprocess.check_call([sys.executable, script_path, "--binary", binary_path])
|
||||
subprocess.check_call([sys.executable, script_path, '--binary', binary_path])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -16,34 +16,34 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
import os
|
||||
import sys
|
||||
import serial
|
||||
import subprocess
|
||||
import re
|
||||
import argparse
|
||||
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
from subprocess import CalledProcessError
|
||||
|
||||
import serial
|
||||
|
||||
|
||||
def get_running_partition(port=None):
|
||||
# Monitor the serial output of target device. The firmware outputs the currently
|
||||
# running partition
|
||||
|
||||
IDF_PATH = os.path.expandvars("$IDF_PATH")
|
||||
IDF_PATH = os.path.expandvars('$IDF_PATH')
|
||||
sys.path.append(os.path.join(IDF_PATH, 'components', 'esptool_py', 'esptool'))
|
||||
import esptool
|
||||
|
||||
ESPTOOL_PY = os.path.join(IDF_PATH, "components", "esptool_py", "esptool", "esptool.py")
|
||||
ESPTOOL_PY = os.path.join(IDF_PATH, 'components', 'esptool_py', 'esptool', 'esptool.py')
|
||||
|
||||
baud = os.environ.get("ESPTOOL_BAUD", esptool.ESPLoader.ESP_ROM_BAUD)
|
||||
baud = os.environ.get('ESPTOOL_BAUD', esptool.ESPLoader.ESP_ROM_BAUD)
|
||||
|
||||
if not port:
|
||||
error_message = "Unable to obtain default target device port.\nSerial log:\n\n"
|
||||
error_message = 'Unable to obtain default target device port.\nSerial log:\n\n'
|
||||
try:
|
||||
# Check what esptool.py finds on what port the device is connected to
|
||||
output = subprocess.check_output([sys.executable, ESPTOOL_PY, "chip_id"]) # may raise CalledProcessError
|
||||
pattern = r"Serial port ([\S]+)"
|
||||
output = subprocess.check_output([sys.executable, ESPTOOL_PY, 'chip_id']) # may raise CalledProcessError
|
||||
pattern = r'Serial port ([\S]+)'
|
||||
pattern = re.compile(pattern.encode())
|
||||
|
||||
port = re.search(pattern, output).group(1) # may raise AttributeError
|
||||
@@ -52,7 +52,7 @@ def get_running_partition(port=None):
|
||||
except AttributeError:
|
||||
raise Exception(error_message + output)
|
||||
|
||||
serial_instance = serial.serial_for_url(port.decode("utf-8"), baud, do_not_open=True)
|
||||
serial_instance = serial.serial_for_url(port.decode('utf-8'), baud, do_not_open=True)
|
||||
|
||||
serial_instance.dtr = False
|
||||
serial_instance.rts = False
|
||||
@@ -62,16 +62,16 @@ def get_running_partition(port=None):
|
||||
serial_instance.rts = False
|
||||
|
||||
# Read until example end and find the currently running partition string
|
||||
content = serial_instance.read_until(b"Example end")
|
||||
pattern = re.compile(b"Running partition: ([a-z0-9_]+)")
|
||||
content = serial_instance.read_until(b'Example end')
|
||||
pattern = re.compile(b'Running partition: ([a-z0-9_]+)')
|
||||
running = re.search(pattern, content).group(1)
|
||||
|
||||
return running.decode("utf-8")
|
||||
return running.decode('utf-8')
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--port", default=None)
|
||||
parser.add_argument('--port', default=None)
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
@@ -83,5 +83,5 @@ def main():
|
||||
print(res)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
@@ -16,16 +16,16 @@
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
import argparse
|
||||
|
||||
from get_running_partition import get_running_partition
|
||||
|
||||
|
||||
def assert_file_same(file1, file2, err):
|
||||
with open(file1, "rb") as f1:
|
||||
with open(file2, "rb") as f2:
|
||||
with open(file1, 'rb') as f1:
|
||||
with open(file2, 'rb') as f2:
|
||||
f1 = f1.read()
|
||||
f2 = f2.read()
|
||||
|
||||
@@ -41,75 +41,75 @@ def assert_file_same(file1, file2, err):
|
||||
def assert_running_partition(expected, port=None):
|
||||
running = get_running_partition(port)
|
||||
if running != expected:
|
||||
raise Exception("Running partition %s does not match expected %s" % (running, expected))
|
||||
raise Exception('Running partition %s does not match expected %s' % (running, expected))
|
||||
|
||||
|
||||
def main():
|
||||
COMPONENTS_PATH = os.path.expandvars(os.path.join("$IDF_PATH", "components"))
|
||||
OTATOOL_DIR = os.path.join(COMPONENTS_PATH, "app_update")
|
||||
COMPONENTS_PATH = os.path.expandvars(os.path.join('$IDF_PATH', 'components'))
|
||||
OTATOOL_DIR = os.path.join(COMPONENTS_PATH, 'app_update')
|
||||
|
||||
sys.path.append(OTATOOL_DIR)
|
||||
from otatool import OtatoolTarget
|
||||
|
||||
parser = argparse.ArgumentParser("ESP-IDF OTA Tool Example")
|
||||
parser = argparse.ArgumentParser('ESP-IDF OTA Tool Example')
|
||||
|
||||
parser.add_argument("--port", "-p", help="port where the device to perform operations on is connected")
|
||||
parser.add_argument("--binary", "-b", help="path to built example binary", default=os.path.join("build", "otatool.bin"))
|
||||
parser.add_argument('--port', '-p', help='port where the device to perform operations on is connected')
|
||||
parser.add_argument('--binary', '-b', help='path to built example binary', default=os.path.join('build', 'otatool.bin'))
|
||||
args = parser.parse_args()
|
||||
|
||||
target = OtatoolTarget(args.port)
|
||||
|
||||
print("Writing factory firmware to ota_0")
|
||||
print('Writing factory firmware to ota_0')
|
||||
target.write_ota_partition(0, args.binary)
|
||||
|
||||
print("Writing factory firmware to ota_1")
|
||||
target.write_ota_partition("ota_1", args.binary)
|
||||
print('Writing factory firmware to ota_1')
|
||||
target.write_ota_partition('ota_1', args.binary)
|
||||
|
||||
# Verify that the contents of the two ota slots are the same as that of the factory partition
|
||||
print("Checking written firmware to ota_0 and ota_1 match factory firmware")
|
||||
target.read_ota_partition("ota_0", "app0.bin")
|
||||
target.read_ota_partition(1, "app1.bin")
|
||||
print('Checking written firmware to ota_0 and ota_1 match factory firmware')
|
||||
target.read_ota_partition('ota_0', 'app0.bin')
|
||||
target.read_ota_partition(1, 'app1.bin')
|
||||
|
||||
assert_file_same("app0.bin", args.binary, "Slot 0 app does not match factory app")
|
||||
assert_file_same("app1.bin", args.binary, "Slot 1 app does not match factory app")
|
||||
assert_file_same('app0.bin', args.binary, 'Slot 0 app does not match factory app')
|
||||
assert_file_same('app1.bin', args.binary, 'Slot 1 app does not match factory app')
|
||||
|
||||
# Switch to factory app
|
||||
print("Switching to factory app")
|
||||
print('Switching to factory app')
|
||||
target.erase_otadata()
|
||||
assert_running_partition("factory")
|
||||
assert_running_partition('factory')
|
||||
|
||||
# Switch to slot 0
|
||||
print("Switching to OTA slot 0")
|
||||
print('Switching to OTA slot 0')
|
||||
target.switch_ota_partition(0)
|
||||
assert_running_partition("ota_0")
|
||||
assert_running_partition('ota_0')
|
||||
|
||||
# Switch to slot 1 twice in a row
|
||||
print("Switching to OTA slot 1 (twice in a row)")
|
||||
print('Switching to OTA slot 1 (twice in a row)')
|
||||
target.switch_ota_partition(1)
|
||||
assert_running_partition("ota_1")
|
||||
target.switch_ota_partition("ota_1")
|
||||
assert_running_partition("ota_1")
|
||||
assert_running_partition('ota_1')
|
||||
target.switch_ota_partition('ota_1')
|
||||
assert_running_partition('ota_1')
|
||||
|
||||
# Switch to slot 0 twice in a row
|
||||
print("Switching to OTA slot 0 (twice in a row)")
|
||||
print('Switching to OTA slot 0 (twice in a row)')
|
||||
target.switch_ota_partition(0)
|
||||
assert_running_partition("ota_0")
|
||||
target.switch_ota_partition("ota_0")
|
||||
assert_running_partition("ota_0")
|
||||
assert_running_partition('ota_0')
|
||||
target.switch_ota_partition('ota_0')
|
||||
assert_running_partition('ota_0')
|
||||
|
||||
# Switch to factory app
|
||||
print("Switching to factory app")
|
||||
print('Switching to factory app')
|
||||
target.erase_otadata()
|
||||
assert_running_partition("factory")
|
||||
assert_running_partition('factory')
|
||||
|
||||
# Switch to slot 1
|
||||
print("Switching to OTA slot 1")
|
||||
print('Switching to OTA slot 1')
|
||||
target.switch_ota_partition(1)
|
||||
assert_running_partition("ota_1")
|
||||
assert_running_partition('ota_1')
|
||||
|
||||
# Example end and cleanup
|
||||
print("\nOTA tool operations executed successfully!")
|
||||
clean_files = ["app0.bin", "app1.bin"]
|
||||
print('\nOTA tool operations executed successfully!')
|
||||
clean_files = ['app0.bin', 'app1.bin']
|
||||
for clean_file in clean_files:
|
||||
os.unlink(clean_file)
|
||||
|
||||
|
||||
@@ -1,68 +1,68 @@
|
||||
import re
|
||||
import os
|
||||
import socket
|
||||
import http.server
|
||||
from threading import Thread
|
||||
import os
|
||||
import re
|
||||
import socket
|
||||
import ssl
|
||||
from threading import Thread
|
||||
|
||||
from tiny_test_fw import DUT
|
||||
import ttfw_idf
|
||||
from tiny_test_fw import DUT
|
||||
|
||||
server_cert = "-----BEGIN CERTIFICATE-----\n" \
|
||||
"MIIDXTCCAkWgAwIBAgIJAP4LF7E72HakMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV\n"\
|
||||
"BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX\n"\
|
||||
"aWRnaXRzIFB0eSBMdGQwHhcNMTkwNjA3MDk1OTE2WhcNMjAwNjA2MDk1OTE2WjBF\n"\
|
||||
"MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50\n"\
|
||||
"ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB\n"\
|
||||
"CgKCAQEAlzfCyv3mIv7TlLkObxunKfCdrJ/zgdANrsx0RBtpEPhV560hWJ0fEin0\n"\
|
||||
"nIOMpJSiF9E6QsPdr6Q+eogH4XnOMU9JE+iG743N1dPfGEzJvRlyct/Ck8SswKPC\n"\
|
||||
"9+VXsnOdZmUw9y/xtANbURA/TspvPzz3Avv382ffffrJGh7ooOmaZSCZFlSYHLZA\n"\
|
||||
"w/XlRr0sSRbLpFGY0gXjaAV8iHHiPDYLy4kZOepjV9U51xi+IGsL4w75zuMgsHyF\n"\
|
||||
"3nJeGYHgtGVBrkL0ZKG5udY0wcBjysjubDJC4iSlNiq2HD3fhs7j6CZddV2v845M\n"\
|
||||
"lVKNxP0kO4Uj4D8r+5USWC8JKfAwxQIDAQABo1AwTjAdBgNVHQ4EFgQU6OE7ssfY\n"\
|
||||
"IIPTDThiUoofUpsD5NwwHwYDVR0jBBgwFoAU6OE7ssfYIIPTDThiUoofUpsD5Nww\n"\
|
||||
"DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAXIlHS/FJWfmcinUAxyBd\n"\
|
||||
"/xd5Lu8ykeru6oaUCci+Vk9lyoMMES7lQ+b/00d5x7AcTawkTil9EWpBTPTOTraA\n"\
|
||||
"lzJMQhNKmSLk0iIoTtAJtSZgUSpIIozqK6lenxQQDsHbXKU6h+u9H6KZE8YcjsFl\n"\
|
||||
"6vL7sw9BVotw/VxfgjQ5OSGLgoLrdVT0z5C2qOuwOgz1c7jNiJhtMdwN+cOtnJp2\n"\
|
||||
"fuBgEYyE3eeuWogvkWoDcIA8r17Ixzkpq2oJsdvZcHZPIZShPKW2SHUsl98KDemu\n"\
|
||||
"y0pQyExmQUbwKE4vbFb9XuWCcL9XaOHQytyszt2DeD67AipvoBwVU7/LBOvqnsmy\n"\
|
||||
"hA==\n"\
|
||||
"-----END CERTIFICATE-----\n"
|
||||
server_cert = '-----BEGIN CERTIFICATE-----\n' \
|
||||
'MIIDXTCCAkWgAwIBAgIJAP4LF7E72HakMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV\n'\
|
||||
'BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX\n'\
|
||||
'aWRnaXRzIFB0eSBMdGQwHhcNMTkwNjA3MDk1OTE2WhcNMjAwNjA2MDk1OTE2WjBF\n'\
|
||||
'MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50\n'\
|
||||
'ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB\n'\
|
||||
'CgKCAQEAlzfCyv3mIv7TlLkObxunKfCdrJ/zgdANrsx0RBtpEPhV560hWJ0fEin0\n'\
|
||||
'nIOMpJSiF9E6QsPdr6Q+eogH4XnOMU9JE+iG743N1dPfGEzJvRlyct/Ck8SswKPC\n'\
|
||||
'9+VXsnOdZmUw9y/xtANbURA/TspvPzz3Avv382ffffrJGh7ooOmaZSCZFlSYHLZA\n'\
|
||||
'w/XlRr0sSRbLpFGY0gXjaAV8iHHiPDYLy4kZOepjV9U51xi+IGsL4w75zuMgsHyF\n'\
|
||||
'3nJeGYHgtGVBrkL0ZKG5udY0wcBjysjubDJC4iSlNiq2HD3fhs7j6CZddV2v845M\n'\
|
||||
'lVKNxP0kO4Uj4D8r+5USWC8JKfAwxQIDAQABo1AwTjAdBgNVHQ4EFgQU6OE7ssfY\n'\
|
||||
'IIPTDThiUoofUpsD5NwwHwYDVR0jBBgwFoAU6OE7ssfYIIPTDThiUoofUpsD5Nww\n'\
|
||||
'DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAXIlHS/FJWfmcinUAxyBd\n'\
|
||||
'/xd5Lu8ykeru6oaUCci+Vk9lyoMMES7lQ+b/00d5x7AcTawkTil9EWpBTPTOTraA\n'\
|
||||
'lzJMQhNKmSLk0iIoTtAJtSZgUSpIIozqK6lenxQQDsHbXKU6h+u9H6KZE8YcjsFl\n'\
|
||||
'6vL7sw9BVotw/VxfgjQ5OSGLgoLrdVT0z5C2qOuwOgz1c7jNiJhtMdwN+cOtnJp2\n'\
|
||||
'fuBgEYyE3eeuWogvkWoDcIA8r17Ixzkpq2oJsdvZcHZPIZShPKW2SHUsl98KDemu\n'\
|
||||
'y0pQyExmQUbwKE4vbFb9XuWCcL9XaOHQytyszt2DeD67AipvoBwVU7/LBOvqnsmy\n'\
|
||||
'hA==\n'\
|
||||
'-----END CERTIFICATE-----\n'
|
||||
|
||||
server_key = "-----BEGIN PRIVATE KEY-----\n"\
|
||||
"MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCXN8LK/eYi/tOU\n"\
|
||||
"uQ5vG6cp8J2sn/OB0A2uzHREG2kQ+FXnrSFYnR8SKfScg4yklKIX0TpCw92vpD56\n"\
|
||||
"iAfhec4xT0kT6Ibvjc3V098YTMm9GXJy38KTxKzAo8L35Veyc51mZTD3L/G0A1tR\n"\
|
||||
"ED9Oym8/PPcC+/fzZ999+skaHuig6ZplIJkWVJgctkDD9eVGvSxJFsukUZjSBeNo\n"\
|
||||
"BXyIceI8NgvLiRk56mNX1TnXGL4gawvjDvnO4yCwfIXecl4ZgeC0ZUGuQvRkobm5\n"\
|
||||
"1jTBwGPKyO5sMkLiJKU2KrYcPd+GzuPoJl11Xa/zjkyVUo3E/SQ7hSPgPyv7lRJY\n"\
|
||||
"Lwkp8DDFAgMBAAECggEAfBhAfQE7mUByNbxgAgI5fot9eaqR1Nf+QpJ6X2H3KPwC\n"\
|
||||
"02sa0HOwieFwYfj6tB1doBoNq7i89mTc+QUlIn4pHgIowHO0OGawomeKz5BEhjCZ\n"\
|
||||
"4XeLYGSoODary2+kNkf2xY8JTfFEcyvGBpJEwc4S2VyYgRRx+IgnumTSH+N5mIKZ\n"\
|
||||
"SXWNdZIuHEmkwod+rPRXs6/r+PH0eVW6WfpINEbr4zVAGXJx2zXQwd2cuV1GTJWh\n"\
|
||||
"cPVOXLu+XJ9im9B370cYN6GqUnR3fui13urYbnWnEf3syvoH/zuZkyrVChauoFf8\n"\
|
||||
"8EGb74/HhXK7Q2s8NRakx2c7OxQifCbcy03liUMmyQKBgQDFAob5B/66N4Q2cq/N\n"\
|
||||
"MWPf98kYBYoLaeEOhEJhLQlKk0pIFCTmtpmUbpoEes2kCUbH7RwczpYko8tlKyoB\n"\
|
||||
"6Fn6RY4zQQ64KZJI6kQVsjkYpcP/ihnOY6rbds+3yyv+4uPX7Eh9sYZwZMggE19M\n"\
|
||||
"CkFHkwAjiwqhiiSlUxe20sWmowKBgQDEfx4lxuFzA1PBPeZKGVBTxYPQf+DSLCre\n"\
|
||||
"ZFg3ZmrxbCjRq1O7Lra4FXWD3dmRq7NDk79JofoW50yD8wD7I0B7opdDfXD2idO8\n"\
|
||||
"0dBnWUKDr2CAXyoLEINce9kJPbx4kFBQRN9PiGF7VkDQxeQ3kfS8CvcErpTKCOdy\n"\
|
||||
"5wOwBTwJdwKBgDiTFTeGeDv5nVoVbS67tDao7XKchJvqd9q3WGiXikeELJyuTDqE\n"\
|
||||
"zW22pTwMF+m3UEAxcxVCrhMvhkUzNAkANHaOatuFHzj7lyqhO5QPbh4J3FMR0X9X\n"\
|
||||
"V8VWRSg+jA/SECP9koOl6zlzd5Tee0tW1pA7QpryXscs6IEhb3ns5R2JAoGAIkzO\n"\
|
||||
"RmnhEOKTzDex611f2D+yMsMfy5BKK2f4vjLymBH5TiBKDXKqEpgsW0huoi8Gq9Uu\n"\
|
||||
"nvvXXAgkIyRYF36f0vUe0nkjLuYAQAWgC2pZYgNLJR13iVbol0xHJoXQUHtgiaJ8\n"\
|
||||
"GLYFzjHQPqFMpSalQe3oELko39uOC1CoJCHFySECgYBeycUnRBikCO2n8DNhY4Eg\n"\
|
||||
"9Y3oxcssRt6ea5BZwgW2eAYi7/XqKkmxoSoOykUt3MJx9+EkkrL17bxFSpkj1tvL\n"\
|
||||
"qvxn7egtsKjjgGNAxwXC4MwCvhveyUQQxtQb8AqGrGqo4jEEN0L15cnP38i2x1Uo\n"\
|
||||
"muhfskWf4MABV0yTUaKcGg==\n"\
|
||||
"-----END PRIVATE KEY-----\n"
|
||||
server_key = '-----BEGIN PRIVATE KEY-----\n'\
|
||||
'MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCXN8LK/eYi/tOU\n'\
|
||||
'uQ5vG6cp8J2sn/OB0A2uzHREG2kQ+FXnrSFYnR8SKfScg4yklKIX0TpCw92vpD56\n'\
|
||||
'iAfhec4xT0kT6Ibvjc3V098YTMm9GXJy38KTxKzAo8L35Veyc51mZTD3L/G0A1tR\n'\
|
||||
'ED9Oym8/PPcC+/fzZ999+skaHuig6ZplIJkWVJgctkDD9eVGvSxJFsukUZjSBeNo\n'\
|
||||
'BXyIceI8NgvLiRk56mNX1TnXGL4gawvjDvnO4yCwfIXecl4ZgeC0ZUGuQvRkobm5\n'\
|
||||
'1jTBwGPKyO5sMkLiJKU2KrYcPd+GzuPoJl11Xa/zjkyVUo3E/SQ7hSPgPyv7lRJY\n'\
|
||||
'Lwkp8DDFAgMBAAECggEAfBhAfQE7mUByNbxgAgI5fot9eaqR1Nf+QpJ6X2H3KPwC\n'\
|
||||
'02sa0HOwieFwYfj6tB1doBoNq7i89mTc+QUlIn4pHgIowHO0OGawomeKz5BEhjCZ\n'\
|
||||
'4XeLYGSoODary2+kNkf2xY8JTfFEcyvGBpJEwc4S2VyYgRRx+IgnumTSH+N5mIKZ\n'\
|
||||
'SXWNdZIuHEmkwod+rPRXs6/r+PH0eVW6WfpINEbr4zVAGXJx2zXQwd2cuV1GTJWh\n'\
|
||||
'cPVOXLu+XJ9im9B370cYN6GqUnR3fui13urYbnWnEf3syvoH/zuZkyrVChauoFf8\n'\
|
||||
'8EGb74/HhXK7Q2s8NRakx2c7OxQifCbcy03liUMmyQKBgQDFAob5B/66N4Q2cq/N\n'\
|
||||
'MWPf98kYBYoLaeEOhEJhLQlKk0pIFCTmtpmUbpoEes2kCUbH7RwczpYko8tlKyoB\n'\
|
||||
'6Fn6RY4zQQ64KZJI6kQVsjkYpcP/ihnOY6rbds+3yyv+4uPX7Eh9sYZwZMggE19M\n'\
|
||||
'CkFHkwAjiwqhiiSlUxe20sWmowKBgQDEfx4lxuFzA1PBPeZKGVBTxYPQf+DSLCre\n'\
|
||||
'ZFg3ZmrxbCjRq1O7Lra4FXWD3dmRq7NDk79JofoW50yD8wD7I0B7opdDfXD2idO8\n'\
|
||||
'0dBnWUKDr2CAXyoLEINce9kJPbx4kFBQRN9PiGF7VkDQxeQ3kfS8CvcErpTKCOdy\n'\
|
||||
'5wOwBTwJdwKBgDiTFTeGeDv5nVoVbS67tDao7XKchJvqd9q3WGiXikeELJyuTDqE\n'\
|
||||
'zW22pTwMF+m3UEAxcxVCrhMvhkUzNAkANHaOatuFHzj7lyqhO5QPbh4J3FMR0X9X\n'\
|
||||
'V8VWRSg+jA/SECP9koOl6zlzd5Tee0tW1pA7QpryXscs6IEhb3ns5R2JAoGAIkzO\n'\
|
||||
'RmnhEOKTzDex611f2D+yMsMfy5BKK2f4vjLymBH5TiBKDXKqEpgsW0huoi8Gq9Uu\n'\
|
||||
'nvvXXAgkIyRYF36f0vUe0nkjLuYAQAWgC2pZYgNLJR13iVbol0xHJoXQUHtgiaJ8\n'\
|
||||
'GLYFzjHQPqFMpSalQe3oELko39uOC1CoJCHFySECgYBeycUnRBikCO2n8DNhY4Eg\n'\
|
||||
'9Y3oxcssRt6ea5BZwgW2eAYi7/XqKkmxoSoOykUt3MJx9+EkkrL17bxFSpkj1tvL\n'\
|
||||
'qvxn7egtsKjjgGNAxwXC4MwCvhveyUQQxtQb8AqGrGqo4jEEN0L15cnP38i2x1Uo\n'\
|
||||
'muhfskWf4MABV0yTUaKcGg==\n'\
|
||||
'-----END PRIVATE KEY-----\n'
|
||||
|
||||
|
||||
def get_my_ip():
|
||||
s1 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
s1.connect(("8.8.8.8", 80))
|
||||
s1.connect(('8.8.8.8', 80))
|
||||
my_ip = s1.getsockname()[0]
|
||||
s1.close()
|
||||
return my_ip
|
||||
@@ -75,13 +75,13 @@ def start_https_server(ota_image_dir, server_ip, server_port):
|
||||
# args = parser.parse_args()
|
||||
os.chdir(ota_image_dir)
|
||||
|
||||
server_file = os.path.join(ota_image_dir, "server_cert.pem")
|
||||
cert_file_handle = open(server_file, "w+")
|
||||
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 = 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()
|
||||
|
||||
@@ -93,7 +93,7 @@ def start_https_server(ota_image_dir, server_ip, server_port):
|
||||
httpd.serve_forever()
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_WIFI")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_WIFI')
|
||||
def test_examples_protocol_simple_ota_example(env, extra_data):
|
||||
"""
|
||||
steps: |
|
||||
@@ -101,33 +101,33 @@ def test_examples_protocol_simple_ota_example(env, extra_data):
|
||||
2. Fetch OTA image over HTTPS
|
||||
3. Reboot with the new OTA image
|
||||
"""
|
||||
dut1 = env.get_dut("simple_ota_example", "examples/system/ota/simple_ota_example", dut_class=ttfw_idf.ESP32DUT)
|
||||
dut1 = env.get_dut('simple_ota_example', 'examples/system/ota/simple_ota_example', dut_class=ttfw_idf.ESP32DUT)
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, "simple_ota.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'simple_ota.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("simple_ota_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('simple_ota_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
thread1 = Thread(target=start_https_server, args=(dut1.app.binary_path, host_ip, 8000))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
dut1.start_app()
|
||||
dut1.expect("Loaded app from partition at offset 0x10000", timeout=30)
|
||||
dut1.expect('Loaded app from partition at offset 0x10000', timeout=30)
|
||||
try:
|
||||
ip_address = dut1.expect(re.compile(r" sta ip: ([^,]+),"), timeout=30)
|
||||
print("Connected to AP with IP: {}".format(ip_address))
|
||||
ip_address = dut1.expect(re.compile(r' sta ip: ([^,]+),'), timeout=30)
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except DUT.ExpectTimeout:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
thread1.close()
|
||||
dut1.expect("Starting OTA example", timeout=30)
|
||||
dut1.expect('Starting OTA example', timeout=30)
|
||||
|
||||
print("writing to device: {}".format("https://" + host_ip + ":8000/simple_ota.bin"))
|
||||
dut1.write("https://" + host_ip + ":8000/simple_ota.bin")
|
||||
dut1.expect("Loaded app from partition at offset 0x110000", timeout=60)
|
||||
dut1.expect("Starting OTA example", timeout=30)
|
||||
print('writing to device: {}'.format('https://' + host_ip + ':8000/simple_ota.bin'))
|
||||
dut1.write('https://' + host_ip + ':8000/simple_ota.bin')
|
||||
dut1.expect('Loaded app from partition at offset 0x110000', timeout=60)
|
||||
dut1.expect('Starting OTA example', timeout=30)
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_EthKitV1")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_EthKitV1')
|
||||
def test_examples_protocol_simple_ota_example_ethernet_with_spiram_config(env, extra_data):
|
||||
"""
|
||||
steps: |
|
||||
@@ -135,33 +135,33 @@ def test_examples_protocol_simple_ota_example_ethernet_with_spiram_config(env, e
|
||||
2. Fetch OTA image over HTTPS
|
||||
3. Reboot with the new OTA image
|
||||
"""
|
||||
dut1 = env.get_dut("simple_ota_example", "examples/system/ota/simple_ota_example", dut_class=ttfw_idf.ESP32DUT, app_config_name='spiram')
|
||||
dut1 = env.get_dut('simple_ota_example', 'examples/system/ota/simple_ota_example', dut_class=ttfw_idf.ESP32DUT, app_config_name='spiram')
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, "simple_ota.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'simple_ota.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("simple_ota_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('simple_ota_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
thread1 = Thread(target=start_https_server, args=(dut1.app.binary_path, host_ip, 8000))
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
dut1.start_app()
|
||||
dut1.expect("Loaded app from partition at offset 0x10000", timeout=30)
|
||||
dut1.expect('Loaded app from partition at offset 0x10000', timeout=30)
|
||||
try:
|
||||
ip_address = dut1.expect(re.compile(r" eth ip: ([^,]+),"), timeout=30)
|
||||
print("Connected to AP with IP: {}".format(ip_address))
|
||||
ip_address = dut1.expect(re.compile(r' eth ip: ([^,]+),'), timeout=30)
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except DUT.ExpectTimeout:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
thread1.close()
|
||||
dut1.expect("Starting OTA example", timeout=30)
|
||||
dut1.expect('Starting OTA example', timeout=30)
|
||||
|
||||
print("writing to device: {}".format("https://" + host_ip + ":8000/simple_ota.bin"))
|
||||
dut1.write("https://" + host_ip + ":8000/simple_ota.bin")
|
||||
dut1.expect("Loaded app from partition at offset 0x110000", timeout=60)
|
||||
dut1.expect("Starting OTA example", timeout=30)
|
||||
print('writing to device: {}'.format('https://' + host_ip + ':8000/simple_ota.bin'))
|
||||
dut1.write('https://' + host_ip + ':8000/simple_ota.bin')
|
||||
dut1.expect('Loaded app from partition at offset 0x110000', timeout=60)
|
||||
dut1.expect('Starting OTA example', timeout=30)
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_Flash_Encryption_OTA")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_Flash_Encryption_OTA')
|
||||
def test_examples_protocol_simple_ota_example_with_flash_encryption(env, extra_data):
|
||||
"""
|
||||
steps: |
|
||||
@@ -169,13 +169,13 @@ def test_examples_protocol_simple_ota_example_with_flash_encryption(env, extra_d
|
||||
2. Fetch OTA image over HTTPS
|
||||
3. Reboot with the new OTA image
|
||||
"""
|
||||
dut1 = env.get_dut("simple_ota_example", "examples/system/ota/simple_ota_example", dut_class=ttfw_idf.ESP32DUT, app_config_name='flash_enc')
|
||||
dut1 = env.get_dut('simple_ota_example', 'examples/system/ota/simple_ota_example', dut_class=ttfw_idf.ESP32DUT, app_config_name='flash_enc')
|
||||
# check and log bin size
|
||||
binary_file = os.path.join(dut1.app.binary_path, "simple_ota.bin")
|
||||
binary_file = os.path.join(dut1.app.binary_path, 'simple_ota.bin')
|
||||
bin_size = os.path.getsize(binary_file)
|
||||
ttfw_idf.log_performance("simple_ota_bin_size", "{}KB".format(bin_size // 1024))
|
||||
ttfw_idf.log_performance('simple_ota_bin_size', '{}KB'.format(bin_size // 1024))
|
||||
# erase flash on the device
|
||||
print("Erasing the flash in order to have an empty NVS key partiton")
|
||||
print('Erasing the flash in order to have an empty NVS key partiton')
|
||||
dut1.erase_flash()
|
||||
# start test
|
||||
host_ip = get_my_ip()
|
||||
@@ -183,21 +183,21 @@ def test_examples_protocol_simple_ota_example_with_flash_encryption(env, extra_d
|
||||
thread1.daemon = True
|
||||
thread1.start()
|
||||
dut1.start_app()
|
||||
dut1.expect("Loaded app from partition at offset 0x20000", timeout=30)
|
||||
dut1.expect("Flash encryption mode is DEVELOPMENT (not secure)", timeout=10)
|
||||
dut1.expect('Loaded app from partition at offset 0x20000', timeout=30)
|
||||
dut1.expect('Flash encryption mode is DEVELOPMENT (not secure)', timeout=10)
|
||||
try:
|
||||
ip_address = dut1.expect(re.compile(r" eth ip: ([^,]+),"), timeout=30)
|
||||
print("Connected to AP with IP: {}".format(ip_address))
|
||||
ip_address = dut1.expect(re.compile(r' eth ip: ([^,]+),'), timeout=30)
|
||||
print('Connected to AP with IP: {}'.format(ip_address))
|
||||
except DUT.ExpectTimeout:
|
||||
raise ValueError('ENV_TEST_FAILURE: Cannot connect to AP')
|
||||
thread1.close()
|
||||
dut1.expect("Starting OTA example", timeout=30)
|
||||
dut1.expect('Starting OTA example', timeout=30)
|
||||
|
||||
print("writing to device: {}".format("https://" + host_ip + ":8000/simple_ota.bin"))
|
||||
dut1.write("https://" + host_ip + ":8000/simple_ota.bin")
|
||||
dut1.expect("Loaded app from partition at offset 0x120000", timeout=60)
|
||||
dut1.expect("Flash encryption mode is DEVELOPMENT (not secure)", timeout=10)
|
||||
dut1.expect("Starting OTA example", timeout=30)
|
||||
print('writing to device: {}'.format('https://' + host_ip + ':8000/simple_ota.bin'))
|
||||
dut1.write('https://' + host_ip + ':8000/simple_ota.bin')
|
||||
dut1.expect('Loaded app from partition at offset 0x120000', timeout=60)
|
||||
dut1.expect('Flash encryption mode is DEVELOPMENT (not secure)', timeout=10)
|
||||
dut1.expect('Starting OTA example', timeout=30)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
import os
|
||||
|
||||
import ttfw_idf
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
|
||||
def get_socket_msgs(i):
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
from __future__ import unicode_literals
|
||||
from io import open
|
||||
import debug_backend
|
||||
|
||||
import os
|
||||
import re
|
||||
import tempfile
|
||||
import time
|
||||
from io import open
|
||||
|
||||
import debug_backend
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="test_jtag_arm")
|
||||
@ttfw_idf.idf_example_test(env_tag='test_jtag_arm')
|
||||
def test_examples_sysview_tracing(env, extra_data):
|
||||
|
||||
rel_project_path = os.path.join('examples', 'system', 'sysview_tracing')
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
from __future__ import unicode_literals
|
||||
from io import open
|
||||
import debug_backend
|
||||
|
||||
import os
|
||||
import re
|
||||
import tempfile
|
||||
from io import open
|
||||
|
||||
import debug_backend
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="test_jtag_arm")
|
||||
@ttfw_idf.idf_example_test(env_tag='test_jtag_arm')
|
||||
def test_examples_sysview_tracing_heap_log(env, extra_data):
|
||||
|
||||
rel_project_path = os.path.join('examples', 'system', 'sysview_tracing_heap_log')
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
from __future__ import unicode_literals
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
import re
|
||||
import time
|
||||
|
||||
import ttfw_idf
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_GENERIC')
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
from __future__ import unicode_literals
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
import re
|
||||
|
||||
import ttfw_idf
|
||||
from tiny_test_fw import Utility
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_GENERIC')
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import re
|
||||
|
||||
import ttfw_idf
|
||||
|
||||
|
||||
|
||||
@@ -19,20 +19,17 @@ The test env Example_ShieldBox do need the following config::
|
||||
apc_ip: "192.168.1.88"
|
||||
pc_nic: "eth0"
|
||||
"""
|
||||
from __future__ import division
|
||||
from __future__ import unicode_literals
|
||||
from builtins import str
|
||||
from builtins import range
|
||||
from builtins import object
|
||||
import re
|
||||
from __future__ import division, unicode_literals
|
||||
|
||||
import os
|
||||
import time
|
||||
import re
|
||||
import subprocess
|
||||
import time
|
||||
from builtins import object, range, str
|
||||
|
||||
from tiny_test_fw import TinyFW, DUT, Utility
|
||||
import ttfw_idf
|
||||
from idf_iperf_test_util import (Attenuator, PowerControl, LineChart, TestReport)
|
||||
|
||||
from idf_iperf_test_util import Attenuator, LineChart, PowerControl, TestReport
|
||||
from tiny_test_fw import DUT, TinyFW, Utility
|
||||
|
||||
# configurations
|
||||
TEST_TIME = TEST_TIMEOUT = 60
|
||||
@@ -46,20 +43,20 @@ ATTEN_VALUE_LIST = range(0, 60, 2)
|
||||
FAILED_TO_SCAN_RSSI = -97
|
||||
INVALID_HEAP_SIZE = 0xFFFFFFFF
|
||||
|
||||
PC_IPERF_TEMP_LOG_FILE = ".tmp_iperf.log"
|
||||
CONFIG_NAME_PATTERN = re.compile(r"sdkconfig\.ci\.(.+)")
|
||||
PC_IPERF_TEMP_LOG_FILE = '.tmp_iperf.log'
|
||||
CONFIG_NAME_PATTERN = re.compile(r'sdkconfig\.ci\.(.+)')
|
||||
|
||||
# We need to auto compare the difference between adjacent configs (01 -> 00, 02 -> 01, ...) and put them to reports.
|
||||
# Using numbers for config will make this easy.
|
||||
# Use default value `99` for config with best performance.
|
||||
BEST_PERFORMANCE_CONFIG = "99"
|
||||
BEST_PERFORMANCE_CONFIG = '99'
|
||||
|
||||
|
||||
class TestResult(object):
|
||||
""" record, analysis test result and convert data to output format """
|
||||
|
||||
PC_BANDWIDTH_LOG_PATTERN = re.compile(r"(\d+).0\s*-\s*(\d+).0\s+sec\s+[\d.]+\s+MBytes\s+([\d.]+)\s+Mbits/sec")
|
||||
DUT_BANDWIDTH_LOG_PATTERN = re.compile(r"(\d+)-\s+(\d+)\s+sec\s+([\d.]+)\s+Mbits/sec")
|
||||
PC_BANDWIDTH_LOG_PATTERN = re.compile(r'(\d+).0\s*-\s*(\d+).0\s+sec\s+[\d.]+\s+MBytes\s+([\d.]+)\s+Mbits/sec')
|
||||
DUT_BANDWIDTH_LOG_PATTERN = re.compile(r'(\d+)-\s+(\d+)\s+sec\s+([\d.]+)\s+Mbits/sec')
|
||||
|
||||
ZERO_POINT_THRESHOLD = -88 # RSSI, dbm
|
||||
ZERO_THROUGHPUT_THRESHOLD = -92 # RSSI, dbm
|
||||
@@ -138,7 +135,7 @@ class TestResult(object):
|
||||
if float(result[2]) == 0 and rssi > self.ZERO_POINT_THRESHOLD \
|
||||
and fall_to_0_recorded < 1:
|
||||
# throughput fall to 0 error. we only record 1 records for one test
|
||||
self.error_list.append("[Error][fall to 0][{}][att: {}][rssi: {}]: 0 throughput interval: {}-{}"
|
||||
self.error_list.append('[Error][fall to 0][{}][att: {}][rssi: {}]: 0 throughput interval: {}-{}'
|
||||
.format(ap_ssid, att, rssi, result[0], result[1]))
|
||||
fall_to_0_recorded += 1
|
||||
|
||||
@@ -148,7 +145,7 @@ class TestResult(object):
|
||||
throughput = 0.0
|
||||
|
||||
if throughput == 0 and rssi > self.ZERO_THROUGHPUT_THRESHOLD:
|
||||
self.error_list.append("[Error][Fatal][{}][att: {}][rssi: {}]: No throughput data found"
|
||||
self.error_list.append('[Error][Fatal][{}][att: {}][rssi: {}]: No throughput data found'
|
||||
.format(ap_ssid, att, rssi))
|
||||
|
||||
self._save_result(throughput, ap_ssid, att, rssi, heap_size)
|
||||
@@ -167,7 +164,7 @@ class TestResult(object):
|
||||
result_dict = data[ap_ssid]
|
||||
index_list = list(result_dict.keys())
|
||||
index_list.sort()
|
||||
if index_type == "att":
|
||||
if index_type == 'att':
|
||||
index_list.reverse()
|
||||
|
||||
for i, index_value in enumerate(index_list[1:]):
|
||||
@@ -176,12 +173,12 @@ class TestResult(object):
|
||||
continue
|
||||
_percentage = result_dict[index_value] / result_dict[index_list[i]]
|
||||
if _percentage < 1 - self.BAD_POINT_PERCENTAGE_THRESHOLD:
|
||||
self.error_list.append("[Error][Bad point][{}][{}: {}]: drop {:.02f}%"
|
||||
self.error_list.append('[Error][Bad point][{}][{}: {}]: drop {:.02f}%'
|
||||
.format(ap_ssid, index_type, index_value,
|
||||
(1 - _percentage) * 100))
|
||||
|
||||
analysis_bad_point(self.throughput_by_rssi, "rssi")
|
||||
analysis_bad_point(self.throughput_by_att, "att")
|
||||
analysis_bad_point(self.throughput_by_rssi, 'rssi')
|
||||
analysis_bad_point(self.throughput_by_att, 'att')
|
||||
|
||||
def draw_throughput_figure(self, path, ap_ssid, draw_type):
|
||||
"""
|
||||
@@ -190,26 +187,26 @@ class TestResult(object):
|
||||
:param draw_type: "att" or "rssi"
|
||||
:return: file_name
|
||||
"""
|
||||
if draw_type == "rssi":
|
||||
type_name = "RSSI"
|
||||
if draw_type == 'rssi':
|
||||
type_name = 'RSSI'
|
||||
data = self.throughput_by_rssi
|
||||
range_list = self.RSSI_RANGE
|
||||
elif draw_type == "att":
|
||||
type_name = "Att"
|
||||
elif draw_type == 'att':
|
||||
type_name = 'Att'
|
||||
data = self.throughput_by_att
|
||||
range_list = self.ATT_RANGE
|
||||
else:
|
||||
raise AssertionError("draw type not supported")
|
||||
raise AssertionError('draw type not supported')
|
||||
if isinstance(ap_ssid, list):
|
||||
file_name = "ThroughputVs{}_{}_{}_{}.html".format(type_name, self.proto, self.direction,
|
||||
file_name = 'ThroughputVs{}_{}_{}_{}.html'.format(type_name, self.proto, self.direction,
|
||||
hash(ap_ssid)[:6])
|
||||
else:
|
||||
file_name = "ThroughputVs{}_{}_{}_{}.html".format(type_name, self.proto, self.direction, ap_ssid)
|
||||
file_name = 'ThroughputVs{}_{}_{}_{}.html'.format(type_name, self.proto, self.direction, ap_ssid)
|
||||
|
||||
LineChart.draw_line_chart(os.path.join(path, file_name),
|
||||
"Throughput Vs {} ({} {})".format(type_name, self.proto, self.direction),
|
||||
"{} (dbm)".format(type_name),
|
||||
"Throughput (Mbps)",
|
||||
'Throughput Vs {} ({} {})'.format(type_name, self.proto, self.direction),
|
||||
'{} (dbm)'.format(type_name),
|
||||
'Throughput (Mbps)',
|
||||
data, range_list)
|
||||
return file_name
|
||||
|
||||
@@ -220,13 +217,13 @@ class TestResult(object):
|
||||
:return: file_name
|
||||
"""
|
||||
if isinstance(ap_ssid, list):
|
||||
file_name = "AttVsRSSI_{}.html".format(hash(ap_ssid)[:6])
|
||||
file_name = 'AttVsRSSI_{}.html'.format(hash(ap_ssid)[:6])
|
||||
else:
|
||||
file_name = "AttVsRSSI_{}.html".format(ap_ssid)
|
||||
file_name = 'AttVsRSSI_{}.html'.format(ap_ssid)
|
||||
LineChart.draw_line_chart(os.path.join(path, file_name),
|
||||
"Att Vs RSSI",
|
||||
"Att (dbm)",
|
||||
"RSSI (dbm)",
|
||||
'Att Vs RSSI',
|
||||
'Att (dbm)',
|
||||
'RSSI (dbm)',
|
||||
self.att_rssi_map,
|
||||
self.ATT_RANGE)
|
||||
return file_name
|
||||
@@ -246,15 +243,15 @@ class TestResult(object):
|
||||
3. min free heap size during test
|
||||
"""
|
||||
if self.throughput_by_att:
|
||||
ret = "[{}_{}][{}]: {}\r\n\r\n".format(self.proto, self.direction, self.config_name,
|
||||
"Fail" if self.error_list else "Success")
|
||||
ret += "Performance for each AP:\r\n"
|
||||
ret = '[{}_{}][{}]: {}\r\n\r\n'.format(self.proto, self.direction, self.config_name,
|
||||
'Fail' if self.error_list else 'Success')
|
||||
ret += 'Performance for each AP:\r\n'
|
||||
for ap_ssid in self.throughput_by_att:
|
||||
ret += "[{}]: {:.02f} Mbps\r\n".format(ap_ssid, max(self.throughput_by_att[ap_ssid].values()))
|
||||
ret += '[{}]: {:.02f} Mbps\r\n'.format(ap_ssid, max(self.throughput_by_att[ap_ssid].values()))
|
||||
if self.heap_size != INVALID_HEAP_SIZE:
|
||||
ret += "Minimum heap size: {}".format(self.heap_size)
|
||||
ret += 'Minimum heap size: {}'.format(self.heap_size)
|
||||
else:
|
||||
ret = ""
|
||||
ret = ''
|
||||
return ret
|
||||
|
||||
|
||||
@@ -275,10 +272,10 @@ class IperfTestUtility(object):
|
||||
self.test_result = test_result
|
||||
else:
|
||||
self.test_result = {
|
||||
"tcp_tx": TestResult("tcp", "tx", config_name),
|
||||
"tcp_rx": TestResult("tcp", "rx", config_name),
|
||||
"udp_tx": TestResult("udp", "tx", config_name),
|
||||
"udp_rx": TestResult("udp", "rx", config_name),
|
||||
'tcp_tx': TestResult('tcp', 'tx', config_name),
|
||||
'tcp_rx': TestResult('tcp', 'rx', config_name),
|
||||
'udp_tx': TestResult('udp', 'tx', config_name),
|
||||
'udp_rx': TestResult('udp', 'rx', config_name),
|
||||
}
|
||||
|
||||
def setup(self):
|
||||
@@ -291,23 +288,23 @@ class IperfTestUtility(object):
|
||||
4. connect to AP
|
||||
"""
|
||||
try:
|
||||
subprocess.check_output("sudo killall iperf 2>&1 > /dev/null", shell=True)
|
||||
subprocess.check_output('sudo killall iperf 2>&1 > /dev/null', shell=True)
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
self.dut.write("restart")
|
||||
self.dut.expect_any("iperf>", "esp32>")
|
||||
self.dut.write("scan {}".format(self.ap_ssid))
|
||||
self.dut.write('restart')
|
||||
self.dut.expect_any('iperf>', 'esp32>')
|
||||
self.dut.write('scan {}'.format(self.ap_ssid))
|
||||
for _ in range(SCAN_RETRY_COUNT):
|
||||
try:
|
||||
rssi = int(self.dut.expect(re.compile(r"\[{}]\[rssi=(-\d+)]".format(self.ap_ssid)),
|
||||
rssi = int(self.dut.expect(re.compile(r'\[{}]\[rssi=(-\d+)]'.format(self.ap_ssid)),
|
||||
timeout=SCAN_TIMEOUT)[0])
|
||||
break
|
||||
except DUT.ExpectTimeout:
|
||||
continue
|
||||
else:
|
||||
raise AssertionError("Failed to scan AP")
|
||||
self.dut.write("sta {} {}".format(self.ap_ssid, self.ap_password))
|
||||
dut_ip = self.dut.expect(re.compile(r"sta ip: ([\d.]+), mask: ([\d.]+), gw: ([\d.]+)"))[0]
|
||||
raise AssertionError('Failed to scan AP')
|
||||
self.dut.write('sta {} {}'.format(self.ap_ssid, self.ap_password))
|
||||
dut_ip = self.dut.expect(re.compile(r'sta ip: ([\d.]+), mask: ([\d.]+), gw: ([\d.]+)'))[0]
|
||||
return dut_ip, rssi
|
||||
|
||||
def _save_test_result(self, test_case, raw_data, att, rssi, heap_size):
|
||||
@@ -318,22 +315,22 @@ class IperfTestUtility(object):
|
||||
# connect and scan to get RSSI
|
||||
dut_ip, rssi = self.setup()
|
||||
|
||||
assert direction in ["rx", "tx"]
|
||||
assert proto in ["tcp", "udp"]
|
||||
assert direction in ['rx', 'tx']
|
||||
assert proto in ['tcp', 'udp']
|
||||
|
||||
# run iperf test
|
||||
if direction == "tx":
|
||||
with open(PC_IPERF_TEMP_LOG_FILE, "w") as f:
|
||||
if proto == "tcp":
|
||||
process = subprocess.Popen(["iperf", "-s", "-B", self.pc_nic_ip,
|
||||
"-t", str(TEST_TIME), "-i", "1", "-f", "m"],
|
||||
if direction == 'tx':
|
||||
with open(PC_IPERF_TEMP_LOG_FILE, 'w') as f:
|
||||
if proto == 'tcp':
|
||||
process = subprocess.Popen(['iperf', '-s', '-B', self.pc_nic_ip,
|
||||
'-t', str(TEST_TIME), '-i', '1', '-f', 'm'],
|
||||
stdout=f, stderr=f)
|
||||
self.dut.write("iperf -c {} -i 1 -t {}".format(self.pc_nic_ip, TEST_TIME))
|
||||
self.dut.write('iperf -c {} -i 1 -t {}'.format(self.pc_nic_ip, TEST_TIME))
|
||||
else:
|
||||
process = subprocess.Popen(["iperf", "-s", "-u", "-B", self.pc_nic_ip,
|
||||
"-t", str(TEST_TIME), "-i", "1", "-f", "m"],
|
||||
process = subprocess.Popen(['iperf', '-s', '-u', '-B', self.pc_nic_ip,
|
||||
'-t', str(TEST_TIME), '-i', '1', '-f', 'm'],
|
||||
stdout=f, stderr=f)
|
||||
self.dut.write("iperf -c {} -u -i 1 -t {}".format(self.pc_nic_ip, TEST_TIME))
|
||||
self.dut.write('iperf -c {} -u -i 1 -t {}'.format(self.pc_nic_ip, TEST_TIME))
|
||||
|
||||
for _ in range(TEST_TIMEOUT):
|
||||
if process.poll() is not None:
|
||||
@@ -342,25 +339,25 @@ class IperfTestUtility(object):
|
||||
else:
|
||||
process.terminate()
|
||||
|
||||
with open(PC_IPERF_TEMP_LOG_FILE, "r") as f:
|
||||
with open(PC_IPERF_TEMP_LOG_FILE, 'r') as f:
|
||||
pc_raw_data = server_raw_data = f.read()
|
||||
else:
|
||||
with open(PC_IPERF_TEMP_LOG_FILE, "w") as f:
|
||||
if proto == "tcp":
|
||||
self.dut.write("iperf -s -i 1 -t {}".format(TEST_TIME))
|
||||
with open(PC_IPERF_TEMP_LOG_FILE, 'w') as f:
|
||||
if proto == 'tcp':
|
||||
self.dut.write('iperf -s -i 1 -t {}'.format(TEST_TIME))
|
||||
# wait until DUT TCP server created
|
||||
try:
|
||||
self.dut.expect("iperf tcp server create successfully", timeout=1)
|
||||
self.dut.expect('iperf tcp server create successfully', timeout=1)
|
||||
except DUT.ExpectTimeout:
|
||||
# compatible with old iperf example binary
|
||||
pass
|
||||
process = subprocess.Popen(["iperf", "-c", dut_ip,
|
||||
"-t", str(TEST_TIME), "-f", "m"],
|
||||
process = subprocess.Popen(['iperf', '-c', dut_ip,
|
||||
'-t', str(TEST_TIME), '-f', 'm'],
|
||||
stdout=f, stderr=f)
|
||||
else:
|
||||
self.dut.write("iperf -s -u -i 1 -t {}".format(TEST_TIME))
|
||||
process = subprocess.Popen(["iperf", "-c", dut_ip, "-u", "-b", "100M",
|
||||
"-t", str(TEST_TIME), "-f", "m"],
|
||||
self.dut.write('iperf -s -u -i 1 -t {}'.format(TEST_TIME))
|
||||
process = subprocess.Popen(['iperf', '-c', dut_ip, '-u', '-b', '100M',
|
||||
'-t', str(TEST_TIME), '-f', 'm'],
|
||||
stdout=f, stderr=f)
|
||||
|
||||
for _ in range(TEST_TIMEOUT):
|
||||
@@ -371,18 +368,18 @@ class IperfTestUtility(object):
|
||||
process.terminate()
|
||||
|
||||
server_raw_data = self.dut.read()
|
||||
with open(PC_IPERF_TEMP_LOG_FILE, "r") as f:
|
||||
with open(PC_IPERF_TEMP_LOG_FILE, 'r') as f:
|
||||
pc_raw_data = f.read()
|
||||
|
||||
# save PC iperf logs to console
|
||||
with open(self.pc_iperf_log_file, "a+") as f:
|
||||
f.write("## [{}] `{}`\r\n##### {}"
|
||||
with open(self.pc_iperf_log_file, 'a+') as f:
|
||||
f.write('## [{}] `{}`\r\n##### {}'
|
||||
.format(self.config_name,
|
||||
"{}_{}".format(proto, direction),
|
||||
time.strftime("%m-%d %H:%M:%S", time.localtime(time.time()))))
|
||||
'{}_{}'.format(proto, direction),
|
||||
time.strftime('%m-%d %H:%M:%S', time.localtime(time.time()))))
|
||||
f.write('\r\n```\r\n\r\n' + pc_raw_data + '\r\n```\r\n')
|
||||
self.dut.write("heap")
|
||||
heap_size = self.dut.expect(re.compile(r"min heap size: (\d+)\D"))[0]
|
||||
self.dut.write('heap')
|
||||
heap_size = self.dut.expect(re.compile(r'min heap size: (\d+)\D'))[0]
|
||||
|
||||
# return server raw data (for parsing test results) and RSSI
|
||||
return server_raw_data, rssi, heap_size
|
||||
@@ -399,14 +396,14 @@ class IperfTestUtility(object):
|
||||
heap_size = INVALID_HEAP_SIZE
|
||||
try:
|
||||
server_raw_data, rssi, heap_size = self._test_once(proto, direction)
|
||||
throughput = self._save_test_result("{}_{}".format(proto, direction),
|
||||
throughput = self._save_test_result('{}_{}'.format(proto, direction),
|
||||
server_raw_data, atten_val,
|
||||
rssi, heap_size)
|
||||
Utility.console_log("[{}][{}_{}][{}][{}]: {:.02f}"
|
||||
Utility.console_log('[{}][{}_{}][{}][{}]: {:.02f}'
|
||||
.format(self.config_name, proto, direction, rssi, self.ap_ssid, throughput))
|
||||
except Exception as e:
|
||||
self._save_test_result("{}_{}".format(proto, direction), "", atten_val, rssi, heap_size)
|
||||
Utility.console_log("Failed during test: {}".format(e))
|
||||
self._save_test_result('{}_{}'.format(proto, direction), '', atten_val, rssi, heap_size)
|
||||
Utility.console_log('Failed during test: {}'.format(e))
|
||||
|
||||
def run_all_cases(self, atten_val):
|
||||
"""
|
||||
@@ -414,10 +411,10 @@ class IperfTestUtility(object):
|
||||
|
||||
:param atten_val: attenuate value
|
||||
"""
|
||||
self.run_test("tcp", "tx", atten_val)
|
||||
self.run_test("tcp", "rx", atten_val)
|
||||
self.run_test("udp", "tx", atten_val)
|
||||
self.run_test("udp", "rx", atten_val)
|
||||
self.run_test('tcp', 'tx', atten_val)
|
||||
self.run_test('tcp', 'rx', atten_val)
|
||||
self.run_test('udp', 'tx', atten_val)
|
||||
self.run_test('udp', 'rx', atten_val)
|
||||
|
||||
def wait_ap_power_on(self):
|
||||
"""
|
||||
@@ -426,12 +423,12 @@ class IperfTestUtility(object):
|
||||
|
||||
:return: True or False
|
||||
"""
|
||||
self.dut.write("restart")
|
||||
self.dut.expect_any("iperf>", "esp32>")
|
||||
self.dut.write('restart')
|
||||
self.dut.expect_any('iperf>', 'esp32>')
|
||||
for _ in range(WAIT_AP_POWER_ON_TIMEOUT // SCAN_TIMEOUT):
|
||||
try:
|
||||
self.dut.write("scan {}".format(self.ap_ssid))
|
||||
self.dut.expect(re.compile(r"\[{}]\[rssi=(-\d+)]".format(self.ap_ssid)),
|
||||
self.dut.write('scan {}'.format(self.ap_ssid))
|
||||
self.dut.expect(re.compile(r'\[{}]\[rssi=(-\d+)]'.format(self.ap_ssid)),
|
||||
timeout=SCAN_TIMEOUT)
|
||||
ret = True
|
||||
break
|
||||
@@ -458,23 +455,23 @@ class IperfTestUtilitySoftap(IperfTestUtility):
|
||||
3. scan to get AP RSSI
|
||||
4. connect to AP
|
||||
"""
|
||||
self.softap_dut.write("restart")
|
||||
self.softap_dut.expect_any("iperf>", "esp32>", timeout=30)
|
||||
self.softap_dut.write("ap {} {}".format(self.ap_ssid, self.ap_password))
|
||||
self.dut.write("restart")
|
||||
self.dut.expect_any("iperf>", "esp32>", timeout=30)
|
||||
self.dut.write("scan {}".format(self.ap_ssid))
|
||||
self.softap_dut.write('restart')
|
||||
self.softap_dut.expect_any('iperf>', 'esp32>', timeout=30)
|
||||
self.softap_dut.write('ap {} {}'.format(self.ap_ssid, self.ap_password))
|
||||
self.dut.write('restart')
|
||||
self.dut.expect_any('iperf>', 'esp32>', timeout=30)
|
||||
self.dut.write('scan {}'.format(self.ap_ssid))
|
||||
for _ in range(SCAN_RETRY_COUNT):
|
||||
try:
|
||||
rssi = int(self.dut.expect(re.compile(r"\[{}]\[rssi=(-\d+)]".format(self.ap_ssid)),
|
||||
rssi = int(self.dut.expect(re.compile(r'\[{}]\[rssi=(-\d+)]'.format(self.ap_ssid)),
|
||||
timeout=SCAN_TIMEOUT)[0])
|
||||
break
|
||||
except DUT.ExpectTimeout:
|
||||
continue
|
||||
else:
|
||||
raise AssertionError("Failed to scan AP")
|
||||
self.dut.write("sta {} {}".format(self.ap_ssid, self.ap_password))
|
||||
dut_ip = self.dut.expect(re.compile(r"sta ip: ([\d.]+), mask: ([\d.]+), gw: ([\d.]+)"))[0]
|
||||
raise AssertionError('Failed to scan AP')
|
||||
self.dut.write('sta {} {}'.format(self.ap_ssid, self.ap_password))
|
||||
dut_ip = self.dut.expect(re.compile(r'sta ip: ([\d.]+), mask: ([\d.]+), gw: ([\d.]+)'))[0]
|
||||
return dut_ip, rssi
|
||||
|
||||
def _test_once(self, proto, direction):
|
||||
@@ -482,69 +479,69 @@ class IperfTestUtilitySoftap(IperfTestUtility):
|
||||
# connect and scan to get RSSI
|
||||
dut_ip, rssi = self.setup()
|
||||
|
||||
assert direction in ["rx", "tx"]
|
||||
assert proto in ["tcp", "udp"]
|
||||
assert direction in ['rx', 'tx']
|
||||
assert proto in ['tcp', 'udp']
|
||||
|
||||
# run iperf test
|
||||
if direction == "tx":
|
||||
if proto == "tcp":
|
||||
self.softap_dut.write("iperf -s -i 1 -t {}".format(TEST_TIME))
|
||||
if direction == 'tx':
|
||||
if proto == 'tcp':
|
||||
self.softap_dut.write('iperf -s -i 1 -t {}'.format(TEST_TIME))
|
||||
# wait until DUT TCP server created
|
||||
try:
|
||||
self.softap_dut.expect("iperf tcp server create successfully", timeout=1)
|
||||
self.softap_dut.expect('iperf tcp server create successfully', timeout=1)
|
||||
except DUT.ExpectTimeout:
|
||||
# compatible with old iperf example binary
|
||||
pass
|
||||
self.dut.write("iperf -c {} -i 1 -t {}".format(self.softap_ip, TEST_TIME))
|
||||
self.dut.write('iperf -c {} -i 1 -t {}'.format(self.softap_ip, TEST_TIME))
|
||||
else:
|
||||
self.softap_dut.write("iperf -s -u -i 1 -t {}".format(TEST_TIME))
|
||||
self.dut.write("iperf -c {} -u -i 1 -t {}".format(self.softap_ip, TEST_TIME))
|
||||
self.softap_dut.write('iperf -s -u -i 1 -t {}'.format(TEST_TIME))
|
||||
self.dut.write('iperf -c {} -u -i 1 -t {}'.format(self.softap_ip, TEST_TIME))
|
||||
else:
|
||||
if proto == "tcp":
|
||||
self.dut.write("iperf -s -i 1 -t {}".format(TEST_TIME))
|
||||
if proto == 'tcp':
|
||||
self.dut.write('iperf -s -i 1 -t {}'.format(TEST_TIME))
|
||||
# wait until DUT TCP server created
|
||||
try:
|
||||
self.dut.expect("iperf tcp server create successfully", timeout=1)
|
||||
self.dut.expect('iperf tcp server create successfully', timeout=1)
|
||||
except DUT.ExpectTimeout:
|
||||
# compatible with old iperf example binary
|
||||
pass
|
||||
self.softap_dut.write("iperf -c {} -i 1 -t {}".format(dut_ip, TEST_TIME))
|
||||
self.softap_dut.write('iperf -c {} -i 1 -t {}'.format(dut_ip, TEST_TIME))
|
||||
else:
|
||||
self.dut.write("iperf -s -u -i 1 -t {}".format(TEST_TIME))
|
||||
self.softap_dut.write("iperf -c {} -u -i 1 -t {}".format(dut_ip, TEST_TIME))
|
||||
self.dut.write('iperf -s -u -i 1 -t {}'.format(TEST_TIME))
|
||||
self.softap_dut.write('iperf -c {} -u -i 1 -t {}'.format(dut_ip, TEST_TIME))
|
||||
time.sleep(60)
|
||||
|
||||
if direction == "tx":
|
||||
if direction == 'tx':
|
||||
server_raw_data = self.dut.read()
|
||||
else:
|
||||
server_raw_data = self.softap_dut.read()
|
||||
self.dut.write("iperf -a")
|
||||
self.softap_dut.write("iperf -a")
|
||||
self.dut.write("heap")
|
||||
heap_size = self.dut.expect(re.compile(r"min heap size: (\d+)\D"))[0]
|
||||
self.dut.write('iperf -a')
|
||||
self.softap_dut.write('iperf -a')
|
||||
self.dut.write('heap')
|
||||
heap_size = self.dut.expect(re.compile(r'min heap size: (\d+)\D'))[0]
|
||||
|
||||
# return server raw data (for parsing test results) and RSSI
|
||||
return server_raw_data, rssi, heap_size
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_ShieldBox_Basic", category="stress")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_ShieldBox_Basic', category='stress')
|
||||
def test_wifi_throughput_with_different_configs(env, extra_data):
|
||||
"""
|
||||
steps: |
|
||||
1. build iperf with specified configs
|
||||
2. test throughput for all routers
|
||||
"""
|
||||
pc_nic_ip = env.get_pc_nic_info("pc_nic", "ipv4")["addr"]
|
||||
pc_iperf_log_file = os.path.join(env.log_path, "pc_iperf_log.md")
|
||||
pc_nic_ip = env.get_pc_nic_info('pc_nic', 'ipv4')['addr']
|
||||
pc_iperf_log_file = os.path.join(env.log_path, 'pc_iperf_log.md')
|
||||
ap_info = {
|
||||
"ssid": env.get_variable("ap_ssid"),
|
||||
"password": env.get_variable("ap_password"),
|
||||
'ssid': env.get_variable('ap_ssid'),
|
||||
'password': env.get_variable('ap_password'),
|
||||
}
|
||||
|
||||
config_names_raw = subprocess.check_output(["ls", os.path.dirname(os.path.abspath(__file__))])
|
||||
config_names_raw = subprocess.check_output(['ls', os.path.dirname(os.path.abspath(__file__))])
|
||||
config_names = CONFIG_NAME_PATTERN.findall(config_names_raw)
|
||||
if not config_names:
|
||||
raise ValueError("no configs found in {}".format(os.path.dirname(__file__)))
|
||||
raise ValueError('no configs found in {}'.format(os.path.dirname(__file__)))
|
||||
|
||||
test_result = dict()
|
||||
sdkconfig_files = dict()
|
||||
@@ -552,24 +549,24 @@ def test_wifi_throughput_with_different_configs(env, extra_data):
|
||||
for config_name in config_names:
|
||||
# 1. get the config
|
||||
sdkconfig_files[config_name] = os.path.join(os.path.dirname(__file__),
|
||||
"sdkconfig.ci.{}".format(config_name))
|
||||
'sdkconfig.ci.{}'.format(config_name))
|
||||
|
||||
# 2. get DUT and download
|
||||
dut = env.get_dut("iperf", "examples/wifi/iperf", dut_class=ttfw_idf.ESP32DUT,
|
||||
dut = env.get_dut('iperf', 'examples/wifi/iperf', dut_class=ttfw_idf.ESP32DUT,
|
||||
app_config_name=config_name)
|
||||
dut.start_app()
|
||||
dut.expect_any("iperf>", "esp32>")
|
||||
dut.expect_any('iperf>', 'esp32>')
|
||||
|
||||
# 3. run test for each required att value
|
||||
test_result[config_name] = {
|
||||
"tcp_tx": TestResult("tcp", "tx", config_name),
|
||||
"tcp_rx": TestResult("tcp", "rx", config_name),
|
||||
"udp_tx": TestResult("udp", "tx", config_name),
|
||||
"udp_rx": TestResult("udp", "rx", config_name),
|
||||
'tcp_tx': TestResult('tcp', 'tx', config_name),
|
||||
'tcp_rx': TestResult('tcp', 'rx', config_name),
|
||||
'udp_tx': TestResult('udp', 'tx', config_name),
|
||||
'udp_rx': TestResult('udp', 'rx', config_name),
|
||||
}
|
||||
|
||||
test_utility = IperfTestUtility(dut, config_name, ap_info["ssid"],
|
||||
ap_info["password"], pc_nic_ip, pc_iperf_log_file, test_result[config_name])
|
||||
test_utility = IperfTestUtility(dut, config_name, ap_info['ssid'],
|
||||
ap_info['password'], pc_nic_ip, pc_iperf_log_file, test_result[config_name])
|
||||
|
||||
for _ in range(RETRY_COUNT_FOR_BEST_PERFORMANCE):
|
||||
test_utility.run_all_cases(0)
|
||||
@@ -577,18 +574,18 @@ def test_wifi_throughput_with_different_configs(env, extra_data):
|
||||
for result_type in test_result[config_name]:
|
||||
summary = str(test_result[config_name][result_type])
|
||||
if summary:
|
||||
Utility.console_log(summary, color="orange")
|
||||
Utility.console_log(summary, color='orange')
|
||||
|
||||
# 4. check test results
|
||||
env.close_dut("iperf")
|
||||
env.close_dut('iperf')
|
||||
|
||||
# 5. generate report
|
||||
report = TestReport.ThroughputForConfigsReport(os.path.join(env.log_path, "ThroughputForConfigsReport"),
|
||||
ap_info["ssid"], test_result, sdkconfig_files)
|
||||
report = TestReport.ThroughputForConfigsReport(os.path.join(env.log_path, 'ThroughputForConfigsReport'),
|
||||
ap_info['ssid'], test_result, sdkconfig_files)
|
||||
report.generate_report()
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_ShieldBox", category="stress")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_ShieldBox', category='stress')
|
||||
def test_wifi_throughput_vs_rssi(env, extra_data):
|
||||
"""
|
||||
steps: |
|
||||
@@ -597,37 +594,37 @@ def test_wifi_throughput_vs_rssi(env, extra_data):
|
||||
3. set attenuator value from 0-60 for each router
|
||||
4. test TCP tx rx and UDP tx rx throughput
|
||||
"""
|
||||
att_port = env.get_variable("attenuator_port")
|
||||
ap_list = env.get_variable("ap_list")
|
||||
pc_nic_ip = env.get_pc_nic_info("pc_nic", "ipv4")["addr"]
|
||||
apc_ip = env.get_variable("apc_ip")
|
||||
pc_iperf_log_file = os.path.join(env.log_path, "pc_iperf_log.md")
|
||||
att_port = env.get_variable('attenuator_port')
|
||||
ap_list = env.get_variable('ap_list')
|
||||
pc_nic_ip = env.get_pc_nic_info('pc_nic', 'ipv4')['addr']
|
||||
apc_ip = env.get_variable('apc_ip')
|
||||
pc_iperf_log_file = os.path.join(env.log_path, 'pc_iperf_log.md')
|
||||
|
||||
test_result = {
|
||||
"tcp_tx": TestResult("tcp", "tx", BEST_PERFORMANCE_CONFIG),
|
||||
"tcp_rx": TestResult("tcp", "rx", BEST_PERFORMANCE_CONFIG),
|
||||
"udp_tx": TestResult("udp", "tx", BEST_PERFORMANCE_CONFIG),
|
||||
"udp_rx": TestResult("udp", "rx", BEST_PERFORMANCE_CONFIG),
|
||||
'tcp_tx': TestResult('tcp', 'tx', BEST_PERFORMANCE_CONFIG),
|
||||
'tcp_rx': TestResult('tcp', 'rx', BEST_PERFORMANCE_CONFIG),
|
||||
'udp_tx': TestResult('udp', 'tx', BEST_PERFORMANCE_CONFIG),
|
||||
'udp_rx': TestResult('udp', 'rx', BEST_PERFORMANCE_CONFIG),
|
||||
}
|
||||
|
||||
# 1. get DUT and download
|
||||
dut = env.get_dut("iperf", "examples/wifi/iperf", dut_class=ttfw_idf.ESP32DUT,
|
||||
dut = env.get_dut('iperf', 'examples/wifi/iperf', dut_class=ttfw_idf.ESP32DUT,
|
||||
app_config_name=BEST_PERFORMANCE_CONFIG)
|
||||
dut.start_app()
|
||||
dut.expect_any("iperf>", "esp32>")
|
||||
dut.expect_any('iperf>', 'esp32>')
|
||||
|
||||
# 2. run test for each required att value
|
||||
for ap_info in ap_list:
|
||||
test_utility = IperfTestUtility(dut, BEST_PERFORMANCE_CONFIG, ap_info["ssid"], ap_info["password"],
|
||||
test_utility = IperfTestUtility(dut, BEST_PERFORMANCE_CONFIG, ap_info['ssid'], ap_info['password'],
|
||||
pc_nic_ip, pc_iperf_log_file, test_result)
|
||||
|
||||
PowerControl.Control.control_rest(apc_ip, ap_info["outlet"], "OFF")
|
||||
PowerControl.Control.control(apc_ip, {ap_info["outlet"]: "ON"})
|
||||
PowerControl.Control.control_rest(apc_ip, ap_info['outlet'], 'OFF')
|
||||
PowerControl.Control.control(apc_ip, {ap_info['outlet']: 'ON'})
|
||||
Attenuator.set_att(att_port, 0)
|
||||
|
||||
if not test_utility.wait_ap_power_on():
|
||||
Utility.console_log("[{}] failed to power on, skip testing this AP"
|
||||
.format(ap_info["ssid"]), color="red")
|
||||
Utility.console_log('[{}] failed to power on, skip testing this AP'
|
||||
.format(ap_info['ssid']), color='red')
|
||||
continue
|
||||
|
||||
for atten_val in ATTEN_VALUE_LIST:
|
||||
@@ -635,44 +632,44 @@ def test_wifi_throughput_vs_rssi(env, extra_data):
|
||||
test_utility.run_all_cases(atten_val)
|
||||
|
||||
# 3. check test results
|
||||
env.close_dut("iperf")
|
||||
env.close_dut('iperf')
|
||||
|
||||
# 4. generate report
|
||||
report = TestReport.ThroughputVsRssiReport(os.path.join(env.log_path, "STAThroughputVsRssiReport"),
|
||||
report = TestReport.ThroughputVsRssiReport(os.path.join(env.log_path, 'STAThroughputVsRssiReport'),
|
||||
test_result)
|
||||
report.generate_report()
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_ShieldBox_Basic")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_ShieldBox_Basic')
|
||||
def test_wifi_throughput_basic(env, extra_data):
|
||||
"""
|
||||
steps: |
|
||||
1. test TCP tx rx and UDP tx rx throughput
|
||||
2. compare with the pre-defined pass standard
|
||||
"""
|
||||
pc_nic_ip = env.get_pc_nic_info("pc_nic", "ipv4")["addr"]
|
||||
pc_iperf_log_file = os.path.join(env.log_path, "pc_iperf_log.md")
|
||||
pc_nic_ip = env.get_pc_nic_info('pc_nic', 'ipv4')['addr']
|
||||
pc_iperf_log_file = os.path.join(env.log_path, 'pc_iperf_log.md')
|
||||
ap_info = {
|
||||
"ssid": env.get_variable("ap_ssid"),
|
||||
"password": env.get_variable("ap_password"),
|
||||
'ssid': env.get_variable('ap_ssid'),
|
||||
'password': env.get_variable('ap_password'),
|
||||
}
|
||||
|
||||
# 1. get DUT
|
||||
dut = env.get_dut("iperf", "examples/wifi/iperf", dut_class=ttfw_idf.ESP32DUT,
|
||||
dut = env.get_dut('iperf', 'examples/wifi/iperf', dut_class=ttfw_idf.ESP32DUT,
|
||||
app_config_name=BEST_PERFORMANCE_CONFIG)
|
||||
dut.start_app()
|
||||
dut.expect_any("iperf>", "esp32>")
|
||||
dut.expect_any('iperf>', 'esp32>')
|
||||
|
||||
# 2. preparing
|
||||
test_result = {
|
||||
"tcp_tx": TestResult("tcp", "tx", BEST_PERFORMANCE_CONFIG),
|
||||
"tcp_rx": TestResult("tcp", "rx", BEST_PERFORMANCE_CONFIG),
|
||||
"udp_tx": TestResult("udp", "tx", BEST_PERFORMANCE_CONFIG),
|
||||
"udp_rx": TestResult("udp", "rx", BEST_PERFORMANCE_CONFIG),
|
||||
'tcp_tx': TestResult('tcp', 'tx', BEST_PERFORMANCE_CONFIG),
|
||||
'tcp_rx': TestResult('tcp', 'rx', BEST_PERFORMANCE_CONFIG),
|
||||
'udp_tx': TestResult('udp', 'tx', BEST_PERFORMANCE_CONFIG),
|
||||
'udp_rx': TestResult('udp', 'rx', BEST_PERFORMANCE_CONFIG),
|
||||
}
|
||||
|
||||
test_utility = IperfTestUtility(dut, BEST_PERFORMANCE_CONFIG, ap_info["ssid"],
|
||||
ap_info["password"], pc_nic_ip, pc_iperf_log_file, test_result)
|
||||
test_utility = IperfTestUtility(dut, BEST_PERFORMANCE_CONFIG, ap_info['ssid'],
|
||||
ap_info['password'], pc_nic_ip, pc_iperf_log_file, test_result)
|
||||
|
||||
# 3. run test for TCP Tx, Rx and UDP Tx, Rx
|
||||
for _ in range(RETRY_COUNT_FOR_BEST_PERFORMANCE):
|
||||
@@ -681,22 +678,22 @@ def test_wifi_throughput_basic(env, extra_data):
|
||||
# 4. log performance and compare with pass standard
|
||||
performance_items = []
|
||||
for throughput_type in test_result:
|
||||
ttfw_idf.log_performance("{}_throughput".format(throughput_type),
|
||||
"{:.02f} Mbps".format(test_result[throughput_type].get_best_throughput()))
|
||||
performance_items.append(["{}_throughput".format(throughput_type),
|
||||
"{:.02f} Mbps".format(test_result[throughput_type].get_best_throughput())])
|
||||
ttfw_idf.log_performance('{}_throughput'.format(throughput_type),
|
||||
'{:.02f} Mbps'.format(test_result[throughput_type].get_best_throughput()))
|
||||
performance_items.append(['{}_throughput'.format(throughput_type),
|
||||
'{:.02f} Mbps'.format(test_result[throughput_type].get_best_throughput())])
|
||||
|
||||
# 5. save to report
|
||||
TinyFW.JunitReport.update_performance(performance_items)
|
||||
# do check after logging, otherwise test will exit immediately if check fail, some performance can't be logged.
|
||||
for throughput_type in test_result:
|
||||
ttfw_idf.check_performance("{}_throughput".format(throughput_type),
|
||||
ttfw_idf.check_performance('{}_throughput'.format(throughput_type),
|
||||
test_result[throughput_type].get_best_throughput(), dut.TARGET)
|
||||
|
||||
env.close_dut("iperf")
|
||||
env.close_dut('iperf')
|
||||
|
||||
|
||||
@ttfw_idf.idf_example_test(env_tag="Example_ShieldBox2", category="stress")
|
||||
@ttfw_idf.idf_example_test(env_tag='Example_ShieldBox2', category='stress')
|
||||
def test_softap_throughput_vs_rssi(env, extra_data):
|
||||
"""
|
||||
steps: |
|
||||
@@ -705,25 +702,25 @@ def test_softap_throughput_vs_rssi(env, extra_data):
|
||||
3. set attenuator value from 0-60 for each router
|
||||
4. test TCP tx rx and UDP tx rx throughput
|
||||
"""
|
||||
att_port = env.get_variable("attenuator_port")
|
||||
att_port = env.get_variable('attenuator_port')
|
||||
|
||||
test_result = {
|
||||
"tcp_tx": TestResult("tcp", "tx", BEST_PERFORMANCE_CONFIG),
|
||||
"tcp_rx": TestResult("tcp", "rx", BEST_PERFORMANCE_CONFIG),
|
||||
"udp_tx": TestResult("udp", "tx", BEST_PERFORMANCE_CONFIG),
|
||||
"udp_rx": TestResult("udp", "rx", BEST_PERFORMANCE_CONFIG),
|
||||
'tcp_tx': TestResult('tcp', 'tx', BEST_PERFORMANCE_CONFIG),
|
||||
'tcp_rx': TestResult('tcp', 'rx', BEST_PERFORMANCE_CONFIG),
|
||||
'udp_tx': TestResult('udp', 'tx', BEST_PERFORMANCE_CONFIG),
|
||||
'udp_rx': TestResult('udp', 'rx', BEST_PERFORMANCE_CONFIG),
|
||||
}
|
||||
|
||||
# 1. get DUT and download
|
||||
softap_dut = env.get_dut("softap_iperf", "examples/wifi/iperf", dut_class=ttfw_idf.ESP32DUT,
|
||||
softap_dut = env.get_dut('softap_iperf', 'examples/wifi/iperf', dut_class=ttfw_idf.ESP32DUT,
|
||||
app_config_name=BEST_PERFORMANCE_CONFIG)
|
||||
softap_dut.start_app()
|
||||
softap_dut.expect_any("iperf>", "esp32>")
|
||||
softap_dut.expect_any('iperf>', 'esp32>')
|
||||
|
||||
sta_dut = env.get_dut("sta_iperf", "examples/wifi/iperf", dut_class=ttfw_idf.ESP32DUT,
|
||||
sta_dut = env.get_dut('sta_iperf', 'examples/wifi/iperf', dut_class=ttfw_idf.ESP32DUT,
|
||||
app_config_name=BEST_PERFORMANCE_CONFIG)
|
||||
sta_dut.start_app()
|
||||
sta_dut.expect_any("iperf>", "esp32>")
|
||||
sta_dut.expect_any('iperf>', 'esp32>')
|
||||
|
||||
# 2. run test for each required att value
|
||||
test_utility = IperfTestUtilitySoftap(sta_dut, softap_dut, BEST_PERFORMANCE_CONFIG, test_result)
|
||||
@@ -734,17 +731,17 @@ def test_softap_throughput_vs_rssi(env, extra_data):
|
||||
assert Attenuator.set_att(att_port, atten_val) is True
|
||||
test_utility.run_all_cases(atten_val)
|
||||
|
||||
env.close_dut("softap_iperf")
|
||||
env.close_dut("sta_iperf")
|
||||
env.close_dut('softap_iperf')
|
||||
env.close_dut('sta_iperf')
|
||||
|
||||
# 3. generate report
|
||||
report = TestReport.ThroughputVsRssiReport(os.path.join(env.log_path, "SoftAPThroughputVsRssiReport"),
|
||||
report = TestReport.ThroughputVsRssiReport(os.path.join(env.log_path, 'SoftAPThroughputVsRssiReport'),
|
||||
test_result)
|
||||
report.generate_report()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
test_wifi_throughput_basic(env_config_file="EnvConfig.yml")
|
||||
test_wifi_throughput_with_different_configs(env_config_file="EnvConfig.yml")
|
||||
test_wifi_throughput_vs_rssi(env_config_file="EnvConfig.yml")
|
||||
test_softap_throughput_vs_rssi(env_config_file="EnvConfig.yml")
|
||||
test_wifi_throughput_basic(env_config_file='EnvConfig.yml')
|
||||
test_wifi_throughput_with_different_configs(env_config_file='EnvConfig.yml')
|
||||
test_wifi_throughput_vs_rssi(env_config_file='EnvConfig.yml')
|
||||
test_softap_throughput_vs_rssi(env_config_file='EnvConfig.yml')
|
||||
|
||||
Reference in New Issue
Block a user