Skip to content

Commit 8be0999

Browse files
ppryga-nordiccarlescufi
authored andcommitted
tests: Bluetooth: df: connectionless cte tx migrate to new ZTEST API
Migrate tests in connectionless_cte_tx to new ZTEST API. Remove main.c source file because is unncessary when automatic unit tests registration is available. Also former use of predicate to select unit tests for execution is removed because the tests are split into two distinct tests suites that has its't own setup and teardown phases. Signed-off-by: Piotr Pryga <[email protected]>
1 parent 11da98f commit 8be0999

File tree

8 files changed

+38
-111
lines changed

8 files changed

+38
-111
lines changed

tests/bluetooth/df/connectionless_cte_tx/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
CONFIG_TEST=y
22
CONFIG_ZTEST=y
3+
CONFIG_ZTEST_NEW_API=y
34

45
CONFIG_BT=y
56
CONFIG_BT_EXT_ADV=y

tests/bluetooth/df/connectionless_cte_tx/src/common.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ void common_create_adv_set(void)
4040

4141
err = bt_le_ext_adv_create(&g_param, NULL, &g_adv);
4242
zassert_equal(err, 0, "Failed to create advertiser set");
43-
test_state.is_adv_set_created = true;
4443
}
4544

4645
void common_delete_adv_set(void)
@@ -49,7 +48,6 @@ void common_delete_adv_set(void)
4948

5049
err = bt_le_ext_adv_delete(g_adv);
5150
zassert_equal(err, 0, "Failed to delete advertiser set");
52-
test_state.is_adv_set_created = false;
5351
}
5452

5553
void common_set_cl_cte_tx_params(void)

tests/bluetooth/df/connectionless_cte_tx/src/common.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,6 @@ extern struct bt_le_ext_adv *g_adv;
88
extern struct bt_le_adv_param g_param;
99
extern uint8_t g_cte_len;
1010

11-
/**
12-
* @brief The test's global state.
13-
*
14-
* This struct is used to script the test. Some suites can only run under specific conditions (such
15-
* as being setup or keep track of the global state of the test
16-
*/
17-
struct bt_test_state {
18-
/** Whether or not ut_bt_setup() was called */
19-
bool is_setup;
20-
/** Whether or not bt_le_ext_adv_create() was called (not deleted) */
21-
bool is_adv_set_created;
22-
};
23-
extern struct bt_test_state test_state;
24-
2511
void common_create_adv_set(void);
2612
void common_delete_adv_set(void);
2713
void common_delete_adv_set(void);

tests/bluetooth/df/connectionless_cte_tx/src/main.c

Lines changed: 0 additions & 26 deletions
This file was deleted.

tests/bluetooth/df/connectionless_cte_tx/src/test_set_cl_cte_tx_enable.c

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
#include <zephyr/sys/byteorder.h>
1414
#include <host/hci_core.h>
1515

16+
#include <bt_common.h>
1617
#include "common.h"
17-
#include "test_set_cl_cte_tx_enable.h"
1818

1919
/* Macros delivering common values for unit tests */
2020
#define ADV_HANDLE_INVALID (CONFIG_BT_CTLR_ADV_AUX_SET + 1)
@@ -53,7 +53,7 @@ int send_set_cl_cte_tx_enable(uint8_t adv_handle, atomic_t *adv_flags,
5353
buf, NULL);
5454
}
5555

56-
void test_set_cl_cte_tx_enable_invalid_adv_set_handle(void)
56+
ZTEST(test_set_cl_cte_tx_enable, test_set_cl_cte_tx_enable_invalid_adv_set_handle)
5757
{
5858
int err;
5959

@@ -62,7 +62,7 @@ void test_set_cl_cte_tx_enable_invalid_adv_set_handle(void)
6262
"wrong advertising set handle");
6363
}
6464

65-
void test_set_cl_cte_tx_enable_cte_params_not_set(void)
65+
ZTEST(test_set_cl_cte_tx_enable, test_set_cl_cte_tx_enable_cte_params_not_set)
6666
{
6767
int err;
6868

@@ -78,7 +78,7 @@ void test_set_cl_cte_tx_enable_cte_params_not_set(void)
7878
common_delete_adv_set();
7979
}
8080

81-
void test_set_cl_cte_tx_enable_per_adv_coded_phy(void)
81+
ZTEST(test_set_cl_cte_tx_enable, test_set_cl_cte_tx_enable_per_adv_coded_phy)
8282
{
8383
int err;
8484

@@ -99,7 +99,7 @@ void test_set_cl_cte_tx_enable_per_adv_coded_phy(void)
9999
g_param.options = g_param.options & (~BT_LE_ADV_OPT_CODED);
100100
}
101101

102-
void test_set_cl_cte_tx_enable(void)
102+
ZTEST(test_set_cl_cte_tx_enable, test_set_cl_cte_tx_enable)
103103
{
104104
int err;
105105

@@ -119,7 +119,7 @@ void test_set_cl_cte_tx_enable(void)
119119
common_delete_adv_set();
120120
}
121121

122-
void test_set_cl_cte_tx_enable_after_per_adv_enabled(void)
122+
ZTEST(test_set_cl_cte_tx_enable, test_set_cl_cte_tx_enable_after_per_adv_enabled)
123123
{
124124
int err;
125125

@@ -142,7 +142,7 @@ void test_set_cl_cte_tx_enable_after_per_adv_enabled(void)
142142
common_delete_adv_set();
143143
}
144144

145-
void test_set_cl_cte_tx_disable_when_no_CTE_enabled(void)
145+
ZTEST(test_set_cl_cte_tx_enable, test_set_cl_cte_tx_disable_when_no_CTE_enabled)
146146
{
147147
int err;
148148

@@ -158,7 +158,7 @@ void test_set_cl_cte_tx_disable_when_no_CTE_enabled(void)
158158
common_delete_adv_set();
159159
}
160160

161-
void test_set_cl_cte_tx_disable_before_per_adv_enable(void)
161+
ZTEST(test_set_cl_cte_tx_enable, test_set_cl_cte_tx_disable_before_per_adv_enable)
162162
{
163163
int err;
164164

@@ -178,7 +178,7 @@ void test_set_cl_cte_tx_disable_before_per_adv_enable(void)
178178
common_delete_adv_set();
179179
}
180180

181-
void test_set_cl_cte_tx_disable_during_per_adv_enable(void)
181+
ZTEST(test_set_cl_cte_tx_enable, test_set_cl_cte_tx_disable_during_per_adv_enable)
182182
{
183183
int err;
184184

@@ -201,7 +201,7 @@ void test_set_cl_cte_tx_disable_during_per_adv_enable(void)
201201
common_delete_adv_set();
202202
}
203203

204-
void test_set_cl_cte_tx_enable_and_update_cte_params(void)
204+
ZTEST(test_set_cl_cte_tx_enable, test_set_cl_cte_tx_enable_and_update_cte_params)
205205
{
206206
uint8_t cte_len_prev;
207207
int err;
@@ -244,19 +244,4 @@ void test_set_cl_cte_tx_enable_and_update_cte_params(void)
244244
common_delete_adv_set();
245245
}
246246

247-
static bool test_set_cl_cte_tx_enable_pragma(const void *state)
248-
{
249-
const struct bt_test_state *s = state;
250-
251-
return s->is_setup && !s->is_adv_set_created;
252-
}
253-
254-
ztest_register_test_suite(test_set_cl_cte_tx_enable, test_set_cl_cte_tx_enable_pragma,
255-
ztest_unit_test(test_set_cl_cte_tx_enable_invalid_adv_set_handle),
256-
ztest_unit_test(test_set_cl_cte_tx_enable_cte_params_not_set),
257-
ztest_unit_test(test_set_cl_cte_tx_enable_per_adv_coded_phy),
258-
ztest_unit_test(test_set_cl_cte_tx_enable),
259-
ztest_unit_test(test_set_cl_cte_tx_enable_after_per_adv_enabled),
260-
ztest_unit_test(test_set_cl_cte_tx_disable_before_per_adv_enable),
261-
ztest_unit_test(test_set_cl_cte_tx_enable_and_update_cte_params),
262-
ztest_unit_test(test_set_cl_cte_tx_disable_during_per_adv_enable));
247+
ZTEST_SUITE(test_set_cl_cte_tx_enable, NULL, ut_bt_setup, NULL, NULL, ut_bt_teardown);

tests/bluetooth/df/connectionless_cte_tx/src/test_set_cl_cte_tx_enable.h

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/bluetooth/df/connectionless_cte_tx/src/test_set_cl_cte_tx_param.c

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <zephyr/sys/byteorder.h>
1414
#include <host/hci_core.h>
1515

16+
#include <bt_common.h>
1617
#include "common.h"
1718

1819
/* Macros delivering common values for unit tests */
@@ -74,7 +75,7 @@ int send_set_cl_cte_tx_params(uint8_t adv_handle, uint8_t cte_len,
7475
buf, NULL);
7576
}
7677

77-
void test_set_cl_cte_tx_params_with_correct_aod_2us(void)
78+
ZTEST(test_set_cl_cte_tx_param, test_set_cl_cte_tx_params_with_correct_aod_2us)
7879
{
7980
int err;
8081

@@ -87,7 +88,7 @@ void test_set_cl_cte_tx_params_with_correct_aod_2us(void)
8788
zassert_equal(err, 0, "Set AoD 2us CTE parameters failed");
8889
}
8990

90-
void test_set_cl_cte_tx_params_with_correct_aod_1us(void)
91+
ZTEST(test_set_cl_cte_tx_param, test_set_cl_cte_tx_params_with_correct_aod_1us)
9192
{
9293
int err;
9394

@@ -100,7 +101,7 @@ void test_set_cl_cte_tx_params_with_correct_aod_1us(void)
100101
zassert_equal(err, 0, "Set AoD 1us CTE parameters failed");
101102
}
102103

103-
void test_set_ct_cte_tx_params_correct_aoa(void)
104+
ZTEST(test_set_cl_cte_tx_param, test_set_ct_cte_tx_params_correct_aoa)
104105
{
105106
int err;
106107

@@ -113,7 +114,7 @@ void test_set_ct_cte_tx_params_correct_aoa(void)
113114
zassert_equal(err, -EIO, "Set AoA CTE parameters failed");
114115
}
115116

116-
void test_set_ct_cte_tx_params_correct_aoa_without_ant_pattern(void)
117+
ZTEST(test_set_cl_cte_tx_param, test_set_ct_cte_tx_params_correct_aoa_without_ant_pattern)
117118
{
118119
int err;
119120

@@ -126,7 +127,7 @@ void test_set_ct_cte_tx_params_correct_aoa_without_ant_pattern(void)
126127
zassert_equal(err, -EIO, "Set AoA CTE parameters failed");
127128
}
128129

129-
void test_set_ct_cte_tx_params_wrong_adv_handle(void)
130+
ZTEST(test_set_cl_cte_tx_param, test_set_ct_cte_tx_params_wrong_adv_handle)
130131
{
131132
int err;
132133

@@ -140,7 +141,7 @@ void test_set_ct_cte_tx_params_wrong_adv_handle(void)
140141
"Unexpected error value for invalid adv handle");
141142
}
142143

143-
void test_set_ct_cte_tx_params_invalid_cte_len(void)
144+
ZTEST(test_set_cl_cte_tx_param, test_set_ct_cte_tx_params_invalid_cte_len)
144145
{
145146
int err;
146147

@@ -154,7 +155,7 @@ void test_set_ct_cte_tx_params_invalid_cte_len(void)
154155
"Unexpected error value for invalid CTE length");
155156
}
156157

157-
void test_set_ct_cte_tx_params_invalid_cte_type(void)
158+
ZTEST(test_set_cl_cte_tx_param, test_set_ct_cte_tx_params_invalid_cte_type)
158159
{
159160
int err;
160161

@@ -168,7 +169,7 @@ void test_set_ct_cte_tx_params_invalid_cte_type(void)
168169
"Unexpected error value for invalid CTE type");
169170
}
170171

171-
void test_set_ct_cte_tx_params_invalid_cte_count(void)
172+
ZTEST(test_set_cl_cte_tx_param, test_set_ct_cte_tx_params_invalid_cte_count)
172173
{
173174
int err;
174175

@@ -182,7 +183,7 @@ void test_set_ct_cte_tx_params_invalid_cte_count(void)
182183
"Unexpected error value for invalid CTE count");
183184
}
184185

185-
void test_set_ct_cte_tx_params_aod_2us_invalid_pattern_len(void)
186+
ZTEST(test_set_cl_cte_tx_param, test_set_ct_cte_tx_params_aod_2us_invalid_pattern_len)
186187
{
187188
int err;
188189

@@ -196,7 +197,7 @@ void test_set_ct_cte_tx_params_aod_2us_invalid_pattern_len(void)
196197
"Unexpected error value for invalid switch pattern len");
197198
}
198199

199-
void test_set_ct_cte_tx_params_aod_1us_invalid_pattern_len(void)
200+
ZTEST(test_set_cl_cte_tx_param, test_set_ct_cte_tx_params_aod_1us_invalid_pattern_len)
200201
{
201202
int err;
202203

@@ -210,7 +211,7 @@ void test_set_ct_cte_tx_params_aod_1us_invalid_pattern_len(void)
210211
"Unexpected error value for invalid switch pattern len");
211212
}
212213

213-
void test_set_ct_cte_tx_params_aoa_invalid_pattern_len(void)
214+
ZTEST(test_set_cl_cte_tx_param, test_set_ct_cte_tx_params_aoa_invalid_pattern_len)
214215
{
215216
int err;
216217

@@ -223,23 +224,21 @@ void test_set_ct_cte_tx_params_aoa_invalid_pattern_len(void)
223224
zassert_equal(err, 0, "Unexpected error value for AoA");
224225
}
225226

226-
static bool enabled_set_cl_cte_tx_para(const void *state)
227+
static void *common_adv_set_setup(void)
227228
{
228-
const struct bt_test_state *s = state;
229+
ut_bt_setup();
229230

230-
return s->is_setup && s->is_adv_set_created;
231+
common_create_adv_set();
232+
233+
return NULL;
234+
}
235+
236+
static void common_adv_set_teardown(void *data)
237+
{
238+
common_delete_adv_set();
239+
240+
ut_bt_teardown(data);
231241
}
232242

233-
ztest_register_test_suite(
234-
test_set_cl_cte_tx_param, enabled_set_cl_cte_tx_para,
235-
ztest_unit_test(test_set_cl_cte_tx_params_with_correct_aod_2us),
236-
ztest_unit_test(test_set_cl_cte_tx_params_with_correct_aod_1us),
237-
ztest_unit_test(test_set_ct_cte_tx_params_correct_aoa),
238-
ztest_unit_test(test_set_ct_cte_tx_params_correct_aoa_without_ant_pattern),
239-
ztest_unit_test(test_set_ct_cte_tx_params_wrong_adv_handle),
240-
ztest_unit_test(test_set_ct_cte_tx_params_invalid_cte_len),
241-
ztest_unit_test(test_set_ct_cte_tx_params_invalid_cte_type),
242-
ztest_unit_test(test_set_ct_cte_tx_params_invalid_cte_count),
243-
ztest_unit_test(test_set_ct_cte_tx_params_aod_2us_invalid_pattern_len),
244-
ztest_unit_test(test_set_ct_cte_tx_params_aod_1us_invalid_pattern_len),
245-
ztest_unit_test(test_set_ct_cte_tx_params_aoa_invalid_pattern_len));
243+
ZTEST_SUITE(test_set_cl_cte_tx_param, NULL, common_adv_set_setup, NULL, NULL,
244+
common_adv_set_teardown);

tests/bluetooth/df/connectionless_cte_tx/src/test_set_cl_cte_tx_params.h

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)