ThrowTheSwitch / CMock

CMock - Mock/stub generator for C
http://throwtheswitch.org
MIT License
684 stars 276 forks source link

When CMock is out of memory it does not tell you so #463

Open Letme opened 1 year ago

Letme commented 1 year ago

I have following flags to compile CMock (tested the latest) with static memory size and alignment:

-DCMOCK_MEM_STATIC -DCMOCK_MEM_SIZE=$(CMOCK_MEMSIZE) -DCMOCK_MEM_ALIGN=$(CMOCK_MEMALIGN)

The values don't matter, but the behavior becomes strange if you overreach the CMOCK_MEMSIZE. It reports Expect was not expected and when you remove that Expect it tells you it actually expected it. So you are in chicken and egg situation. I checked the code and CMock_Guts_MemNew actually reports CMOCK_GUTS_NONE in this case, but the message CMockStringOutOfMemory is never triggered/displayed. I checked unit tests and I am missing this case. I am not sure if it was intended to be implemented, or not.

mvandervoord commented 1 year ago

That definitely doesn't sound like the intended implementation! Like you, I would want it to report the out-of-memory error first and foremost, since it's the root reason for the failure. Thanks for noticing this!

When you say "overreach", I assume you mean selecting any size that can't actually be returned by the heap on that target?

Letme commented 1 year ago

Yes, well array size that is available for a static array is not big enough but instead of reporting out of memory error, I just got strange behavior above. Removing one init/verify file solved that problem (or increase in CMOCK_MEM_SIZE variable)

mvandervoord commented 1 year ago

Thanks. I'm understanding. :)

Letme commented 1 year ago

https://github.com/ThrowTheSwitch/CMock/blob/c548629a478ef07f89db8b86c1dd4041a1cf4053/src/cmock.c#L56 this line in C file gets hit, but then I loose why the out of memory message is not displayed (cant follow though Ruby scripts). Hope that helps, but I think tests in this repo could be enhanced to catch this case (not just reported error code but also to get the message reported).

mvandervoord commented 1 year ago

Hey @Letme -- I'm not finding why this would be a problem yet... You're sure it's CMock_Guts_MemNew that is returning the error? I only see it getting called in one place in the scripts. It's immediately passed to CMock_Guts_GetAddressFor which correctly returns a null when encountered... and the null check is the next line of the base expectation.

Can you do me a favor? Can you send me a snapshot of your project.yml (or however you're configuring cmock) and one of the generated mock files (it'd be good if it was one giving you this problem)