Skip to content

Commit

Permalink
zephyr: Update OTS support
Browse files Browse the repository at this point in the history
This adds dedicated service for testing OTS and updates errata list.
  • Loading branch information
sjanc committed Apr 30, 2024
1 parent 5116f4e commit 215e5c1
Show file tree
Hide file tree
Showing 15 changed files with 184 additions and 99 deletions.
11 changes: 10 additions & 1 deletion autopts/bot/iut_config/zephyr.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,22 @@
]
},

"ots_no_dir_list.conf": {
"overlay": {
'CONFIG_BT_OTS_DIR_LIST_OBJ': 'n',
},
"test_cases": [
'OTS/SR/OLE/BI-03-C',
]
},

"overlay-le-audio.conf": {
"overlay": {
# The overlay file exists in zephyr repo. Leave this empty.
},
"test_cases": [
'VOCS', 'VCS', 'AICS', 'IAS', 'PACS', 'ASCS', 'BAP', 'HAS', 'CSIS', 'MICP',
'MICS', 'VCP', 'MCP', 'CAP', 'BASS', 'GMCS', 'CCP', 'HAP', 'TBS', 'GTBS', 'OTS',
'MICS', 'VCP', 'MCP', 'CAP', 'BASS', 'GMCS', 'CCP', 'HAP', 'TBS', 'GTBS',
'TMAP',
]
},
Expand Down
2 changes: 1 addition & 1 deletion autopts/ptsprojects/stack/layers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@
from .csip import *
from .tbs import *
from .gtbs import *
from .ots import *
from .tmap import *
from .ots import *
# GENERATOR append 1
15 changes: 8 additions & 7 deletions autopts/ptsprojects/stack/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"CSIP": 1 << defs.BTP_SERVICE_ID_CSIP,
"TBS": 1 << defs.BTP_SERVICE_ID_TBS,
"TMAP": 1 << defs.BTP_SERVICE_ID_TMAP,
"OTS": 1 << defs.BTP_SERVICE_ID_OTS,
# GENERATOR append 1
}

Expand Down Expand Up @@ -84,8 +85,8 @@ def __init__(self):
self.csip = None
self.tbs = None
self.gtbs = None
self.ots = None
self.tmap = None
self.ots = None
# GENERATOR append 2

def is_svc_supported(self, svc):
Expand Down Expand Up @@ -179,12 +180,12 @@ def tbs_init(self):
def gtbs_init(self):
self.gtbs = GTBS()

def ots_init(self):
self.ots = OTS()

def tmap_init(self):
self.tmap = TMAP()

def ots_init(self):
self.ots = OTS()

# GENERATOR append 3

def cleanup(self):
Expand Down Expand Up @@ -260,12 +261,12 @@ def cleanup(self):
if self.gtbs:
self.gtbs_init()

if self.ots:
self.ots_init()

if self.tmap:
self.tmap_init()

if self.ots:
self.ots_init()

# GENERATOR append 4


Expand Down
2 changes: 1 addition & 1 deletion autopts/ptsprojects/zephyr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
import autopts.ptsprojects.zephyr.gmcs
import autopts.ptsprojects.zephyr.tbs
import autopts.ptsprojects.zephyr.gtbs
import autopts.ptsprojects.zephyr.ots
import autopts.ptsprojects.zephyr.tmap
import autopts.ptsprojects.zephyr.ots
# GENERATOR append 1

# Constants
Expand Down
85 changes: 53 additions & 32 deletions autopts/ptsprojects/zephyr/ots.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# auto-pts - The Bluetooth PTS Automation Framework
#
# Copyright (c) 2023, Codecoup.
# Copyright (c) 2024, Codecoup.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms and conditions of the GNU General Public License,
Expand All @@ -13,22 +13,13 @@
# more details.
#

"""OTS test cases"""

from autopts.pybtp import btp
from autopts.client import get_unique_name
from autopts.ptsprojects.stack import get_stack
from autopts.ptsprojects.testcase import TestFunc
from autopts.ptsprojects.zephyr.ots_wid import ots_wid_hdl
from autopts.ptsprojects.zephyr.ztestcase import ZTestCase
from autopts.pybtp.types import IOCap, Addr
from queue import Queue

queue = Queue()


def set_addr(addr):
queue.put(addr)
from autopts.pybtp import btp
from autopts.ptsprojects.zephyr.ots_wid import ots_wid_hdl
from autopts.client import get_unique_name
from autopts.pybtp.types import Addr


def set_pixits(ptses):
Expand All @@ -53,47 +44,77 @@ def set_pixits(ptses):
pts.set_pixit("OTS", "TSPX_use_dynamic_pin", "FALSE")
pts.set_pixit("OTS", "TSPX_delete_ltk", "TRUE")
pts.set_pixit("OTS", "TSPX_security_enabled", "TRUE")
pts.set_pixit("OTS", "TSPX_iut_object_name", "Object 1 with very long name")
pts.set_pixit("OTS", "TSPX_iut_object_size_create", "100")
pts.set_pixit("OTS", "TSPX_iut_object_read_offset", "20")
pts.set_pixit("OTS", "TSPX_iut_object_write_offset", "20")
pts.set_pixit("OTS", "TSPX_iut_object_write_length", "20")


def test_cases(ptses):
"""Returns a list of OTS Server test cases"""
"""
Returns a list of OTS test cases
ptses -- list of PyPTS instances
"""

pts = ptses[0]

pts_bd_addr = pts.q_bd_addr
iut_device_name = get_unique_name(pts)
stack = get_stack()

# Generic preconditions for all test case in the profile
pre_conditions = [
TestFunc(btp.core_reg_svc_gap),
TestFunc(stack.gap_init, iut_device_name),
TestFunc(btp.core_reg_svc_gatt),
TestFunc(btp.gap_read_ctrl_info),
TestFunc(lambda: pts.update_pixit_param(
"OTS", "TSPX_bd_addr_iut",
stack.gap.iut_addr_get_str())),
TestFunc(lambda: set_addr(
stack.gap.iut_addr_get_str())),
TestFunc(btp.gap_set_io_cap, IOCap.display_only),
TestFunc(lambda: pts.update_pixit_param("OTS", "TSPX_bd_addr_iut", stack.gap.iut_addr_get_str())),
TestFunc(btp.set_pts_addr, pts_bd_addr, Addr.le_public),
TestFunc(btp.core_reg_svc_gatt),
TestFunc(stack.gatt_init),
TestFunc(btp.gap_set_conn),
TestFunc(btp.gap_set_gendiscov),
# OTS cannot be initialized as a primary service on zephyr. For now, for test
# purposes we initialize GMCS where OTS is secondary service.
TestFunc(btp.core_reg_svc_gmcs),
TestFunc(lambda: pts.update_pixit_param(
"OTS", "TSPX_iut_device_name_in_adv_packet_for_random_address", iut_device_name)),
TestFunc(btp.core_reg_svc_ots),
TestFunc(stack.ots_init)
]

pre_conditions_props = [
TestFunc(btp.otc_register_object, 0, "Object 1 with very long name", 0x01, 0xff, 100, 50)

]

pre_conditions_no_props = [
TestFunc(btp.otc_register_object, 0, "Object 1 with very long name", 0x01, 0x00, 100, 50)
]

custom_test_cases = [
ZTestCase('OTS', 'OTS/SR/OAE/BI-06-C',
cmds=pre_conditions + pre_conditions_no_props,
generic_wid_hdl=ots_wid_hdl),
ZTestCase('OTS', 'OTS/SR/OAE/BI-07-C',
cmds=pre_conditions + pre_conditions_no_props,
generic_wid_hdl=ots_wid_hdl),
ZTestCase('OTS', 'OTS/SR/OAE/BI-08-C',
cmds=pre_conditions + pre_conditions_no_props,
generic_wid_hdl=ots_wid_hdl),
ZTestCase('OTS', 'OTS/SR/OAE/BI-09-C',
cmds=pre_conditions + pre_conditions_no_props,
generic_wid_hdl=ots_wid_hdl),
ZTestCase('OTS', 'OTS/SR/OLE/BI-03-C',
cmds=pre_conditions,
generic_wid_hdl=ots_wid_hdl),
]

test_case_name_list = pts.get_test_case_list('OTS')
tc_list = []

# Use the same preconditions and MMI/WID handler for all test cases of the profile
for tc_name in test_case_name_list:
instance = ZTestCase("OTS", tc_name,
cmds=pre_conditions,
instance = ZTestCase('OTS', tc_name, cmds=pre_conditions + pre_conditions_props,
generic_wid_hdl=ots_wid_hdl)

for custom_tc in custom_test_cases:
if tc_name == custom_tc.name:
instance = custom_tc
break

tc_list.append(instance)

return tc_list
8 changes: 4 additions & 4 deletions autopts/ptsprojects/zephyr/ots_wid.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# auto-pts - The Bluetooth PTS Automation Framework
#
# Copyright (c) 2023, Codecoup.
# Copyright (c) 2024, Codecoup.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms and conditions of the GNU General Public License,
Expand All @@ -13,15 +13,15 @@
# more details.
#


import logging

from autopts.pybtp.types import WIDParams
from autopts.wid import generic_wid_hdl
from autopts.pybtp import btp
from autopts.ptsprojects.zephyr.iutctl import get_iut

log = logging.debug


def ots_wid_hdl(wid, description, test_case_name):
log(f'{ots_wid_hdl.__name__}, {wid}, {description}, {test_case_name}')
return generic_wid_hdl(wid, description, test_case_name, [__name__, 'autopts.wid.ots'])
return generic_wid_hdl(wid, description, test_case_name, [__name__, 'autopts.wid.ots'])
2 changes: 1 addition & 1 deletion autopts/pybtp/btp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@
from autopts.pybtp.btp.cap import *
from autopts.pybtp.btp.csip import *
from autopts.pybtp.btp.tbs import *
from autopts.pybtp.btp.ots import *
from autopts.pybtp.btp.tmap import *
from autopts.pybtp.btp.ots import *
# GENERATOR append 1
9 changes: 7 additions & 2 deletions autopts/pybtp/btp/btp.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
LeAdv = namedtuple('LeAdv', 'addr_type addr rssi flags eir')

CONTROLLER_INDEX = 0
CONTROLLER_INDEX_NONE = 0xff


def read_supp_svcs():
Expand Down Expand Up @@ -126,6 +127,8 @@ def read_supp_svcs():
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_TBS),
"tmap_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_TMAP),
"ots_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_OTS),
# GENERATOR append 4
"read_supp_cmds": (defs.BTP_SERVICE_ID_CORE,
defs.CORE_READ_SUPPORTED_COMMANDS,
Expand Down Expand Up @@ -694,15 +697,15 @@ def core_reg_svc_tbs():
iutctl.btp_socket.send_wait_rsp(*CORE['tbs_reg'])


# GENERATOR append 1

def core_reg_svc_ots():
logging.debug("%s", core_reg_svc_ots.__name__)

iutctl = get_iut()
iutctl.btp_socket.send_wait_rsp(*CORE['ots_reg'])


# GENERATOR append 1

def core_reg_svc_rsp_succ():
logging.debug("%s", core_reg_svc_rsp_succ.__name__)
iutctl = get_iut()
Expand Down Expand Up @@ -801,6 +804,7 @@ def init(get_iut_method):
from .csip import CSIP_EV
from .tbs import TBS_EV
from .tmap import TMAP_EV
from .ots import OTS_EV
# GENERATOR append 2

from autopts.pybtp.iutctl_common import set_event_handler
Expand Down Expand Up @@ -839,6 +843,7 @@ def event_handler(hdr, data):
defs.BTP_SERVICE_ID_CSIP: (CSIP_EV, stack.csip),
defs.BTP_SERVICE_ID_TBS: (TBS_EV, stack.tbs),
defs.BTP_SERVICE_ID_TMAP: (TMAP_EV, stack.tmap),
defs.BTP_SERVICE_ID_OTS: (OTS_EV, stack.ots),
# GENERATOR append 3
}

Expand Down
49 changes: 36 additions & 13 deletions autopts/pybtp/btp/ots.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#
# auto-pts - The Bluetooth PTS Automation Framework
#
# Copyright (c) 2023, Codecoup.
# Copyright (c) 2024, Codecoup.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms and conditions of the GNU General Public License,
Expand All @@ -13,27 +13,50 @@
# more details.
#

"""Wrapper around btp messages. The functions are added as needed."""
import binascii
import logging
import struct

from autopts.pybtp import defs
from autopts.pybtp.btp.btp import CONTROLLER_INDEX, get_iut_method as get_iut, btp_hdr_check, pts_addr_get, \
pts_addr_type_get
from autopts.pybtp.types import BTPError, addr2btp_ba
from autopts.pybtp.btp.btp import CONTROLLER_INDEX, CONTROLLER_INDEX_NONE, get_iut_method as get_iut, \
btp_hdr_check
from autopts.pybtp.types import BTPError

log = logging.debug


OTS = {
'read_supported_cmds': (defs.BTP_SERVICE_ID_OTS,
defs.OTS_READ_SUPPORTED_COMMANDS,
CONTROLLER_INDEX_NONE),
'register_object': (defs.BTP_SERVICE_ID_OTS,
defs.OTS_REGISTER_OBJECT,
CONTROLLER_INDEX),
}


def address_to_ba(bd_addr_type=None, bd_addr=None):
data = bytearray()
bd_addr_ba = addr2btp_ba(pts_addr_get(bd_addr))
bd_addr_type_ba = chr(pts_addr_type_get(bd_addr_type)).encode('utf-8')
data.extend(bd_addr_type_ba)
data.extend(bd_addr_ba)
return data
def otc_register_object(index, name, flags=0, props=0, alloc_size=0, current_size=0):
logging.debug(f"{otc_register_object.__name__}")

data_ba = bytearray(struct.pack('<BIIIB', flags, props, alloc_size, current_size, len(name)))
data_ba.extend(name.encode())

iutctl = get_iut()
iutctl.btp_socket.send(*OTS['register_object'], data=data_ba)

ots_command_rsp_succ()


def ots_command_rsp_succ(timeout=20.0):
logging.debug("%s", ots_command_rsp_succ.__name__)

iutctl = get_iut()

tuple_hdr, tuple_data = iutctl.btp_socket.read(timeout)
logging.debug("received %r %r", tuple_hdr, tuple_data)

btp_hdr_check(tuple_hdr, defs.BTP_SERVICE_ID_OTS)

return tuple_data

OTS_EV = {}
OTS_EV = {}
Loading

0 comments on commit 215e5c1

Please sign in to comment.