-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunit_test.sh
More file actions
70 lines (62 loc) · 1.97 KB
/
unit_test.sh
File metadata and controls
70 lines (62 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
ENABLE_COV=true
if [ "x${1:-}" = "x--disable-cov" ]; then ENABLE_COV=false; fi
TOP_DIR=$(pwd)
HELPER_SRC_DIR="${HELPER_SRC_DIR:-../reboot-helper/src}"
FETCHER_SRC_DIR="${FETCHER_SRC_DIR:-../reboot-reason-fetcher/src}"
cd unittest/
if [ -f Makefile ]; then
make distclean || make clean || true
fi
automake --add-missing || true
autoreconf --force --install
./configure
if [ "$ENABLE_COV" = true ]; then
export CXXFLAGS="-g -O0 -fprofile-arcs -ftest-coverage"
export CFLAGS="-g -O0 -fprofile-arcs -ftest-coverage"
export LDFLAGS="-lgcov --coverage"
fi
make clean
## Remove stale coverage data to avoid gcov timestamp errors
find . -name '*.gcda' -delete || true
find ../src -name '*.gcda' -delete || true
make -j$(nproc || echo 2)
fail=0
for test in \
./reboot_utils_gtest \
./reboot_cyclic_gtest \
./reboot_system_gtest \
./reboot_main_gtest \
./reboot_json_gtest \
./reboot_parodus_gtest \
./reboot_log_parser_gtest \
./reboot_classify_gtest \
./rebootreason_main_gtest
do
echo "Running $test"
$test || fail=1
done
if [ $fail -ne 0 ]; then
echo "Some unit tests failed."
exit 1
fi
if [ "$ENABLE_COV" = true ]; then
echo "Listing all .gcda files in unittest, src, and parent directories:"
find . -name '*.gcda'
find "$HELPER_SRC_DIR" -name '*.gcda'
find "$FETCHER_SRC_DIR" -name '*.gcda'
find .. -name '*.gcda'
echo "Generating coverage report from both unittest and src directories"
lcov --capture \
--directory . \
--directory "$HELPER_SRC_DIR" \
--directory "$FETCHER_SRC_DIR" \
--output-file coverage.info
# Remove system and common test/mocks paths (keep build dir entries)
lcov --remove coverage.info '/usr/*' --output-file coverage.info
lcov --remove coverage.info '*/mocks/*' '*/gtest/*' '*/gmock/*' --output-file coverage.info
# Restrict to product sources
lcov --extract coverage.info '*/reboot-helper/src/*' '*/reboot-reason-fetcher/src/*' --output-file coverage.info
lcov --list coverage.info
fi
cd "$TOP_DIR"