@@ -578,17 +578,19 @@ ZTEST_F(zms, test_zms_gc_corrupt_close_ate)
578578 int err ;
579579
580580 Z_TEST_SKIP_IFNDEF (CONFIG_FLASH_SIMULATOR_DOUBLE_WRITES );
581- close_ate .id = 0xffffffff ;
581+ memset (& close_ate , 0xff , sizeof (struct zms_ate ));
582+ close_ate .id = ZMS_HEAD_ID ;
582583 close_ate .offset = fixture -> fs .sector_size - sizeof (struct zms_ate ) * 5 ;
583584 close_ate .len = 0 ;
584- close_ate .metadata = 0xffffffff ;
585585 close_ate .cycle_cnt = 1 ;
586586 close_ate .crc8 = 0xff ; /* Incorrect crc8 */
587587
588- empty_ate . id = 0xffffffff ;
589- empty_ate .offset = 0 ;
588+ memset ( & empty_ate , 0 , sizeof ( struct zms_ate )) ;
589+ empty_ate .id = ZMS_HEAD_ID ;
590590 empty_ate .len = 0xffff ;
591- empty_ate .metadata = 0x4201 ;
591+ empty_ate .metadata = FIELD_PREP (ZMS_VERSION_MASK , ZMS_DEFAULT_VERSION ) |
592+ FIELD_PREP (ZMS_MAGIC_NUMBER_MASK , ZMS_MAGIC_NUMBER ) |
593+ FIELD_PREP (ZMS_ATE_FORMAT_MASK , ZMS_DEFAULT_ATE_FORMAT );
592594 empty_ate .cycle_cnt = 1 ;
593595 empty_ate .crc8 =
594596 crc8_ccitt (0xff , (uint8_t * )& empty_ate + SIZEOF_FIELD (struct zms_ate , crc8 ),
@@ -649,7 +651,7 @@ ZTEST_F(zms, test_zms_gc_corrupt_ate)
649651 struct zms_ate close_ate ;
650652 int err ;
651653
652- close_ate .id = 0xffffffff ;
654+ close_ate .id = ZMS_HEAD_ID ;
653655 close_ate .offset = fixture -> fs .sector_size / 2 ;
654656 close_ate .len = 0 ;
655657 close_ate .crc8 =
@@ -896,3 +898,45 @@ ZTEST_F(zms, test_zms_cache_hash_quality)
896898 ztest_test_skip ();
897899#endif
898900}
901+
902+ /*
903+ * Test 64 bit ZMS ID support.
904+ */
905+ ZTEST_F (zms , test_zms_id_64bit )
906+ {
907+ int err ;
908+ ssize_t len ;
909+ uint64_t data ;
910+ uint64_t filling_id = 0xdeadbeefULL ;
911+
912+ Z_TEST_SKIP_IFNDEF (CONFIG_ZMS_ID_64BIT );
913+
914+ err = zms_mount (& fixture -> fs );
915+ zassert_true (err == 0 , "zms_mount call failure: %d" , err );
916+
917+ /* Fill the first sector with writes of different IDs */
918+
919+ while (fixture -> fs .data_wra + sizeof (data ) + sizeof (struct zms_ate ) <=
920+ fixture -> fs .ate_wra ) {
921+ data = filling_id ;
922+ len = zms_write (& fixture -> fs , (zms_id_t )filling_id , & data , sizeof (data ));
923+ zassert_true (len == sizeof (data ), "zms_write failed: %d" , len );
924+
925+ /* Choose the next ID so that its lower 32 bits stay invariant.
926+ * The purpose is to test that ZMS doesn't mistakenly cast the
927+ * 64 bit ID to a 32 bit one somewhere.
928+ */
929+ filling_id += BIT64 (32 );
930+ }
931+
932+ /* Read back the written entries and check that they're all unique */
933+
934+ for (uint64_t id = 0xdeadbeefULL ; id < filling_id ; id += BIT64 (32 )) {
935+ len = zms_read_hist (& fixture -> fs , (zms_id_t )id , & data , sizeof (data ), 0 );
936+ zassert_true (len == sizeof (data ), "zms_read_hist unexpected failure: %d" , len );
937+ zassert_equal (data , id , "read unexpected data: %llx instead of %llx" , data , id );
938+
939+ len = zms_read_hist (& fixture -> fs , (zms_id_t )id , & data , sizeof (data ), 1 );
940+ zassert_true (len == - ENOENT , "zms_read_hist unexpected failure: %d" , len );
941+ }
942+ }
0 commit comments