Extend XSDK for Test-Driven-Development

This is a description how to use ceedling and doxygen within the Xilinx XSDK for TDD.

 

Install ceedling


Ceedling is based on ruby. Ruby in versionm 1.9.2 is recommended by throwtheswitch

gem install ceedling

or if you want to install into your local home:

gem install –user-install ceedling export PATH=$PATH:/PATH_TO_HOME/.gem/ruby/1.8/bin

Download the gcovr script and place it somewhere, where it can be executed

cd ~/bin
wget https://raw.githubusercontent.com/gcovr/gcovr/master/scripts/gcovr
chmod +x gcovr

 

Install Eclipse Plugins


 Install eclox doxygen plugin

(XSDK) Help -> Install New Software…

Enter http://anb0s.github.io/eclox and install eclox, Eclox Doxygen and Doxygen binaries

C/C++ Unit Testing Support

XSDK 2017.2 uses the Eclipse Neon version, so the following path for installing new software has to be added:

Neon - http://download.eclipse.org/releases/neon

Loading all package sources may take some time.

Search for C/C++ Unit Testing Support

gcov code coverage

in Neon - http://download.eclipse.org/releases/neon

Search for gcov

Install Eclipse Marketplace (optional)

in Neon - http://download.eclipse.org/releases/neon

Search for Marketplace Client

 

Configuration Settings


 Configure Doxygen

In XSDK, select > File -> New -> Application Project to generate a new HelloWolrd project.

Select the @ Symbol and select Build Doxyfile…. The doxygen configuration file can now be added by the GUI. The documentation can now be build.

If the build fails, doxygen is not installed on the system. Select > Window -> references -> Doxygen and select the Bundled version, which was installed with the eclipse plugin. This is recommended in general, as the bundled version is always the newest one.

 eclox_config

Configure ceedling

The original description, how to install ceedling for eclipse can be found here. Moreover, there are good tipps to generate unit tests faster.

Make sure you have selected the project folder, that you want to use. Then select > Run -> Run Configurations … and double click C/C++ Unit.

The conifguration settings have to be set in the following way:

ceedling_config1

ceedling_config2

ceedling_config3ceedling_config4

THEN CLICK APPLY, NOT RUN!

Generate Ceedling Configuration

After creating a new HelloWolrd project, move to the eclipse workspace folder with a bash. Then execute

ceedling new <PROJECT_FOLDER_NAME>

Thus, the ceedling folder structure and the files for testing were created.

  • build/
  • src/
  • test/
  • vendor/
  • project.yml

To make ceedling compatible with the Xilinx XSDK, some adaptions on the project.yml are helpful:

mkdir ceedling_build

...

:build_root: ceedling_build

...

:gcov:
   :html_report_type: detailed

...

:plugins:
   :enabled:
      #- stdout_pretty_tests_report
      - stdout_gtestlike_tests_report
      - module_generator
      - gcov

...

To create a FILENAME.h, and a FILENAME.c in src/ and a test_FILENAME.c in test/, go to the
main folder of the Application Project and type

ceedling module:create[FILENAME]

The folder build can now be removed. In XSDK, select the folders
ceedling_build, test and vendor and do a right click to select
-> Resource Configurations -> Exclude from Build…

 

Results


 

Unit Tests

After all configuration steps, you can build the project as usual again. To run a unit test, go to the Run Configrations and select the before added PROJECT_NAME Unit Testing and click run.

ceedling_tests

Code Coverage

Under ceedling_build/gcov/out the built files of gcov can be found. To watch the results in the XSDK GUI, double click on the test_platform.gcda. Then the following window should appear:

gcov_settings

Here the binary file ceedling_build/gcov/out/test_platform.out sould be selected and the bullet Show coverage for the whole selected binary file should be enabled.

As a result, you can see the code coverage of the different files during the unit tests. To get a good code quality, it is important that all source files have a high code coverage rates.

gcov_result

For normal applications using gcov in eclipse, it is possible to double click on a file in the gcov window to get code highlighting within the eclipse editor. However, this feature does not work yet when selecting the binary manually.

However, the highlighted source code can be viewed by an external browser, since gcovr provides code coverage statistics in html located in ceedling_build/artifacts/gcov.

Doxygen

The doxygen configuration PROJECTNAME.doxyfile can now be edited in the XSDK GUI. By default, doxygen generates the folder html, where the main file index.html is located. Depending on several system configurations, it might be useful to open the resulting documentation in an external browser.

FAQs and Errors

Version of ruby or gem is too old on cae00:

/home.local/steff/.gem/ruby/1.8/gems/ceedling-0.28.2/bin/ceedling:211: undefined method `exists?' for Dir:Class (NoMethodError) from /home.local/steff/.gem/ruby/1.8/bin/ceedling:19:in `load' from /home.local/steff/.gem/ruby/1.8/bin/ceedling:19

Further Tutorials and Links

Tutorial

Mocking Example

Advanced Embedded C Programming with Ceedling