Tests

From Eigen
Revision as of 15:49, 31 July 2013 by Hauke (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Prerequisites

First of all, this page applies to the development branch, not 2.0.

You need to know how to use CMake, see our page on that topic.

From now on, we assume that we are in the build directory and that you have already run cmake. There is no need to pass a particular option to CMake to enable tests.

Building and running unit tests

To build and run all tests using CTest, use the check target. For example, if your platform uses make:

 $ make check

This will not send a report to the online dashboard. If you want to do that, see below.

We do not use the "test" target because of a well-documented limitation of CTest (the "test" target does not build the tests).

If you only want to build the tests, not run them, use the buildtests target. For example, with make, do:

 $ make buildtests

Working on one specific test

Each test has its own build target, so for example, for the 'basicstuff' test, you can do:

 $ make basicstuff

Notice that if you want to rebuild a test in debug mode, see below.

Inside each test, each executable (under the default behavior of splitting tests into smaller executables) has its own build target, so for instance you can do:

 $ make basicstuff_2

If you want to run specifically that executable and see its output, run it directly:

 $ test/basicstuff_2

Note that these test executables take optional command-line parameters to control the number of repetitions and the seed. Alternatively, this can be controlled by the environment variables EIGEN_REPEAT and EIGEN_SEED. To get some help, just pass anything on the command line, like 'help':

 $ test/basicstuff_2 help

Filtering tests with regular expressions

We have two scripts for that, directly in your build directory. They currently assume "make" and the Bash shell, feel free to port them to your platform.

To build all tests matching a regular expression pattern, do:

 $ ./buildtests.sh regexp

To build and run all tests matching a regular expression pattern, do:

 $ ./check.sh regexp

Notice that that is the same as doing "./buildtests.sh" followed by "ctest -R".

These scripts honor the EIGEN_MAKE_ARGS and EIGEN_CTEST_ARGS environment variables, allowing to pass arguments to make and ctest. For example, you could put this in your '.bashrc' file, or wherever you put your custom environment variables:

 # The following works with GNU make and lets it use 5 concurrent build jobs:
 export EIGEN_MAKE_ARGS=-j5
 # The following works with CTest >= 2.8 and lets it use 8 concurrent test jobs:
 export EIGEN_CTEST_ARGS=-j8

Build types and debugging

There are 2 build types, Debug and Release.

The default build type is "Release".

If you have a test that fails and want to debug into it, you'll probably have to rebuild it in Debug mode. This is controlled by the standard CMake variable CMAKE_BUILD_TYPE. On Windows/MSVC, this is controlled from within the IDE as usual. Otherwise, we provide scripts for re-running CMake with that variable changed, just do:

 $ ./debug.sh

and

 $ ./release.sh

Note that in Debug mode, optimization is disabled and full debugging info is generated. Tests take a ton of disk space, and a very long time to finish.

Submitting test suite reports to the dashboard

Submissions on Unix Systems

To submit reports to the dashboard:

  • Update your mercurial clone to the desired branch:
 cd path/to/eigen
 hg pull -u

Make sure you are in the branch that you want (hg branch, hg up <branchname>).

  • Configure a build directory with the desired compiler version and cmake options, e.g.:
 mkdir build-XXX
 cd build-XXX
 CXX="g++-4.6" cmake path/to/eigen -DEIGEN_TEST_OPENMP=ON
  • Run ctest with the -D option, e.g.:
 ctest -D Continuous

For a nightly build use Nightly instead of Continuous. It is straightforward to create a shell script automatizing these steps for a couple of different compilers/options.

Submissions on MSVC Systems

To submit reports to the dashboard, checkout/clone Eigen to any folder on your hard disk. Now run CMake to create a build folder and choose a generator of your choice, e.g. 'Visual Studio 11 Win64'.

Now you have to choices. Either open the IDE and build the 'Experimental' target or open a command prompt (e.g. via Start -> Run -> cmd) and change to the build directory in which you have created the build files with CMake. Once you are in the build directory run the following command

  ctest -C Release -D Experimental

or in case you want to trigger just an incremental build run

  ctest --build-noclean -C Release -D Experimental

The tests are build automatically by CTest with the exact configuration you have defined while running CMake. The advantage of running the tests from the command prompt is the possibility to perform incremental builds without a full rebuild which could take up to 3 hours.

Checking your results

Then you can check the results on our dashboard: http://manao.inria.fr/CDash/index.php?project=Eigen

For further information, check theses web pages:

Writing unit tests

If you want to add a simple test of small feature highly related to an existing unit test, then simply extend the existing one. Otherwise, you have to create a new unit test. Let's call it mytest.

  • Create a new file mytest.cpp in the eigen/test (or eigen/unsupported/test) folder.
  • Your file must start by including the file main.h and define a function test_mytest. CMake will take care of letting the main function know that it should call test_mytest(). Do as follows:
  #include <main.h>
  void test_mytest()
  {
    /* ... */
  }
  • If you don't know how to fill the blank, have a look at the other unit test files in eigen/test.
  • Add it to the respective CMakeLists.txt file by adding the line:
  ei_add_test(mytest)

Important: splitting your test into small executables

To limit compiler memory usage and enable more parallel builds, it's good to split tests into smaller executables. It makes the most sense to group together instantiations of the same types, e.g. one executable with MatrixXf, one with Matrix4d, etc... Fortunately, we have infrastructure that makes doing that very easy.

In your test file, just replace CALL_SUBTEST by CALL_SUBTEST_1, CALL_SUBTEST_2, etc... (can go up to 16) and CMake will automatically parse that, create multiple executables, each with only one channel activated. For code that doesn't go through CALL_SUBTEST, you can directly check for this symbol: EIGEN_TEST_PART_i where i=1,2,... and again, CMake parses for that and creates corresponding executables.

See existing test files for examples.

Advanced: optional ei_add_test parameters

The macro ei_add_test takes two optional arguments:

  • The first one specifies additional compile flags.
  • The second one contains the additional libraries to link with.