Skip to content

Commit 58545b1

Browse files
author
Seppo Takalo
committed
Extend Greentea storage tests with de-init test case
This verifies that data is kept intact between deinit() and init().
1 parent c268ad0 commit 58545b1

File tree

1 file changed

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

1 file changed

+39
-0
lines changed

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "BufferedBlockDevice.h"
2828
#include "BlockDevice.h"
2929
#include <algorithm>
30+
#include "MbedCRC.h"
3031

3132
#if COMPONENT_SPIF
3233
#include "SPIFBlockDevice.h"
@@ -690,6 +691,43 @@ void test_deinit_bd()
690691
block_device = NULL;
691692
}
692693

694+
void test_write_deinit_init()
695+
{
696+
TEST_SKIP_UNLESS_MESSAGE(block_device != NULL, "no block device found.");
697+
MbedCRC<POLY_32BIT_ANSI, 32> ct;
698+
// Determine start_address & stop_address, choose random block somewhere
699+
uint8_t sector_num = rand() % (num_of_sectors - 2);
700+
bd_addr_t addr = sectors_addr[sector_num];
701+
bd_addr_t end = sectors_addr[sector_num + 1];
702+
bd_size_t size = end - addr;
703+
uint8_t *buf = (uint8_t *) malloc(size);
704+
TEST_ASSERT_NOT_EQUAL(buf, 0);
705+
uint32_t crc[2];
706+
707+
for (int i = 0; i < 10; i++) {
708+
// Generate test pattern
709+
for (int j = 0; j < size; j++) {
710+
buf[j] = (uint8_t)'0' + i + j;
711+
}
712+
ct.compute((void *)buf, size, &crc[0]);
713+
714+
int err;
715+
err = block_device->erase(addr, size);
716+
TEST_ASSERT_EQUAL(err, 0);
717+
err = block_device->program(buf, addr, size);
718+
TEST_ASSERT_EQUAL(err, 0);
719+
memset(buf, 0, size);
720+
err = block_device->deinit();
721+
TEST_ASSERT_EQUAL(0, err);
722+
err = block_device->init();
723+
TEST_ASSERT_EQUAL(0, err);
724+
err = block_device->read(buf, addr, size);
725+
ct.compute((void *)buf, size, &crc[1]);
726+
TEST_ASSERT_EQUAL(crc[0], crc[1]);
727+
}
728+
free(buf);
729+
}
730+
693731
void test_get_type_functionality()
694732
{
695733
utest_printf("\nTest get blockdevice type..\n");
@@ -727,6 +765,7 @@ typedef struct {
727765

728766
template_case_t template_cases[] = {
729767
{"Testing Init block device", test_init_bd, greentea_failure_handler},
768+
{"Testing write -> deinit -> init -> read", test_write_deinit_init, greentea_failure_handler},
730769
{"Testing read write random blocks", test_random_program_read_erase, greentea_failure_handler},
731770
#if defined(MBED_CONF_RTOS_PRESENT)
732771
{"Testing multi threads erase program read", test_multi_threads, greentea_failure_handler},

0 commit comments

Comments
 (0)