Unit tests required anywhere?

I’m looking to refresh my unit testing skills. Can core developers comment if there are any modules/libraries etc in PX4 repository I could start adding unit tests to? My preference is to use CPPunit unless GoogleTest is already being used in the codebase.

Google Test is already being used. So just where it can further be used?

There are unit tests, integration tests. Feel free to add tests wherever you see the need.

I don’t think the test framework matters in this case. As long as there are conditions being checked, that’s a test.

Ok. I wanted to chew something small, so tried adding tests to src/drivers/gps, src/examples/hello_world and /src/examples/hello.
Because of the CMake dependencies(use of px4_add_module that didn’t work as expected:
CMake Error at CMakeLists.txt:49 (px4_add_git_submodule):
Unknown CMake command “px4_add_git_submodule”.
) that I’m still figuring out, please suggest some self contained ‘CMake projects’, if any, as good starting points in the repository. Thank you.

Looking at the root CMakeLists.txt:

# optionally enable cmake testing (supported only on posix)
option(CMAKE_TESTING "Configure test targets" OFF)
if(${PX4_CONFIG} STREQUAL "px4_sitl_test")
        set(CMAKE_TESTING ON)
endif() 
if(CMAKE_TESTING)
        include(CTest) # sets BUILD_TESTING variable
endif()

I tried to build using make px4_sitl_test but the build failed with the following error:


CMake Error at build/px4_sitl_test/_deps/googletest-src/googletest/cmake/internal_utils.cmake:159 (add_library):
  add_library cannot create target "gtest" because another target with the
  same name already exists.  The existing target is a static library created
  in source directory
  "/Users/suc/PX4-Autopilot-unittests/build/px4_sitl_test/googletest-src/googletest".
  See documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  build/px4_sitl_test/_deps/googletest-src/googletest/cmake/internal_utils.cmake:213 (cxx_library_with_type)
  build/px4_sitl_test/_deps/googletest-src/googletest/CMakeLists.txt:126 (cxx_library)


CMake Error at build/px4_sitl_test/_deps/googletest-src/googletest/cmake/internal_utils.cmake:159 (add_library):
  add_library cannot create target "gtest_main" because another target with
  the same name already exists.  The existing target is a static library
  created in source directory
  "/Users/suc/PX4-Autopilot-unittests/build/px4_sitl_test/googletest-src/googletest".
  See documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  build/px4_sitl_test/_deps/googletest-src/googletest/cmake/internal_utils.cmake:213 (cxx_library_with_type)
  build/px4_sitl_test/_deps/googletest-src/googletest/CMakeLists.txt:144 (cxx_library)


CMake Error at build/px4_sitl_test/_deps/googletest-src/googletest/CMakeLists.txt:161 (target_link_libraries):
  Attempt to add link library "gtest" to target "gtest_main" which is not
  built in this directory.

  This is allowed only when policy CMP0079 is set to NEW.


CMake Error at build/px4_sitl_test/_deps/googletest-src/googletest/cmake/internal_utils.cmake:159 (add_library):
  add_library cannot create target "gmock" because another target with the
  same name already exists.  The existing target is a static library created
  in source directory
  "/Users/suc/PX4-Autopilot-unittests/build/px4_sitl_test/googletest-src/googlemock".
  See documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  build/px4_sitl_test/_deps/googletest-src/googletest/cmake/internal_utils.cmake:213 (cxx_library_with_type)
  build/px4_sitl_test/_deps/googletest-src/googlemock/CMakeLists.txt:97 (cxx_library)


CMake Error at build/px4_sitl_test/_deps/googletest-src/googlemock/CMakeLists.txt:98 (target_link_libraries):
  Attempt to add link library "gtest" to target "gmock" which is not built in
  this directory.

  This is allowed only when policy CMP0079 is set to NEW.


CMake Error at build/px4_sitl_test/_deps/googletest-src/googletest/cmake/internal_utils.cmake:159 (add_library):
  add_library cannot create target "gmock_main" because another target with
  the same name already exists.  The existing target is a static library
  created in source directory
  "/Users/suc/PX4-Autopilot-unittests/build/px4_sitl_test/googletest-src/googlemock".
  See documentation for policy CMP0002 for more details.
Call Stack (most recent call first):
  build/px4_sitl_test/_deps/googletest-src/googletest/cmake/internal_utils.cmake:213 (cxx_library_with_type)
  build/px4_sitl_test/_deps/googletest-src/googlemock/CMakeLists.txt:100 (cxx_library)


CMake Error at build/px4_sitl_test/_deps/googletest-src/googlemock/CMakeLists.txt:101 (target_link_libraries):
  Attempt to add link library "gmock" to target "gmock_main" which is not
  built in this directory.

  This is allowed only when policy CMP0079 is set to NEW.

Any pointers how to resolve this? As a user, I expected this to build flawlessly unless I missed any steps. I followed instructions at: MacOS Development Environment | PX4 Guide (main)
Building PX4 Software | PX4 Guide (main)