Skip to content

Commit 67e3455

Browse files
canard/tests: add run_test.sh
1 parent 537e978 commit 67e3455

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

canard/tests/run_test.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
# # This script runs the unit tests for the library.
4+
# # build native bit version
5+
# cmake $* -S . -B build && cmake --build build || exit 1
6+
# # run tests
7+
# pushd build/
8+
# ctest || exit 1
9+
# popd
10+
11+
function run_cmake() {
12+
# # remove build directory if it exists
13+
# rm -rf build
14+
# # make build directory
15+
# mkdir build
16+
# echo with highlighted text
17+
echo -e "\e[1;32mRunning cmake with options: $*\e[0m"
18+
cmake $* -S . -B build || exit 1
19+
pushd build/
20+
make || exit 1
21+
ctest || exit 1
22+
# also run the coverage if coverage is enabled
23+
if [[ $* == *-DCANARD_ENABLE_COVERAGE=1* ]]; then
24+
echo -e "\e[1;32mRunning coverage test\e[0m"
25+
make coverage || exit 1
26+
# copy and merge the coverage.info file to ../coverage.info if it exists
27+
if [ -f ../coverage.info ]; then
28+
echo -e "\e[1;32mMerging coverage.info to ../coverage.info\e[0m"
29+
lcov --add-tracefile coverage.info --add-tracefile ../coverage.info --output-file ../coverage.info
30+
else
31+
echo -e "\e[1;32mCopying coverage.info to ../coverage.info\e[0m"
32+
cp coverage.info ../coverage.info
33+
fi
34+
# print the coverage
35+
echo -e "\e[1;32mCoverage:\e[0m"
36+
lcov --list ../coverage.info
37+
fi
38+
popd
39+
}
40+
41+
OPTIONS=( CMAKE_32BIT CANARD_ENABLE_CANFD CANARD_ENABLE_DEADLINE CANARD_MULTI_IFACE )
42+
43+
# if no argument is given, run all possible combinations
44+
if [ $# -eq 0 ]; then
45+
# remove existing coverage report
46+
rm -f coverage.info
47+
for (( i = 0; i < 2 ** ${#OPTIONS[@]}; i++ )); do
48+
OPTS=""
49+
for (( j = 0; j < ${#OPTIONS[@]}; j++ )); do
50+
if [ $(( i & ( 1 << j ) )) -ne 0 ]; then
51+
OPTS="$OPTS -D${OPTIONS[j]}=1"
52+
fi
53+
done
54+
run_cmake -DCANARD_ENABLE_COVERAGE=1 $OPTS
55+
done
56+
else
57+
run_cmake $*
58+
fi
59+

0 commit comments

Comments
 (0)