From 6eaefc959d9de66ca5ee69e8a9c9f7bd57fd7ac9 Mon Sep 17 00:00:00 2001 From: Tomas Baca Date: Fri, 9 Feb 2024 09:42:14 +0100 Subject: [PATCH] updated test format --- CMakeLists.txt | 6 ++++-- test/all_tests.sh | 34 ---------------------------------- test/compile_tests.sh | 2 +- test/gather_coverage.sh | 25 +++++++++++++++++++++++++ test/run_tests.sh | 8 ++++++++ 5 files changed, 38 insertions(+), 37 deletions(-) delete mode 100755 test/all_tests.sh create mode 100755 test/gather_coverage.sh create mode 100755 test/run_tests.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 95bff21..28d4b0d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) add_definitions(-Wall) add_definitions(-Wextra) -if(NOT TESTING) +if(NOT MRS_ENABLE_TESTING) message(WARNING "relwithdebinfo profile detected, building with -O3") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -O3") endif() @@ -451,7 +451,9 @@ target_link_libraries(uvdar_led_manager_node ## | Testing | ## -------------------------------------------------------------- -if(CATKIN_ENABLE_TESTING) +if(CATKIN_ENABLE_TESTING AND MRS_ENABLE_TESTING) + + message(WARNING "Testing enabled.") add_subdirectory(test) diff --git a/test/all_tests.sh b/test/all_tests.sh deleted file mode 100755 index 6614ec3..0000000 --- a/test/all_tests.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -set -e - -trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG -trap 'echo "$0: \"${last_command}\" command failed with exit code $?"' ERR - -ORIGINAL_PATH=`pwd` - -while [ ! -e ".catkin_tools" ]; do - cd .. - if [[ `pwd` == "/" ]]; then - # we reached the root and didn't find the build/COLCON_IGNORE file - that's a fail! - echo "$0: could not find the root of the current workspace". - return 1 - fi -done - -cd build - -OLD_FILES=$(find . -name "*.gcda") - -for FILE in $OLD_FILES; do - echo "$0: removing old coverage file '$FILE'" - rm $FILE -done - -cd $ORIGINAL_PATH - -# build the package -catkin build --this # it has to be fully built normally before building with --catkin-make-args tests -catkin build --this --no-deps --catkin-make-args tests - -catkin test --this -i -p 1 -s diff --git a/test/compile_tests.sh b/test/compile_tests.sh index 999699e..efbc058 100755 --- a/test/compile_tests.sh +++ b/test/compile_tests.sh @@ -7,4 +7,4 @@ trap 'echo "$0: \"${last_command}\" command failed with exit code $?"' ERR # build the package catkin build --this # it has to be fully built normally before building with --catkin-make-args tests -catkin build --this --no-deps --catkin-make-args tests +catkin build --this -DMRS_ENABLE_TESTING=1 --no-deps --catkin-make-args tests diff --git a/test/gather_coverage.sh b/test/gather_coverage.sh new file mode 100755 index 0000000..27404da --- /dev/null +++ b/test/gather_coverage.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +while [ ! -e ".catkin_tools" ]; do + cd .. + if [[ `pwd` == "/" ]]; then + # we reached the root and didn't find the build/COLCON_IGNORE file - that's a fail! + echo "$0: could not find the root of the current workspace". + return 1 + fi +done + +WORKSPACE_NAME=${PWD##*/} + +cd build + +lcov --capture --directory . --output-file coverage.info +lcov --remove coverage.info "*/test/*" --output-file coverage.info.removed +lcov --extract coverage.info.removed "*/${WORKSPACE_NAME}/src/*" --output-file coverage.info.cleaned +genhtml --title "MRS UAV System - Test coverage report" --demangle-cpp --legend --frames --show-details -o coverage_html coverage.info.cleaned | tee /tmp/genhtml.log + +COVERAGE_PCT=`cat /tmp/genhtml.log | tail -n 1 | awk '{print $2}'` + +echo "Coverage: $COVERAGE_PCT" + +xdg-open coverage_html/index.html diff --git a/test/run_tests.sh b/test/run_tests.sh new file mode 100755 index 0000000..6f0fb27 --- /dev/null +++ b/test/run_tests.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +set -e + +trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG +trap 'echo "$0: \"${last_command}\" command failed with exit code $?"' ERR + +catkin test --this -i -p 1 -s