mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-13 02:58:57 +00:00
trezor.config: add compaction test
This commit is contained in:
parent
b39b4a4947
commit
626a8885ce
@ -214,7 +214,7 @@ static void compact()
|
||||
|
||||
norcow_erase(norcow_active_sector, secfalse);
|
||||
norcow_active_sector = norcow_next_sector;
|
||||
norcow_active_offset = offsetw;
|
||||
norcow_active_offset = find_free_offset(norcow_active_sector);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -52,15 +52,12 @@ static const uint32_t sector_table[SECTOR_COUNT + 1] = {
|
||||
[24] = 0x08200000, // last element - not a valid sector
|
||||
};
|
||||
|
||||
static int flash_fd;
|
||||
static uint8_t *flash_buffer;
|
||||
|
||||
static void flash_exit(void)
|
||||
{
|
||||
int r = munmap(flash_buffer, FLASH_SIZE);
|
||||
ensure(sectrue * (r == 0), "munmap failed");
|
||||
r = close(flash_fd);
|
||||
ensure(sectrue * (r == 0), "close failed");
|
||||
}
|
||||
|
||||
secbool flash_init(void)
|
||||
@ -90,7 +87,6 @@ secbool flash_init(void)
|
||||
void *map = mmap(0, FLASH_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
||||
ensure(sectrue * (map != MAP_FAILED), "mmap failed");
|
||||
|
||||
flash_fd = fd;
|
||||
flash_buffer = (uint8_t *)map;
|
||||
|
||||
atexit(flash_exit);
|
||||
|
@ -84,6 +84,17 @@ class TestConfig(unittest.TestCase):
|
||||
value2 = config.get(appid, key)
|
||||
self.assertEqual(value, value2)
|
||||
|
||||
def test_compact(self):
|
||||
config.init()
|
||||
config.wipe()
|
||||
self.assertEqual(config.unlock(''), True)
|
||||
appid, key = 1, 1
|
||||
for _ in range(259):
|
||||
value = random.bytes(259)
|
||||
config.set(appid, key, value)
|
||||
value2 = config.get(appid, key)
|
||||
self.assertEqual(value, value2)
|
||||
|
||||
def test_get_default(self):
|
||||
config.init()
|
||||
config.wipe()
|
||||
|
Loading…
Reference in New Issue
Block a user