From 30a73416dcd649f14a3b220753a3248f8495ccc0 Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Thu, 26 Dec 2019 12:36:24 -0500 Subject: [PATCH] mavsdk SITL testing code coverage and upload to codecov.io --- .github/workflows/sitl_tests_coverage.yml | 23 +++++++++++++++++++ CMakeLists.txt | 2 +- Makefile | 10 ++++++-- Tools/setup/requirements.txt | 1 + platforms/posix/cmake/sitl_tests.cmake | 5 +++- platforms/posix/src/px4/common/CMakeLists.txt | 5 ++-- 6 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/sitl_tests_coverage.yml diff --git a/.github/workflows/sitl_tests_coverage.yml b/.github/workflows/sitl_tests_coverage.yml new file mode 100644 index 0000000000..f36cbac6e3 --- /dev/null +++ b/.github/workflows/sitl_tests_coverage.yml @@ -0,0 +1,23 @@ +name: SITL Tests (Code Coverage) + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + container: px4io/px4-dev-simulation-bionic:2019-12-18 + steps: + - uses: actions/checkout@v1 + with: + token: ${{ secrets.ACCESS_TOKEN }} + - name: Set Python 3 as default + run: update-alternatives --install /usr/bin/python python /usr/bin/python3 10 + - name: Install psutil + run: pip3 install psutil + - name: Run simulation tests + run: make tests_integration_coverage + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v1 + with: + token: ${{ secrets.CODECOV_TOKEN }} + flags: mavsdk diff --git a/CMakeLists.txt b/CMakeLists.txt index 27bf218f30..cee32f30bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -358,7 +358,7 @@ endif() # optionally enable cmake testing (supported only on posix) option(CMAKE_TESTING "Configure test targets" OFF) -if (${PX4_CONFIG} STREQUAL "px4_sitl_test") +if(${PX4_CONFIG} STREQUAL "px4_sitl_test") set(CMAKE_TESTING ON) endif() if(CMAKE_TESTING) diff --git a/Makefile b/Makefile index ef1ec29712..ae3750d0e2 100644 --- a/Makefile +++ b/Makefile @@ -357,10 +357,16 @@ tests_coverage: rostest: px4_sitl_default @$(MAKE) --no-print-directory px4_sitl_default sitl_gazebo -tests_integration: px4_sitl gazebo mavsdk_tests -# Missing step: Gazebo model generation +tests_integration: px4_sitl_default + @$(MAKE) --no-print-directory px4_sitl_default sitl_gazebo @"$(SRC_DIR)"/test/mavsdk_tests/mavsdk_test_runner.py --speed-factor 100 +tests_integration_coverage: + @$(MAKE) clean + @$(MAKE) --no-print-directory px4_sitl_default PX4_CMAKE_BUILD_TYPE=Coverage + @$(MAKE) --no-print-directory px4_sitl_default sitl_gazebo PX4_CMAKE_BUILD_TYPE=Coverage + @"$(SRC_DIR)"/test/mavsdk_tests/mavsdk_test_runner.py --speed-factor 20 --iterations 1 --fail-early + tests_mission: rostest @"$(SRC_DIR)"/test/rostest_px4_run.sh mavros_posix_tests_missions.test diff --git a/Tools/setup/requirements.txt b/Tools/setup/requirements.txt index 7c655be500..0908b55e61 100644 --- a/Tools/setup/requirements.txt +++ b/Tools/setup/requirements.txt @@ -6,6 +6,7 @@ matplotlib nose numpy>=1.13 pandas>=0.21 +psutil pyserial>=3.0 pyulog>=0.5.0 pyyaml diff --git a/platforms/posix/cmake/sitl_tests.cmake b/platforms/posix/cmake/sitl_tests.cmake index a0d9ffbea1..755f0fbbc4 100644 --- a/platforms/posix/cmake/sitl_tests.cmake +++ b/platforms/posix/cmake/sitl_tests.cmake @@ -141,7 +141,10 @@ foreach(cmd_name ${test_cmds}) set_tests_properties(posix_${cmd_name} PROPERTIES PASS_REGULAR_EXPRESSION "Shutting down") endforeach() -if (CMAKE_BUILD_TYPE STREQUAL Coverage) +if(CMAKE_BUILD_TYPE STREQUAL Coverage) setup_target_for_coverage(test_coverage "${CMAKE_CTEST_COMMAND} --output-on-failure -T Test" tests) setup_target_for_coverage(generate_coverage "${CMAKE_COMMAND} -E echo" generic) + + # TODO: + #setup_target_for_coverage(mavsdk_coverage "${PX4_SOURCE_DIR}/test/mavsdk_tests/mavsdk_test_runner.py --speed-factor 20 --iterations 1 --fail-early" mavsdk) endif() diff --git a/platforms/posix/src/px4/common/CMakeLists.txt b/platforms/posix/src/px4/common/CMakeLists.txt index 79a9354940..2bc9318cae 100644 --- a/platforms/posix/src/px4/common/CMakeLists.txt +++ b/platforms/posix/src/px4/common/CMakeLists.txt @@ -68,13 +68,12 @@ if(ENABLE_LOCKSTEP_SCHEDULER) endif() -if (EXTRA_DEPENDS) +if(EXTRA_DEPENDS) add_dependencies(px4_layer ${EXTRA_DEPENDS}) endif() -if (BUILD_TESTING) +if(BUILD_TESTING) add_subdirectory(test_stubs) add_subdirectory(gtest_runner) endif() -