-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgcov_gen.sh
executable file
·144 lines (131 loc) · 2.89 KB
/
gcov_gen.sh
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
usage() {
echo "usage: `basename $0` [options]"
echo -e "\tThis script generates gcov coverage reports.\n"
echo -e "Options:"
echo -e "\t-d DIR\t: Indicate project dir.\n\n"
echo -e "\t-b\t: generate baseline info (Call before running tests)."
echo -e "\t-t\t: generate total info (Call after running tests)."
echo -e "\t-r DIR\t: generate HTML reports and place in specified DIR(Call after running tests).\n\n"
echo -e "\t-c\t: clean all gcov files in project dir."
echo -e "\t-q\t: Quiet."
echo -e "\t-h\t: Show this help message.\n\n"
}
ERRORS=0
CLEAN=
QUIET=
BASELINE=
TOTAL=
HTML=
HTMLDIR=
PJDIR=.
while getopts "hcbtqr:d:" OPTION
do
case $OPTION in
h)
usage
exit 1
;;
c)
CLEAN=1
;;
q)
QUIET=1
;;
d)
PJDIR=$OPTARG
;;
b)
BASELINE=1
;;
t)
TOTAL=1
;;
r)
HTML=1
HTMLDIR=$OPTARG
;;
?)
usage
exit
;;
esac
done
if [[ -z $BASELINE ]] && [[ -z $TOTAL ]] && [[ -z $HTML ]] && [[ -z $CLEAN ]];
then
echo -e "No appropriate option flag passed!\n"
usage
exit 1
fi
if [[ $BASELINE == 1 ]];
then
echo "Generating baseline info files..."
for i in $(find $PJDIR -maxdepth 1 -type d | awk '{ if (NR != 1) { print } }' | sed 's/\.\///');
do
if [[ ! -z $QUIET ]];
then
lcov -c -i -d $PJDIR/$i -o ${i}_baseline.info >/dev/null 2>&1
else
lcov -c -i -d $PJDIR/$i -o ${i}_baseline.info
fi
done
echo "You may now run your regression."
exit 0;
fi
if [[ $TOTAL == 1 ]];
then
echo "Generating test info and gcov files..."
for i in $(find $PJDIR -maxdepth 1 -type d | awk '{ if (NR != 1) { print } }' | sed 's/\.\///');
do
if [[ ! -z $QUIET ]];
then
lcov -c -d $PJDIR/$i -o $PJDIR/${i}_test.info >/dev/null 2>&1
lcov -a $PJDIR/${i}_baseline.info -a $PJDIR/${i}_test.info -o $PJDIR/${i}_total.info >/dev/null 2>&1
else
lcov -c -d $PJDIR/$i -o $PJDIR/${i}_test.info
lcov -a $PJDIR/${i}_baseline.info -a $PJDIR/${i}_test.info -o $PJDIR/${i}_total.info
fi
if [[ ! -z $? ]];
then
ERRORS=1
fi
done
fi
if [[ $HTML == 1 ]];
then
echo "Generating html reports..."
for i in $(find $PJDIR -maxdepth 1 -type d | awk '{ if (NR != 1) { print } }' | sed 's/\.\///');
do
if [[ -e $PJDIR/${i}_total.info ]];
then
mkdir -p $HTMLDIR/${i}
if [[ ! -z $QUIET ]];
then
genhtml -o $HTMLDIR/${i} $PJDIR/${i}_total.info >/dev/null 2>&1
else
genhtml -o $HTMLDIR/${i} $PJDIR/${i}_total.info
fi
if [[ ! -z $? ]];
then
ERRORS=1
fi
fi
done
fi
if [[ $CLEAN == 1 ]];
then
echo "Removing info files..."
rm $PJDIR/*_baseline.info
rm $PJDIR/*_test.info
rm $PJDIR/*_total.info
echo "Removing gcda files..."
find $PJDIR -type f -name "*.gcda" -exec rm -f {} \;
fi
if [[ ! -z $ERRORS ]];
then
echo -e "\033[1mWARNING\033[0m:\tScript completed succesfully but there were non-critical errors."
if [[ $QUIET == 1 ]];
then
echo -e "\t\tconsider running the script in verbose (non-quiet) mode."
fi
fi