cvra / platform-abstraction

Platform abstraction layer for microcontrollers
3 stars 6 forks source link

No way to assert if a function call contained atomic code #28

Closed antoinealb closed 10 years ago

antoinealb commented 10 years ago

It would be useful to have a way to test if a function did some atomic calls and verify if they were polite enough to release the locks. For example :

TEST(...)
{
foo();
CHECK(atomic_count() > 0);
CHECK_FALSE(atomic_still_aquired());
}
pierluca commented 10 years ago

Too generic. Please clarify. What do you define as "atomic calls" ? Mutex ? critical section ? another sync primitive? All of them?

antoinealb commented 10 years ago

Sorry, I meant a critical section.

For other sync primitives, I can already check for their usage using the acquired_count field.

pierluca commented 10 years ago

Given they're macros rather than proper functions working on a struct, I don't really know how to implement this in a meaningful way. Global variable in mock header doesn't seem appropriate because it would be shared between all critical sections being tested.

Will think about it but I'd be happy to hear your ideas.

antoinealb commented 10 years ago

A global variable could work, if we reset its state between each test, no ?

antoinealb commented 10 years ago

Another option I see would be to do it using a mock object and recording expectations. Not a huge fan of this because it makes the tests more fragile (you test the implementation not the behaviour).

antoinealb commented 10 years ago

I have a working implementation based on Cppumock. I will push it tomorrow after I reviewed it carefully.

antoinealb commented 10 years ago

fixed in #31 .