Skip to content

Commit dd1c33a

Browse files
author
Amir Cohen
committed
Modifing general block device tests doe to targets enhancement
Due to targets enhancement some boards failed the general block device tests for flashiap component, The fails were due to boards containing inconsistent sector sizes. The tests were modified but should be improved to address the problem. Rand() function issues were fixed.
1 parent 8a3cc4c commit dd1c33a

File tree

1 file changed

+32
-7
lines changed
  • features/storage/TESTS/blockdevice/general_block_device

1 file changed

+32
-7
lines changed

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

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ static BlockDevice *get_bd_instance(uint8_t bd_type)
183183
// Mutex is also protecting printouts for clear logs.
184184
// Mutex is NOT protecting Block Device actions: erase/program/read - which is the purpose of the multithreaded test!
185185
void basic_erase_program_read_test(BlockDevice *block_device, bd_size_t block_size, uint8_t *write_block,
186-
uint8_t *read_block, unsigned addrwidth)
186+
uint8_t *read_block, unsigned addrwidth, int thread_num)
187187
{
188188
int err = 0;
189189
_mutex->lock();
@@ -193,7 +193,13 @@ void basic_erase_program_read_test(BlockDevice *block_device, bd_size_t block_si
193193
srand(block_seed++);
194194

195195
// Find a random block
196-
bd_addr_t block = (rand() * block_size) % (block_device->size());
196+
int threaded_rand_number = (rand() * TEST_NUM_OF_THREADS) + thread_num;
197+
bd_addr_t block = (threaded_rand_number * block_size) % block_device->size();
198+
199+
// Flashiap boards with inconsistent sector size will not align with random start addresses
200+
if (bd_arr[test_iteration] == flashiap) {
201+
block = 0;
202+
}
197203

198204
// Use next random number as temporary seed to keep
199205
// the address progressing in the pseudorandom sequence
@@ -206,7 +212,11 @@ void basic_erase_program_read_test(BlockDevice *block_device, bd_size_t block_si
206212
}
207213
// Write, sync, and read the block
208214
utest_printf("test %0*llx:%llu...\n", addrwidth, block, block_size);
209-
_mutex->unlock();
215+
216+
// Thread test for flashiap write to the same sector, so all write/read/erase actions should be locked
217+
if (bd_arr[test_iteration] != flashiap) {
218+
_mutex->unlock();
219+
}
210220

211221
err = block_device->erase(block, block_size);
212222
TEST_ASSERT_EQUAL(0, err);
@@ -217,7 +227,10 @@ void basic_erase_program_read_test(BlockDevice *block_device, bd_size_t block_si
217227
err = block_device->read(read_block, block, block_size);
218228
TEST_ASSERT_EQUAL(0, err);
219229

220-
_mutex->lock();
230+
if (bd_arr[test_iteration] != flashiap) {
231+
_mutex->lock();
232+
}
233+
221234
// Check that the data was unmodified
222235
srand(seed);
223236
int val_rand;
@@ -276,7 +289,7 @@ void test_random_program_read_erase()
276289
}
277290

278291
for (int b = 0; b < TEST_BLOCK_COUNT; b++) {
279-
basic_erase_program_read_test(block_device, block_size, write_block, read_block, addrwidth);
292+
basic_erase_program_read_test(block_device, block_size, write_block, read_block, addrwidth, 0);
280293
}
281294

282295
end:
@@ -287,7 +300,9 @@ void test_random_program_read_erase()
287300
static void test_thread_job(void *block_device_ptr)
288301
{
289302
static int thread_num = 0;
290-
thread_num++;
303+
_mutex->lock();
304+
int block_num = thread_num++;
305+
_mutex->unlock();
291306
BlockDevice *block_device = (BlockDevice *)block_device_ptr;
292307

293308
bd_size_t block_size = block_device->get_erase_size();
@@ -302,7 +317,7 @@ static void test_thread_job(void *block_device_ptr)
302317
}
303318

304319
for (int b = 0; b < TEST_BLOCK_COUNT; b++) {
305-
basic_erase_program_read_test(block_device, block_size, write_block, read_block, addrwidth);
320+
basic_erase_program_read_test(block_device, block_size, write_block, read_block, addrwidth, block_num);
306321
}
307322

308323
end:
@@ -384,6 +399,11 @@ void test_erase_functionality()
384399
start_address -= start_address % erase_size; // align with erase_block
385400
utest_printf("start_address=0x%016" PRIx64 "\n", start_address);
386401

402+
// Flashiap boards with inconsistent sector size will not align with random start addresses
403+
if (bd_arr[test_iteration] == flashiap) {
404+
start_address = 0;
405+
}
406+
387407
// Allocate buffer for write test data
388408
uint8_t *data_buf = (uint8_t *)malloc(data_buf_size);
389409
TEST_SKIP_UNLESS_MESSAGE(data_buf, "Not enough memory for test.\n");
@@ -446,6 +466,11 @@ void test_contiguous_erase_write_read()
446466

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

469+
// Flashiap boards with inconsistent sector size will not align with random start addresses
470+
if (bd_arr[test_iteration] == flashiap) {
471+
return;
472+
}
473+
449474
// Test flow:
450475
// 1. Erase whole test area
451476
// - Tests contiguous erase

0 commit comments

Comments
 (0)