From f8eae3f023b1968d6cff77aa09bedb096232cad9 Mon Sep 17 00:00:00 2001 From: tychovrahe Date: Mon, 21 Aug 2023 11:01:00 +0200 Subject: [PATCH] fix(storage/tests): fix norcow active offset initialization, add missing assert in test_set_locked [no changelog] --- storage/tests/python/src/consts.py | 1 - storage/tests/python/src/norcow.py | 12 +++++++++++- storage/tests/tests/test_set_get.py | 4 ++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/storage/tests/python/src/consts.py b/storage/tests/python/src/consts.py index a02d6a72fa..39e0a186d2 100644 --- a/storage/tests/python/src/consts.py +++ b/storage/tests/python/src/consts.py @@ -70,7 +70,6 @@ WIPE_CODE_TAG_SIZE = 8 WIPE_CODE_EMPTY = "\0\0\0\0" # Size of counter. 4B integer and 8B tail. -COUNTER_TAIL = 12 COUNTER_TAIL_SIZE = 8 COUNTER_MAX_TAIL = 64 diff --git a/storage/tests/python/src/norcow.py b/storage/tests/python/src/norcow.py index f3c9510d57..f7cbb4ad4d 100644 --- a/storage/tests/python/src/norcow.py +++ b/storage/tests/python/src/norcow.py @@ -22,11 +22,21 @@ class Norcow: for sector in range(consts.NORCOW_SECTOR_COUNT): if self.sectors[sector][:8] == consts.NORCOW_MAGIC_AND_VERSION: self.active_sector = sector - self.active_offset = len(consts.NORCOW_MAGIC_AND_VERSION) + self.active_offset = self.find_free_offset() break else: self.wipe() + def find_free_offset(self): + offset = len(consts.NORCOW_MAGIC_AND_VERSION) + while True: + try: + k, v = self._read_item(offset) + except ValueError: + break + offset = offset + self._norcow_item_length(v) + return offset + def wipe(self, sector: int = None): if sector is None: sector = self.active_sector diff --git a/storage/tests/tests/test_set_get.py b/storage/tests/tests/test_set_get.py index 5fce933641..b2a03b0eb9 100644 --- a/storage/tests/tests/test_set_get.py +++ b/storage/tests/tests/test_set_get.py @@ -165,8 +165,8 @@ def test_set_locked(): assert common.memory_equals(sc, sp) for s in (sc, sp): - s.get(0xC001) == b"Ahoj" - s.get(0xC003) == b"test" + assert s.get(0xC001) == b"Ahoj" + assert s.get(0xC003) == b"test" def test_counter():