How to use gtest in ardupilot ?

Hi, several days ago,
i watched a commit from peterbarker , which add gtests for snprintf : AP_HAL: add gtests for snprintf · ArduPilot/ardupilot@412bf24 · GitHub

Here is my questions:

How to run gtest in ardupilot in sitl build ?
Where to get the gtest result?

Can someone tell me how, thanks a lot.

OK, so I broke this the other day with a commit which added a compiler
sanity check which the gtest suite fails. I’ll be patching that in the
next day or so.

In the meantime, the addition step you need to take is to comment out the
addition of -Werror=suggest-overrides in Tools/ardupilotwaf/boards.py

Past that, this is how you run the gtests:

./waf configure --board=linux
./waf tests
ls ./build/linux/tests/

pbarker@bluebottle:~/rc/ardupilot(master)$ build/linux/tests/test_math
[==========] Running 10 tests from 3 test cases.
[----------] Global test environment set-up.
[----------] 1 test from VectorTest
[ RUN ] VectorTest.Rotations
[ OK ] VectorTest.Rotations (0 ms)
[----------] 1 test from VectorTest (0 ms total)

[----------] 5 tests from MathTest
[ RUN ] MathTest.IsZero
[ OK ] MathTest.IsZero (0 ms)
[ RUN ] MathTest.IsEqual
[ OK ] MathTest.IsEqual (0 ms)
[ RUN ] MathTest.Square
[ OK ] MathTest.Square (0 ms)
[ RUN ] MathTest.Norm
[ OK ] MathTest.Norm (0 ms)
[ RUN ] MathTest.Constrain
[ OK ] MathTest.Constrain (0 ms)
[----------] 5 tests from MathTest (0 ms total)

[----------] 4 tests from MathWrapTest
[ RUN ] MathWrapTest.Angle180
[ OK ] MathWrapTest.Angle180 (0 ms)
[ RUN ] MathWrapTest.Angle360
[ OK ] MathWrapTest.Angle360 (1 ms)
[ RUN ] MathWrapTest.AnglePI
[ OK ] MathWrapTest.AnglePI (0 ms)
[ RUN ] MathWrapTest.Angle2PI
[ OK ] MathWrapTest.Angle2PI (0 ms)
[----------] 4 tests from MathWrapTest (1 ms total)

[----------] Global test environment tear-down
[==========] 10 tests from 3 test cases ran. (1 ms total)
[ PASSED ] 10 tests.
pbarker@bluebottle:~/rc/ardupilot(master)$

More tests are always welcome :slight_smile:

1 Like

Hi peterbarker, i follow your guide and it work perfectly, thanks a lot.

Just to complement: you can use waf to run the tests: ./waf check (which runs all tests that haven’t run or have failed before) or ./waf check-all (which always runs all tests).

1 Like

got it, thanks for reply.