2222#include "ble_hs_test_util.h"
2323
2424static struct ble_store_status_event ble_store_test_status_event ;
25+ uint8_t database_hash [16 ] = { 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 ,
26+ 0x08 , 0x09 , 0x0a , 0x0b , 0x0c , 0x0d , 0x0e , 0x0f };
2527
2628static void
2729ble_store_test_util_verify_peer_deleted (const ble_addr_t * addr )
@@ -50,6 +52,11 @@ ble_store_test_util_verify_peer_deleted(const ble_addr_t *addr)
5052 rc = ble_store_read (BLE_STORE_OBJ_TYPE_PEER_CL_SUP_FEAT , & key , & value );
5153 TEST_ASSERT (rc == BLE_HS_ENOENT );
5254
55+ memset (& key , 0 , sizeof key );
56+ key .feat .peer_addr = * addr ;
57+ rc = ble_store_read (BLE_STORE_OBJ_TYPE_DB_HASH , & key , & value );
58+ TEST_ASSERT (rc == BLE_HS_ENOENT );
59+
5360 rc = ble_store_util_bonded_peers (addrs , & num_addrs ,
5461 sizeof addrs / sizeof addrs [0 ]);
5562 TEST_ASSERT_FATAL (rc == 0 );
@@ -213,6 +220,16 @@ TEST_CASE_SELF(ble_store_test_delete_peer)
213220 .peer_cl_sup_feat [0 ] = 0 ,
214221 },
215222 };
223+ struct ble_store_value_db_hash hashes [2 ] = {
224+ {
225+ .peer_addr = secs [0 ].peer_addr ,
226+ .db_hash = database_hash ,
227+ },
228+ {
229+ .peer_addr = secs [1 ].peer_addr ,
230+ .db_hash = database_hash ,
231+ },
232+ };
216233 union ble_store_value value ;
217234 union ble_store_key key ;
218235 int count ;
@@ -238,6 +255,11 @@ TEST_CASE_SELF(ble_store_test_delete_peer)
238255 TEST_ASSERT_FATAL (rc == 0 );
239256 }
240257
258+ for (i = 0 ; i < sizeof hashes / sizeof hashes [0 ]; i ++ ) {
259+ rc = ble_store_write_db_hash (hashes + i );
260+ TEST_ASSERT_FATAL (rc == 0 );
261+ }
262+
241263 /* Delete first peer. */
242264 rc = ble_store_util_delete_peer (& secs [0 ].peer_addr );
243265 TEST_ASSERT_FATAL (rc == 0 );
@@ -284,6 +306,16 @@ TEST_CASE_SELF(ble_store_test_delete_peer)
284306 TEST_ASSERT_FATAL (rc == 0 );
285307 TEST_ASSERT (memcmp (& value .feat , feats + 1 , sizeof value .feat ) == 0 );
286308
309+ ble_store_key_from_value_db_hash (& key .db_hash , hashes + 1 );
310+
311+ rc = ble_store_util_count (BLE_STORE_OBJ_TYPE_DB_HASH , & count );
312+ TEST_ASSERT_FATAL (rc == 0 );
313+ TEST_ASSERT (count == 1 );
314+
315+ rc = ble_store_read_db_hash (& key .db_hash , & value .db_hash );
316+ TEST_ASSERT_FATAL (rc == 0 );
317+ TEST_ASSERT (memcmp (& value .db_hash , hashes + 1 , sizeof value .db_hash ) == 0 );
318+
287319 /* Delete second peer. */
288320 rc = ble_store_util_delete_peer (& secs [1 ].peer_addr );
289321 TEST_ASSERT_FATAL (rc == 0 );
@@ -334,6 +366,16 @@ TEST_CASE_SELF(ble_store_test_count)
334366 .peer_cl_sup_feat [0 ] = 0 ,
335367 },
336368 };
369+ struct ble_store_value_db_hash hashes [2 ] = {
370+ {
371+ .peer_addr = secs [0 ].peer_addr ,
372+ .db_hash = database_hash ,
373+ },
374+ {
375+ .peer_addr = secs [1 ].peer_addr ,
376+ .db_hash = database_hash ,
377+ },
378+ };
337379 int count ;
338380 int rc ;
339381 int i ;
@@ -358,6 +400,10 @@ TEST_CASE_SELF(ble_store_test_count)
358400 TEST_ASSERT_FATAL (rc == 0 );
359401 TEST_ASSERT (count == 0 );
360402
403+ rc = ble_store_util_count (BLE_STORE_OBJ_TYPE_DB_HASH , & count );
404+ TEST_ASSERT_FATAL (rc == 0 );
405+ TEST_ASSERT (count == 0 );
406+
361407 /* Write some test data. */
362408
363409 for (i = 0 ; i < 3 ; i ++ ) {
@@ -376,6 +422,10 @@ TEST_CASE_SELF(ble_store_test_count)
376422 rc = ble_store_write_peer_cl_sup_feat (feats + i );
377423 TEST_ASSERT_FATAL (rc == 0 );
378424 }
425+ for (i = 0 ; i < 1 ; i ++ ) {
426+ rc = ble_store_write_db_hash (hashes + i );
427+ TEST_ASSERT_FATAL (rc == 0 );
428+ }
379429
380430 /*** Verify counts after populating store. */
381431 rc = ble_store_util_count (BLE_STORE_OBJ_TYPE_OUR_SEC , & count );
@@ -394,6 +444,10 @@ TEST_CASE_SELF(ble_store_test_count)
394444 TEST_ASSERT_FATAL (rc == 0 );
395445 TEST_ASSERT (count == 1 );
396446
447+ rc = ble_store_util_count (BLE_STORE_OBJ_TYPE_DB_HASH , & count );
448+ TEST_ASSERT_FATAL (rc == 0 );
449+ TEST_ASSERT (count == 1 );
450+
397451 ble_hs_test_util_assert_mbufs_freed (NULL );
398452}
399453
@@ -445,6 +499,16 @@ TEST_CASE_SELF(ble_store_test_clear)
445499 .peer_cl_sup_feat [0 ] = 0 ,
446500 },
447501 };
502+ struct ble_store_value_db_hash hashes [2 ] = {
503+ {
504+ .peer_addr = secs [0 ].peer_addr ,
505+ .db_hash = database_hash ,
506+ },
507+ {
508+ .peer_addr = secs [1 ].peer_addr ,
509+ .db_hash = database_hash ,
510+ },
511+ };
448512 int rc ;
449513 int i ;
450514
@@ -467,6 +531,11 @@ TEST_CASE_SELF(ble_store_test_clear)
467531 TEST_ASSERT_FATAL (rc == 0 );
468532 }
469533
534+ for (i = 0 ; i < sizeof hashes / sizeof hashes [0 ]; i ++ ) {
535+ rc = ble_store_write_db_hash (hashes + i );
536+ TEST_ASSERT_FATAL (rc == 0 );
537+ }
538+
470539 /* Sanity check. */
471540 TEST_ASSERT_FATAL (
472541 ble_store_test_util_count (BLE_STORE_OBJ_TYPE_OUR_SEC ) == 2 );
@@ -476,6 +545,7 @@ TEST_CASE_SELF(ble_store_test_clear)
476545 ble_store_test_util_count (BLE_STORE_OBJ_TYPE_CCCD ) == 3 );
477546 TEST_ASSERT_FATAL (
478547 ble_store_test_util_count (BLE_STORE_OBJ_TYPE_PEER_CL_SUP_FEAT ) == 2 );
548+ TEST_ASSERT_FATAL (ble_store_test_util_count (BLE_STORE_OBJ_TYPE_DB_HASH ) == 2 );
479549
480550 /* Ensure store is empty after clear gets called. */
481551 rc = ble_store_clear ();
@@ -484,6 +554,7 @@ TEST_CASE_SELF(ble_store_test_clear)
484554 TEST_ASSERT (ble_store_test_util_count (BLE_STORE_OBJ_TYPE_PEER_SEC ) == 0 );
485555 TEST_ASSERT (ble_store_test_util_count (BLE_STORE_OBJ_TYPE_CCCD ) == 0 );
486556 TEST_ASSERT (ble_store_test_util_count (BLE_STORE_OBJ_TYPE_PEER_CL_SUP_FEAT ) == 0 );
557+ TEST_ASSERT (ble_store_test_util_count (BLE_STORE_OBJ_TYPE_DB_HASH ) == 0 );
487558
488559 /* Ensure second clear succeeds with no effect. */
489560 rc = ble_store_clear ();
@@ -492,6 +563,7 @@ TEST_CASE_SELF(ble_store_test_clear)
492563 TEST_ASSERT (ble_store_test_util_count (BLE_STORE_OBJ_TYPE_PEER_SEC ) == 0 );
493564 TEST_ASSERT (ble_store_test_util_count (BLE_STORE_OBJ_TYPE_CCCD ) == 0 );
494565 TEST_ASSERT (ble_store_test_util_count (BLE_STORE_OBJ_TYPE_PEER_CL_SUP_FEAT ) == 0 );
566+ TEST_ASSERT (ble_store_test_util_count (BLE_STORE_OBJ_TYPE_DB_HASH ) == 0 );
495567
496568 ble_hs_test_util_assert_mbufs_freed (NULL );
497569}
0 commit comments