Unit testing for dsPIC in a simulator

178 views
Skip to first unread message

Łukasz Przeniosło

unread,
Feb 22, 2021, 4:46:49 PM2/22/21
to ThrowTheSwitch Forums
Hello there,
I have some legacy code to cover with unit tests. This code is design for the Microchips dsPIC MCU (16 bit arch). I have gathered already some information about the available tools (Unity, CMock and Ceedling) and completed the 1st intro course on Udemy.

What I am still puzzled about is how to properly setup the testing environment. Ideally, I would use the MPLABX IDE provided by Microchip to create a separate project for each Unit test module. I would then run in via available simulator (testing natively, but not on the target). 

What my question is whether this approach has any flaws and maybe there is a better way for this? Maybe someone has already done some unit testing for Microchip's MCU's via simulator and could share their insights? Also, while I am sure I want to use Unity and CMock for this, I am still uncertain about using Ceedling- whether I really need it.

I would appreciate all help. 

Marcelo Jo

unread,
Feb 22, 2021, 6:04:21 PM2/22/21
to throwth...@googlegroups.com
Hi,
Take a look in this post.. maybe it will help you

Good luck!

--
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/b1acf3c6-1089-4759-a4fb-6b6b439b0686n%40googlegroups.com.

Łukasz Przeniosło

unread,
Feb 23, 2021, 5:26:55 AM2/23/21
to ThrowTheSwitch Forums
Hi There,
Thank you for your feedback. I am wondering why is Ceedling proposed to be used instead of just seting the project up with MPLABX? Do you have any preference and reason for that?

Łukasz Przeniosło

unread,
Feb 23, 2021, 5:41:38 AM2/23/21
to ThrowTheSwitch Forums
For instance, I was evaluating the possibilities in printing to the standard output via Microchips simulator. The only way around it I found was to use the emulated UART peripheral for that. I am wondering whether this Ceedling utility somehow overcomes that?

Mark Vander Voord

unread,
Feb 23, 2021, 7:52:29 AM2/23/21
to ThrowTheSwitch Forums
Yes, there is a big reason that people use Ceedling (or some other command-line oriented tool that they've customized like make or rake): To properly unit test, we want to test each unit completely, independent of its neighbors. To do that in C, the easiest way is to build those unit tests in its own executable.

For example, if I had a project that was only two modules A.c and B.c. and A made calls to B, it would be easy to write tests for B... but writing tests for A can be challenging. What do we do when it makes its calls to B? If we compile them both together, then a test for A also involves retesting B along with it (in a much less effective way) and we still may not be able to full test A. The problem gets worse as the number of modules goes up.

The build systems built into most IDE's are focused on creating a single executable, not an executable for every test file. Ceedling, on the other hand, was built specifically for managing tests and can build and run all the different test files and circle back with the summarized answers when finished.

You CAN get it to work another way, but it's going to be harder and ilkely less effective.

This also applies to your second question. You CAN use a simulated peripheral, but you're less likely to be able to fully unit-test a module doing that. Do those types of tests still have value? Absolutely! Particularly they have value when you're trying to write a driver for that peripheral in the first place... it's good to get that feedback that you're on the right track. But if/when you want to unit test that module, it's unlikely the simulated peripheral is going to provide all the means of emulating error conditions and whatnot that you'll need to do the job right.

Make sense?

Mark

Łukasz Przeniosło

unread,
Feb 23, 2021, 7:56:06 AM2/23/21
to throwth...@googlegroups.com, Mark Vander Voord
Hi Mark,
Yes, I bwlieve this makes good sense, thank you. On my way to Ceedling co figuration than.

--
Pozdrawiam / Best Regards,
Łukasz Przeniosło

You received this message because you are subscribed to a topic in the Google Groups "ThrowTheSwitch Forums" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/throwtheswitch/7DouEc7ef98/unsubscribe.
To unsubscribe from this group and all its topics, send an email to throwtheswitc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/throwtheswitch/CAAu8-XHdt6eWdRjRcq4nkCzHDaJDcK0r3kcO7g7TAkUX9Zo%3DAw%40mail.gmail.com.

Reply all
Reply to author
Forward
0 new messages