-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add MemoryPool test. #4936
Conversation
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.
There's couple of indentation errors. Also please split the PR into two commits: fixes to the original header and the tests.
rtos/MemoryPool.h
Outdated
@@ -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]; |
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.
Can we have a short comment why we are doing that.
rtos/MemoryPool.h
Outdated
@@ -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 |
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.
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[] = { |
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.
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> |
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'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> |
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's way too long can you split it in multiple small tests.
* Then operation fails with osErrorResource status. | ||
* | ||
*/ | ||
template<typename T, AllocType atype> |
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's too long can you please split it in multiple tests.
a22eb0c
to
47ddbd2
Compare
* | ||
* */ | ||
template<typename T, const uint32_t numOfEntries, AllocType atype> | ||
void test_mem_pool_alloc_success() { |
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.
starting {
on the new line, below if
also.
See https://docs.mbed.com/docs/mbed-os-handbook/en/5.1/cont/code_style/
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.
@0xc0170 codding style has been updated.
T * p_blocks[numOfEntries]; | ||
uint32_t i; | ||
|
||
/* Create a memory pool. */ |
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.
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() { |
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.
typo - parameter
47ddbd2
to
e2323a7
Compare
* | ||
* Given MemoryPool object of the specified type and queue size has | ||
* been successfully created. | ||
* When max number of blocks is allocated form the pool. |
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.
typo -> from the pool
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.
Fixed.
T * p_blocks[numOfEntries]; | ||
uint32_t i; | ||
|
||
p_mem_pool = new MemoryPool<T, numOfEntries>(); |
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.
Why are you use dynamic allocation of the pool?
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.
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"); |
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.
Can we go lower than 45 or is it actually as long as it takes?
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.
Timeout has been modified to 20 s.
e2323a7
to
03af8b5
Compare
@0xc0170 can you have a look /morph test |
Result: FAILUREYour command has finished executing! Here's what you wrote!
OutputBuild failed! |
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) | ||
{ |
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.
please align this file according to https://docs.mbed.com/docs/mbed-os-handbook/en/latest/cont/code_style/
db0aeff
to
f501fa2
Compare
@0xc0170 Could you review please? /morph test |
Result: FAILUREYour command has finished executing! Here's what you wrote!
OutputBuild failed! |
f501fa2
to
8745845
Compare
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. |
Shall this be splitted as requested prior we run another CI? |
This was my first PR and it initially provided two features:
As requested this has been splitted into two PRs. Currently this PR provides only the test. |
Build : FAILUREBuild number : 181 |
Test : FAILUREBuild number : 82 |
/morph test |
Test : FAILUREBuild number : 94 |
/morph build |
Build : FAILUREBuild number : 225 |
@mprse Please look at the latest build, there's linker error for one device. |
Build error on NUMAKER_PFM_NANO130/IAR:
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). |
1156e1e
to
6f40a80
Compare
/morph uvisor-test |
/morph build |
Build : SUCCESSBuild number : 337 Triggering tests/morph test |
Test : SUCCESSBuild number : 150 |
@bulislaw Can you rereview after the update, tests are now green |
@@ -0,0 +1,608 @@ | |||
#include "mbed.h" |
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.
Can you please add the license header here, every file should have it
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.
Licence header has been added.
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.
Only the header is missing
Add test for MemoryPool.
6f40a80
to
b7e2776
Compare
/morph build |
Build : SUCCESSBuild number : 360 Triggering tests/morph test |
Test : SUCCESSBuild number : 173 |
Description
Add test for MemoryPool.
Status
READY
Migrations
No