1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-14 03:30:02 +00:00

trezor.config: add compaction test

This commit is contained in:
Pavol Rusnak 2017-12-08 16:46:13 +01:00
parent b39b4a4947
commit 626a8885ce
No known key found for this signature in database
GPG Key ID: 91F3B339B9A02A3D
3 changed files with 12 additions and 5 deletions

View File

@ -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);
}
/*

View File

@ -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);

View File

@ -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()