Skip to content

Commit

Permalink
btp: Apply proper naming convention for btp commands and events
Browse files Browse the repository at this point in the history
This commit changes naming convention of variables that are opcodes for
btp commands and events. This is needed for socat log parser, but will also
enhance clarity in files like defs.py, especially for services like GAP for
which many service related variables share the same value.
For now changes applied only for following svcs:
Core, Gap, Gatt, GattCL, L2CAP.
  • Loading branch information
piotrnarajowski committed Oct 29, 2024
1 parent d3326fd commit 04cd19f
Show file tree
Hide file tree
Showing 14 changed files with 391 additions and 390 deletions.
2 changes: 1 addition & 1 deletion autopts/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1540,7 +1540,7 @@ def run_recovery(args, ptses):
# mynewt project has not been refactored yet to reduce the number of
# IUT board resets.
if stack_inst.core:
stack_inst.core.event_received(defs.CORE_EV_IUT_READY, True)
stack_inst.core.event_received(defs.BTP_EV_CORE_IUT_READY, True)

log('Recovery finished')

Expand Down
2 changes: 1 addition & 1 deletion autopts/ptsprojects/bluez/iutctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def wait_iut_ready_event(self):

try:
if (tuple_hdr.svc_id != defs.BTP_SERVICE_ID_CORE or
tuple_hdr.op != defs.CORE_EV_IUT_READY):
tuple_hdr.op != defs.BTP_EV_CORE_IUT_READY):
raise BTPError("Failed to get ready event")
except BTPError as err:
log("Unexpected event received (%s), expected IUT ready!", err)
Expand Down
2 changes: 1 addition & 1 deletion autopts/ptsprojects/mynewt/iutctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def wait_iut_ready_event(self):

try:
if (tuple_hdr.svc_id != defs.BTP_SERVICE_ID_CORE or
tuple_hdr.op != defs.CORE_EV_IUT_READY):
tuple_hdr.op != defs.BTP_EV_CORE_IUT_READY):
raise BTPError("Failed to get ready event")
except BTPError as err:
log("Unexpected event received (%s), expected IUT ready!", err)
Expand Down
6 changes: 3 additions & 3 deletions autopts/ptsprojects/stack/layers/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@
class CORE:
def __init__(self):
self.event_queues = {
defs.CORE_EV_IUT_READY: [],
defs.BTP_EV_CORE_IUT_READY: [],
}

def event_received(self, event_type, event_data_tuple):
self.event_queues[event_type].append(event_data_tuple)

def wait_iut_ready_ev(self, timeout, remove=True):
return wait_for_queue_event(
self.event_queues[defs.CORE_EV_IUT_READY],
self.event_queues[defs.BTP_EV_CORE_IUT_READY],
lambda *_: True,
timeout, remove)

def cleanup(self):
for key in self.event_queues:
if key == defs.CORE_EV_IUT_READY:
if key == defs.BTP_EV_CORE_IUT_READY:
# To pass IUT ready event between test cases
continue

Expand Down
6 changes: 3 additions & 3 deletions autopts/ptsprojects/zephyr/iutctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def wait_iut_ready_event(self, reset=True):
ev = stack.core.wait_iut_ready_ev(30)
# If the board has reset unexpectedly in the middle of a test case,
# two IUT events may be received because of cleanup.
stack.core.event_queues[defs.CORE_EV_IUT_READY].clear()
stack.core.event_queues[defs.BTP_EV_CORE_IUT_READY].clear()
if not ev:
self.stop()
raise Exception('IUT ready event NOT received!')
Expand All @@ -241,7 +241,7 @@ def hw_reset(self):
# test case, to avoid double reset let's use 'hw_reset'
# only if it was not received, e.g. at the beginning of
# the first test case.
if len(stack.core.event_queues[defs.CORE_EV_IUT_READY]) == 0:
if len(stack.core.event_queues[defs.BTP_EV_CORE_IUT_READY]) == 0:
self.board.reset()

def stop(self):
Expand All @@ -258,7 +258,7 @@ def stop(self):
if not self.gdb and self.board and \
stack.core and not get_global_end():

stack.core.event_queues[defs.CORE_EV_IUT_READY].clear()
stack.core.event_queues[defs.BTP_EV_CORE_IUT_READY].clear()
self.board.reset()

# We have to wait for IUT ready event before we close socket
Expand Down
82 changes: 41 additions & 41 deletions autopts/pybtp/btp/btp.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,90 +53,90 @@ def read_supp_svcs():
tuple_hdr, tuple_data = iutctl.btp_socket.read()
btp_hdr_check(tuple_hdr,
defs.BTP_SERVICE_ID_CORE,
defs.CORE_READ_SUPPORTED_SERVICES)
defs.BTP_CMD_CORE_READ_SUPPORTED_SERVICES)
logging.debug("%s received %r %r", read_supp_svcs.__name__,
tuple_hdr, tuple_data)

stack.supported_svcs = int.from_bytes(tuple_data[0], 'little')


CORE = {
"gap_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"gap_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_GAP),
"gap_unreg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_UNREGISTER_SERVICE,
"gap_unreg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_UNREGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_GAP),
"gatt_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"gatt_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_GATT),
"gatt_unreg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_UNREGISTER_SERVICE,
"gatt_unreg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_UNREGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_GATT),
"l2cap_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"l2cap_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_L2CAP),
"l2cap_unreg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_UNREGISTER_SERVICE,
"l2cap_unreg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_UNREGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_L2CAP),
"mesh_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"mesh_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_MESH),
"mesh_unreg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_UNREGISTER_SERVICE,
"mesh_unreg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_UNREGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_MESH),
"mmdl_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"mmdl_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_MMDL),
"mmdl_unreg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_UNREGISTER_SERVICE,
"mmdl_unreg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_UNREGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_MMDL),
"gatt_cl_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"gatt_cl_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_GATTC),
"gatt_cl_unreg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_UNREGISTER_SERVICE,
"gatt_cl_unreg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_UNREGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_GATTC),
"vcs_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"vcs_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_VCS),
"vocs_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"vocs_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_VOCS),
"aics_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"aics_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_AICS),
"ias_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"ias_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_IAS),
"pacs_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"pacs_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_PACS),
"ascs_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"ascs_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_ASCS),
"bap_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"bap_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_BAP),
"has_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"has_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_HAS),
"csis_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"csis_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_CSIS),
"micp_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"micp_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_MICP),
"mics_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"mics_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_MICS),
"ccp_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"ccp_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_CCP),
"vcp_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"vcp_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_VCP),
"cas_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"cas_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_CAS),
"mcp_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"mcp_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_MCP),
"gmcs_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"gmcs_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_GMCS),
"hap_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"hap_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_HAP),
"cap_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"cap_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_CAP),
"csip_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"csip_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_CSIP),
"tbs_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"tbs_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_TBS),
"tmap_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"tmap_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE, defs.BTP_SERVICE_ID_TMAP),
"ots_reg": (defs.BTP_SERVICE_ID_CORE, defs.CORE_REGISTER_SERVICE,
"ots_reg": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_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,
defs.BTP_CMD_CORE_READ_SUPPORTED_COMMANDS,
defs.BTP_INDEX_NONE, ""),
"read_supp_svcs": (defs.BTP_SERVICE_ID_CORE,
defs.CORE_READ_SUPPORTED_SERVICES,
defs.BTP_CMD_CORE_READ_SUPPORTED_SERVICES,
defs.BTP_INDEX_NONE, ""),
"log_message": (defs.BTP_SERVICE_ID_CORE, defs.CORE_LOG_MESSAGE,
"log_message": (defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_LOG_MESSAGE,
defs.BTP_INDEX_NONE),
}

Expand Down Expand Up @@ -711,7 +711,7 @@ def core_reg_svc_rsp_succ():
iutctl = get_iut()

expected_frame = ((defs.BTP_SERVICE_ID_CORE,
defs.CORE_REGISTER_SERVICE,
defs.BTP_CMD_CORE_REGISTER_SERVICE,
defs.BTP_INDEX_NONE,
0),
(b'',))
Expand All @@ -732,7 +732,7 @@ def core_unreg_svc_rsp_succ():
iutctl = get_iut()

expected_frame = ((defs.BTP_SERVICE_ID_CORE,
defs.CORE_UNREGISTER_SERVICE,
defs.BTP_CMD_CORE_UNREGISTER_SERVICE,
defs.BTP_INDEX_NONE,
0),
(b'',))
Expand All @@ -759,7 +759,7 @@ def core_log_message(message):
tuple_hdr, tuple_data = iutctl.btp_socket.read()
logging.debug("received %r %r", tuple_hdr, tuple_data)

btp_hdr_check(tuple_hdr, defs.BTP_SERVICE_ID_CORE, defs.CORE_LOG_MESSAGE)
btp_hdr_check(tuple_hdr, defs.BTP_SERVICE_ID_CORE, defs.BTP_CMD_CORE_LOG_MESSAGE)


def btp2uuid(uuid_len, uu):
Expand Down
4 changes: 2 additions & 2 deletions autopts/pybtp/btp/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
def core_iut_ready_ev(core, data, data_len):
logging.debug("%s", core_iut_ready_ev.__name__)

core.event_received(defs.CORE_EV_IUT_READY, True)
core.event_received(defs.BTP_EV_CORE_IUT_READY, True)


CORE_EV = {
defs.CORE_EV_IUT_READY: core_iut_ready_ev,
defs.BTP_EV_CORE_IUT_READY: core_iut_ready_ev,
}
Loading

0 comments on commit 04cd19f

Please sign in to comment.