@@ -19,6 +19,12 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL_INF);
1919
2020#define WAIT_TIME 60 /*seconds*/
2121
22+ enum suspending_ctx {
23+ NOT_SUSPENDED ,
24+ SUSPENDED_IN_CTX ,
25+ SUSPENDED_IN_CB
26+ };
27+
2228extern const struct bt_mesh_comp comp ;
2329
2430static uint8_t test_prov_uuid [16 ] = { 0x6c , 0x69 , 0x6e , 0x67 , 0x61 , 0xaa };
@@ -796,7 +802,7 @@ static void adv_resume(void)
796802}
797803
798804struct adv_suspend_ctx {
799- bool suspend ;
805+ enum suspending_ctx suspend ;
800806 int instance_idx ;
801807};
802808
@@ -812,7 +818,7 @@ static void adv_send_end(int err, void *cb_data)
812818
813819 ASSERT_EQUAL (err , 0 );
814820
815- if (adv_data -> suspend ) {
821+ if (adv_data -> suspend != NOT_SUSPENDED ) {
816822 /* When suspending, the end callback will be called only for the first adv, because
817823 * it was already scheduled.
818824 */
@@ -831,8 +837,8 @@ static void adv_send_start(uint16_t duration, int err, void *cb_data)
831837 LOG_DBG ("start(): err (%d), suspend (%d), i (%d)" , err , adv_data -> suspend ,
832838 adv_data -> instance_idx );
833839
834- if (adv_data -> suspend ) {
835- if (adv_data -> instance_idx == 0 ) {
840+ if (adv_data -> suspend != NOT_SUSPENDED ) {
841+ if (adv_data -> instance_idx == 0 && adv_data -> suspend == SUSPENDED_IN_CB ) {
836842 ASSERT_EQUAL (err , 0 );
837843 adv_suspend ();
838844 } else {
@@ -851,7 +857,8 @@ static void adv_send_start(uint16_t duration, int err, void *cb_data)
851857 }
852858}
853859
854- static void adv_create_and_send (bool suspend , uint8_t first_byte , struct adv_suspend_ctx * adv_data )
860+ static void adv_create_and_send (enum suspending_ctx suspend , uint8_t first_byte ,
861+ struct adv_suspend_ctx * adv_data )
855862{
856863 struct bt_mesh_adv * advs [CONFIG_BT_MESH_ADV_BUF_COUNT ];
857864 static const struct bt_mesh_send_cb send_cb = {
@@ -864,7 +871,7 @@ static void adv_create_and_send(bool suspend, uint8_t first_byte, struct adv_sus
864871 adv_data [i ].instance_idx = i ;
865872
866873 advs [i ] = bt_mesh_adv_create (BT_MESH_ADV_DATA , BT_MESH_ADV_TAG_LOCAL ,
867- BT_MESH_TRANSMIT (2 , 20 ), K_NO_WAIT );
874+ BT_MESH_TRANSMIT (2 , 20 ), K_NO_WAIT );
868875 ASSERT_FALSE_MSG (!advs [i ], "Out of advs\n" );
869876
870877 net_buf_simple_add_u8 (& advs [i ]-> b , first_byte );
@@ -877,29 +884,41 @@ static void adv_create_and_send(bool suspend, uint8_t first_byte, struct adv_sus
877884 }
878885}
879886
880- static void test_tx_disable (void )
887+ static void check_suspending (void )
881888{
882- struct adv_suspend_ctx adv_data [CONFIG_BT_MESH_ADV_BUF_COUNT ];
883889 struct bt_mesh_adv * extra_adv ;
884890 int err ;
885891
886- bt_init ();
887- adv_init ();
888-
889- /* Fill up the adv pool and suspend the advertiser in the first start callback call. */
890- adv_create_and_send (true, 0xAA , adv_data );
891-
892892 err = k_sem_take (& adv_suspended_sem , K_SECONDS (10 ));
893893 ASSERT_OK_MSG (err , "Not all advs were sent" );
894894
895895 extra_adv = bt_mesh_adv_create (BT_MESH_ADV_DATA , BT_MESH_ADV_TAG_LOCAL ,
896896 BT_MESH_TRANSMIT (2 , 20 ), K_NO_WAIT );
897897 ASSERT_TRUE_MSG (!extra_adv , "Created adv while suspended" );
898+ }
899+
900+ static void test_tx_disable (void )
901+ {
902+ struct adv_suspend_ctx adv_data [CONFIG_BT_MESH_ADV_BUF_COUNT ];
903+ int err ;
904+
905+ bt_init ();
906+ adv_init ();
907+
908+ LOG_INF ("Fill up the adv pool and suspend the advertiser right after in the same context." );
909+ adv_create_and_send (SUSPENDED_IN_CTX , 0xAA , adv_data );
910+ adv_suspend ();
911+ check_suspending ();
912+ adv_resume ();
898913
914+ LOG_INF ("Fill up the adv pool and suspend the advertiser in the first start callback "
915+ "call." );
916+ adv_create_and_send (SUSPENDED_IN_CB , 0xAA , adv_data );
917+ check_suspending ();
899918 adv_resume ();
900919
901- /* Fill up the adv pool and suspend the advertiser and let it send all advs. */
902- adv_create_and_send (false , 0xBB , adv_data );
920+ LOG_INF ( " Fill up the adv pool and suspend the advertiser and let it send all advs" );
921+ adv_create_and_send (NOT_SUSPENDED , 0xBB , adv_data );
903922
904923 err = k_sem_take (& adv_sent_sem , K_SECONDS (10 ));
905924 ASSERT_OK_MSG (err , "Not all advs were sent" );
0 commit comments