diff --git a/autopts/wid/hap.py b/autopts/wid/hap.py index 35f6c41ac7..7d5836c91f 100644 --- a/autopts/wid/hap.py +++ b/autopts/wid/hap.py @@ -14,6 +14,7 @@ # import logging +import re from argparse import Namespace from autopts.pybtp import btp @@ -21,7 +22,7 @@ from autopts.ptsprojects.testcase import MMI from autopts.pybtp.defs import AUDIO_METADATA_STREAMING_AUDIO_CONTEXTS from autopts.pybtp.types import * -from autopts.pybtp.btp.btp import pts_addr_get, pts_addr_type_get +from autopts.pybtp.btp.btp import pts_addr_get, pts_addr_type_get, lt2_addr_get, lt2_addr_type_get from autopts.wid import generic_wid_hdl log = logging.debug @@ -49,6 +50,247 @@ def hap_wid_hdl(wid, description, test_case_name): # wid handlers section begin +def hdl_wid_462(params: WIDParams): + """ + Please write Set Active Preset opcode with index: X. + """ + + if params.test_case_name.endswith('LT2'): + addr = lt2_addr_get() + addr_type = lt2_addr_type_get() + else: + addr = pts_addr_get() + addr_type = pts_addr_type_get() + + preset_index = int(re.search(r'\d+', params.description).group()) + btp.hap_set_active_preset(preset_index, 0, addr_type, addr) + + return True + + +def hdl_wid_463(params: WIDParams): + """ + Please write Set Next Preset opcode + """ + + if params.test_case_name.endswith('LT2'): + addr = lt2_addr_get() + addr_type = lt2_addr_type_get() + else: + addr = pts_addr_get() + addr_type = pts_addr_type_get() + + btp.hap_set_next_preset(0, addr_type, addr) + + return True + + +def hdl_wid_464(params: WIDParams): + """ + Please write Set Previous Preset opcode + """ + + if params.test_case_name.endswith('LT2'): + addr = lt2_addr_get() + addr_type = lt2_addr_type_get() + else: + addr = pts_addr_get() + addr_type = pts_addr_type_get() + + btp.hap_set_previous_preset(0, addr_type, addr) + + return True + + +def hdl_wid_465(params: WIDParams): + """ + Please write Read Preset opcode with index 0x01 and num presets to 0xff. + """ + + if params.test_case_name.endswith('LT2'): + addr = lt2_addr_get() + addr_type = lt2_addr_type_get() + else: + addr = pts_addr_get() + addr_type = pts_addr_type_get() + + numbers = re.findall(r'0x[0-9a-fA-F]+', params.description) + start_index = int(numbers[0], 16) + num_presets = int(numbers[1], 16) + btp.hap_read_presets(start_index, num_presets, addr_type, addr) + + return True + + +def hdl_wid_466(params: WIDParams): + """ + Please write Read Preset Index opcode with index: 2, numPresets: 1. + """ + + if params.test_case_name.endswith('LT2'): + addr = lt2_addr_get() + addr_type = lt2_addr_type_get() + else: + addr = pts_addr_get() + addr_type = pts_addr_type_get() + + numbers = re.findall(r'\d+', params.description) + start_index = int(numbers[0]) + num_presets = int(numbers[0]) + btp.hap_read_presets(start_index, num_presets, addr_type, addr) + + return True + +def hdl_wid_467(params: WIDParams): + """ + Please confirm that new preset record was added to IUT's internal list. + """ + + if params.test_case_name.endswith('LT2'): + addr = lt2_addr_get() + addr_type = lt2_addr_type_get() + else: + addr = pts_addr_get() + addr_type = pts_addr_type_get() + + stack = get_stack() + preset_change_received = stack.hap.wait_preset_changed_ev(addr_type, addr, 0, 30) + + return preset_change_received + + +def hdl_wid_468(params: WIDParams): + """ + Please update Index: 2 with new name in "New Preset Name" + """ + + if params.test_case_name.endswith('LT2'): + addr = lt2_addr_get() + addr_type = lt2_addr_type_get() + else: + addr = pts_addr_get() + addr_type = pts_addr_type_get() + + match = re.search(r'Index:\s*(\d+)\s*with new name in\s*"([^"]+)"', params.description) + if not match: + return False + + preset_index = int(match.group(1)) + name = match.group(2) + btp.hap_write_preset_name(preset_index, name, addr_type, addr) + + return True + + +def hdl_wid_469(params: WIDParams): + """ + Please write Set Active Preset Synchronized Locally opcode with index: X. + """ + + if params.test_case_name.endswith('LT2'): + addr = lt2_addr_get() + addr_type = lt2_addr_type_get() + else: + addr = pts_addr_get() + addr_type = pts_addr_type_get() + + preset_index = int(re.search(r'\d+', params.description).group()) + btp.hap_set_active_preset(preset_index, 1, addr_type, addr) + + return True + + +def hdl_wid_470(params: WIDParams): + """ + Please write Set Next Preset Synchronized Locally opcode + """ + + if params.test_case_name.endswith('LT2'): + addr = lt2_addr_get() + addr_type = lt2_addr_type_get() + else: + addr = pts_addr_get() + addr_type = pts_addr_type_get() + + btp.hap_set_next_preset(1, addr_type, addr) + + return True + + +def hdl_wid_471(params: WIDParams): + """ + Please write Set Previous Preset Synchronized Locally opcode. + """ + + if params.test_case_name.endswith('LT2'): + addr = lt2_addr_get() + addr_type = lt2_addr_type_get() + else: + addr = pts_addr_get() + addr_type = pts_addr_type_get() + + btp.hap_set_previous_preset(1, addr_type, addr) + + return True + + +def hdl_wid_472(params: WIDParams): + """ + Please write Set Active Preset opcode with index: 2. Do not expect to receive the message + """ + + # similar to 'Please write Set Active Preset opcode with index: X' + return hdl_wid_462(params) + + +def hdl_wid_473(params: WIDParams): + """ + Please update Index: 1 with new name in random 40 characters + """ + + if params.test_case_name.endswith('LT2'): + addr = lt2_addr_get() + addr_type = lt2_addr_type_get() + else: + addr = pts_addr_get() + addr_type = pts_addr_type_get() + + # Extract index and new name + match = re.search(r'Index: (\d+) with new name in random (\d+) characters', params.description) + if not match: + return False + + preset_index = int(match.group(1)) + num_characters = int(match.group(2)) + name = 'r' * num_characters + btp.hap_write_preset_name(preset_index, name, addr_type, addr) + + return True + + +def hdl_wid_474(_: WIDParams): + """ + Please click OK when both lower testers are performed operation (MMI poped up both Lower testers) + """ + + # Synchronized in ptsproject/hap.py + + return True + +def hdl_wid_476(_: WIDParams): + """ + Please send exchange MTU command to the PTS with MTU size greater than 49. + """ + + # BTstack exchanges MTU before any GATT Client requests, so just discover something + stack = get_stack() + addr = pts_addr_get() + addr_type = pts_addr_type_get() + btp.hap_hauc_discover(addr_type, addr) + stack.hap.wait_hauc_discovery_complete_ev(addr_type, addr, 30) + + return True + def hdl_wid_477(_: WIDParams): """ Please verify that the IUT starts alerting with a High Alert. @@ -59,6 +301,23 @@ def hdl_wid_477(_: WIDParams): return stack.ias.alert_lvl == 2 +def hdl_wid_478(params: WIDParams): + """ + Please write preset name to index: 1 with random string. + """ + if params.test_case_name.endswith('LT2'): + addr = lt2_addr_get() + addr_type = lt2_addr_type_get() + else: + addr = pts_addr_get() + addr_type = pts_addr_type_get() + + preset_index = int(re.search(r'\d+', params.description).group()) + name = "random string" + btp.hap_write_preset_name(preset_index, name, addr_type, addr) + + return True + def hdl_wid_479(_: WIDParams): """ @@ -78,15 +337,19 @@ def hdl_wid_480(_: WIDParams): return True -def hdl_wid_481(_: WIDParams): +def hdl_wid_481(params: WIDParams): """ Please read SIRK Characteristic. """ - stack = get_stack() - addr = pts_addr_get() - addr_type = pts_addr_type_get() + if params.test_case_name.endswith('LT2'): + addr = lt2_addr_get() + addr_type = lt2_addr_type_get() + else: + addr = pts_addr_get() + addr_type = pts_addr_type_get() # SIRK is read during CSIP discovery + stack = get_stack() btp.csip_discover(addr_type, addr) ev = stack.csip.wait_discovery_completed_ev(addr_type, addr, 30) @@ -198,6 +461,34 @@ def hdl_wid_489(_: WIDParams): return not ev is None +def hdl_wid_490(_: WIDParams): + """ + Please click OK after IUT discovered and configured. + """ + # no idea what this means, but we can click OK for sure + return True + + +def hdl_wid_491(_: WIDParams): + """ + Please update Index: 2 with new name in LT2. Do not expect IUT to send command to LT2. + """ + addr = lt2_addr_get() + addr_type = lt2_addr_type_get() + + # as we're not supposed to actually send this, the values don't matter + btp.hap_write_preset_name(2, "New Name", addr_type, addr) + + return True + + +def hdl_wid_493(_: WIDParams): + """ + Please click OK when IUT is ready to receive Preset Changed message + """ + return True + + def hdl_wid_20001(_: WIDParams): """ Please prepare IUT into a connectable mode. @@ -209,15 +500,19 @@ def hdl_wid_20001(_: WIDParams): return True -def hdl_wid_20100(_: WIDParams): +def hdl_wid_20100(params: WIDParams): """ Please initiate a GATT connection to the PTS. Description: Verify that the Implementation Under Test (IUT) can initiate a GATT connect request to the PTS. """ - addr = pts_addr_get() - addr_type = pts_addr_type_get() - stack = get_stack() + if params.test_case_name.endswith('LT2'): + addr = lt2_addr_get() + addr_type = lt2_addr_type_get() + else: + addr = pts_addr_get() + addr_type = pts_addr_type_get() + stack = get_stack() btp.gap_conn(addr, addr_type) stack.gap.wait_for_connection(timeout=10, addr=addr) stack.gap.gap_wait_for_sec_lvl_change(level=2, timeout=30, addr=addr) @@ -246,17 +541,49 @@ def hdl_wid_20103(params: WIDParams): return True -def hdl_wid_20106(_: WIDParams): +def hdl_wid_20105(params: WIDParams): + """ + Please write to Client Characteristic Configuration Descriptor of Hearing Aid Preset + Control Point characteristic to enable indication. + """ + if params.test_case_name.endswith('LT2'): + addr = lt2_addr_get() + addr_type = lt2_addr_type_get() + else: + addr = pts_addr_get() + addr_type = pts_addr_type_get() + + stack = get_stack() + peer = stack.hap.get_peer(addr_type, addr) + if peer.discovery_completed: + log('Skip HAP discovery, discovery completed before') + + # Skip if discovery has been done already + return True + + btp.hap_hauc_discover(addr_type, addr) + stack.hap.wait_hauc_discovery_complete_ev(addr_type, addr, 30) + + return True + + +def hdl_wid_20106(params: WIDParams): """ Please write to Client Characteristic Configuration Descriptor of ASE Control Point characteristic to enable notification. """ - addr = pts_addr_get() - addr_type = pts_addr_type_get() - stack = get_stack() + if params.test_case_name.endswith('LT2'): + addr = lt2_addr_get() + addr_type = lt2_addr_type_get() + else: + addr = pts_addr_get() + addr_type = pts_addr_type_get() + stack = get_stack() peer = stack.bap.get_peer(addr_type, addr) if peer.discovery_completed: + log('Skip BAP discovery, discovery completed before') + # Skip if discovery has been done already return True @@ -265,6 +592,28 @@ def hdl_wid_20106(_: WIDParams): return True +def hdl_wid_20107(params: WIDParams): + """ + Please send Read Request to read X characteristic with handle = Y. + """ + addr = pts_addr_get() + addr_type = pts_addr_type_get() + stack = get_stack() + + MMI.reset() + MMI.parse_description(params.description) + + value_handle = MMI.args[0] + + if not value_handle: + logging.debug("parsing error") + return False + + # Read Characteristic Value and wait for response + btp.gattc_read(addr_type, addr, value_handle) + btp.gattc_read_rsp() + + return True def hdl_wid_20116(_: WIDParams): """