From 626a8885cecd4583d4ddca95df7e4fbd7c10cebb Mon Sep 17 00:00:00 2001 From: Pavol Rusnak Date: Fri, 8 Dec 2017 16:46:13 +0100 Subject: [PATCH] trezor.config: add compaction test --- embed/extmod/modtrezorconfig/norcow.c | 2 +- embed/unix/flash.c | 4 ---- tests/test_trezor.config.py | 11 +++++++++++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/embed/extmod/modtrezorconfig/norcow.c b/embed/extmod/modtrezorconfig/norcow.c index 91878a56..8f4b49c7 100644 --- a/embed/extmod/modtrezorconfig/norcow.c +++ b/embed/extmod/modtrezorconfig/norcow.c @@ -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); } /* diff --git a/embed/unix/flash.c b/embed/unix/flash.c index c800b356..c8bf0c0e 100644 --- a/embed/unix/flash.c +++ b/embed/unix/flash.c @@ -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); diff --git a/tests/test_trezor.config.py b/tests/test_trezor.config.py index b47523d4..b97d4bce 100644 --- a/tests/test_trezor.config.py +++ b/tests/test_trezor.config.py @@ -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()