Skip to content

Commit

Permalink
adding coverage to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
klaxalk committed Nov 28, 2023
1 parent 207f524 commit 398e293
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ target_link_libraries(MrsUavManagers_TransformManager

if(CATKIN_ENABLE_TESTING)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")

add_subdirectory(test)

endif()
Expand Down
4 changes: 3 additions & 1 deletion test/all_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ VERBOSE=1

# build the package
catkin build $PACKAGE # it has to be fully built normally before building with --catkin-make-args tests
catkin build $PACKAGE --catkin-make-args tests
catkin build $PACKAGE --no-deps --catkin-make-args tests

TEST_FILES=$(find . -name "*.test" -type f -printf "%f\n")

for TEST_FILE in `echo $TEST_FILES`; do

echo "$0: running test '$TEST_FILE'"

# folder for test results
TEST_RESULT_PATH=$(realpath /tmp/$RANDOM)
mkdir -p $TEST_RESULT_PATH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ mrs_uav_managers:

MpcController:
eland_threshold: 0.0 # [m], position error triggering eland
failsafe_threshold: 0.2 # [m], position error triggering failsafe land
failsafe_threshold: 0.1 # [m], position error triggering failsafe land
odometry_innovation_threshold: 0.0 # [m], position odometry innovation threshold
12 changes: 12 additions & 0 deletions test/coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

cd ~/hw_api/test_workspace/build

lcov --capture --directory . --output-file coverage.info
lcov --remove coverage.info "*/test/" --output-file coverage.info.removed
lcov --extract coverage.info.removed "*/*workspace/*" --output-file coverage.info.cleaned
genhtml -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"
4 changes: 2 additions & 2 deletions test/single_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ VERBOSE=1

# build the package
catkin build $PACKAGE # it has to be fully built normally before building with --catkin-make-args tests
catkin build $PACKAGE --catkin-make-args tests
catkin build $PACKAGE --no-deps --catkin-make-args tests

# folder for test results
TEST_RESULT_PATH=$(realpath /tmp/$RANDOM)
mkdir -p $TEST_RESULT_PATH

# run the test
rostest $PACKAGE uav_manager_takeoff.test $TEXT_OUTPUT --results-filename=$PACKAGE.test --results-base-dir="$TEST_RESULT_PATH"
rostest $PACKAGE control_manager_eland_control_error.test $TEXT_OUTPUT --results-filename=$PACKAGE.test --results-base-dir="$TEST_RESULT_PATH"

# evaluate the test results
echo test result path is $TEST_RESULT_PATH
Expand Down

0 comments on commit 398e293

Please sign in to comment.