Skip to content

Commit

Permalink
TDBStore Whitebox tests: fix memory check
Browse files Browse the repository at this point in the history
Each block of HeapBlockDevice is only allocated from the heap when
that block is programmed. And erasing a block frees the associated
buffer.

To decide if there is enough heap to run the TDBStore Whitebox tests,
we need to perform a trial program() instead of erase().
  • Loading branch information
LDong-Arm committed Apr 1, 2021
1 parent 261ddbd commit e4dd420
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions storage/kvstore/tdbstore/tests/TESTS/tdbstore/whitebox/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,14 @@ static void white_box_test()
} else {
test_bd = &heap_bd;
// We need to skip the test if we don't have enough memory for the heap block device.
// However, this device allocates the erase units on the fly, so "erase" it via the flash
// simulator. A failure here means we haven't got enough memory.
heap_bd.init();
result = heap_bd.erase(0, heap_bd.size());
TEST_SKIP_UNLESS_MESSAGE(!result, "Not enough heap to run test");
// However, this device allocates the blocks on the fly when programmed. A failure
// here means we haven't got enough memory.
result = heap_bd.init();
TEST_SKIP_UNLESS_MESSAGE(result == BD_ERROR_OK, "Not enough heap to run test")
for (bd_addr_t addr = 0; addr < heap_bd.size(); addr += heap_bd.get_program_size()) {
result = heap_bd.program(dummy, addr, heap_bd.get_program_size());
TEST_SKIP_UNLESS_MESSAGE(result == BD_ERROR_OK, "Not enough heap to run test")
}
heap_bd.deinit();
}

Expand Down Expand Up @@ -345,11 +348,14 @@ static void multi_set_test()

#ifdef USE_HEAP_BD
// We need to skip the test if we don't have enough memory for the heap block device.
// However, this device allocates the erase units on the fly, so "erase" it via the flash
// simulator. A failure here means we haven't got enough memory.
flash_bd.init();
result = flash_bd.erase(0, flash_bd.size());
TEST_SKIP_UNLESS_MESSAGE(!result, "Not enough heap to run test");
// However, this device allocates the blocks on the fly when programmed. A failure
// here means we haven't got enough memory.
result = flash_bd.init();
TEST_SKIP_UNLESS_MESSAGE(result == BD_ERROR_OK, "Not enough heap to run test")
for (bd_addr_t addr = 0; addr < flash_bd.size(); addr += flash_bd.get_program_size()) {
result = flash_bd.program(dummy, addr, flash_bd.get_program_size());
TEST_SKIP_UNLESS_MESSAGE(result == BD_ERROR_OK, "Not enough heap to run test")
}
flash_bd.deinit();
#endif

Expand Down

0 comments on commit e4dd420

Please sign in to comment.