Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

common-io: Refactoring FLASH test cases #1883

Merged

Conversation

osloapps-max
Copy link
Contributor

Description

This pull request is rather large (sorry for this), the main contributions is the following:

  • Refactored flash test cases to use TEST_PROTECT sections to guard against cascading failures.
  • Refactored flash test cases, moving common code for writing, reading, verifying dummy data out of each test case into global privates. This should simplify maintaining the tests as.
  • Updated AFQP_IotFlashReadInfo to allow block >= sector >= page >= flash (in other words, moved from "greater than" to "greater than or equal") as this is a valid scenario.

Checklist:

  • I have tested my changes. No regression in existing tests.
  • My code is Linted.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.


/* Open flash to initialize hardware. */
if( gIotFlashHandle == NULL )
Copy link

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

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.

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.

Copy link
Contributor Author

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?

Copy link
Contributor Author

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() )
Copy link

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 );
Copy link

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" );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data was not written.

Copy link
Contributor Author

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. */
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong comment

Copy link
Contributor Author

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 */
Copy link

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?

Copy link
Contributor Author

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 );
Copy link

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

Copy link
Contributor Author

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.

@dcgaws dcgaws requested a review from cobusve April 13, 2020 20:25
qiutongs
qiutongs previously approved these changes May 11, 2020
cobusve
cobusve previously approved these changes May 11, 2020
@qiutongs
Copy link
Contributor

/bot run checks

1 similar comment
@qiutongs
Copy link
Contributor

/bot run checks

@qiutongs
Copy link
Contributor

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.
https://github.com/osloapps-max/amazon-freertos

@osloapps-max
Copy link
Contributor Author

osloapps-max commented May 13, 2020

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.
https://github.com/osloapps-max/amazon-freertos

You should have an invite pending now.

@qiutongs
Copy link
Contributor

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.
https://github.com/osloapps-max/amazon-freertos

You should have an invite pending now.

Thank you! I accepted it.

@qiutongs qiutongs dismissed stale reviews from cobusve and themself via cb8b1d6 May 13, 2020 19:53
@qiutongs qiutongs force-pushed the fix/common-io-flash-test-refactoring branch from a18ef56 to cb8b1d6 Compare May 13, 2020 19:53
@qiutongs
Copy link
Contributor

/bot run checks

1 similar comment
@qiutongs
Copy link
Contributor

/bot run checks

qiutongs
qiutongs previously approved these changes May 13, 2020
@qiutongs
Copy link
Contributor

/bot run checks

1 similar comment
@qiutongs
Copy link
Contributor

/bot run checks

@qiutongs qiutongs merged commit 0858694 into aws:master May 14, 2020
alfred2g pushed a commit to alfred2g/amazon-freertos that referenced this pull request May 21, 2020
Co-authored-by: Max Wennerfeldt <[email protected]>
Co-authored-by: qiutongs <songqt01@gmail,com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants