Porting Cppunit to Tensilica Xtensa Processors


As CppUnit is a popular C++ unit testing framework. This page is created to explain how to porting CppUnit to Xtensa Processor.
I create this page for developers who have the same porting requirement. I have spent 2 working days for this porting work and writing this document.

CppUnit Download

Download cppunit-1.12.0.tar.gz from SourceForge download page.
Unzip the source code with command:

tar -zxvf cppunit-1.12.0.tar.gz .

Modify CppUnit

  • As we have the exception flag problem1 for Xtensa compiler, we need to add the -fexceptions flag to the configure command in the next section.
  • src/DllPlugInTester, src/qttestrunner and src/msvc6. We know that all these three functions are not designed for embedded systems. In the next section, I just use some ugly methods to avoid errors about these source codes. If you have better ideas, please email me.

Configure and Compile CppUnit

Before we configure the CppUnit, we should make sure that the xtensa tool-chain is accessible.

./configure LD=xt-ld CXX=xt-xc++ CC=xt-xcc CXXFLAGS="-g -O2 -fexceptions" --host=xtensa --disable-shared

Oops, We get several errors about DllPlugInTester. Don't worry, we already finish the most important CppUnit compilation. Let's get the CppUnit library.
cp src/cppunit/.libs/libcppunit.a lib/

Test CppUnit Library

Should we test the library? Sure, let's do it. We can use the existed money example to test our library.

cd examples/money/
xt-xc++ MoneyApp.cpp MoneyTest.cpp -I. -I../../include -lcppunit -L../../lib -fexceptions
xt-run ./a.out

Congratulation, you can see four dot and "OK (4)". That means your CppUnit library is working. Now, you can design your unit test vectors and test your system.
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License