Skip to content

Commit ebe899a

Browse files
HaavardReim-alperen-sener
authored andcommitted
[nrf fromtree] Bluetooth: Host: More bsim refactoring
Commit does the following changes: * Use functionality from the `babbelkit` library for common functions related to flags, test progression (failing, passing etc.) and synchronization between two devices. Locally defined equivalents are removed. * Removes the files containing only functionality that is provided by the `babblekit` library. * Remove the `test_pre_init_f` and `test_tick_f` functions (commonly implemented as `test_init` and `test_tick`) from the modified tests. These functions are not needed as they were only used to fail the test if a device didn't complete the test within a certain time frame. This is already handled by the `sim_length` argument used in the test scripts. Signed-off-by: Håvard Reierstad <[email protected]> (cherry picked from commit 7737483)
1 parent 89ddc0a commit ebe899a

File tree

181 files changed

+996
-2544
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+996
-2544
lines changed

tests/bsim/bluetooth/host/adv/chain/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ cmake_minimum_required(VERSION 3.20.0)
55
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
66
project(bsim_test_adv_chain)
77

8+
add_subdirectory(${ZEPHYR_BASE}/tests/bsim/babblekit babblekit)
9+
target_link_libraries(app PRIVATE babblekit)
10+
811
target_sources(app PRIVATE
912
src/main.c
1013
${ZEPHYR_BASE}/samples/bluetooth/broadcaster_multiple/src/broadcaster_multiple.c

tests/bsim/bluetooth/host/adv/chain/src/main.c

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,7 @@
1414
#include <zephyr/bluetooth/bluetooth.h>
1515
#include <zephyr/bluetooth/hci.h>
1616

17-
#include "bs_types.h"
18-
#include "bs_tracing.h"
19-
#include "time_machine.h"
20-
#include "bstests.h"
21-
22-
#define FAIL(...) \
23-
do { \
24-
bst_result = Failed; \
25-
bs_trace_error_time_line(__VA_ARGS__); \
26-
} while (0)
27-
28-
#define PASS(...) \
29-
do { \
30-
bst_result = Passed; \
31-
bs_trace_info_time(1, __VA_ARGS__); \
32-
} while (0)
17+
#include "babblekit/testcase.h"
3318

3419
#define NAME_LEN 30
3520
#define BT_AD_DATA_NAME_SIZE (sizeof(CONFIG_BT_DEVICE_NAME) - 1U + 2U)
@@ -44,30 +29,28 @@
4429

4530
static K_SEM_DEFINE(sem_recv, 0, 1);
4631

47-
extern enum bst_result_t bst_result;
48-
4932
static void test_adv_main(void)
5033
{
5134
extern int broadcaster_multiple(void);
5235
int err;
5336

5437
err = bt_enable(NULL);
5538
if (err) {
56-
FAIL("Bluetooth init failed\n");
39+
TEST_FAIL("Bluetooth init failed");
5740

5841
bs_trace_silent_exit(err);
5942
return;
6043
}
6144

6245
err = broadcaster_multiple();
6346
if (err) {
64-
FAIL("Adv tests failed\n");
47+
TEST_FAIL("Adv tests failed");
6548
bs_trace_silent_exit(err);
6649
return;
6750
}
6851

6952
/* Successfully started advertising multiple sets */
70-
PASS("Adv tests passed\n");
53+
TEST_PASS("Adv tests passed");
7154

7255
/* Let the scanner receive the reports */
7356
k_sleep(K_SECONDS(10));
@@ -146,7 +129,7 @@ static void test_scan_main(void)
146129

147130
err = bt_enable(NULL);
148131
if (err) {
149-
FAIL("Bluetooth init failed\n");
132+
TEST_FAIL("Bluetooth init failed");
150133

151134
bs_trace_silent_exit(err);
152135
return;
@@ -156,7 +139,7 @@ static void test_scan_main(void)
156139

157140
err = observer_start();
158141
if (err) {
159-
FAIL("Observer start failed\n");
142+
TEST_FAIL("Observer start failed");
160143

161144
bs_trace_silent_exit(err);
162145
return;
@@ -167,42 +150,26 @@ static void test_scan_main(void)
167150

168151
err = k_sem_take(&sem_recv, K_NO_WAIT);
169152
if (err) {
170-
FAIL("Scan receive failed\n");
153+
TEST_FAIL("Scan receive failed");
171154

172155
bs_trace_silent_exit(err);
173156
return;
174157
}
175158

176-
PASS("Scan tests passed\n");
159+
TEST_PASS("Scan tests passed");
177160

178161
bs_trace_silent_exit(0);
179162
}
180163

181-
static void test_adv_chain_init(void)
182-
{
183-
bst_ticker_set_next_tick_absolute(60e6);
184-
bst_result = In_progress;
185-
}
186-
187-
static void test_adv_chain_tick(bs_time_t HW_device_time)
188-
{
189-
bst_result = Failed;
190-
bs_trace_error_line("Test GATT Write finished.\n");
191-
}
192-
193164
static const struct bst_test_instance test_def[] = {
194165
{
195166
.test_id = "adv",
196167
.test_descr = "Central GATT Write",
197-
.test_pre_init_f = test_adv_chain_init,
198-
.test_tick_f = test_adv_chain_tick,
199168
.test_main_f = test_adv_main
200169
},
201170
{
202171
.test_id = "scan",
203172
.test_descr = "Peripheral GATT Write",
204-
.test_pre_init_f = test_adv_chain_init,
205-
.test_tick_f = test_adv_chain_tick,
206173
.test_main_f = test_scan_main
207174
},
208175
BSTEST_END_MARKER

tests/bsim/bluetooth/host/adv/extended/src/ext_adv_advertiser.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ extern enum bst_result_t bst_result;
1818

1919
static struct bt_conn *g_conn;
2020

21-
static DEFINE_FLAG(flag_connected);
22-
static DEFINE_FLAG(flag_conn_recycled);
21+
DEFINE_FLAG_STATIC(flag_connected);
22+
DEFINE_FLAG_STATIC(flag_conn_recycled);
2323

2424
static void common_init(void)
2525
{

tests/bsim/bluetooth/host/adv/extended/src/ext_adv_scanner.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ extern enum bst_result_t bst_result;
1818

1919
static struct bt_conn *g_conn;
2020

21-
static DEFINE_FLAG(flag_ext_adv_seen);
22-
static DEFINE_FLAG(flag_connected);
23-
static DEFINE_FLAG(flag_conn_recycled);
21+
DEFINE_FLAG_STATIC(flag_ext_adv_seen);
22+
DEFINE_FLAG_STATIC(flag_connected);
23+
DEFINE_FLAG_STATIC(flag_conn_recycled);
2424

2525
static void connected(struct bt_conn *conn, uint8_t err)
2626
{

tests/bsim/bluetooth/host/adv/long_ad/src/advertiser.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static void create_adv(struct bt_le_ext_adv **adv)
3232

3333
err = bt_le_ext_adv_create(&params, NULL, adv);
3434
if (err) {
35-
TEST_FAIL("Failed to create advertiser (%d)\n", err);
35+
TEST_FAIL("Failed to create advertiser (%d)", err);
3636
}
3737
}
3838

@@ -49,7 +49,7 @@ static void start_adv(struct bt_le_ext_adv *adv)
4949

5050
err = bt_le_ext_adv_start(adv, &start_params);
5151
if (err) {
52-
TEST_FAIL("Failed to start advertiser (%d)\n", err);
52+
TEST_FAIL("Failed to start advertiser (%d)", err);
5353
}
5454
}
5555

@@ -99,7 +99,7 @@ static int set_ad_data(struct bt_le_ext_adv *adv, const uint8_t *serialized_ad,
9999

100100
err = bt_le_ext_adv_set_data(adv, ad, ad_len, NULL, 0);
101101
if (err != 0 && err != -EDOM) {
102-
TEST_FAIL("Failed to set advertising data (%d)\n", err);
102+
TEST_FAIL("Failed to set advertising data (%d)", err);
103103
}
104104

105105
return err;

tests/bsim/bluetooth/host/adv/long_ad/src/scanner.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ static void start_scan(void)
6262

6363
err = bt_le_scan_start(BT_LE_SCAN_PASSIVE, device_found);
6464
if (err) {
65-
TEST_FAIL("Scanning failed to start (err %d)\n", err);
65+
TEST_FAIL("Scanning failed to start (err %d)", err);
6666
}
6767

6868
LOG_DBG("Scanning successfully started");

tests/bsim/bluetooth/host/adv/periodic/src/per_adv_advertiser.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ extern enum bst_result_t bst_result;
2323

2424
static struct bt_conn *g_conn;
2525

26-
static DEFINE_FLAG(flag_connected);
27-
static DEFINE_FLAG(flag_bonded);
26+
DEFINE_FLAG_STATIC(flag_connected);
27+
DEFINE_FLAG_STATIC(flag_bonded);
2828

2929
static void connected(struct bt_conn *conn, uint8_t err)
3030
{

tests/bsim/bluetooth/host/adv/periodic/src/per_adv_sync.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ static struct bt_conn *g_conn;
2525
static bt_addr_le_t per_addr;
2626
static uint8_t per_sid;
2727

28-
static DEFINE_FLAG(flag_connected);
29-
static DEFINE_FLAG(flag_bonded);
30-
static DEFINE_FLAG(flag_per_adv);
31-
static DEFINE_FLAG(flag_per_adv_sync);
32-
static DEFINE_FLAG(flag_per_adv_sync_lost);
33-
static DEFINE_FLAG(flag_per_adv_recv);
28+
DEFINE_FLAG_STATIC(flag_connected);
29+
DEFINE_FLAG_STATIC(flag_bonded);
30+
DEFINE_FLAG_STATIC(flag_per_adv);
31+
DEFINE_FLAG_STATIC(flag_per_adv_sync);
32+
DEFINE_FLAG_STATIC(flag_per_adv_sync_lost);
33+
DEFINE_FLAG_STATIC(flag_per_adv_recv);
3434

3535
static void connected(struct bt_conn *conn, uint8_t err)
3636
{

tests/bsim/bluetooth/host/att/eatt/src/main_reconfigure.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
#define NEW_MTU 100
1717

18-
static DEFINE_FLAG(flag_reconfigured);
18+
DEFINE_FLAG_STATIC(flag_reconfigured);
1919

2020
void att_mtu_updated(struct bt_conn *conn, uint16_t tx, uint16_t rx)
2121
{

tests/bsim/bluetooth/host/att/eatt_notif/src/client_test.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
#include "babblekit/sync.h"
3131
#include "common.h"
3232

33-
static DEFINE_FLAG(flag_is_connected);
34-
static DEFINE_FLAG(flag_discover_complete);
35-
static DEFINE_FLAG(flag_is_encrypted);
33+
DEFINE_FLAG_STATIC(flag_is_connected);
34+
DEFINE_FLAG_STATIC(flag_discover_complete);
35+
DEFINE_FLAG_STATIC(flag_is_encrypted);
3636

3737
static struct bt_conn *g_conn;
3838
static const struct bt_gatt_attr *local_attr;

0 commit comments

Comments
 (0)