@@ -19,6 +19,12 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL_INF);
19
19
20
20
#define WAIT_TIME 60 /*seconds*/
21
21
22
+ enum suspending_ctx {
23
+ NOT_SUSPENDED ,
24
+ SUSPENDED_IN_CTX ,
25
+ SUSPENDED_IN_CB
26
+ };
27
+
22
28
extern const struct bt_mesh_comp comp ;
23
29
24
30
static uint8_t test_prov_uuid [16 ] = { 0x6c , 0x69 , 0x6e , 0x67 , 0x61 , 0xaa };
@@ -796,7 +802,7 @@ static void adv_resume(void)
796
802
}
797
803
798
804
struct adv_suspend_ctx {
799
- bool suspend ;
805
+ enum suspending_ctx suspend ;
800
806
int instance_idx ;
801
807
};
802
808
@@ -812,7 +818,7 @@ static void adv_send_end(int err, void *cb_data)
812
818
813
819
ASSERT_EQUAL (err , 0 );
814
820
815
- if (adv_data -> suspend ) {
821
+ if (adv_data -> suspend != NOT_SUSPENDED ) {
816
822
/* When suspending, the end callback will be called only for the first adv, because
817
823
* it was already scheduled.
818
824
*/
@@ -831,8 +837,8 @@ static void adv_send_start(uint16_t duration, int err, void *cb_data)
831
837
LOG_DBG ("start(): err (%d), suspend (%d), i (%d)" , err , adv_data -> suspend ,
832
838
adv_data -> instance_idx );
833
839
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 ) {
836
842
ASSERT_EQUAL (err , 0 );
837
843
adv_suspend ();
838
844
} else {
@@ -851,7 +857,8 @@ static void adv_send_start(uint16_t duration, int err, void *cb_data)
851
857
}
852
858
}
853
859
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 )
855
862
{
856
863
struct bt_mesh_adv * advs [CONFIG_BT_MESH_ADV_BUF_COUNT ];
857
864
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
864
871
adv_data [i ].instance_idx = i ;
865
872
866
873
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 );
868
875
ASSERT_FALSE_MSG (!advs [i ], "Out of advs\n" );
869
876
870
877
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
877
884
}
878
885
}
879
886
880
- static void test_tx_disable (void )
887
+ static void check_suspending (void )
881
888
{
882
- struct adv_suspend_ctx adv_data [CONFIG_BT_MESH_ADV_BUF_COUNT ];
883
889
struct bt_mesh_adv * extra_adv ;
884
890
int err ;
885
891
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
-
892
892
err = k_sem_take (& adv_suspended_sem , K_SECONDS (10 ));
893
893
ASSERT_OK_MSG (err , "Not all advs were sent" );
894
894
895
895
extra_adv = bt_mesh_adv_create (BT_MESH_ADV_DATA , BT_MESH_ADV_TAG_LOCAL ,
896
896
BT_MESH_TRANSMIT (2 , 20 ), K_NO_WAIT );
897
897
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 ();
898
913
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 ();
899
918
adv_resume ();
900
919
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 );
903
922
904
923
err = k_sem_take (& adv_sent_sem , K_SECONDS (10 ));
905
924
ASSERT_OK_MSG (err , "Not all advs were sent" );
0 commit comments