Skip to content

Commit e423349

Browse files
ppryga-nordicnashif
authored andcommitted
tests: Bluetooth: df: Move common code to separate source file
Move common code that may be used by different test units from main.c to common.c. Main.c should be clean and responsible for unit tests executioon only. Common functionalities should be stored in separate file and provided to test source files by appropriate header file. Signed-off-by: Piotr Pryga <[email protected]>
1 parent 6281902 commit e423349

File tree

4 files changed

+71
-36
lines changed

4 files changed

+71
-36
lines changed

tests/bluetooth/df/src/common.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright (c) 2021 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr.h>
8+
#include <stddef.h>
9+
#include <ztest.h>
10+
11+
#include <bluetooth/bluetooth.h>
12+
#include <bluetooth/hci.h>
13+
#include <bluetooth/direction.h>
14+
#include <host/hci_core.h>
15+
16+
#include "common.h"
17+
18+
struct bt_le_ext_adv *g_adv;
19+
struct bt_le_adv_param g_param =
20+
BT_LE_ADV_PARAM_INIT(BT_LE_ADV_OPT_EXT_ADV |
21+
BT_LE_ADV_OPT_NOTIFY_SCAN_REQ,
22+
BT_GAP_ADV_FAST_INT_MIN_2,
23+
BT_GAP_ADV_FAST_INT_MAX_2,
24+
NULL);
25+
26+
static struct bt_le_per_adv_param per_param = {
27+
.interval_min = BT_GAP_ADV_SLOW_INT_MIN,
28+
.interval_max = BT_GAP_ADV_SLOW_INT_MAX,
29+
.options = BT_LE_ADV_OPT_USE_TX_POWER,
30+
};
31+
32+
void common_setup(void)
33+
{
34+
int err;
35+
36+
/* Initialize bluetooth subsystem */
37+
err = bt_enable(NULL);
38+
zassert_equal(err, 0, "Bluetooth subsystem initialization failed");
39+
}
40+
41+
void common_create_adv_set(void)
42+
{
43+
int err;
44+
45+
err = bt_le_ext_adv_create(&g_param, NULL, &g_adv);
46+
zassert_equal(err, 0, "Failed to create advertiser set");
47+
}
48+
49+
void common_delete_adv_set(void)
50+
{
51+
int err;
52+
53+
err = bt_le_ext_adv_delete(g_adv);
54+
zassert_equal(err, 0, "Failed to delete advertiser set");
55+
}

tests/bluetooth/df/src/common.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright (c) 2021 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
extern struct bt_le_ext_adv *g_adv;
8+
extern struct bt_le_adv_param g_param;
9+
10+
void common_setup(void);
11+
void common_create_adv_set(void);
12+
void common_delete_adv_set(void);

tests/bluetooth/df/src/main.c

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,48 +4,16 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
#include <zephyr.h>
8-
#include <stddef.h>
9-
#include <ztest.h>
10-
11-
#include <bluetooth/bluetooth.h>
12-
#include <bluetooth/hci.h>
13-
#include <sys/byteorder.h>
7+
#include <stdint.h>
148

9+
#include "common.h"
1510
#include "test_set_cl_cte_tx_params.h"
1611

17-
struct bt_le_ext_adv *g_adv;
18-
19-
static void common_setup(void)
20-
{
21-
static struct bt_le_adv_param param =
22-
BT_LE_ADV_PARAM_INIT(BT_LE_ADV_OPT_EXT_ADV |
23-
BT_LE_ADV_OPT_NOTIFY_SCAN_REQ,
24-
BT_GAP_ADV_FAST_INT_MIN_2,
25-
BT_GAP_ADV_FAST_INT_MAX_2,
26-
NULL);
27-
struct bt_le_per_adv_param per_param = {
28-
.interval_min = BT_GAP_ADV_SLOW_INT_MIN,
29-
.interval_max = BT_GAP_ADV_SLOW_INT_MAX,
30-
.options = BT_LE_ADV_OPT_USE_TX_POWER,
31-
};
32-
int err;
33-
34-
/* Initialize bluetooth subsystem */
35-
err = bt_enable(NULL);
36-
zassert_equal(err, 0, "Bluetooth subsystem initialization failed");
37-
38-
err = bt_le_ext_adv_create(&param, NULL, &g_adv);
39-
zassert_equal(err, 0, "Failed to create advertiser set");
40-
41-
42-
err = bt_le_per_adv_set_param(g_adv, &per_param);
43-
zassert_equal(err, 0, "Failed to set periodic advertising params");
44-
}
4512

4613
/*test case main entry*/
4714
void test_main(void)
4815
{
4916
common_setup();
17+
common_create_adv_set();
5018
run_set_cl_cte_tx_params_tests();
5119
}

tests/bluetooth/df/src/test_set_cl_cte_tx_param.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include <sys/byteorder.h>
1414
#include <host/hci_core.h>
1515

16-
extern struct bt_le_ext_adv *g_adv;
16+
#include "common.h"
1717

1818
/* Macros delivering common values for unit tests */
1919
#define CTE_LEN_VALID (BT_HCI_LE_CTE_LEN_MIN + 5)

0 commit comments

Comments
 (0)