User Tools

Site Tools


for_developers:testing

Testing

We use Google Test as our test framework. Read https://github.com/google/googletest/blob/master/googletest/docs/primer.md to understand how to use the available macros for defining test cases.

Naming

All the tests must be named in the following manner.

TEST(testName, testMethodName) { ... }

testName should include the name of the package, e.g. controlDeMuxBlock or safetyEventTest. This allows for running only the tests in a certain package. testMethodName can be any meaningful name to identify the test method.

Running the Tests

Make sure to compile the unit tests with the cmake argument -DUSE_TESTS=TRUE. Navigate to the directory test of the build directory of eeros and run the tests as follows.:

$ ./unitTests  --library sim                  // run all the tests using the simulator as hal
$ ./unitTests  -l sim                         // run all the tests using the simulator, short option
$ ./unitTests  -l flink                       // run all the tests using flink, short option
$ ./unitTests  -l comedi                      // run all the tests using comedi, short option
$ ./unitTests  --gtest_filter=control*        // run all the tests in control
$ ./unitTests  --gtest_filter=math*           // run all the tests in math
$ ./unitTests  --gtest_filter=mathMatrix*     // run all the tests in math/Matrix
$ ./unitTests  --gtest_filter=-hal*           // run all the tests without hal
$ ./unitTests  -l sim --gtest_filter=hal*     // run all the tests in hal using the simulator

For the test with the HAL you need to install the simulator and set the library path (see Deploying) so that the simulator library can be found.

Suppress Logger Output

We do not want to mangle output from control blocks or from the safety system with output from the testing framework. If you test a component which uses the logger framework, make sure to set the default stream logger and to set 'cout' to 'failed' state. This will prevent output to be written to the log.

std::cout.setstate(std::ios_base::badbit);
eeros::logger::Logger::setDefaultStreamLogger(std::cout);
for_developers/testing.txt · Last modified: 2021/05/25 14:11 by ursgraf