Skip to content

Commit

Permalink
Test coverage reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
teapotd committed Nov 18, 2023
1 parent 9610c86 commit ec5339e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
4 changes: 3 additions & 1 deletion tests/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -e
ROOT=`pwd`

if [ $# -ne 2 ]; then
echo "usage: ./build.sh [b|d] [path to cpp file]"
echo "usage: ./build.sh [b|d|c] [path to cpp file]"
exit 1
fi

Expand All @@ -20,6 +20,8 @@ if [ $1 = "b" ]; then
FLAGS+=" -O2"
elif [ $1 = "d" ]; then
FLAGS+=" -O0 -g -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2 -fsanitize=address,undefined"
elif [ $1 = "c" ]; then
FLAGS+=" -O0 --coverage"
else
echo "usage: ./build.sh [b|d] [path to cpp file]"
exit 1
Expand Down
5 changes: 5 additions & 0 deletions tests/clear-coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash
set -e -o pipefail

find ../build/tests/ -name '*.gcda' -delete -or -name '*.gcno' -delete
find ../build/tests/ -name '*.gcda' -or -name '*.gcno'
13 changes: 10 additions & 3 deletions tests/own/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -e -o pipefail

if [ $# -lt 3 ]; then
echo "usage: ./test.sh [b|d] [deterministic|fuzz|bench] [files...]"
echo "usage: ./test.sh [b|d|c] [deterministic|fuzz|bench] [files...]"
exit 1
fi

Expand All @@ -11,7 +11,10 @@ TEST_MODE=$2
FILES=$(find ${@:3} -name '*.cpp' | sort)

cd ..
ROOT=`pwd`

if [ $BUILD_MODE = "c" ]; then
./clear-coverage.sh
fi

for CPP_FILE in $FILES; do
echo
Expand All @@ -20,5 +23,9 @@ for CPP_FILE in $FILES; do
echo ================================================================
./build.sh $BUILD_MODE own/$CPP_FILE
echo start
time $ROOT/../build/tests/own/$CPP_FILE.e $TEST_MODE
time ../build/tests/own/$CPP_FILE.e $TEST_MODE
done

if [ $BUILD_MODE = "c" ]; then
./report-coverage.sh
fi
7 changes: 7 additions & 0 deletions tests/report-coverage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
set -e -o pipefail

mkdir -p ../build/coverage
gcovr --root ../src/ --object-directory ../build/ \
--html-details ../build/coverage/index.html \
--html-tab-size=2 --merge-mode-functions=separate
10 changes: 9 additions & 1 deletion tests/yosupo/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -e -o pipefail

if [ $# -lt 2 ]; then
echo "usage: ./test.sh [b|d] [files...]"
echo "usage: ./test.sh [b|d|c] [files...]"
exit 1
fi

Expand All @@ -12,6 +12,10 @@ FILES=$(find ${@:2} -name '*.cpp' | sort)
cd ..
ROOT=`pwd`

# if [ $BUILD_MODE = "c" ]; then
# ./clear-coverage.sh
# fi

for CPP_FILE in $FILES; do
echo
echo ================================================================
Expand Down Expand Up @@ -44,3 +48,7 @@ for CPP_FILE in $FILES; do
fi
done
done

if [ $BUILD_MODE = "c" ]; then
./report-coverage.sh
fi

0 comments on commit ec5339e

Please sign in to comment.