Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

find_mocks and how to do it with Make

16 views
Skip to first unread message

Kris Boultbee

unread,
May 13, 2024, 4:54:27 PM5/13/24
to ThrowTheSwitch Forums
I have reasons to be using gnu make to build our project. Those reasons are out of scope of this discussion.

There used to be a separate script called find_mocks.rb as part of cmock. This was quite a long time ago to be fair, but my build system relied upon it. It appears that similar functionality exists now but is rolled into the generate_test_runner.rb as a method of the UnityTestRunnerGenerator class. I'm trying to figure out how to get these mocks to get generated, or retrieve a list of those mocks in the test harness file. 

Maybe there is a way to generate that list to the command line that I can then pass to create_mock.rb or there's a way to get it to generate them when I call generate_test_runner.rb when I'm already creating the runner C file for the test harness.

I've been digging for a while to figure out how to do this. Part of the problem is that I'm no Ruby expert at all.

I have a copy of the find_mocks.rb script that I can just use, but I'd like to figure out how to generate them using the latest version of unity/cmock if possible.

Thanks,

Kris

Mark Vander Voord

unread,
May 14, 2024, 10:02:54 AM5/14/24
to throwth...@googlegroups.com
Kris:

My apologies for removing it. That's on me. I honestly thought it was only being used by other scripts, so when I did some cleanup, I removed it. I'm happy to rebuild it.

(An aside: You're never going to get harassment from me about using make. It has a lot of positives and it's everywhere. We've continued to keep unity, cmock, and ceedling maintained as separate projects because people have different needs.)

So let's talk about needs. What's the best version of this script look like for a make user? Does it accept a test header and directly return a list of mocks? Is stdout best or a file? Is it useful to have an option to return mocks, and an option to return unmocked headers?

Mark

--
You received this message because you are subscribed to the Google Groups "ThrowTheSwitch Forums" group.
To unsubscribe from this group and stop receiving emails from it, send an email to throwtheswitc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/throwtheswitch/7389a150-5fa7-42f7-acef-049ae26bd92an%40googlegroups.com.

Kris Boultbee

unread,
May 14, 2024, 10:29:36 AM5/14/24
to ThrowTheSwitch Forums
Mark,

Thanks for getting back, and apologies for the preemptive defensiveness. I've gotten too used to asking questions on stack overflow where some yahoo decides my question is wrong and tells me to do something unrelated to what I asked. I'm glad you're not doing that. :)

So the way I use the script right now is as follows:

1. My make finds my test harnesses
2. for each of those harnesses is generates a runner
3. for each of those harnesses it generates a list of the mocks included in that harness
4. dependencies are created based on that list
5. cmock.rb is called for all the mocks found in that list

So for my specific use case, the most useful is the find_mocks.rb that generates a space separated list of mocks found in the harness to stdout. An option to specify the mock prefix would also be useful although I use what I think is the default of "mock_". 

As for your other questions, I prefer stdout right now, but there might be some use to generate a file, specifically a .dep file like output so that resulting file could just be included. This I think would of course require an option to specify the directory where these mocks would be placed.

Somethign like this:

my_test_harness.c : mock_module_a.h mock_module_q.h

Or with the directory

modules/my_module/test/my_test_harness.c : out/mocks/mock_module_a.h out/mocks/mock_module_q.h

Alternatively it could just output such a make rule to stdout, because that can always be redirected to a file.

For the list of unmocked headers, I don't see a use for that, but you're probably thinking of something I'm not. I'd like to know what road you were going down for that because it might lead to something useful.

Finally, If there is some way to make  generate_test_runner.rb automatically generate such a makefile as above or generate the same list as the find_mocks.rb and that make cmock cleaner, that's also a fine way to handle things. The idea of  generate_test_runner.rb generating the list of mocks when it has to be run anyway to generate the runner for each harness anyway has some appeal because it's just one less step. 

Thanks for this, Mark.

Kris

Reply all
Reply to author
Forward
0 new messages