@@ -578,17 +578,18 @@ 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 =
592+ FIELD_PREP (ZMS_MAGIC_NUMBER_MASK , ZMS_MAGIC_NUMBER ) | ZMS_DEFAULT_VERSION ;
592593 empty_ate .cycle_cnt = 1 ;
593594 empty_ate .crc8 =
594595 crc8_ccitt (0xff , (uint8_t * )& empty_ate + SIZEOF_FIELD (struct zms_ate , crc8 ),
@@ -649,7 +650,7 @@ ZTEST_F(zms, test_zms_gc_corrupt_ate)
649650 struct zms_ate close_ate ;
650651 int err ;
651652
652- close_ate .id = 0xffffffff ;
653+ close_ate .id = ZMS_HEAD_ID ;
653654 close_ate .offset = fixture -> fs .sector_size / 2 ;
654655 close_ate .len = 0 ;
655656 close_ate .crc8 =
@@ -896,3 +897,45 @@ ZTEST_F(zms, test_zms_cache_hash_quality)
896897 ztest_test_skip ();
897898#endif
898899}
900+
901+ /*
902+ * Test 64 bit ZMS ID support.
903+ */
904+ ZTEST_F (zms , test_zms_id_64bit )
905+ {
906+ int err ;
907+ ssize_t len ;
908+ uint64_t data ;
909+ uint64_t filling_id = 0xdeadbeefULL ;
910+
911+ Z_TEST_SKIP_IFNDEF (CONFIG_ZMS_ID_64BIT );
912+
913+ err = zms_mount (& fixture -> fs );
914+ zassert_true (err == 0 , "zms_mount call failure: %d" , err );
915+
916+ /* Fill the first sector with writes of different IDs */
917+
918+ while (fixture -> fs .data_wra + sizeof (data ) + sizeof (struct zms_ate ) <=
919+ fixture -> fs .ate_wra ) {
920+ data = filling_id ;
921+ len = zms_write (& fixture -> fs , (zms_id_t )filling_id , & data , sizeof (data ));
922+ zassert_true (len == sizeof (data ), "zms_write failed: %d" , len );
923+
924+ /* Choose the next ID so that its lower 32 bits stay invariant.
925+ * The purpose is to test that ZMS doesn't mistakenly cast the
926+ * 64 bit ID to a 32 bit one somewhere.
927+ */
928+ filling_id += BIT64 (32 );
929+ }
930+
931+ /* Read back the written entries and check that they're all unique */
932+
933+ for (uint64_t id = 0xdeadbeefULL ; id < filling_id ; id += BIT64 (32 )) {
934+ len = zms_read_hist (& fixture -> fs , (zms_id_t )id , & data , sizeof (data ), 0 );
935+ zassert_true (len == sizeof (data ), "zms_read_hist unexpected failure: %d" , len );
936+ zassert_equal (data , id , "read unexpected data: %llx instead of %llx" , data , id );
937+
938+ len = zms_read_hist (& fixture -> fs , (zms_id_t )id , & data , sizeof (data ), 1 );
939+ zassert_true (len == - ENOENT , "zms_read_hist unexpected failure: %d" , len );
940+ }
941+ }
0 commit comments