Cross-compiling unit tests using CppUnit or similar

Has anyone used a package like CppUnit to cross-compile C ++ unit tests to run on an embedded platform?

I use g ++ in a Linux box to compile executables that should run on the LynxOS board. It seems I can’t get any of the common unit test packages to configure and build something that will create unit tests.

I see a lot of unit test, CppUnit, UnitTest ++, GTest, CppUTest, etc. packages, but very little about using these packages in a cross-compiler script. Those with a β€œconfigure” script mean that this is possible, but I cannot get them to configure and build.

+7
c ++ unit-testing cross-compiling
source share
6 answers
./configure --prefix=/sandBox --build=`config.guess` --host=sh4-linux 

sh4-linux is the platform on which you want to run the program.

+3
source share

You can watch CxxTest . I did not use it for cross-compilation, but it is completely based on headers and a Python script - not a compiled library. It may be easier to adapt than others.

+2
source share

My practice, when the unit testing code that is compiled, is to compile the unit tests themselves with the built-in toolchain - usually some kind of x86 compiler flavor. These unit tests are performed on a prefabricated machine, not on an integrated target. If you write rigorous unit tests (as opposed to integration tests) with stubs and mockups, you should not have a dependency on embedded hardware. If not ... it's never too late to start.

One of the advantages of this approach is that for built-in purposes other than x86, this type of unit testing helps eliminate content problems, uninitialized variables, and other interesting errors.

+2
source share

I do not provide an answer here, but I would not advise NOT to run your unit tests for different purposes: you still need to, preferably both system and unit tests.

Otherwise, simple things like alignment errors on ARM / other embedded CPUs will not be caught.

0
source share

It looks like you need to have a unit test library compiled for your OS and architecture, as well as what's on your dev / build machines (s). For this, I prefer the Boost ++ unit test. You can either download something that was created for your architecture, but as a rule, you will have to compile it yourself. I found several search engine optimization solutions in order to compile boost (e.g. http://goodliffe.blogspot.com/2008/05/cross-compiling-boost.html ). CppUnit may be easier to compile, have not tried. The general principle is the same, you are compiling the same version of the library for your development architecture and for your target machine.

My setup for new purposes is to compile the necessary Boost ++ libraries for my target OS / arch, and then to write tests to link with both the Boost ++ libraries and the test code.

The advantage is that you can associate yourself with your x86 Linux Boost ++ libs or against your target Boost ++ libs, so you can run tests on your target as well as on your dev / build machines.

My general setup is as follows:

 libs/boost/<arch>/<boost libs> src/foo.{cpp,h} tests/test_foo.cpp build/foo build/test_foo.<arch> 

I put the compiled Boost ++ libs into different architectures that I need in libs / dir for all my projects, and reference these libraries in my Makefiles. The source and tests get the assembly with the arch variable specified for the command, so I can run test_foo.x86 on my dev and test_foo machines. {Arm, mips, ppc, etc.} For my purposes.

0
source share

To cross compile CppUTest (v3.3), I had to override the LD, CXX, and CC make variables.

To get the CppUTest and CppUTestExt libraries (for CppUMock) and their tests, I used the following commands from the CPPUTEST_HOME directory:

To create libCppUTest.a:

 make all LD=sh4-linux-g++ CXX=sh4-linux-g++ CC=sh4-linux-gcc 

To create libCppUTestExt.a (for CppUMock):

 make extensions LD=sh4-linux-g++ CXX=sh4-linux-g++ CC=sh4-linux-gcc 

You can then copy the executables CppUTest_tests and CppUTestExt_tests created in your CPPUTEST_HOME to your target device and execute them there.

Assuming CppUTest passes your own tests to your target, you are ready to develop your tests with CppUTest. Just link your test code to the cross-compiled CppUTest libraries and copy the resulting executable to your target. Then run to get unit test results from the target platform.

0
source share

All Articles