Unit Testing with the Firmware Module System

Writing unit tests with the Firmware Module System is a powerful and easy way to increase your project's quality level.  Unit tests are run directly on your embedded target during the build flow when 'fm test' is invoked.

The TestSupport and Test modules in the fm.test package, supplied by the FM_Test Module, handle the setup of test application environment and provide a unit test framework.  The unit test framework allows the test developer to write small, focused test functions called Test Cases and organize them into Test Suites.  The test cases can leverage any target-domain content - typically firmware functions and libraries that comprise the project.

A test runner is supplied with the Test module and will run all of the test cases that you have specified in the test application config file (e.g. tests.cfg).  Your test results will be shown on the console at build/test time, and failures will output detailed messages indicating the mode and location of the failure.

The following steps summarize the unit test creation process in the Firmware Module System.

  1. Create a new package to host the tests.  On the command line, use the package creation template: 'fm xs fm.core.tools.mkpkg tests'.  This will create a package called 'tests' under Internal\packages.
  2. In the package's package.bld, uncomment the section pertaining to the TestSupport module.
  3. Create a unit test source file, e.g. 'tests.c'. 
  4. In your unit test source file, include

    #include <fm/test/Test.h>

  5. Create your test cases by adding functions of the following form: Test_CASE(SuiteName, CaseName) { ... arbitrary 'c' code...  }

  6. Add assert statements to your Test_CASEs.  The asserts are described in the fm.test.Test.xdc module documentation.  Common assert statements include Test_ASSERT_TRUE(condition); or Test_ASSERT_EQ(expected, actual);
  7. In your package.bld, add your test source files to the list of sources passed into TestSupport.buildTests(). 
  8. In your tests.cfg, specify the test cases you want to be run by passing an array of "<suite name> <case name>" strings to the Tests.addTests() function like this: var Test = xdc.useModule("fm.test.Test");
    var testList = [ 'SuiteName1 TestCase1', 'SuiteName1 TestCase2',  'SuiteName2 TestCase1', 'SuiteName2 TestCase2',];  Test.addTests(testList);
  9. Ensure your supported embedded target is connected to your PC and invoke 'fm test'.
  10. The test run results will show on your console in real-time as in this example:


  • There are no comments yet. Be the first one to post a comment on this article!

Leave a comment

Please note, comments must be approved before they are published