@@ -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 =
@@ -955,3 +957,45 @@ ZTEST_F(zms, test_zms_input_validation)
955957 err = zms_delete (& fixture -> fs , 0 );
956958 zassert_true (err == - EACCES , "zms_delete call before mount fs failure: %d" , err );
957959}
960+
961+ /*
962+ * Test 64 bit ZMS ID support.
963+ */
964+ ZTEST_F (zms , test_zms_id_64bit )
965+ {
966+ int err ;
967+ ssize_t len ;
968+ uint64_t data ;
969+ uint64_t filling_id = 0xdeadbeefULL ;
970+
971+ Z_TEST_SKIP_IFNDEF (CONFIG_ZMS_ID_64BIT );
972+
973+ err = zms_mount (& fixture -> fs );
974+ zassert_true (err == 0 , "zms_mount call failure: %d" , err );
975+
976+ /* Fill the first sector with writes of different IDs */
977+
978+ while (fixture -> fs .data_wra + sizeof (data ) + sizeof (struct zms_ate ) <=
979+ fixture -> fs .ate_wra ) {
980+ data = filling_id ;
981+ len = zms_write (& fixture -> fs , (zms_id_t )filling_id , & data , sizeof (data ));
982+ zassert_true (len == sizeof (data ), "zms_write failed: %d" , len );
983+
984+ /* Choose the next ID so that its lower 32 bits stay invariant.
985+ * The purpose is to test that ZMS doesn't mistakenly cast the
986+ * 64 bit ID to a 32 bit one somewhere.
987+ */
988+ filling_id += BIT64 (32 );
989+ }
990+
991+ /* Read back the written entries and check that they're all unique */
992+
993+ for (uint64_t id = 0xdeadbeefULL ; id < filling_id ; id += BIT64 (32 )) {
994+ len = zms_read_hist (& fixture -> fs , (zms_id_t )id , & data , sizeof (data ), 0 );
995+ zassert_true (len == sizeof (data ), "zms_read_hist unexpected failure: %d" , len );
996+ zassert_equal (data , id , "read unexpected data: %llx instead of %llx" , data , id );
997+
998+ len = zms_read_hist (& fixture -> fs , (zms_id_t )id , & data , sizeof (data ), 1 );
999+ zassert_true (len == - ENOENT , "zms_read_hist unexpected failure: %d" , len );
1000+ }
1001+ }
0 commit comments