@@ -68,6 +68,7 @@ using namespace utest::v1;
68
68
69
69
uint8_t num_of_sectors = TEST_NUM_OF_THREADS * TEST_BLOCK_COUNT;
70
70
uint32_t sectors_addr[TEST_NUM_OF_THREADS * TEST_BLOCK_COUNT] = {0 };
71
+ bd_size_t max_sector_size = 0 ;
71
72
72
73
const struct {
73
74
const char *name;
@@ -261,11 +262,16 @@ void test_init_bd()
261
262
TEST_ASSERT_EQUAL (0 , err);
262
263
263
264
bd_addr_t start_address = 0 ;
265
+ bd_size_t curr_sector_size = 0 ;
264
266
uint8_t i = 0 ;
265
267
for (; i < num_of_sectors && start_address < block_device->size (); i++) {
266
268
sectors_addr[i] = start_address;
267
- DEBUG_PRINTF (" start_address = 0x%llx, sector_size = %d\n " , start_address, block_device->get_erase_size (start_address));
268
- start_address += block_device->get_erase_size (start_address);
269
+ curr_sector_size = block_device->get_erase_size (start_address);
270
+ DEBUG_PRINTF (" start_address = 0x%llx, sector_size = %d\n " , start_address, curr_sector_size);
271
+ if (curr_sector_size > max_sector_size) {
272
+ max_sector_size = curr_sector_size;
273
+ }
274
+ start_address += curr_sector_size;
269
275
}
270
276
num_of_sectors = i;
271
277
}
@@ -288,24 +294,25 @@ void test_random_program_read_erase()
288
294
}
289
295
}
290
296
291
- bd_size_t block_size = block_device->get_erase_size ();
292
297
unsigned addrwidth = ceil (log (float (block_device->size () - 1 )) / log (float (16 ))) + 1 ;
293
298
294
- uint8_t *write_block = new (std::nothrow) uint8_t [block_size ];
295
- uint8_t *read_block = new (std::nothrow) uint8_t [block_size ];
299
+ uint8_t *write_buffer = new (std::nothrow) uint8_t [max_sector_size ];
300
+ uint8_t *read_buffer = new (std::nothrow) uint8_t [max_sector_size ];
296
301
297
- if (!write_block || !read_block ) {
302
+ if (!write_buffer || !read_buffer ) {
298
303
utest_printf (" Not enough memory for test\n " );
299
304
goto end;
300
305
}
301
306
302
307
for (int b = 0 ; b < std::min ((uint8_t )TEST_BLOCK_COUNT, num_of_sectors); b++) {
303
- basic_erase_program_read_test (block_device, block_size, write_block, read_block, addrwidth, b);
308
+ // basic_erase_program_read_test() can handle non-uniform sector sizes
309
+ // and use only part of the buffers if the sector is smaller
310
+ basic_erase_program_read_test (block_device, max_sector_size, write_buffer, read_buffer, addrwidth, b);
304
311
}
305
312
306
313
end:
307
- delete[] read_block ;
308
- delete[] write_block ;
314
+ delete[] read_buffer ;
315
+ delete[] write_buffer ;
309
316
}
310
317
311
318
#if defined(MBED_CONF_RTOS_PRESENT)
@@ -318,24 +325,27 @@ static void test_thread_job()
318
325
319
326
uint8_t sector_per_thread = (num_of_sectors / TEST_NUM_OF_THREADS);
320
327
321
- bd_size_t block_size = block_device->get_erase_size ();
322
328
unsigned addrwidth = ceil (log (float (block_device->size () - 1 )) / log (float (16 ))) + 1 ;
323
329
324
- uint8_t *write_block = new (std::nothrow) uint8_t [block_size ];
325
- uint8_t *read_block = new (std::nothrow) uint8_t [block_size ];
330
+ uint8_t *write_buffer = new (std::nothrow) uint8_t [max_sector_size ];
331
+ uint8_t *read_buffer = new (std::nothrow) uint8_t [max_sector_size ];
326
332
327
- if (!write_block || !read_block) {
328
- utest_printf (" Not enough memory for test\n " );
333
+ if (!write_buffer || !read_buffer) {
334
+ // Some targets have sectors up to 256KB each and a relatively small RAM.
335
+ // This test may not be able to run in this case.
336
+ utest_printf (" Not enough memory for test, is the sector size (%llu) too big?\n " , max_sector_size);
329
337
goto end;
330
338
}
331
339
332
340
for (int b = 0 ; b < sector_per_thread; b++) {
333
- basic_erase_program_read_test (block_device, block_size, write_block, read_block, addrwidth, block_num * sector_per_thread + b);
341
+ // basic_erase_program_read_test() can handle non-uniform sector sizes
342
+ // and use only part of the buffers if the sector is smaller
343
+ basic_erase_program_read_test (block_device, max_sector_size, write_buffer, read_buffer, addrwidth, block_num * sector_per_thread + b);
334
344
}
335
345
336
346
end:
337
- delete[] read_block ;
338
- delete[] write_block ;
347
+ delete[] read_buffer ;
348
+ delete[] write_buffer ;
339
349
}
340
350
341
351
void test_multi_threads ()
@@ -584,7 +594,6 @@ void test_program_read_small_data_sizes()
584
594
585
595
TEST_SKIP_UNLESS_MESSAGE (block_device != NULL , " no block device found." );
586
596
587
- bd_size_t erase_size = block_device->get_erase_size ();
588
597
bd_size_t program_size = block_device->get_program_size ();
589
598
bd_size_t read_size = block_device->get_read_size ();
590
599
TEST_ASSERT (program_size > 0 );
@@ -606,6 +615,7 @@ void test_program_read_small_data_sizes()
606
615
607
616
// Determine starting address
608
617
bd_addr_t start_address = 0 ;
618
+ bd_size_t erase_size = block_device->get_erase_size (start_address);
609
619
610
620
for (int i = 1 ; i <= 7 ; i++) {
611
621
err = buff_block_device->erase (start_address, erase_size);
0 commit comments