Skip to content

Commit 94bb831

Browse files
author
Seppo Takalo
committed
Extend storage tests with de-init test case
1 parent 829a3cd commit 94bb831

File tree

1 file changed

+35
-0
lines changed
  • features/storage/TESTS/blockdevice/general_block_device

1 file changed

+35
-0
lines changed

features/storage/TESTS/blockdevice/general_block_device/main.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,40 @@ void test_deinit_bd()
690690
block_device = NULL;
691691
}
692692

693+
void test_write_deinit_init()
694+
{
695+
TEST_SKIP_UNLESS_MESSAGE(block_device != NULL, "no block device found.");
696+
// Determine start_address & stop_address
697+
bd_addr_t addr = sectors_addr[rand() % num_of_sectors];
698+
bd_size_t erase_size = block_device->get_erase_size(addr);
699+
bd_size_t prog_size = block_device->get_program_size();
700+
uint8_t *prog = (uint8_t *) malloc(prog_size);
701+
TEST_ASSERT_NOT_EQUAL(prog, 0);
702+
uint8_t *buf = (uint8_t *) malloc(prog_size);
703+
TEST_ASSERT_NOT_EQUAL(buf, 0);
704+
705+
for (int i = 0; i < 3; i++) {
706+
// Generate test pattern
707+
for (int j = 0; j < prog_size; j++) {
708+
prog[j] = (uint8_t)'0' + i + j;
709+
}
710+
711+
int err;
712+
err = block_device->erase(addr, erase_size);
713+
TEST_ASSERT_EQUAL(err, 0);
714+
err = block_device->program(prog, addr, prog_size);
715+
TEST_ASSERT_EQUAL(err, 0);
716+
err = block_device->deinit();
717+
TEST_ASSERT_EQUAL(0, err);
718+
err = block_device->init();
719+
TEST_ASSERT_EQUAL(0, err);
720+
err = block_device->read(buf, addr, prog_size);
721+
TEST_ASSERT_EQUAL(0, memcmp(prog, buf, prog_size));
722+
}
723+
free(prog);
724+
free(buf);
725+
}
726+
693727
void test_get_type_functionality()
694728
{
695729
utest_printf("\nTest get blockdevice type..\n");
@@ -727,6 +761,7 @@ typedef struct {
727761

728762
template_case_t template_cases[] = {
729763
{"Testing Init block device", test_init_bd, greentea_failure_handler},
764+
{"Testing write -> deinit -> init -> read", test_write_deinit_init, greentea_failure_handler},
730765
{"Testing read write random blocks", test_random_program_read_erase, greentea_failure_handler},
731766
#if defined(MBED_CONF_RTOS_PRESENT)
732767
{"Testing multi threads erase program read", test_multi_threads, greentea_failure_handler},

0 commit comments

Comments
 (0)