ble-wifi-example-tests: Add fixes and cleanups to ble and wifi tests

This commit is contained in:
Shivani Tipnis
2021-04-07 17:13:02 +05:30
parent b9911e01b3
commit 2d22374460
10 changed files with 953 additions and 982 deletions

View File

@@ -17,9 +17,14 @@
from __future__ import print_function
import os
import re
import subprocess
import uuid
import threading
import traceback
try:
import Queue
except ImportError:
import queue as Queue
import ttfw_idf
from ble import lib_ble_client
@@ -30,21 +35,75 @@ from tiny_test_fw import Utility
# > make print_flash_cmd | tail -n 1 > build/download.config
def blecent_client_task(dut):
interface = 'hci0'
adv_host_name = 'BleCentTestApp'
adv_type = 'peripheral'
adv_uuid = '1811'
# Get BLE client module
ble_client_obj = lib_ble_client.BLE_Bluez_Client(iface=interface)
# Discover Bluetooth Adapter and power on
is_adapter_set = ble_client_obj.set_adapter()
if not is_adapter_set:
return
'''
Blecent application run:
Create GATT data
Register GATT Application
Create Advertising data
Register advertisement
Start advertising
'''
# Create Gatt Application
# Register GATT Application
ble_client_obj.register_gatt_app()
# Register Advertisement
# Check read/write/subscribe is received from device
ble_client_obj.register_adv(adv_host_name, adv_type, adv_uuid)
# Check dut responses
dut.expect('Connection established', timeout=30)
dut.expect('Service discovery complete; status=0', timeout=30)
dut.expect('GATT procedure initiated: read;', timeout=30)
dut.expect('Read complete; status=0', timeout=30)
dut.expect('GATT procedure initiated: write;', timeout=30)
dut.expect('Write complete; status=0', timeout=30)
dut.expect('GATT procedure initiated: write;', timeout=30)
dut.expect('Subscribe complete; status=0', timeout=30)
dut.expect('received notification;', timeout=30)
class BleCentThread(threading.Thread):
def __init__(self, dut, exceptions_queue):
threading.Thread.__init__(self)
self.dut = dut
self.exceptions_queue = exceptions_queue
def run(self):
try:
blecent_client_task(self.dut)
except RuntimeError:
self.exceptions_queue.put(traceback.format_exc(), block=False)
@ttfw_idf.idf_example_test(env_tag='Example_WIFI_BT')
def test_example_app_ble_central(env, extra_data):
"""
Steps:
1. Discover Bluetooth Adapter and Power On
2. Connect BLE Device
3. Start Notifications
4. Updated value is retrieved
5. Stop Notifications
"""
# Remove cached bluetooth devices of any previous connections
subprocess.check_output(['rm', '-rf', '/var/lib/bluetooth/*'])
subprocess.check_output(['hciconfig', 'hci0', 'reset'])
interface = 'hci0'
adv_host_name = 'BleCentTestApp'
adv_iface_index = 0
adv_type = 'peripheral'
adv_uuid = '1811'
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)
@@ -58,52 +117,23 @@ def test_example_app_ble_central(env, extra_data):
dut.start_app()
dut.reset()
device_addr = ':'.join(re.findall('..', '%012x' % uuid.getnode()))
exceptions_queue = Queue.Queue()
# Starting a py-client in a separate thread
blehr_thread_obj = BleCentThread(dut, exceptions_queue)
blehr_thread_obj.start()
blehr_thread_obj.join()
# 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 !!')
exception_msg = None
while True:
try:
exception_msg = exceptions_queue.get(block=False)
except Queue.Empty:
break
else:
Utility.console_log('\n' + exception_msg)
# 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 !!')
# Write device address to dut
dut.expect('BLE Host Task Started', timeout=60)
dut.write(device_addr + '\n')
'''
Blecent application run:
Create GATT data
Register GATT Application
Create Advertising data
Register advertisement
Start advertising
'''
ble_client_obj.start_advertising(adv_host_name, adv_iface_index, adv_type, adv_uuid)
# Call disconnect to perform cleanup operations before exiting application
ble_client_obj.disconnect()
# Check dut responses
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('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('Subscribe complete; status=0', timeout=60)
print('Subscribe passed\n\tClientCharacteristicConfigurationDescriptor\n\tSubscribe Status: 0')
if exception_msg:
raise Exception('Blecent thread did not run successfully')
if __name__ == '__main__':