@@ -17,43 +17,67 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
17
17
* Tests both the provisioner and device role in various scenarios.
18
18
*/
19
19
20
+ #define PROV_MULTI_COUNT 3
21
+
22
+ enum test_flags {
23
+ IS_PROVISIONER ,
24
+
25
+ TEST_FLAGS ,
26
+ };
27
+
28
+ static ATOMIC_DEFINE (flags , TEST_FLAGS ) ;
29
+ extern const struct bt_mesh_comp comp ;
30
+ extern const uint8_t test_net_key [16 ];
31
+ extern uint global_device_nbr ;
32
+
20
33
/* Timeout semaphore */
21
34
static struct k_sem prov_sem ;
35
+ static uint16_t prov_addr = 0x0002 ;
36
+ static const uint8_t dev_key [16 ] = { 0x01 , 0x02 , 0x03 , 0x04 , 0x05 };
37
+ static uint8_t dev_uuid [16 ] = { 0x6c , 0x69 , 0x6e , 0x67 , 0x61 , 0x6f };
22
38
23
39
#define WAIT_TIME 60 /*seconds*/
24
40
25
41
static void test_device_init (void )
26
42
{
43
+ /* Ensure that the UUID is unique: */
44
+ dev_uuid [6 ] = '0' + global_device_nbr ;
45
+
27
46
bt_mesh_test_cfg_set (NULL , WAIT_TIME );
28
47
}
29
48
30
49
static void test_provisioner_init (void )
31
50
{
51
+ atomic_set_bit (flags , IS_PROVISIONER );
32
52
bt_mesh_test_cfg_set (NULL , WAIT_TIME );
33
53
}
34
54
35
55
static void unprovisioned_beacon (uint8_t uuid [16 ],
36
56
bt_mesh_prov_oob_info_t oob_info ,
37
57
uint32_t * uri_hash )
38
58
{
39
- bt_mesh_provision_adv (uuid , 0 , 0 , 0 );
59
+ if (!atomic_test_bit (flags , IS_PROVISIONER )) {
60
+ return ;
61
+ }
62
+
63
+ bt_mesh_provision_adv (uuid , 0 , prov_addr , 0 );
40
64
}
41
65
42
66
static void prov_complete (uint16_t net_idx , uint16_t addr )
43
67
{
44
- k_sem_give (& prov_sem );
68
+ if (!atomic_test_bit (flags , IS_PROVISIONER )) {
69
+ k_sem_give (& prov_sem );
70
+ }
45
71
}
46
72
47
73
static void prov_node_added (uint16_t net_idx , uint8_t uuid [16 ], uint16_t addr ,
48
74
uint8_t num_elem )
49
75
{
76
+ LOG_INF ("Device 0x%04x provisioned" , prov_addr );
77
+ prov_addr ++ ;
50
78
k_sem_give (& prov_sem );
51
79
}
52
80
53
- extern const struct bt_mesh_comp comp ;
54
- extern const uint8_t test_net_key [16 ];
55
- static const uint8_t dev_key [16 ] = { 0x01 , 0x02 , 0x03 , 0x04 , 0x05 };
56
- static const uint8_t dev_uuid [16 ] = { 0x6c , 0x69 , 0x6e , 0x67 , 0x61 , 0x6f };
57
81
static struct bt_mesh_prov prov = {
58
82
.uuid = dev_uuid ,
59
83
.unprovisioned_beacon = unprovisioned_beacon ,
@@ -95,7 +119,8 @@ static void test_device_pb_adv_no_oob(void)
95
119
96
120
LOG_INF ("Mesh initialized\n" );
97
121
98
- ASSERT_OK (k_sem_take (& prov_sem , K_SECONDS (20 )),
122
+ /* Keep a long timeout so the prov multi case has time to finish: */
123
+ ASSERT_OK (k_sem_take (& prov_sem , K_SECONDS (40 )),
99
124
"Device provision fail" );
100
125
101
126
PASS ();
@@ -117,14 +142,36 @@ static void test_provisioner_pb_adv_no_oob(void)
117
142
err = bt_mesh_provision (test_net_key , 0 , 0 , 0 , 0x0001 , dev_key );
118
143
ASSERT_OK (err , "Provisioning failed (err %d)" , err );
119
144
120
- k_sem_take (& prov_sem , K_NO_WAIT );
121
-
122
- ASSERT_OK (k_sem_take (& prov_sem , K_SECONDS (20 )),
145
+ ASSERT_OK (k_sem_take (& prov_sem , K_SECONDS (5 )),
123
146
"Provisioner provision fail" );
124
147
125
148
PASS ();
126
149
}
127
150
151
+ /** @brief Verify that the provisioner can provision multiple devices in a row
152
+ */
153
+ static void test_provisioner_pb_adv_multi (void )
154
+ {
155
+ int err ;
156
+
157
+ k_sem_init (& prov_sem , 0 , 1 );
158
+
159
+ bt_mesh_device_setup ();
160
+
161
+ err = bt_mesh_cdb_create (test_net_key );
162
+ ASSERT_OK (err , "Failed to create CDB (err %d)\n" , err );
163
+
164
+ err = bt_mesh_provision (test_net_key , 0 , 0 , 0 , 0x0001 , dev_key );
165
+ ASSERT_OK (err , "Provisioning failed (err %d)" , err );
166
+
167
+ for (int i = 0 ; i < PROV_MULTI_COUNT ; i ++ ) {
168
+ ASSERT_OK (k_sem_take (& prov_sem , K_SECONDS (20 )),
169
+ "Provisioner provision #%d fail" , i );
170
+ }
171
+
172
+ PASS ();
173
+ }
174
+
128
175
#define TEST_CASE (role , name , description ) \
129
176
{ \
130
177
.test_id = "prov_" #role "_" #name, .test_descr = description, \
@@ -139,6 +186,8 @@ static const struct bst_test_instance test_connect[] = {
139
186
140
187
TEST_CASE (provisioner , pb_adv_no_oob ,
141
188
"Provisioner: pb-adv provisioning use no-oob method" ),
189
+ TEST_CASE (provisioner , pb_adv_multi ,
190
+ "Provisioner: pb-adv provisioning multiple devices" ),
142
191
143
192
BSTEST_END_MARKER
144
193
};
0 commit comments