Skip to content

Commit abad49b

Browse files
Thalleykartben
authored andcommitted
tests: Bluetooth: BSIM: Store last sent opcode for BT tester
The BT Tester will not provide the opcode in the case of a BTP error. To help log this for developers, we store the opcode of the currently outstanding command, so that we can log it. Signed-off-by: Emil Gydesen <[email protected]>
1 parent faec7c5 commit abad49b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

tests/bsim/bluetooth/tester/src/bsim_btp.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <zephyr/kernel.h>
1616
#include <zephyr/logging/log.h>
1717
#include <zephyr/net_buf.h>
18+
#include <zephyr/sys/atomic.h>
19+
#include <zephyr/sys/atomic_types.h>
1820
#include <zephyr/sys/byteorder.h>
1921
#include <zephyr/sys/util.h>
2022
#include <zephyr/sys_clock.h>
@@ -31,6 +33,7 @@ K_FIFO_DEFINE(btp_evt_fifo);
3133
NET_BUF_POOL_FIXED_DEFINE(btp_evt_pool, 100, BTP_MTU, 0, NULL);
3234

3335
static const struct device *const dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
36+
static atomic_val_t last_send_opcode;
3437

3538
static bool is_valid_core_packet_len(const struct btp_hdr *hdr, struct net_buf_simple *buf_simple)
3639
{
@@ -1854,8 +1857,8 @@ static bool recv_cb(uint8_t buf[], size_t buf_len)
18541857

18551858
TEST_ASSERT(is_valid_packet_len(buf, buf_len),
18561859
"Header len %u does not match expected packet length for "
1857-
"service 0x%02X and opcode 0x%02X",
1858-
hdr->len, hdr->service, hdr->opcode);
1860+
"service 0x%02X and opcode 0x%02X (last sent opcode 0x%02X)",
1861+
hdr->len, hdr->service, hdr->opcode, (uint8_t)atomic_get(&last_send_opcode));
18591862

18601863
if (hdr->opcode < BTP_EVENT_OPCODE) {
18611864
struct net_buf *net_buf = net_buf_alloc(&btp_rsp_pool, K_NO_WAIT);
@@ -1940,10 +1943,13 @@ void bsim_btp_send_to_tester(const uint8_t *data, size_t len)
19401943

19411944
cmd_hdr = (const struct btp_hdr *)data;
19421945
LOG_DBG("cmd service 0x%02X and opcode 0x%02X", cmd_hdr->service, cmd_hdr->opcode);
1946+
atomic_set(&last_send_opcode, cmd_hdr->opcode);
19431947

19441948
for (size_t i = 0U; i < len; i++) {
19451949
uart_poll_out(dev, data[i]);
19461950
}
19471951

19481952
wait_for_response(cmd_hdr);
1953+
1954+
atomic_clear(&last_send_opcode);
19491955
}

0 commit comments

Comments
 (0)