Has anyone attempted to use Unity in Simplicity Studio 5 for embedded C unit testing? My understanding is that in Studio 5 I can create and setup build configurations so that I can generate a makefile that looks like the following:
If yes, is there a tutorial that I can follow? Or is it recommended to uncheck "Generate Makefiles automatically" and use custom makefile instead?
Thank you for your time!
Hi Jui Yen Chua,
Perhaps other customers have used the Unity Test harness and can offer suggestions on using it with Simplicity Studio.
I have glanced at the provided github link and it appears that Unity adds a few files to the project, so it sounds like you are asking if you can create a build configuration that includes those files and have another build configuration that does not include those files.
Eclipse definitely supports multiple build configurations and so they can be added to a Simplicity Studio 5 project. The issue is that the Simplicity Studio Project Configurator is not designed to support multiple build configurations so as changes are made in the Project Configurator there might be some issues using the different build configurations.
I offer these suggestions for creating and dealing with multiple build configurations, but realize you might run into issues as you switch between the build configurations and make changes in the Project Configurator:
1. Create a new build configuration - Do not clone an existing build configuration
Right click the project folder and select [Build Configurations] > [Manage...] then select [New...] and check the box for the build configuration on which to base the new configuration:
Now select the new build configuration and hit [Edit...] to rename it and then click [Set Active] to make it the default build configuration:
2. Now add the unit test specific files to the project. They can be dragged from the operating systems file browser application into the project folder in the Simplicity Studio Project Explorer window.
3. Change / Verify the Resource Configuration settings for the new file so that they are only included in the Unit Test build configuration.
Select the files / folders and then right click the selection and select [Resource Configuration...] > [Exclude from build...] and then check the boxes for the build configurations that should not use the Unit Test files - so the Unit Test build configuration box should not be checked since the files will be included in that configuration:
I hope this helps you get started. I do not have experience using the Unity Test Harness and I am not sure if other Application Engineers at Silicon Labs have ever used it or not.
If you do run into build issues with one of the build configurations as changes are made in the Project Configurator, then after setting the build configuration "Active", open the Project Configurator file (.slcp) and do a [Force Generation] and see if the project then builds successfully. Also check the Resource Configuration settings for any files that are causing errors.
Thanks for the response! Ah I see. By the way just curious, is there an alternative test harness that Silicon Labs support/would recommend?
Hi Jui Yen Chua,
I am asking if there is any unit test software that Silicon Labs would recommend, but I probably will not have an answer before next week.
As far as Simplicity Studio support for unit test software, it would probably need to be an Eclipse plugin. From [Install] > [Manage installed packages] then select the [Tools] tab you can install the [EPP Marketplace Client] and then see what third party plugins are available. After installing that package and restarting Simplicity Studio go to [Help] > [Eclipse Marketplace...]. Using any of those plugins would be at your own risk and Silicon Labs does not take a stance on any of them. I do see the "Cute C++ Unit Testing Easier" plugin but I have no idea how good it is or it's ease of use.
I will let update this thread when I have more information.
A project I worked on that used IAR Embedded Workbench made use of Cpputest (http://cpputest.github.io) to test portions of the project.
It required creating "mocks" for a lot of the Gecko SDK code, but it was possible to test functions in individual .C files to ensure that certain inputs resulted in specific outputs.
It gets much more complicated when you're trying to unit tests a program with communication between tasks, but it is good to validate logic in many of the support functions you'll end up writing. If you organize your files well, you can put most of the logic into testable functions/files that don't require much more than the Standard C Library. That leaves simple hardware-specific or RTOS-specific code with minimal logic to test/validate.
Or, mock the hardware/RTOS calls to essentially be no-ops where you configure the return values in the test setup.
All of this runs from gcc on the command-line in the development environment, or on whatever you might use as your CI (continuous integration) platform.
Hi Jui Yen Chua,
I did get some feedback that Unity is used by internally at Silicon Labs. It was suggested that the Unity library can be added to the project and then iostream used to print the Unity results to a console. This definition would help with that:
#define UNITY_OUTPUT_CHAR(a) sl_iostream_putchar(SL_IOSTREAM_STDOUT, a);
Let me know if that helps.