Skip to content

Commit 77bdc8a

Browse files
theob-prokartben
authored andcommitted
Bluetooth: Add usage of util_eq and util_memeq
Update `bt_irk_eq` to use `util_memeq` instead of `memcmp` and the "disconnect" BabbleSim test to use `util_eq` instead of a first assertion on the size followed by a `memcmp`. This is done as an example usage of the two new functions. Signed-off-by: Théo Battrel <[email protected]>
1 parent 716e6bf commit 77bdc8a

File tree

2 files changed

+4
-3
lines changed
  • subsys/bluetooth/host
  • tests/bsim/bluetooth/host/misc/disconnect/tester/src

2 files changed

+4
-3
lines changed

subsys/bluetooth/host/keys.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef ZEPHYR_SUBSYS_BLUETOOTH_HOST_KEYS_H_
1010
#define ZEPHYR_SUBSYS_BLUETOOTH_HOST_KEYS_H_
1111

12+
#include <zephyr/sys/util.h>
1213
#include <zephyr/bluetooth/bluetooth.h>
1314

1415
/** @cond INTERNAL_HIDDEN */
@@ -54,7 +55,7 @@ struct bt_irk {
5455

5556
static inline bool bt_irk_eq(struct bt_irk const *a, struct bt_irk const *b)
5657
{
57-
return (memcmp(a->val, b->val, sizeof(a->val)) == 0);
58+
return util_memeq(a->val, b->val, sizeof(a->val));
5859
}
5960

6061
struct bt_csrk {

tests/bsim/bluetooth/host/misc/disconnect/tester/src/main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include <zephyr/kernel.h>
8+
#include <zephyr/sys/util.h>
89
#include <zephyr/sys/byteorder.h>
910
#include <zephyr/sys/__assert.h>
1011

@@ -191,8 +192,7 @@ static void handle_att_write(struct net_buf *buf)
191192

192193
static uint8_t ccc_write[2] = {0x03, 0x00};
193194

194-
TEST_ASSERT(buf->len == 2, "unexpected write length: %d", buf->len);
195-
TEST_ASSERT(memcmp(buf->data, ccc_write, sizeof(ccc_write)) == 0, "bad data");
195+
TEST_ASSERT(util_eq(buf->data, buf->len, ccc_write, sizeof(ccc_write)), "bad data\n");
196196

197197
send_write_rsp();
198198
}

0 commit comments

Comments
 (0)