Skip to content

Commit 723bb46

Browse files
Yuval Peressnashif
authored andcommitted
tests: BT: migrate connectionless tx to ztest register
Migrating the test suites to the register functionality allows the main.c source to focus on the state of the system instead of "which" test to run. In this example, test_main() now calls: * ut_bt_setup() and updates the state * common_create_adv_set(), updates the state, and notifies the registered tests that the state has been updated which would trigger a run. * common_delete_adv_set(), updates the state, and again notifies the registered tests that the state has been updated. Signed-off-by: Yuval Peress <[email protected]>
1 parent 63873a1 commit 723bb46

File tree

5 files changed

+55
-30
lines changed

5 files changed

+55
-30
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ 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;
4344
}
4445

4546
void common_delete_adv_set(void)
@@ -48,6 +49,7 @@ void common_delete_adv_set(void)
4849

4950
err = bt_le_ext_adv_delete(g_adv);
5051
zassert_equal(err, 0, "Failed to delete advertiser set");
52+
test_state.is_adv_set_created = false;
5153
}
5254

5355
void common_set_cl_cte_tx_params(void)

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,20 @@ 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-
void common_setup(void);
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+
1225
void common_create_adv_set(void);
1326
void common_delete_adv_set(void);
1427
void common_delete_adv_set(void);

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@
77
#include <stdint.h>
88

99
#include <bt_common.h>
10+
#include <ztest.h>
1011
#include "common.h"
11-
#include "test_set_cl_cte_tx_params.h"
12-
#include "test_set_cl_cte_tx_enable.h"
12+
13+
struct bt_test_state test_state;
1314

1415
/*test case main entry*/
1516
void test_main(void)
1617
{
1718
ut_bt_setup();
19+
test_state.is_setup = true;
1820

1921
common_create_adv_set();
20-
run_set_cl_cte_tx_params_tests();
22+
ztest_run_registered_test_suites(&test_state);
23+
2124
common_delete_adv_set();
22-
run_set_cl_cte_tx_enable_tests();
25+
ztest_run_registered_test_suites(&test_state);
2326
}

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,19 @@ void test_set_cl_cte_tx_enable_and_update_cte_params(void)
244244
common_delete_adv_set();
245245
}
246246

247-
void run_set_cl_cte_tx_enable_tests(void)
247+
static bool test_set_cl_cte_tx_enable_pragma(const void *state)
248248
{
249-
ztest_test_suite(test_hci_df_info,
250-
ztest_unit_test(test_set_cl_cte_tx_enable_invalid_adv_set_handle),
251-
ztest_unit_test(test_set_cl_cte_tx_enable_cte_params_not_set),
252-
ztest_unit_test(test_set_cl_cte_tx_enable_per_adv_coded_phy),
253-
ztest_unit_test(test_set_cl_cte_tx_enable),
254-
ztest_unit_test(test_set_cl_cte_tx_enable_after_per_adv_enabled),
255-
ztest_unit_test(test_set_cl_cte_tx_disable_before_per_adv_enable),
256-
ztest_unit_test(test_set_cl_cte_tx_enable_and_update_cte_params),
257-
ztest_unit_test(test_set_cl_cte_tx_disable_during_per_adv_enable));
258-
ztest_run_test_suite(test_hci_df_info);
249+
const struct bt_test_state *s = state;
250+
251+
return s->is_setup && !s->is_adv_set_created;
259252
}
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));

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -223,19 +223,23 @@ void test_set_ct_cte_tx_params_aoa_invalid_pattern_len(void)
223223
zassert_equal(err, 0, "Unexpected error value for AoA");
224224
}
225225

226-
void run_set_cl_cte_tx_params_tests(void)
226+
static bool enabled_set_cl_cte_tx_para(const void *state)
227227
{
228-
ztest_test_suite(test_hci_df_info,
229-
ztest_unit_test(test_set_cl_cte_tx_params_with_correct_aod_2us),
230-
ztest_unit_test(test_set_cl_cte_tx_params_with_correct_aod_1us),
231-
ztest_unit_test(test_set_ct_cte_tx_params_correct_aoa),
232-
ztest_unit_test(test_set_ct_cte_tx_params_correct_aoa_without_ant_pattern),
233-
ztest_unit_test(test_set_ct_cte_tx_params_wrong_adv_handle),
234-
ztest_unit_test(test_set_ct_cte_tx_params_invalid_cte_len),
235-
ztest_unit_test(test_set_ct_cte_tx_params_invalid_cte_type),
236-
ztest_unit_test(test_set_ct_cte_tx_params_invalid_cte_count),
237-
ztest_unit_test(test_set_ct_cte_tx_params_aod_2us_invalid_pattern_len),
238-
ztest_unit_test(test_set_ct_cte_tx_params_aod_1us_invalid_pattern_len),
239-
ztest_unit_test(test_set_ct_cte_tx_params_aoa_invalid_pattern_len));
240-
ztest_run_test_suite(test_hci_df_info);
228+
const struct bt_test_state *s = state;
229+
230+
return s->is_setup && s->is_adv_set_created;
241231
}
232+
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));

0 commit comments

Comments
 (0)