Skip to content

Add MemoryPool test. #4936

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 1 commit into from
Oct 30, 2017
Merged

Conversation

mprse
Copy link
Contributor

@mprse mprse commented Aug 18, 2017

Description

Add test for MemoryPool.

Status

READY

Migrations

No

Copy link
Member

@bulislaw bulislaw left a comment

Choose a reason for hiding this comment

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

There's couple of indentation errors. Also please split the PR into two commits: fixes to the original header and the tests.

@@ -92,7 +96,7 @@ class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {
private:
osMemoryPoolId_t _id;
osMemoryPoolAttr_t _attr;
char _pool_mem[sizeof(T) * pool_sz];
char _pool_mem[ ((sizeof(T) + 3) & ~3) * pool_sz];
Copy link
Member

Choose a reason for hiding this comment

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

Can we have a short comment why we are doing that.

@@ -83,7 +84,10 @@ class MemoryPool : private mbed::NonCopyable<MemoryPool<T, pool_sz> > {

/** Free a memory block.
@param block address of the allocated memory block to be freed.
@return status code that indicates the execution status of the function.
@return osOK on successful deallocation, osErrorParameter if parameter mp_id
Copy link
Member

Choose a reason for hiding this comment

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

what is mb_id in our case? From the perspective of C++ API it doesn't exist. I don't think we should be quoting it, instead we could say something like internal error for both.

return verbose_test_setup_handler(number_of_cases);
}

Case cases[] = {
Copy link
Member

Choose a reason for hiding this comment

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

Please fix the indentation.

* When free operation is executed on this block again.
* Then operation fails with osErrorResource status.
*/
template<typename T, const uint32_t numOfEntries, AllocType atype>
Copy link
Member

Choose a reason for hiding this comment

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

That's way too long can you split it in multiple tests.

* When free operation is executed on this block again.
* Then operation fails with osErrorResource status.
*/
template<typename T, const uint32_t numOfEntries, AllocType atype>
Copy link
Member

Choose a reason for hiding this comment

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

that's way too long can you split it in multiple small tests.

* Then operation fails with osErrorResource status.
*
*/
template<typename T, AllocType atype>
Copy link
Member

Choose a reason for hiding this comment

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

That's too long can you please split it in multiple tests.

@mprse mprse force-pushed the memPool_test_and_fixes branch 7 times, most recently from a22eb0c to 47ddbd2 Compare August 21, 2017 08:02
@mprse mprse changed the title Add MemoryPool test and fixes in MemoryPool.h file. Add MemoryPool test. Aug 21, 2017
*
* */
template<typename T, const uint32_t numOfEntries, AllocType atype>
void test_mem_pool_alloc_success() {
Copy link
Contributor

Choose a reason for hiding this comment

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

starting { on the new line, below if also.
See https://docs.mbed.com/docs/mbed-os-handbook/en/5.1/cont/code_style/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@0xc0170 codding style has been updated.

T * p_blocks[numOfEntries];
uint32_t i;

/* Create a memory pool. */
Copy link
Contributor

Choose a reason for hiding this comment

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

It is good to have comments but I find a lot of them redundant . like create a memory pool, it is obvious from the code.

the comment on line 80 below for instance is fine.

* Then deallocation fails with osErrorParameter error.
*
*/
void free_block_invalid_prarameter_null() {
Copy link
Contributor

Choose a reason for hiding this comment

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

typo - parameter

@mprse mprse force-pushed the memPool_test_and_fixes branch from 47ddbd2 to e2323a7 Compare August 21, 2017 13:29
*
* Given MemoryPool object of the specified type and queue size has
* been successfully created.
* When max number of blocks is allocated form the pool.
Copy link
Member

Choose a reason for hiding this comment

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

typo -> from the pool

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

T * p_blocks[numOfEntries];
uint32_t i;

p_mem_pool = new MemoryPool<T, numOfEntries>();
Copy link
Member

Choose a reason for hiding this comment

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

Why are you use dynamic allocation of the pool?

Copy link
Contributor Author

@mprse mprse Aug 23, 2017

Choose a reason for hiding this comment

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

The intention was to not allocate lots of data on stack. In case when for example block size is equal to 12 bytes and pool consists of 100 blocks. In this case we would need over 1kB of memory for such memory pool. But then we agreed that such large numbers do not need to be tested. On the other hand why using dynamic allocation is a problem?


utest::v1::status_t test_setup(const size_t number_of_cases)
{
GREENTEA_SETUP(45, "default_auto");
Copy link
Member

Choose a reason for hiding this comment

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

Can we go lower than 45 or is it actually as long as it takes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Timeout has been modified to 20 s.

@mprse mprse force-pushed the memPool_test_and_fixes branch from e2323a7 to 03af8b5 Compare August 24, 2017 08:28
@bulislaw
Copy link
Member

@0xc0170 can you have a look

/morph test

@mbed-bot
Copy link

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 1119

Build failed!

@0xc0170
Copy link
Contributor

0xc0170 commented Aug 31, 2017

I restarted Travis, should become green. In case not, please close/opne the PR to restart travis. It sometimes does not report the status back

if(object->a == 0 &&
object->b == 0 &&
object->c == 0)
{
Copy link
Contributor

Choose a reason for hiding this comment

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

@mprse mprse force-pushed the memPool_test_and_fixes branch 2 times, most recently from db0aeff to f501fa2 Compare September 11, 2017 09:18
@theotherjimmy
Copy link
Contributor

@0xc0170 Could you review please?

/morph test

@mbed-bot
Copy link

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph test

Output

mbed Build Number: 1353

Build failed!

@mprse mprse force-pushed the memPool_test_and_fixes branch from f501fa2 to 8745845 Compare September 22, 2017 08:17
@mprse
Copy link
Contributor Author

mprse commented Sep 22, 2017

Output
mbed Build Number: 1353
Build failed!

One error on NUMAKER_PFM_NANO130 platform using IAR compiler: unable to allocate space for sections/blocks with a total estimated minimum size of 0x3b90 bytes (max align 0x8) in <[0x20000000-0x20003fff]> (total uncommitted space 0x3a00).

Test has been updated. Memory usage has been decreased.

@theotherjimmy could you please re-run morph test.

@0xc0170
Copy link
Contributor

0xc0170 commented Sep 22, 2017

There's couple of indentation errors. Also please split the PR into two commits: fixes to the original header and the tests.

Shall this be splitted as requested prior we run another CI?

@mprse
Copy link
Contributor Author

mprse commented Sep 22, 2017

Shall this be splitted as requested prior we run another CI?

This was my first PR and it initially provided two features:

  • fix in memory pool header file, and
  • memory pool test.

As requested this has been splitted into two PRs. Currently this PR provides only the test.
The header file has been fixed here:
#4941

@mbed-ci
Copy link

mbed-ci commented Oct 16, 2017

Build : FAILURE

Build number : 181
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/4936/

@mbed-ci
Copy link

mbed-ci commented Oct 16, 2017

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 17, 2017

/morph test

@mbed-ci
Copy link

mbed-ci commented Oct 17, 2017

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 18, 2017

/morph build

@mbed-ci
Copy link

mbed-ci commented Oct 18, 2017

Build : FAILURE

Build number : 225
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/4936/

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 18, 2017

@mprse Please look at the latest build, there's linker error for one device.

@mprse
Copy link
Contributor Author

mprse commented Oct 19, 2017

Test : FAILURE

Build error on NUMAKER_PFM_NANO130/IAR:

Output: IAR ELF Linker V7.80.1.28/LNX for ARM
Output: Copyright 2007-2016 IAR Systems AB.
Output:
Output: 47 710 bytes of readonly code memory
Output: 4 481 bytes of readonly data memory
Output: 1 536 bytes of readwrite data memory
Output:
Output: Errors: 2
Output: Warnings: none
Output:
Output: Link time: 0.19 (CPU) 1.00 (elapsed)
Errors: Error[Lp011]: section placement failed
Errors: unable to allocate space for sections/blocks with a total estimated
Errors: minimum size of 0x3a28 bytes (max align 0x8) in
Errors: <[0x20000000-0x20003fff]> (total uncommitted space
Errors: 0x3a00).
Errors: Error[Lp021]: the destination for compressed initializer batch "P2-P3-1" is
Errors: placed at an address that is dependent on the size of the batch,
Errors: which is not allowed when using lz77 compression. Consider using
Errors: "initialize by copy with packing = zeros" (or none) instead.

Decreased memory usage by reducing number of test cases. Wrapper functions have been used to test alloc() and calloc() memory allocation types together (in one test case).
Hopefully this will solve the problem for time longer than two weeks.

@mprse mprse force-pushed the memPool_test_and_fixes branch 2 times, most recently from 1156e1e to 6f40a80 Compare October 23, 2017 13:34
@adbridge
Copy link
Contributor

/morph uvisor-test

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 25, 2017

/morph build

@mbed-ci
Copy link

mbed-ci commented Oct 25, 2017

Build : SUCCESS

Build number : 337
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/4936/

Triggering tests

/morph test
/morph uvisor-test

@mbed-ci
Copy link

mbed-ci commented Oct 25, 2017

@0xc0170
Copy link
Contributor

0xc0170 commented Oct 26, 2017

@bulislaw Can you rereview after the update, tests are now green

@@ -0,0 +1,608 @@
#include "mbed.h"
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 please add the license header here, every file should have it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Licence header has been added.

Copy link
Member

@bulislaw bulislaw left a comment

Choose a reason for hiding this comment

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

Only the header is missing

Add test for MemoryPool.
@mprse mprse force-pushed the memPool_test_and_fixes branch from 6f40a80 to b7e2776 Compare October 27, 2017 06:08
@0xc0170
Copy link
Contributor

0xc0170 commented Oct 27, 2017

/morph build

@mbed-ci
Copy link

mbed-ci commented Oct 27, 2017

Build : SUCCESS

Build number : 360
Build artifacts/logs : http://mbed-os.s3-website-eu-west-1.amazonaws.com/?prefix=builds/4936/

Triggering tests

/morph test
/morph uvisor-test

@mbed-ci
Copy link

mbed-ci commented Oct 27, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants