-
Notifications
You must be signed in to change notification settings - Fork 1.1k
common-io: Refactoring FLASH test cases #1883
common-io: Refactoring FLASH test cases #1883
Conversation
794d3a7
to
b2b42a2
Compare
|
||
/* Open flash to initialize hardware. */ | ||
if( gIotFlashHandle == NULL ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was added to make sure we can run the tests even if the handle was open by someone else. What was the reason to remove this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vjjunnut, as most test also tear-down the handle on finish, this would only really apply to single test cases being run. Is this a common use-case in the test system and what is the gain from it?
My understanding of the way the original tests was structured, running any group tests would result in the first test using the globally opened handle to then close it again and force the following tests to open it for them to succeed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that the caller can still control which handle is being opened as the refactoring also added a global "ltestIotFlashInstance" which can be set prior to running the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is correct that the first test uses the global handle and then closes it so that the rest of the tests can open it again and close.
Usually there will be only one flash, so the instance will be the same. But even if there are multiple flash parts - we still need to be able to use it, even if it was open by the application which runs the tests. You can argue that application shall not open if its only to run the tests. But on some boards, flash is read first to get some context in startup code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is correct that the first test uses the global handle and then closes it so that the rest of the tests can open it again and close.
Usually there will be only one flash, so the instance will be the same. But even if there are multiple flash parts - we still need to be able to use it, even if it was open by the application which runs the tests. You can argue that application shall not open if its only to run the tests. But on some boards, flash is read first to get some context in startup code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fully understand that there might be a need to use the flash prior to running the tests. It just seems to me that it makes more sense to ensure that such tests setups leaves the hardware in a known state before running the tests. In other words, if the flash is used prior to the tests, the original owner using the flash should also release it.
Bringing in an external from outside the scope just to close it not only leaves the original owner being uncertain of the state of the handle, what happens if the one using the flash prior to the tests do not actually utilize the handle?
Furthermore, none of the test cases as of now resets the global handle to NULL once closing it, which would let the following tests to believe that it was still valid, even while it was not.
Is there some reason that the original owner cannot release the handle prior to running the tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@qiutongs Any thoughts on this?
/* Get the flash information. */ | ||
pxFlashInfo = iot_flash_getinfo( xFlashHandle ); | ||
TEST_ASSERT_NOT_EQUAL( NULL, pxFlashInfo ); | ||
if( TEST_PROTECT() ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this.
xFlashHandle = gIotFlashHandle; | ||
} | ||
/* Open the flash instance */ | ||
xFlashHandle = iot_flash_open( ltestIotFlashInstance ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to bring back checking for the gIotFlashHandle
{ | ||
if( uctestIotFlashReadBuffer[ i ] != ( i & 0xFF ) ) | ||
{ | ||
TEST_ASSERT_MESSAGE( 0, "Data was NOT erased" ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Data was not written.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this, will look into it and push an update.
remaining_size ); | ||
TEST_ASSERT_EQUAL( IOT_FLASH_SUCCESS, lRetVal ); | ||
|
||
/* Verify the data is erased. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrong comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this, will look into it and push an update.
|
||
if( remaining_size > 0 ) | ||
{ | ||
/* Read back the data written */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
read back the data erased?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching this, will look into it and push an update.
TEST_ASSERT_MESSAGE( 0, "Contents do NOT match when readback" ); | ||
} | ||
/* Write the a full page and verify the data by reading it back */ | ||
prvIotFlashWriteReadVerify( xFlashHandle, ultestIotFlashStartOffset, pxFlashInfo->ulPageSize ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function writes and reads the same data. When reading back - that data should be erased data, and not written data. Please modify this call to write and then ReadVerifyErased
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, fixing this asap.
/bot run checks |
1 similar comment
/bot run checks |
There is a build failure that is not related to your PR. But it needs to rebase to the latest master. Sorry for that inconvenience. Do you mind giving me writing access to your fork? I am help rebase it. |
You should have an invite pending now. |
Thank you! I accepted it. |
a18ef56
to
cb8b1d6
Compare
/bot run checks |
1 similar comment
/bot run checks |
/bot run checks |
1 similar comment
/bot run checks |
Co-authored-by: Max Wennerfeldt <[email protected]> Co-authored-by: qiutongs <songqt01@gmail,com>
Description
This pull request is rather large (sorry for this), the main contributions is the following:
Checklist:
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.