0
$\begingroup$

I was trying to do the beginner level testing of ROS 2 packages by following the official ROS 2 Documentation, Writing Basic Tests with C++ with GTest, and when I tried to build the package and run the dummy test I am getting the following errors,

details about the package I created : package name : test_package

command I tried to run

colcon build --packages-select test_package

The package got successfully build. and then when I tried the next command given bellow I am getting errors

COMMAND : colcon test --packages-select test_package --ctest-args tests

RESULT

jishnu@Legion:~/testros/workspace$ colcon test --packages-select test_package --ctest-args tests
Starting >>> test_package
--- stderr: test_package                   
Errors while running CTest
Output from these tests are in: /home/jishnu/testros/workspace/build/test_package/Testing/Temporary/LastTest.log
Use "--rerun-failed --output-on-failure" to re-run the failed cases verbosely.
---
Finished <<< test_package [1.41s]       [ with test failures ]

Summary: 1 package finished [1.59s]
  1 package had stderr output: test_package
  1 package had test failures: test_package

COMMAND : colcon test --packages-select test_package --event-handlers console_direct+

RESULT

jishnu@Legion:~/testros/workspace$ colcon test --packages-select test_package --event-handlers console_direct+ 
Starting >>> test_package
UpdateCTestConfiguration  from :/home/jishnu/testros/workspace/build/test_package/CTestConfiguration.ini
Parse Config file:/home/jishnu/testros/workspace/build/test_package/CTestConfiguration.ini
   Site: Legion
   Build name: (empty)
 Add coverage exclude regular expressions.
Create new tag: 20230425-1728 - Experimental
UpdateCTestConfiguration  from :/home/jishnu/testros/workspace/build/test_package/CTestConfiguration.ini
Parse Config file:/home/jishnu/testros/workspace/build/test_package/CTestConfiguration.ini
Test project /home/jishnu/testros/workspace/build/test_package
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 1
    Start 1: test_package_tutorial_test

1: Test command: /usr/bin/python3.10 "-u" "/opt/ros/humble/share/ament_cmake_test/cmake/run_test.py" "/home/jishnu/testros/workspace/build/test_package/test_results/test_package/test_package_tutorial_test.gtest.xml" "--package-name" "test_package" "--output-file" "/home/jishnu/testros/workspace/build/test_package/ament_cmake_gtest/test_package_tutorial_test.txt" "--command" "/home/jishnu/testros/workspace/build/test_package/test_package_tutorial_test" "--gtest_output=xml:/home/jishnu/testros/workspace/build/test_package/test_results/test_package/test_package_tutorial_test.gtest.xml"
1: Test timeout computed to be: 60
1: -- run_test.py: invoking following command in '/home/jishnu/testros/workspace/build/test_package':
1:  - /home/jishnu/testros/workspace/build/test_package/test_package_tutorial_test --gtest_output=xml:/home/jishnu/testros/workspace/build/test_package/test_results/test_package/test_package_tutorial_test.gtest.xml
1: [==========] Running 1 test from 1 test suite.
1: [----------] Global test environment set-up.
1: [----------] 1 test from package_name
1: [ RUN      ] package_name.a_first_test
1: [       OK ] package_name.a_first_test (0 ms)
1: [----------] 1 test from package_name (0 ms total)
1: 
1: [----------] Global test environment tear-down
1: [==========] 1 test from 1 test suite ran. (1 ms total)
1: [  PASSED  ] 1 test.
1: -- run_test.py: return code 0
1: -- run_test.py: inject classname prefix into gtest result file '/home/jishnu/testros/workspace/build/test_package/test_results/test_package/test_package_tutorial_test.gtest.xml'
1: -- run_test.py: verify result file '/home/jishnu/testros/workspace/build/test_package/test_results/test_package/test_package_tutorial_test.gtest.xml'
1/5 Test #1: test_package_tutorial_test .......   Passed    0.09 sec
test 2
    Start 2: cppcheck

2: Test command: /usr/bin/python3.10 "-u" "/opt/ros/humble/share/ament_cmake_test/cmake/run_test.py" "/home/jishnu/testros/workspace/build/test_package/test_results/test_package/cppcheck.xunit.xml" "--package-name" "test_package" "--output-file" "/home/jishnu/testros/workspace/build/test_package/ament_cppcheck/cppcheck.txt" "--command" "/opt/ros/humble/bin/ament_cppcheck" "--xunit-file" "/home/jishnu/testros/workspace/build/test_package/test_results/test_package/cppcheck.xunit.xml" "--include_dirs" "/home/jishnu/testros/workspace/test_package/include"
2: Test timeout computed to be: 300
2: -- run_test.py: invoking following command in '/home/jishnu/testros/workspace/test_package':
2:  - /opt/ros/humble/bin/ament_cppcheck --xunit-file /home/jishnu/testros/workspace/build/test_package/test_results/test_package/cppcheck.xunit.xml --include_dirs /home/jishnu/testros/workspace/test_package/include
2: cppcheck 2.7 has known performance issues and therefore will not be used, set the AMENT_CPPCHECK_ALLOW_SLOW_VERSIONS environment variable to override this.
2: -- run_test.py: return code 0
2: -- run_test.py: verify result file '/home/jishnu/testros/workspace/build/test_package/test_results/test_package/cppcheck.xunit.xml'
2/5 Test #2: cppcheck .........................   Passed    0.23 sec
test 3
    Start 3: lint_cmake

3: Test command: /usr/bin/python3.10 "-u" "/opt/ros/humble/share/ament_cmake_test/cmake/run_test.py" "/home/jishnu/testros/workspace/build/test_package/test_results/test_package/lint_cmake.xunit.xml" "--package-name" "test_package" "--output-file" "/home/jishnu/testros/workspace/build/test_package/ament_lint_cmake/lint_cmake.txt" "--command" "/opt/ros/humble/bin/ament_lint_cmake" "--xunit-file" "/home/jishnu/testros/workspace/build/test_package/test_results/test_package/lint_cmake.xunit.xml"
3: Test timeout computed to be: 60
3: -- run_test.py: invoking following command in '/home/jishnu/testros/workspace/test_package':
3:  - /opt/ros/humble/bin/ament_lint_cmake --xunit-file /home/jishnu/testros/workspace/build/test_package/test_results/test_package/lint_cmake.xunit.xml
3:                                         
3: No problems found
3: -- run_test.py: return code 0
3: -- run_test.py: verify result file '/home/jishnu/testros/workspace/build/test_package/test_results/test_package/lint_cmake.xunit.xml'
3/5 Test #3: lint_cmake .......................   Passed    0.20 sec
test 4
    Start 4: uncrustify

4: Test command: /usr/bin/python3.10 "-u" "/opt/ros/humble/share/ament_cmake_test/cmake/run_test.py" "/home/jishnu/testros/workspace/build/test_package/test_results/test_package/uncrustify.xunit.xml" "--package-name" "test_package" "--output-file" "/home/jishnu/testros/workspace/build/test_package/ament_uncrustify/uncrustify.txt" "--command" "/opt/ros/humble/bin/ament_uncrustify" "--xunit-file" "/home/jishnu/testros/workspace/build/test_package/test_results/test_package/uncrustify.xunit.xml"
4: Test timeout computed to be: 60
4: -- run_test.py: invoking following command in '/home/jishnu/testros/workspace/test_package':
4:  - /opt/ros/humble/bin/ament_uncrustify --xunit-file /home/jishnu/testros/workspace/build/test_package/test_results/test_package/uncrustify.xunit.xml
4: Code style divergence in file 'src/SystemTests.cpp':
4: 
4: --- src/SystemTests.cpp
4: +++ src/SystemTests.cpp.uncrustify
4: @@ -5 +5 @@
4: -    ASSERT_EQ(4, 2 + 2);
4: +  ASSERT_EQ(4, 2 + 2);
4: @@ -8 +8 @@
4: -int main(int argc, char **argv)
4: +int main(int argc, char ** argv)
4: @@ -10,3 +10,3 @@
4: -    testing::InitGoogleTest(&argc, argv);
4: -    return RUN_ALL_TESTS();
4: -}
4: +  testing::InitGoogleTest(&argc, argv);
4: +  return RUN_ALL_TESTS();
4: +}
4: 
4: 1 files with code style divergence
4: -- run_test.py: return code 1
4: -- run_test.py: verify result file '/home/jishnu/testros/workspace/build/test_package/test_results/test_package/uncrustify.xunit.xml'
4/5 Test #4: uncrustify .......................***Failed    0.27 sec
test 5
    Start 5: xmllint

5: Test command: /usr/bin/python3.10 "-u" "/opt/ros/humble/share/ament_cmake_test/cmake/run_test.py" "/home/jishnu/testros/workspace/build/test_package/test_results/test_package/xmllint.xunit.xml" "--package-name" "test_package" "--output-file" "/home/jishnu/testros/workspace/build/test_package/ament_xmllint/xmllint.txt" "--command" "/opt/ros/humble/bin/ament_xmllint" "--xunit-file" "/home/jishnu/testros/workspace/build/test_package/test_results/test_package/xmllint.xunit.xml"
5: Test timeout computed to be: 60
5: -- run_test.py: invoking following command in '/home/jishnu/testros/workspace/test_package':
5:  - /opt/ros/humble/bin/ament_xmllint --xunit-file /home/jishnu/testros/workspace/build/test_package/test_results/test_package/xmllint.xunit.xml
5: File 'package.xml' is valid             
5: 
5: No problems found
5: -- run_test.py: return code 0
5: -- run_test.py: verify result file '/home/jishnu/testros/workspace/build/test_package/test_results/test_package/xmllint.xunit.xml'
5/5 Test #5: xmllint ..........................   Passed    1.60 sec

80% tests passed, 1 tests failed out of 5

Label Time Summary:
cppcheck      =   0.23 sec*proc (1 test)
gtest         =   0.09 sec*proc (1 test)
lint_cmake    =   0.20 sec*proc (1 test)
linter        =   2.30 sec*proc (4 tests)
uncrustify    =   0.27 sec*proc (1 test)
xmllint       =   1.60 sec*proc (1 test)

Total Test time (real) =   2.42 sec

The following tests FAILED:
          4 - uncrustify (Failed)
Errors while running CTest
Output from these tests are in: /home/jishnu/testros/workspace/build/test_package/Testing/Temporary/LastTest.log
Use "--rerun-failed --output-on-failure" to re-run the failed cases verbosely.
--- stderr: test_package
Errors while running CTest
Output from these tests are in: /home/jishnu/testros/workspace/build/test_package/Testing/Temporary/LastTest.log
Use "--rerun-failed --output-on-failure" to re-run the failed cases verbosely.
---
Finished <<< test_package [5.11s]       [ with test failures ]

Summary: 1 package finished [5.29s]
  1 package had stderr output: test_package
  1 package had test failures: test_package

Is there a way to by pass this system generated test and only conduct the custom tests provided in the test file?

$\endgroup$
5
  • $\begingroup$ You can run the test_package_tutorial_test binary (not using colcon) which only executes your GoogleTest. $\endgroup$
    – Bi0T1N
    Commented Apr 27, 2023 at 7:10
  • $\begingroup$ How to run only the binary ? Is it by using ros2 run? $\endgroup$
    – Jishnu
    Commented Apr 27, 2023 at 10:47
  • $\begingroup$ Also, I have tried formatting the file containing the cpp code for the GTest according to the uncrustify code beautifier formatting. I don't quite understand why that error still prevails. $\endgroup$
    – Jishnu
    Commented Apr 27, 2023 at 10:52
  • $\begingroup$ Run the binary with ./home/jishnu/testros/workspace/build/test_package/test_package_tutorial_test, it's listed in your result output above in step 1. The additional --gtest_output flag specifies to generate a XML report (see google.github.io/googletest/…) $\endgroup$
    – Bi0T1N
    Commented Apr 27, 2023 at 14:20
  • $\begingroup$ Okay, Thank you! I will try that way. $\endgroup$
    – Jishnu
    Commented Apr 28, 2023 at 3:36

1 Answer 1

0
$\begingroup$

I have found out the solution for this, the system tests are coming from the automatically generated boiler plate code during ros2 pkg create used to create a ROS 2 package.

Below given is the BUILD_TESTING part of the boiler plate code

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # comment the line when a copyright and license is added to all source files
  set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # comment the line when this package is in a git repo and when
  # a copyright and license is added to all source files
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

In the above code the last two lines, are responsible for including the cpp_lint tests, and commenting it out solved my issue.

set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()

I still wonder, why the error still prevailed even after formatting the problematic code according to the code formats.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.