1 /* Copyright (c) 2023 Nordic Semiconductor ASA
2 * SPDX-License-Identifier: Apache-2.0
3 */
4
5 #include <zephyr/kernel.h>
6 #include <zephyr/irq.h>
7
8 #include <zephyr/logging/log.h>
9 #include <zephyr/settings/settings.h>
10
11 #include <zephyr/bluetooth/bluetooth.h>
12 #include <zephyr/bluetooth/addr.h>
13
14 #include "common.h"
15
16 LOG_MODULE_DECLARE(bt_bsim_id_settings, LOG_LEVEL_DBG);
17
run_dut1(void)18 void run_dut1(void)
19 {
20 int err;
21 size_t bt_id_count;
22
23 LOG_DBG("Starting DUT 1");
24
25 err = bt_enable(NULL);
26 if (err) {
27 FAIL("Bluetooth init failed (err %d)\n", err);
28 }
29
30 LOG_DBG("Bluetooth initialised");
31
32 err = settings_load();
33 if (err) {
34 FAIL("Failed to load settings (err %d)\n", err);
35 }
36
37 bt_id_get(NULL, &bt_id_count);
38 LOG_DBG("Number of Bluetooth identities after settings load: %d", bt_id_count);
39
40 err = bt_id_create(NULL, NULL);
41 if (err < 0) {
42 FAIL("Failed to create a new identity (err %d)\n", err);
43 }
44
45 bt_id_get(NULL, &bt_id_count);
46 LOG_DBG("Number of Bluetooth identities after identity creation: %d", bt_id_count);
47
48 /* Wait for the workqueue to complete before switching device */
49 k_msleep(100);
50
51 PASS("Test passed (DUT 1)\n");
52 }
53
run_dut2(void)54 void run_dut2(void)
55 {
56 int err;
57 size_t bt_id_count;
58 size_t expected_id_count = 2;
59
60 LOG_DBG("Starting DUT 2");
61
62 err = bt_enable(NULL);
63 if (err) {
64 FAIL("Bluetooth init failed (err %d)\n", err);
65 }
66
67 LOG_DBG("Bluetooth initialised");
68
69 err = settings_load();
70 if (err) {
71 FAIL("Failed to load settings (err %d)\n", err);
72 }
73
74 LOG_DBG("Settings loaded");
75
76 bt_id_get(NULL, &bt_id_count);
77 if (bt_id_count != expected_id_count) {
78 FAIL("Wrong ID count (got %d; expected %d)\n", bt_id_count, expected_id_count);
79 }
80
81 PASS("Test passed (DUT 2)\n");
82 }
83