Skip to content

Commit 7b763be

Browse files
committed
TDBStore Whitebox tests: fix memory check
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().
1 parent aedc600 commit 7b763be

File tree

1 file changed

+16
-10
lines changed
  • storage/kvstore/tdbstore/tests/TESTS/tdbstore/whitebox

1 file changed

+16
-10
lines changed

storage/kvstore/tdbstore/tests/TESTS/tdbstore/whitebox/main.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,14 @@ static void white_box_test()
132132
} else {
133133
test_bd = &heap_bd;
134134
// We need to skip the test if we don't have enough memory for the heap block device.
135-
// However, this device allocates the erase units on the fly, so "erase" it via the flash
136-
// simulator. A failure here means we haven't got enough memory.
137-
heap_bd.init();
138-
result = heap_bd.erase(0, heap_bd.size());
139-
TEST_SKIP_UNLESS_MESSAGE(!result, "Not enough heap to run test");
135+
// However, this device allocates the blocks on the fly when programmed. A failure
136+
// here means we haven't got enough memory.
137+
result = heap_bd.init();
138+
TEST_SKIP_UNLESS_MESSAGE(result == BD_ERROR_OK, "Not enough heap to run test")
139+
for (bd_addr_t addr = 0; addr < heap_bd.size(); addr += heap_bd.get_program_size()) {
140+
result = heap_bd.program(dummy, addr, heap_bd.get_program_size());
141+
TEST_SKIP_UNLESS_MESSAGE(result == BD_ERROR_OK, "Not enough heap to run test")
142+
}
140143
heap_bd.deinit();
141144
}
142145

@@ -345,11 +348,14 @@ static void multi_set_test()
345348

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

0 commit comments

Comments
 (0)