@@ -95,9 +95,7 @@ static uint8_t test_mod_data[] = { 0xfa, 0xff, 0xf4, 0x43 };
9595#define TEST_VND_MOD_DATA_NAME "vtmdata"
9696static uint8_t vnd_test_mod_data [] = { 0xad , 0xdf , 0x14 , 0x53 , 0x54 , 0x1f };
9797
98- static ssize_t test_preset = -1 ;
99- static bool test_settings_clear ;
100- static struct {
98+ struct access_cfg {
10199 struct bt_mesh_cfg_mod_pub pub_params ;
102100
103101 size_t appkeys_count ;
@@ -107,9 +105,15 @@ static struct {
107105 uint16_t subs [CONFIG_BT_MESH_MODEL_GROUP_COUNT ];
108106
109107 size_t mod_data_len ;
110- } test_access_presets [][2 ] = {
111- /* Default */
112- {
108+ };
109+ static const struct access_cfg (* current_access_cfg )[2 ];
110+ enum {
111+ CONFIGURED ,
112+ NEW_SUBS ,
113+ NOT_CONFIGURED ,
114+ };
115+ static const struct access_cfg access_cfgs [][2 ] = {
116+ [CONFIGURED ] = {
113117 /* SIG model. */
114118 {
115119 .pub_params = TEST_MOD_PUB_PARAMS ,
@@ -127,8 +131,7 @@ static struct {
127131 },
128132 },
129133
130- /* After subscription overwrite */
131- {
134+ [NEW_SUBS ] = {
132135 /* SIG model. */
133136 {
134137 .pub_params = TEST_MOD_PUB_PARAMS ,
@@ -146,8 +149,7 @@ static struct {
146149 },
147150 },
148151
149- /* After remove */
150- {
152+ [NOT_CONFIGURED ] = {
151153 /* SIG model. */
152154 {
153155 .pub_params = DISABLED_MOD_PUB_PARAMS ,
@@ -166,7 +168,7 @@ static struct {
166168 },
167169};
168170
169- static const struct {
171+ static const struct stack_cfg {
170172 uint8_t beacon ;
171173 uint8_t ttl ;
172174 uint8_t gatt_proxy ;
@@ -176,7 +178,7 @@ static const struct {
176178 enum bt_mesh_feat_state state ;
177179 uint8_t transmit ;
178180 } relay ;
179- } test_cfg_presets [] = {
181+ } stack_cfgs [] = {
180182 {
181183 .beacon = 1 ,
182184 .ttl = 12 ,
@@ -194,19 +196,32 @@ static const struct {
194196 .relay = { .state = BT_MESH_FEATURE_ENABLED , .transmit = BT_MESH_TRANSMIT (1 , 10 ) },
195197 },
196198};
199+ static const struct stack_cfg * current_stack_cfg ;
200+
201+ static bool clear_settings ;
197202
198203static void test_args_parse (int argc , char * argv [])
199204{
205+ char * access_cfg_str = NULL ;
206+ int32_t stack_cfg = -1 ;
207+
200208 bs_args_struct_t args_struct [] = {
201209 {
202- .dest = & test_preset ,
203- .type = 'u' ,
204- .name = "{0, 1, 2}" ,
205- .option = "test-preset" ,
210+ .dest = & access_cfg_str ,
211+ .type = 's' ,
212+ .name = "{configured, new-subs, not-configured}" ,
213+ .option = "access-cfg" ,
214+ .descript = ""
215+ },
216+ {
217+ .dest = & stack_cfg ,
218+ .type = 'i' ,
219+ .name = "{0, 1}" ,
220+ .option = "stack-cfg" ,
206221 .descript = ""
207222 },
208223 {
209- .dest = & test_settings_clear ,
224+ .dest = & clear_settings ,
210225 .type = 'b' ,
211226 .name = "{0, 1}" ,
212227 .option = "clear-settings" ,
@@ -215,6 +230,20 @@ static void test_args_parse(int argc, char *argv[])
215230 };
216231
217232 bs_args_parse_all_cmd_line (argc , argv , args_struct );
233+
234+ if (access_cfg_str != NULL ) {
235+ if (!strcmp (access_cfg_str , "configured" )) {
236+ current_access_cfg = & access_cfgs [CONFIGURED ];
237+ } else if (!strcmp (access_cfg_str , "new-subs" )) {
238+ current_access_cfg = & access_cfgs [NEW_SUBS ];
239+ } else if (!strcmp (access_cfg_str , "not-configured" )) {
240+ current_access_cfg = & access_cfgs [NOT_CONFIGURED ];
241+ }
242+ }
243+
244+ if (stack_cfg >= 0 && stack_cfg < ARRAY_SIZE (stack_cfgs )) {
245+ current_stack_cfg = & stack_cfgs [stack_cfg ];
246+ }
218247}
219248
220249static struct k_sem prov_sem ;
@@ -251,8 +280,8 @@ static void prov_node_added(uint16_t net_idx, uint8_t uuid[16], uint16_t addr, u
251280 k_sem_give (& prov_sem );
252281}
253282
254- static void check_mod_pub_params (struct bt_mesh_cfg_mod_pub * expected ,
255- struct bt_mesh_cfg_mod_pub * got )
283+ static void check_mod_pub_params (const struct bt_mesh_cfg_mod_pub * expected ,
284+ const struct bt_mesh_cfg_mod_pub * got )
256285{
257286 ASSERT_EQUAL (expected -> addr , got -> addr );
258287 ASSERT_EQUAL (expected -> app_idx , got -> app_idx );
@@ -277,11 +306,11 @@ int test_model_settings_set(struct bt_mesh_model *model,
277306 settings_name_next (name , & name );
278307 ASSERT_TRUE (name == NULL );
279308
280- ASSERT_TRUE (test_preset >= 0 && test_preset <= 2 );
309+ ASSERT_TRUE (current_access_cfg != NULL );
281310 result = read_cb (cb_arg , & data , sizeof (data ));
282- ASSERT_EQUAL (test_access_presets [ test_preset ] [0 ].mod_data_len , result );
311+ ASSERT_EQUAL (( * current_access_cfg ) [0 ].mod_data_len , result );
283312
284- if (memcmp (data , test_mod_data , test_access_presets [ test_preset ] [0 ].mod_data_len )) {
313+ if (memcmp (data , test_mod_data , ( * current_access_cfg ) [0 ].mod_data_len )) {
285314 FAIL ("Incorrect data restored" );
286315 }
287316
@@ -308,11 +337,11 @@ int test_vnd_model_settings_set(struct bt_mesh_model *model,
308337 settings_name_next (name , & name );
309338 ASSERT_TRUE (name == NULL );
310339
311- ASSERT_TRUE (test_preset >= 0 && test_preset <= 2 );
340+ ASSERT_TRUE (current_access_cfg != NULL );
312341 result = read_cb (cb_arg , & data , sizeof (data ));
313- ASSERT_EQUAL (test_access_presets [ test_preset ] [1 ].mod_data_len , result );
342+ ASSERT_EQUAL (( * current_access_cfg ) [1 ].mod_data_len , result );
314343
315- if (memcmp (data , vnd_test_mod_data , test_access_presets [ test_preset ] [1 ].mod_data_len )) {
344+ if (memcmp (data , vnd_test_mod_data , ( * current_access_cfg ) [1 ].mod_data_len )) {
316345 FAIL ("Incorrect data restored" );
317346 }
318347
@@ -563,7 +592,7 @@ static void test_access_data_save(void)
563592 PASS ();
564593}
565594
566- static void node_configuration_check (size_t preset )
595+ static void node_configuration_check (const struct access_cfg ( * cfg )[ 2 ] )
567596{
568597 uint16_t appkeys [CONFIG_BT_MESH_MODEL_KEY_COUNT + 1 ];
569598 size_t appkeys_count = ARRAY_SIZE (appkeys );
@@ -588,9 +617,9 @@ static void node_configuration_check(size_t preset)
588617 FAIL ("Mod app get failed (err %d, status %u)" , err , status );
589618 }
590619
591- ASSERT_EQUAL (test_access_presets [ preset ] [m ].appkeys_count , appkeys_count );
620+ ASSERT_EQUAL (( * cfg ) [m ].appkeys_count , appkeys_count );
592621 for (size_t i = 0 ; i < appkeys_count ; i ++ ) {
593- ASSERT_EQUAL (test_access_presets [ preset ] [m ].appkeys [i ], appkeys [i ]);
622+ ASSERT_EQUAL (( * cfg ) [m ].appkeys [i ], appkeys [i ]);
594623 }
595624
596625 if (!vnd ) {
@@ -605,9 +634,9 @@ static void node_configuration_check(size_t preset)
605634 FAIL ("Mod sub get failed (err %d, status %u)" , err , status );
606635 }
607636
608- ASSERT_EQUAL (test_access_presets [ preset ] [m ].subs_count , subs_count );
637+ ASSERT_EQUAL (( * cfg ) [m ].subs_count , subs_count );
609638 for (size_t i = 0 ; i < subs_count ; i ++ ) {
610- ASSERT_EQUAL (test_access_presets [ preset ] [m ].subs [i ], subs [i ]);
639+ ASSERT_EQUAL (( * cfg ) [m ].subs [i ], subs [i ]);
611640 }
612641
613642 struct bt_mesh_cfg_mod_pub pub_params = {};
@@ -624,13 +653,13 @@ static void node_configuration_check(size_t preset)
624653 FAIL ("Mod pub get failed (err %d, status %u)" , err , status );
625654 }
626655
627- check_mod_pub_params (& test_access_presets [ preset ] [m ].pub_params , & pub_params );
656+ check_mod_pub_params (& ( * cfg ) [m ].pub_params , & pub_params );
628657 }
629658}
630659
631660static void test_access_data_load (void )
632661{
633- ASSERT_TRUE (test_preset >= 0 && test_preset <= 2 );
662+ ASSERT_TRUE (current_access_cfg != NULL );
634663
635664 /* In this test stack should boot as provisioned */
636665 bt_mesh_test_cfg_set (NULL , WAIT_TIME );
@@ -639,7 +668,7 @@ static void test_access_data_load(void)
639668 FAIL ("Device should boot up as already provisioned" );
640669 }
641670
642- node_configuration_check (test_preset );
671+ node_configuration_check (current_access_cfg );
643672
644673 PASS ();
645674}
@@ -767,7 +796,7 @@ static void test_cfg_save(void)
767796 uint8_t status ;
768797 int err ;
769798
770- ASSERT_TRUE (test_preset >= 0 && test_preset <= 1 );
799+ ASSERT_TRUE (current_stack_cfg != NULL );
771800
772801 settings_test_backend_clear ();
773802 bt_mesh_test_cfg_set (NULL , WAIT_TIME );
@@ -777,44 +806,44 @@ static void test_cfg_save(void)
777806 }
778807
779808 err = bt_mesh_cfg_beacon_set (test_netkey_idx , TEST_ADDR ,
780- test_cfg_presets [ test_preset ]. beacon , & status );
781- if (err || status != test_cfg_presets [ test_preset ]. beacon ) {
809+ current_stack_cfg -> beacon , & status );
810+ if (err || status != current_stack_cfg -> beacon ) {
782811 FAIL ("Beacon set failed (err %d, status %u)" , err , status );
783812 }
784813
785814 err = bt_mesh_cfg_ttl_set (test_netkey_idx , TEST_ADDR ,
786- test_cfg_presets [ test_preset ]. ttl , & status );
787- if (err || status != test_cfg_presets [ test_preset ]. ttl ) {
815+ current_stack_cfg -> ttl , & status );
816+ if (err || status != current_stack_cfg -> ttl ) {
788817 FAIL ("TTL set failed (err %d, status %u)" , err , status );
789818 }
790819
791820 err = bt_mesh_cfg_gatt_proxy_set (test_netkey_idx , TEST_ADDR ,
792- test_cfg_presets [ test_preset ]. gatt_proxy , & status );
793- if (err || status != test_cfg_presets [ test_preset ]. gatt_proxy ) {
821+ current_stack_cfg -> gatt_proxy , & status );
822+ if (err || status != current_stack_cfg -> gatt_proxy ) {
794823 FAIL ("GATT Proxy set failed (err %d, status %u)" , err , status );
795824 }
796825
797826 err = bt_mesh_cfg_friend_set (test_netkey_idx , TEST_ADDR ,
798- test_cfg_presets [ test_preset ]. friend , & status );
799- if (err || status != test_cfg_presets [ test_preset ]. friend ) {
827+ current_stack_cfg -> friend , & status );
828+ if (err || status != current_stack_cfg -> friend ) {
800829 FAIL ("Friend set failed (err %d, status %u)" , err , status );
801830 }
802831
803832 err = bt_mesh_cfg_net_transmit_set (test_netkey_idx , TEST_ADDR ,
804- test_cfg_presets [ test_preset ]. net_transmit ,
833+ current_stack_cfg -> net_transmit ,
805834 & transmit );
806- if (err || transmit != test_cfg_presets [ test_preset ]. net_transmit ) {
835+ if (err || transmit != current_stack_cfg -> net_transmit ) {
807836 FAIL ("Net transmit set failed (err %d, trasmit %x)" , err , transmit );
808837 }
809838
810839 err = bt_mesh_cfg_relay_set (test_netkey_idx , TEST_ADDR ,
811- test_cfg_presets [ test_preset ]. relay .state ,
812- test_cfg_presets [ test_preset ]. relay .transmit ,
840+ current_stack_cfg -> relay .state ,
841+ current_stack_cfg -> relay .transmit ,
813842 & status , & transmit );
814- if (err || status != test_cfg_presets [ test_preset ]. relay .state ||
815- transmit != test_cfg_presets [ test_preset ]. relay .transmit ) {
843+ if (err || status != current_stack_cfg -> relay .state ||
844+ transmit != current_stack_cfg -> relay .transmit ) {
816845 FAIL ("Relay set failed (err %d, status %u, transmit %x)" , err , status ,
817- test_cfg_presets [ test_preset ]. relay .transmit );
846+ current_stack_cfg -> relay .transmit );
818847 }
819848
820849 k_sleep (K_SECONDS (CONFIG_BT_MESH_STORE_TIMEOUT ));
@@ -828,7 +857,7 @@ static void test_cfg_load(void)
828857 uint8_t status ;
829858 int err ;
830859
831- ASSERT_TRUE (test_preset >= 0 && test_preset <= 1 );
860+ ASSERT_TRUE (current_stack_cfg != NULL );
832861
833862 /* In this test stack should boot as provisioned */
834863 bt_mesh_test_cfg_set (NULL , WAIT_TIME );
@@ -838,33 +867,33 @@ static void test_cfg_load(void)
838867 }
839868
840869 err = bt_mesh_cfg_beacon_get (test_netkey_idx , TEST_ADDR , & status );
841- if (err || status != test_cfg_presets [ test_preset ]. beacon ) {
870+ if (err || status != current_stack_cfg -> beacon ) {
842871 FAIL ("Beacon get failed (err %d, status %u)" , err , status );
843872 }
844873
845874 err = bt_mesh_cfg_ttl_get (test_netkey_idx , TEST_ADDR , & status );
846- if (err || status != test_cfg_presets [ test_preset ]. ttl ) {
875+ if (err || status != current_stack_cfg -> ttl ) {
847876 FAIL ("TTL get failed (err %d, status %u)" , err , status );
848877 }
849878
850879 err = bt_mesh_cfg_gatt_proxy_get (test_netkey_idx , TEST_ADDR , & status );
851- if (err || status != test_cfg_presets [ test_preset ]. gatt_proxy ) {
880+ if (err || status != current_stack_cfg -> gatt_proxy ) {
852881 FAIL ("GATT Proxy get failed (err %d, status %u)" , err , status );
853882 }
854883
855884 err = bt_mesh_cfg_friend_get (test_netkey_idx , TEST_ADDR , & status );
856- if (err || status != test_cfg_presets [ test_preset ]. friend ) {
885+ if (err || status != current_stack_cfg -> friend ) {
857886 FAIL ("Friend get failed (err %d, status %u)" , err , status );
858887 }
859888
860889 err = bt_mesh_cfg_net_transmit_get (test_netkey_idx , TEST_ADDR , & status );
861- if (err || status != test_cfg_presets [ test_preset ]. net_transmit ) {
890+ if (err || status != current_stack_cfg -> net_transmit ) {
862891 FAIL ("Net transmit get failed (err %d, status %u)" , err , status );
863892 }
864893
865894 err = bt_mesh_cfg_relay_get (test_netkey_idx , TEST_ADDR , & status , & transmit );
866- if (err || status != test_cfg_presets [ test_preset ]. relay .state ||
867- transmit != test_cfg_presets [ test_preset ]. relay .transmit ) {
895+ if (err || status != current_stack_cfg -> relay .state ||
896+ transmit != current_stack_cfg -> relay .transmit ) {
868897 FAIL ("Relay get failed (err %d, state %u, transmit %x)" , err , status , transmit );
869898 }
870899
@@ -877,7 +906,7 @@ static void test_cfg_load(void)
877906 */
878907static void test_reprovisioning_device (void )
879908{
880- if (test_settings_clear ) {
909+ if (clear_settings ) {
881910 settings_test_backend_clear ();
882911 }
883912
@@ -918,7 +947,7 @@ static void test_reprovisioning_provisioner(void)
918947 ASSERT_OK (k_sem_take (& prov_sem , K_SECONDS (40 )));
919948
920949 /* Verify that the remote device is not configured. */
921- node_configuration_check (2 );
950+ node_configuration_check (& access_cfgs [ NOT_CONFIGURED ] );
922951
923952 /* Configure the remote device. */
924953 node_configure ();
0 commit comments