Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ void basic_erase_program_read_test(SPIFBlockDevice &block_device, bd_size_t bloc
_mutex->lock();

// Make sure block address per each test is unique
static unsigned block_seed = SPIF_TEST_NUM_OF_THREADS;
srand(block_seed);
block_seed += 2;
static unsigned block_seed = 1;
srand(block_seed++);

// Find a random block
bd_addr_t block = (rand() * block_size) % block_device.size();
Expand Down
44 changes: 34 additions & 10 deletions features/storage/TESTS/blockdevice/general_block_device/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,18 +183,23 @@ static BlockDevice *get_bd_instance(uint8_t bd_type)
// Mutex is also protecting printouts for clear logs.
// Mutex is NOT protecting Block Device actions: erase/program/read - which is the purpose of the multithreaded test!
void basic_erase_program_read_test(BlockDevice *block_device, bd_size_t block_size, uint8_t *write_block,
uint8_t *read_block, unsigned addrwidth)
uint8_t *read_block, unsigned addrwidth, int thread_num)
{
int err = 0;
_mutex->lock();

// Make sure block address per each test is unique
static unsigned block_seed = TEST_NUM_OF_THREADS;
srand(block_seed);
block_seed += 2;
static unsigned block_seed = 1;
srand(block_seed++);

// Find a random block
bd_addr_t block = (rand() * block_size) % (block_device->size());
int threaded_rand_number = (rand() * TEST_NUM_OF_THREADS) + thread_num;
bd_addr_t block = (threaded_rand_number * block_size) % block_device->size();

// Flashiap boards with inconsistent sector size will not align with random start addresses
if (bd_arr[test_iteration] == flashiap) {
block = 0;
}

// Use next random number as temporary seed to keep
// the address progressing in the pseudorandom sequence
Expand All @@ -207,7 +212,11 @@ void basic_erase_program_read_test(BlockDevice *block_device, bd_size_t block_si
}
// Write, sync, and read the block
utest_printf("test %0*llx:%llu...\n", addrwidth, block, block_size);
_mutex->unlock();

// Thread test for flashiap write to the same sector, so all write/read/erase actions should be locked
if (bd_arr[test_iteration] != flashiap) {
_mutex->unlock();
}

err = block_device->erase(block, block_size);
TEST_ASSERT_EQUAL(0, err);
Expand All @@ -218,7 +227,10 @@ void basic_erase_program_read_test(BlockDevice *block_device, bd_size_t block_si
err = block_device->read(read_block, block, block_size);
TEST_ASSERT_EQUAL(0, err);

_mutex->lock();
if (bd_arr[test_iteration] != flashiap) {
_mutex->lock();
}

// Check that the data was unmodified
srand(seed);
int val_rand;
Expand Down Expand Up @@ -277,7 +289,7 @@ void test_random_program_read_erase()
}

for (int b = 0; b < TEST_BLOCK_COUNT; b++) {
basic_erase_program_read_test(block_device, block_size, write_block, read_block, addrwidth);
basic_erase_program_read_test(block_device, block_size, write_block, read_block, addrwidth, 0);
}

end:
Expand All @@ -288,7 +300,9 @@ void test_random_program_read_erase()
static void test_thread_job(void *block_device_ptr)
{
static int thread_num = 0;
thread_num++;
_mutex->lock();
int block_num = thread_num++;
_mutex->unlock();
BlockDevice *block_device = (BlockDevice *)block_device_ptr;

bd_size_t block_size = block_device->get_erase_size();
Expand All @@ -303,7 +317,7 @@ static void test_thread_job(void *block_device_ptr)
}

for (int b = 0; b < TEST_BLOCK_COUNT; b++) {
basic_erase_program_read_test(block_device, block_size, write_block, read_block, addrwidth);
basic_erase_program_read_test(block_device, block_size, write_block, read_block, addrwidth, block_num);
}

end:
Expand Down Expand Up @@ -385,6 +399,11 @@ void test_erase_functionality()
start_address -= start_address % erase_size; // align with erase_block
utest_printf("start_address=0x%016" PRIx64 "\n", start_address);

// Flashiap boards with inconsistent sector size will not align with random start addresses
if (bd_arr[test_iteration] == flashiap) {
start_address = 0;
}

// Allocate buffer for write test data
uint8_t *data_buf = (uint8_t *)malloc(data_buf_size);
TEST_SKIP_UNLESS_MESSAGE(data_buf, "Not enough memory for test.\n");
Expand Down Expand Up @@ -447,6 +466,11 @@ void test_contiguous_erase_write_read()

TEST_SKIP_UNLESS_MESSAGE(block_device != NULL, "no block device found.");

// Flashiap boards with inconsistent sector size will not align with random start addresses
if (bd_arr[test_iteration] == flashiap) {
return;
}

// Test flow:
// 1. Erase whole test area
// - Tests contiguous erase
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
22 changes: 15 additions & 7 deletions targets/targets.json
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,7 @@
},
"SDT64B": {
"inherits": ["K64F"],
"components_add": ["FLASHIAP"],
"extra_labels_add": ["K64F"],
"extra_labels_remove": ["FRDM"],
"components_remove": ["SD"],
Expand Down Expand Up @@ -2200,6 +2201,7 @@
},
"NUCLEO_F207ZG": {
"inherits": ["FAMILY_STM32"],
"components_add": ["FLASHIAP"],
"supported_form_factors": ["ARDUINO", "MORPHO"],
"core": "Cortex-M3",
"extra_labels_add": ["STM32F2", "STM32F207ZG", "STM_EMAC"],
Expand Down Expand Up @@ -2479,7 +2481,7 @@
},
"MTB_MXCHIP_EMW3166": {
"inherits": ["FAMILY_STM32"],
"supported_toolchains": ["ARM", "uARM", "GCC_ARM"],
"supported_toolchains": ["ARM", "GCC_ARM", "IAR"],
"core": "Cortex-M4F",
"extra_labels_add": [
"STM32F4",
Expand All @@ -2496,7 +2498,7 @@
"FLASH",
"MPU"
],
"release_versions": [],
"release_versions": ["5"],
"device_name": "STM32F412ZG",
"bootloader_supported": true,
"config": {
Expand All @@ -2512,7 +2514,7 @@
},
"USI_WM_BN_BM_22": {
"inherits": ["FAMILY_STM32"],
"supported_toolchains": ["ARM", "uARM", "GCC_ARM"],
"supported_toolchains": ["ARM", "GCC_ARM", "IAR"],
"components_add": ["SPIF", "FLASHIAP"],
"core": "Cortex-M4F",
"extra_labels_add": [
Expand All @@ -2531,7 +2533,7 @@
"FLASH",
"MPU"
],
"release_versions": [],
"release_versions": ["5"],
"device_name": "STM32F412ZG",
"bootloader_supported": true,
"public": false,
Expand Down Expand Up @@ -2565,7 +2567,7 @@
}
},
"DISCO_F413ZH": {
"components_add": ["QSPIF"],
"components_add": ["QSPIF", "FLASHIAP"],
"inherits": ["FAMILY_STM32"],
"supported_form_factors": ["ARDUINO"],
"core": "Cortex-M4F",
Expand Down Expand Up @@ -2931,6 +2933,7 @@
},
"NUCLEO_F767ZI": {
"inherits": ["FAMILY_STM32"],
"components_add": ["FLASHIAP"],
"core": "Cortex-M7FD",
"extra_labels_add": [
"STM32F7",
Expand Down Expand Up @@ -3796,7 +3799,7 @@
"STM32F746NG",
"STM_EMAC"
],
"components_add": ["QSPIF"],
"components_add": ["QSPIF", "FLASHIAP"],
"supported_form_factors": ["ARDUINO"],
"config": {
"clock_source": {
Expand Down Expand Up @@ -4304,7 +4307,7 @@
"release_versions": ["5"],
"device_has_remove": [],
"extra_labels_add": ["PSA"],
"components_add": ["FLASHIAP"],
"components_add": ["SD", "FLASHIAP"],
"macros_add": [
"MBEDTLS_PSA_CRYPTO_C"
],
Expand Down Expand Up @@ -4390,6 +4393,7 @@
},
"UBLOX_C030_U201": {
"inherits": ["UBLOX_C030"],
"components_add": ["SD", "FLASHIAP"],
"release_versions": ["5"]
},
"UBLOX_C030_N211": {
Expand Down Expand Up @@ -5249,6 +5253,7 @@
},
"GR_LYCHEE": {
"inherits": ["RZ_A1XX"],
"components_add": ["SD", "FLASHIAP"],
"supported_form_factors": ["ARDUINO"],
"extra_labels_add": ["RZA1UL", "MBRZA1LU"],
"components_add": ["SD"],
Expand Down Expand Up @@ -7012,6 +7017,7 @@
},
"NUMAKER_PFM_NUC472": {
"core": "Cortex-M4F",
"components_add": ["SD", "FLASHIAP"],
"default_toolchain": "ARM",
"extra_labels": [
"NUVOTON",
Expand Down Expand Up @@ -7584,10 +7590,12 @@
},
"NUMAKER_PFM_M487": {
"inherits": ["MCU_M480"],
"components_add": ["SD", "FLASHIAP"],
"device_name": "M487JIDAE"
},
"NUMAKER_IOT_M487": {
"inherits": ["MCU_M480"],
"components_add": ["FLASHIAP"],
"device_name": "M487JIDAE"
},
"TMPM066": {
Expand Down