@@ -183,7 +183,7 @@ static BlockDevice *get_bd_instance(uint8_t bd_type)
183
183
// Mutex is also protecting printouts for clear logs.
184
184
// Mutex is NOT protecting Block Device actions: erase/program/read - which is the purpose of the multithreaded test!
185
185
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 )
187
187
{
188
188
int err = 0 ;
189
189
_mutex->lock ();
@@ -193,7 +193,13 @@ void basic_erase_program_read_test(BlockDevice *block_device, bd_size_t block_si
193
193
srand (block_seed++);
194
194
195
195
// 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
+ }
197
203
198
204
// Use next random number as temporary seed to keep
199
205
// 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
206
212
}
207
213
// Write, sync, and read the block
208
214
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
+ }
210
220
211
221
err = block_device->erase (block, block_size);
212
222
TEST_ASSERT_EQUAL (0 , err);
@@ -217,7 +227,10 @@ void basic_erase_program_read_test(BlockDevice *block_device, bd_size_t block_si
217
227
err = block_device->read (read_block, block, block_size);
218
228
TEST_ASSERT_EQUAL (0 , err);
219
229
220
- _mutex->lock ();
230
+ if (bd_arr[test_iteration] != flashiap) {
231
+ _mutex->lock ();
232
+ }
233
+
221
234
// Check that the data was unmodified
222
235
srand (seed);
223
236
int val_rand;
@@ -276,7 +289,7 @@ void test_random_program_read_erase()
276
289
}
277
290
278
291
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 );
280
293
}
281
294
282
295
end:
@@ -287,7 +300,9 @@ void test_random_program_read_erase()
287
300
static void test_thread_job (void *block_device_ptr)
288
301
{
289
302
static int thread_num = 0 ;
290
- thread_num++;
303
+ _mutex->lock ();
304
+ int block_num = thread_num++;
305
+ _mutex->unlock ();
291
306
BlockDevice *block_device = (BlockDevice *)block_device_ptr;
292
307
293
308
bd_size_t block_size = block_device->get_erase_size ();
@@ -302,7 +317,7 @@ static void test_thread_job(void *block_device_ptr)
302
317
}
303
318
304
319
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 );
306
321
}
307
322
308
323
end:
@@ -384,6 +399,11 @@ void test_erase_functionality()
384
399
start_address -= start_address % erase_size; // align with erase_block
385
400
utest_printf (" start_address=0x%016" PRIx64 " \n " , start_address);
386
401
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
+
387
407
// Allocate buffer for write test data
388
408
uint8_t *data_buf = (uint8_t *)malloc (data_buf_size);
389
409
TEST_SKIP_UNLESS_MESSAGE (data_buf, " Not enough memory for test.\n " );
@@ -446,6 +466,11 @@ void test_contiguous_erase_write_read()
446
466
447
467
TEST_SKIP_UNLESS_MESSAGE (block_device != NULL , " no block device found." );
448
468
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
+
449
474
// Test flow:
450
475
// 1. Erase whole test area
451
476
// - Tests contiguous erase
0 commit comments