Skip to content

Commit 2428d3c

Browse files
jhedbergdkalowsk
authored andcommitted
tests: bluetooth: addr: Cover bt_addr_le_is_resolved() and copy_resolved()
Add a ZTEST suite for the two internal helpers that translate the address types found in HCI LE events: - bt_addr_le_is_resolved() is true for the two identity types only, and false for public, random and the anonymous and unresolved sentinels - bt_addr_le_copy_resolved() maps an identity type to its base type and keeps the address bytes Assisted-by: Claude:claude-fable-5-1 Signed-off-by: Johan Hedberg <johan.hedberg@silabs.com>
1 parent d3157a6 commit 2428d3c

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

‎tests/bluetooth/addr/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ target_sources(app PRIVATE
1313
src/test_bt_addr_le_eq.c
1414
src/test_bt_addr_from_str.c
1515
src/test_bt_addr_le_resolve.c
16+
src/test_bt_addr_le_is_resolved.c
1617
)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/* Copyright (c) 2026 Silicon Laboratories Inc.
2+
* SPDX-License-Identifier: Apache-2.0
3+
*/
4+
5+
#include <zephyr/bluetooth/addr.h>
6+
#include <zephyr/ztest.h>
7+
8+
#include <host/addr_internal.h>
9+
10+
ZTEST_SUITE(bt_addr_le_is_resolved, NULL, NULL, NULL, NULL, NULL);
11+
12+
static const bt_addr_t example = { { 0x66, 0x55, 0x44, 0x33, 0x22, 0x11 } };
13+
14+
static ZTEST(bt_addr_le_is_resolved, test_identity_types_are_resolved)
15+
{
16+
bt_addr_le_t a = { .a = example };
17+
18+
a.type = BT_ADDR_LE_PUBLIC_ID;
19+
zassert_true(bt_addr_le_is_resolved(&a));
20+
21+
a.type = BT_ADDR_LE_RANDOM_ID;
22+
zassert_true(bt_addr_le_is_resolved(&a));
23+
}
24+
25+
static ZTEST(bt_addr_le_is_resolved, test_plain_types_are_not_resolved)
26+
{
27+
bt_addr_le_t a = { .a = example };
28+
29+
a.type = BT_ADDR_LE_PUBLIC;
30+
zassert_false(bt_addr_le_is_resolved(&a));
31+
32+
a.type = BT_ADDR_LE_RANDOM;
33+
zassert_false(bt_addr_le_is_resolved(&a));
34+
}
35+
36+
static ZTEST(bt_addr_le_is_resolved, test_sentinels_are_not_resolved)
37+
{
38+
/* The LE Extended Advertising Report sentinels have bit 1 set as well,
39+
* but neither is a Controller-resolved identity address.
40+
*/
41+
bt_addr_le_t a = { .a = example };
42+
43+
a.type = BT_ADDR_LE_UNRESOLVED;
44+
zassert_false(bt_addr_le_is_resolved(&a));
45+
46+
a.type = BT_ADDR_LE_ANONYMOUS;
47+
zassert_false(bt_addr_le_is_resolved(&a));
48+
}
49+
50+
static ZTEST(bt_addr_le_is_resolved, test_copy_resolved_yields_base_type)
51+
{
52+
bt_addr_le_t src = { .a = example };
53+
bt_addr_le_t dst;
54+
55+
src.type = BT_ADDR_LE_PUBLIC_ID;
56+
bt_addr_le_copy_resolved(&dst, &src);
57+
zassert_equal(dst.type, BT_ADDR_LE_PUBLIC);
58+
zassert_true(bt_addr_eq(&dst.a, &example));
59+
60+
src.type = BT_ADDR_LE_RANDOM_ID;
61+
bt_addr_le_copy_resolved(&dst, &src);
62+
zassert_equal(dst.type, BT_ADDR_LE_RANDOM);
63+
zassert_true(bt_addr_eq(&dst.a, &example));
64+
}

0 commit comments

Comments
 (0)