Skip to content

Commit 591159d

Browse files
author
Rohit Grover
committed
in tests for programData, move initialization of buffer just before calling ProgramData
1 parent f6f204f commit 591159d

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

TESTS/storage_abstraction/basicAPI/basicAPI.cpp

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,14 @@ void programDataCompleteCallback(int32_t status, ARM_STORAGE_OPERATION operation
297297
TEST_ASSERT((operation == ARM_STORAGE_OPERATION_ERASE) || (operation == ARM_STORAGE_OPERATION_PROGRAM_DATA));
298298
if (operation == ARM_STORAGE_OPERATION_ERASE) {
299299
// printf("programming %u bytes at address %lu with pattern 0x%" PRIx32 "\n", sizeofData, (uint32_t)addr, BYTE_PATTERN);
300+
301+
size_t sizeofData = info.program_unit;
302+
TEST_ASSERT(BUFFER_SIZE >= sizeofData);
303+
TEST_ASSERT((sizeofData % sizeof(uint32_t)) == 0);
304+
for (size_t index = 0; index < sizeofData / sizeof(uint32_t); index++) {
305+
((uint32_t *)buffer)[index] = BYTE_PATTERN;
306+
}
307+
300308
status = drv->ProgramData(addr, buffer, sizeofData);
301309
if (status < ARM_DRIVER_OK) {
302310
return; /* failure. this will trigger a timeout and cause test failure. */
@@ -345,13 +353,6 @@ control_t test_programDataUsingProgramUnit(const size_t call_count)
345353

346354
/* initialize the buffer to hold the pattern. */
347355
ARM_STORAGE_CAPABILITIES capabilities = drv->GetCapabilities();
348-
static const uint32_t BYTE_PATTERN = 0xAA551122;
349-
size_t sizeofData = info.program_unit;
350-
TEST_ASSERT(BUFFER_SIZE >= sizeofData);
351-
TEST_ASSERT((sizeofData % sizeof(uint32_t)) == 0);
352-
for (size_t index = 0; index < sizeofData / sizeof(uint32_t); index++) {
353-
((uint32_t *)buffer)[index] = BYTE_PATTERN;
354-
}
355356

356357
/* Update the completion callback to 'programDataCompleteCallback'. */
357358
if (call_count == 2) {
@@ -373,6 +374,14 @@ control_t test_programDataUsingProgramUnit(const size_t call_count)
373374
} else {
374375
TEST_ASSERT_EQUAL(firstBlock.attributes.erase_unit, rc);
375376

377+
static const uint32_t BYTE_PATTERN = 0xAA551122;
378+
size_t sizeofData = info.program_unit;
379+
TEST_ASSERT(BUFFER_SIZE >= sizeofData);
380+
TEST_ASSERT((sizeofData % sizeof(uint32_t)) == 0);
381+
for (size_t index = 0; index < sizeofData / sizeof(uint32_t); index++) {
382+
((uint32_t *)buffer)[index] = BYTE_PATTERN;
383+
}
384+
376385
/* program the sector at addr */
377386
// printf("programming %u bytes at address %lu with pattern 0x%" PRIx32 "\n", sizeofData, (uint32_t)addr, BYTE_PATTERN);
378387
rc = drv->ProgramData((uint32_t)addr, buffer, sizeofData);
@@ -413,6 +422,10 @@ void programDataOptimalCompleteCallback(int32_t status, ARM_STORAGE_OPERATION op
413422
#ifndef __CC_ARM
414423
printf("programming %u bytes at address %lu with pattern 0x%x\n", sizeofData, (uint32_t)addr, BYTE_PATTERN);
415424
#endif
425+
size_t sizeofData = info.optimal_program_unit;
426+
TEST_ASSERT(BUFFER_SIZE >= sizeofData);
427+
memset(buffer, BYTE_PATTERN, sizeofData);
428+
416429
status = drv->ProgramData(addr, buffer, sizeofData);
417430
if (status < ARM_DRIVER_OK) {
418431
return; /* failure. this will trigger a timeout and cause test failure. */
@@ -461,10 +474,6 @@ control_t test_programDataUsingOptimalProgramUnit(const size_t call_count)
461474

462475
/* initialize the buffer to hold the pattern. */
463476
ARM_STORAGE_CAPABILITIES capabilities = drv->GetCapabilities();
464-
static const uint8_t BYTE_PATTERN = 0xAA;
465-
size_t sizeofData = info.optimal_program_unit;
466-
TEST_ASSERT(BUFFER_SIZE >= sizeofData);
467-
memset(buffer, BYTE_PATTERN, sizeofData);
468477

469478
/* Update the completion callback to 'programDataCompleteCallback'. */
470479
if (call_count == 2) {
@@ -487,6 +496,11 @@ control_t test_programDataUsingOptimalProgramUnit(const size_t call_count)
487496
TEST_ASSERT_EQUAL(firstBlock.attributes.erase_unit, rc);
488497
verifyBytePattern(addr, firstBlock.attributes.erase_unit, (uint8_t)0xFF);
489498

499+
static const uint8_t BYTE_PATTERN = 0xAA;
500+
size_t sizeofData = info.optimal_program_unit;
501+
TEST_ASSERT(BUFFER_SIZE >= sizeofData);
502+
memset(buffer, BYTE_PATTERN, sizeofData);
503+
490504
/* program the sector at addr */
491505
printf("programming %u bytes at address %lu with pattern 0x%x\n", sizeofData, (uint32_t)addr, BYTE_PATTERN);
492506
rc = drv->ProgramData((uint32_t)addr, buffer, sizeofData);

0 commit comments

Comments
 (0)