Skip to content

Commit fcd5f3b

Browse files
authored
Merge pull request #454 from rgrover/master
fix tests to work correctly for synchronous operation
2 parents 2921db8 + 6d5a89b commit fcd5f3b

File tree

2 files changed

+45
-37
lines changed

2 files changed

+45
-37
lines changed

TESTS/storage_abstraction/basicAPI/basicAPI.cpp

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,6 @@ void test_getInfo()
112112

113113
TEST_ASSERT_EQUAL(0, info.security.reserved1);
114114
TEST_ASSERT_EQUAL(0, info.security.reserved2);
115-
TEST_ASSERT_EQUAL(1, info.erased_value);
116-
TEST_ASSERT((info.program_cycles == ARM_STORAGE_PROGRAM_CYCLES_INFINITE) || (info.program_cycles > 0));
117115
TEST_ASSERT(info.total_storage > 0);
118116
}
119117

@@ -299,8 +297,15 @@ void programDataCompleteCallback(int32_t status, ARM_STORAGE_OPERATION operation
299297
TEST_ASSERT((operation == ARM_STORAGE_OPERATION_ERASE) || (operation == ARM_STORAGE_OPERATION_PROGRAM_DATA));
300298
if (operation == ARM_STORAGE_OPERATION_ERASE) {
301299
// printf("programming %u bytes at address %lu with pattern 0x%" PRIx32 "\n", sizeofData, (uint32_t)addr, BYTE_PATTERN);
302-
status = drv->ProgramData(addr, buffer, sizeofData);
303300

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+
308+
status = drv->ProgramData(addr, buffer, sizeofData);
304309
if (status < ARM_DRIVER_OK) {
305310
return; /* failure. this will trigger a timeout and cause test failure. */
306311
}
@@ -348,13 +353,6 @@ control_t test_programDataUsingProgramUnit(const size_t call_count)
348353

349354
/* initialize the buffer to hold the pattern. */
350355
ARM_STORAGE_CAPABILITIES capabilities = drv->GetCapabilities();
351-
static const uint32_t BYTE_PATTERN = 0xAA551122;
352-
size_t sizeofData = info.program_unit;
353-
TEST_ASSERT(BUFFER_SIZE >= sizeofData);
354-
TEST_ASSERT((sizeofData % sizeof(uint32_t)) == 0);
355-
for (size_t index = 0; index < sizeofData / sizeof(uint32_t); index++) {
356-
((uint32_t *)buffer)[index] = BYTE_PATTERN;
357-
}
358356

359357
/* Update the completion callback to 'programDataCompleteCallback'. */
360358
if (call_count == 2) {
@@ -374,7 +372,16 @@ control_t test_programDataUsingProgramUnit(const size_t call_count)
374372
TEST_ASSERT_EQUAL(1, capabilities.asynchronous_ops);
375373
return (call_count < REPEAT_INSTANCES) ? CaseTimeout(200) + CaseRepeatAll: CaseTimeout(200);
376374
} else {
377-
TEST_ASSERT(rc > 0);
375+
TEST_ASSERT_EQUAL(firstBlock.attributes.erase_unit, rc);
376+
verifyBytePattern(addr, firstBlock.attributes.erase_unit, (uint8_t)0xFF);
377+
378+
static const uint32_t BYTE_PATTERN = 0xAA551122;
379+
size_t sizeofData = info.program_unit;
380+
TEST_ASSERT(BUFFER_SIZE >= sizeofData);
381+
TEST_ASSERT((sizeofData % sizeof(uint32_t)) == 0);
382+
for (size_t index = 0; index < sizeofData / sizeof(uint32_t); index++) {
383+
((uint32_t *)buffer)[index] = BYTE_PATTERN;
384+
}
378385

379386
/* program the sector at addr */
380387
// printf("programming %u bytes at address %lu with pattern 0x%" PRIx32 "\n", sizeofData, (uint32_t)addr, BYTE_PATTERN);
@@ -416,8 +423,11 @@ void programDataOptimalCompleteCallback(int32_t status, ARM_STORAGE_OPERATION op
416423
#ifndef __CC_ARM
417424
printf("programming %u bytes at address %lu with pattern 0x%x\n", sizeofData, (uint32_t)addr, BYTE_PATTERN);
418425
#endif
419-
status = drv->ProgramData(addr, buffer, sizeofData);
426+
size_t sizeofData = info.optimal_program_unit;
427+
TEST_ASSERT(BUFFER_SIZE >= sizeofData);
428+
memset(buffer, BYTE_PATTERN, sizeofData);
420429

430+
status = drv->ProgramData(addr, buffer, sizeofData);
421431
if (status < ARM_DRIVER_OK) {
422432
return; /* failure. this will trigger a timeout and cause test failure. */
423433
}
@@ -465,10 +475,6 @@ control_t test_programDataUsingOptimalProgramUnit(const size_t call_count)
465475

466476
/* initialize the buffer to hold the pattern. */
467477
ARM_STORAGE_CAPABILITIES capabilities = drv->GetCapabilities();
468-
static const uint8_t BYTE_PATTERN = 0xAA;
469-
size_t sizeofData = info.optimal_program_unit;
470-
TEST_ASSERT(BUFFER_SIZE >= sizeofData);
471-
memset(buffer, BYTE_PATTERN, sizeofData);
472478

473479
/* Update the completion callback to 'programDataCompleteCallback'. */
474480
if (call_count == 2) {
@@ -491,14 +497,19 @@ control_t test_programDataUsingOptimalProgramUnit(const size_t call_count)
491497
TEST_ASSERT_EQUAL(firstBlock.attributes.erase_unit, rc);
492498
verifyBytePattern(addr, firstBlock.attributes.erase_unit, (uint8_t)0xFF);
493499

500+
static const uint8_t BYTE_PATTERN = 0xAA;
501+
size_t sizeofData = info.optimal_program_unit;
502+
TEST_ASSERT(BUFFER_SIZE >= sizeofData);
503+
memset(buffer, BYTE_PATTERN, sizeofData);
504+
494505
/* program the sector at addr */
495506
printf("programming %u bytes at address %lu with pattern 0x%x\n", sizeofData, (uint32_t)addr, BYTE_PATTERN);
496507
rc = drv->ProgramData((uint32_t)addr, buffer, sizeofData);
497508
if (rc == ARM_DRIVER_OK) {
498509
TEST_ASSERT_EQUAL(1, capabilities.asynchronous_ops);
499510
return (call_count < REPEAT_INSTANCES) ? CaseTimeout(200) + CaseRepeatAll: CaseTimeout(200);
500511
} else {
501-
TEST_ASSERT(rc > 0);
512+
TEST_ASSERT_EQUAL(sizeofData, rc);
502513

503514
printf("verifying programmed sector at addr %lu\n", (uint32_t)addr);
504515
verifyBytePattern(addr, sizeofData, BYTE_PATTERN);
@@ -858,6 +869,11 @@ control_t test_programDataWithMultipleProgramUnits(const size_t call_count)
858869
return CaseNext; /* first block isn't large enough for the intended operation */
859870
}
860871

872+
if (rangeNeededForTest > BUFFER_SIZE) {
873+
printf("buffer (%u) not large enough; rangeNeededForTest: %u\n", BUFFER_SIZE, rangeNeededForTest);
874+
return CaseNext;
875+
}
876+
861877
// printf("erasing %u bytes at addr %lu\n", rangeNeededForTest, (uint32_t)firstBlock.addr);
862878
rc = drv->Erase(firstBlock.addr, rangeNeededForTest);
863879
TEST_ASSERT(rc >= 0);
@@ -867,8 +883,6 @@ control_t test_programDataWithMultipleProgramUnits(const size_t call_count)
867883
} else {
868884
TEST_ASSERT_EQUAL(rangeNeededForTest, rc);
869885

870-
TEST_ASSERT((N_UNITS * info.program_unit) <= BUFFER_SIZE);
871-
872886
/* setup byte pattern in buffer */
873887
static const uint32_t BYTE_PATTERN = 0xABCDEF00;
874888
if (info.program_unit >= sizeof(BYTE_PATTERN)) {

features/storage/TESTS/flash_journal/basicAPI/basicAPI.cpp

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ control_t test_resetAndInitialize(const size_t call_count)
159159
if (rc == JOURNAL_STATUS_OK) {
160160
return CaseTimeout(200);
161161
}
162+
TEST_ASSERT_EQUAL(1, rc); /* synchronous completion of initialize() is expected to return 1 */
162163

163164
/* fall through */
164165
case NEEDS_VERIFICATION_FOLLOWING_INITIALIZE:
@@ -227,16 +228,11 @@ control_t test_logSmallWithoutCommit(const size_t call_count)
227228
/* initialize */
228229
rc = FlashJournal_initialize(&journal, drv, &FLASH_JOURNAL_STRATEGY_SEQUENTIAL, callbackHandler);
229230
TEST_ASSERT(rc >= ARM_DRIVER_OK);
230-
if (drv->GetCapabilities().asynchronous_ops) {
231-
if (rc == ARM_DRIVER_OK) {
232-
return CaseTimeout(200) + CaseRepeatAll;
233-
} else {
234-
return CaseRepeatAll;
235-
}
236-
} else {
237-
return CaseRepeatAll;
231+
if (rc == ARM_DRIVER_OK) {
232+
return CaseTimeout(200) + CaseRepeatAll;
238233
}
239-
break;
234+
TEST_ASSERT_EQUAL(1, rc); /* synchronous completion of initialize() is expected to return 1 */
235+
return CaseRepeatAll;
240236

241237
case 2:
242238
/* log without commit */
@@ -324,6 +320,7 @@ control_t test_initializeAfterLogSmallAndCommit(const size_t call_count)
324320
printf("asynchronous_ops for init\n");
325321
return CaseTimeout(200) + CaseRepeatAll;
326322
}
323+
TEST_ASSERT_EQUAL(1, rc); /* synchronous completion of initialize() is expected to return 1 */
327324
}
328325

329326
FlashJournal_Info_t info;
@@ -344,15 +341,11 @@ control_t test_logLargeWithoutCommit(const size_t call_count)
344341
case 1:
345342
rc = FlashJournal_initialize(&journal, drv, &FLASH_JOURNAL_STRATEGY_SEQUENTIAL, callbackHandler);
346343
TEST_ASSERT(rc >= ARM_DRIVER_OK);
347-
if (drv->GetCapabilities().asynchronous_ops) {
348-
if (rc == ARM_DRIVER_OK) {
349-
return CaseTimeout(200) + CaseRepeatAll;
350-
} else {
351-
return CaseRepeatAll;
352-
}
353-
} else {
354-
return CaseRepeatAll;
344+
if (rc == ARM_DRIVER_OK) {
345+
return CaseTimeout(200) + CaseRepeatAll;
355346
}
347+
TEST_ASSERT_EQUAL(1, rc); /* synchronous completion of initialize() is expected to return 1 */
348+
return CaseRepeatAll;
356349

357350
case 2:
358351
memset(buffer, 0xAA, SIZEOF_LARGE_WRITE);
@@ -440,6 +433,7 @@ control_t test_initializeAfterLogLargeAndCommit(const size_t call_count)
440433
printf("test_initializeAfterLogLargeAndCommit: asynchronous_ops for init\n");
441434
return CaseTimeout(200) + CaseRepeatAll;
442435
}
436+
TEST_ASSERT_EQUAL(1, rc); /* synchronous completion of initialize() is expected to return 1 */
443437
}
444438

445439
FlashJournal_Info_t info;
@@ -791,7 +785,7 @@ control_t test_failedSmallWriteFollowedByPaddedWrite(const size_t call_count)
791785
TEST_ASSERT_EQUAL(1, drv->GetCapabilities().asynchronous_ops);
792786
return CaseTimeout(500) + CaseRepeatAll;
793787
}
794-
TEST_ASSERT_EQUAL((SIZEOF_WRITE + 1), rc);
788+
TEST_ASSERT_EQUAL(1, rc);
795789
callbackStatus = rc;
796790
return CaseRepeatAll;
797791
} else {

0 commit comments

Comments
 (0)