Skip to content

Multi thread Block Device Tests Fix - Ensure unique block address #9650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ void basic_erase_program_read_test(SPIFBlockDevice &block_device, bd_size_t bloc
{
int err = 0;
_mutex->lock();

// Make sure block address per each test is unique
static unsigned block_seed = 1;
srand(block_seed++);
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this is sufficient (block seed) for the test purpose or rather using time like getting from us ticker ?

Copy link
Contributor Author

@offirko offirko Feb 11, 2019

Choose a reason for hiding this comment

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

I didn't want to make a drastic change. I think this should be sufficient for this test purpose.
We simply need ~50 different addresses for this test, they don't have to be random per each test.I'm saying ~50 ((5 Threads x 10 iterations) because addresses may repeat as long as they do not run concurrently for different threads.

Because seed/rand are not really random, I believe once the test runs successfully it will remain stable. Using time will actually 'random' and then we might have collision issue (very very low probability as David mentioned below)

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add this to the commit, will help


// Find a random block
bd_addr_t block = (rand() * block_size) % block_device.size();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ void basic_erase_program_read_test(BlockDevice *block_device, bd_size_t block_si
{
int err = 0;
_mutex->lock();

// Make sure block address per each test is unique
static unsigned block_seed = 1;
srand(block_seed++);

// Find a random block
bd_addr_t block = (rand() * block_size) % (block_device->size());

Expand Down