@@ -8,18 +8,224 @@ export CC="${CC:-gcc}"
8
8
TOOLS=( " $CC " " gcov" )
9
9
10
10
function check_tools() {
11
- local tool
12
-
13
- for tool in " ${TOOLS[@]} " ; do
14
- if ! type -P " $tool " > /dev/null ; then
15
- echo " Error: Missing tool '$tool '"
16
- exit 2
17
- fi
18
- done
11
+ local tool
12
+
13
+ for tool in " ${TOOLS[@]} " ; do
14
+ if ! type -P " $tool " > /dev/null ; then
15
+ echo " Error: Missing tool '$tool '"
16
+ exit 2
17
+ fi
18
+ done
19
19
}
20
20
21
+ set +x
22
+
23
+ CLEAN_ONLY=0
24
+ COVER=
25
+
26
+ PARALLEL=' --parallel 0'
27
+ PROFILE=" --profile"
28
+ COVER_DB=' cover_db'
29
+ LOCAL_COVERAGE=1
30
+ KEEP_GOING=0
31
+ while [ $# -gt 0 ] ; do
32
+
33
+ OPT=$1
34
+ shift
35
+ case $OPT in
36
+
37
+ --clean | clean )
38
+ CLEAN_ONLY=1
39
+ ;;
40
+
41
+ -v | --verbose | verbose )
42
+ set -x
43
+ ;;
44
+
45
+ --keep-going )
46
+ KEEP_GOING=1
47
+ ;;
48
+
49
+ --coverage )
50
+ # COVER="perl -MDevel::Cover "
51
+ if [[ " $1 " x != ' x' && $1 != " -" * ]] ; then
52
+ COVER_DB=$1
53
+ LOCAL_COVERAGE=0
54
+ shift
55
+ fi
56
+ COVER=" perl -MDevel::Cover=-db,$COVER_DB ,-coverage,statement,branch,condition,subroutine "
57
+ ;;
58
+
59
+ --home | -home )
60
+ LCOV_HOME=$1
61
+ shift
62
+ if [ ! -f $LCOV_HOME /bin/lcov ] ; then
63
+ echo " LCOV_HOME '$LCOV_HOME ' does not exist"
64
+ exit 1
65
+ fi
66
+ ;;
67
+
68
+ --no-parallel )
69
+ PARALLEL=' '
70
+ ;;
71
+
72
+ --no-profile )
73
+ PROFILE=' '
74
+ ;;
75
+
76
+ * )
77
+ echo " Error: unexpected option '$OPT '"
78
+ exit 1
79
+ ;;
80
+ esac
81
+ done
82
+
83
+ if [[ " x" == ${LCOV_HOME} x ]] ; then
84
+ if [ -f ../../../bin/lcov ] ; then
85
+ LCOV_HOME=../../..
86
+ else
87
+ LCOV_HOME=../../../../releng/coverage/lcov
88
+ fi
89
+ fi
90
+ LCOV_HOME=` (cd ${LCOV_HOME} ; pwd)`
91
+
92
+ if [[ ! ( -d $LCOV_HOME /bin && -d $LCOV_HOME /lib && -x $LCOV_HOME /bin/genhtml && ( -f $LCOV_HOME /lib/lcovutil.pm || -f $LCOV_HOME /lib/lcov/lcovutil.pm ) ) ]] ; then
93
+ echo " LCOV_HOME '$LCOV_HOME ' seems not to be invalid"
94
+ exit 1
95
+ fi
96
+
97
+ export PATH=${LCOV_HOME} /bin:${LCOV_HOME} /share:${PATH}
98
+ export MANPATH=${MANPATH} :${LCOV_HOME} /man
99
+
100
+ if [ ' x' == " x$GENHTML_TOOL " ] ; then
101
+ GENHTML_TOOL=${LCOV_HOME} /bin/genhtml
102
+ LCOV_TOOL=${LCOV_HOME} /bin/lcov
103
+ GENINFO_TOOL=${LCOV_HOME} /bin/geninfo
104
+ fi
105
+
106
+ rm -f test * .gcno * .gcda
107
+
108
+ if [ " x$COVER " != ' x' ] && [ 0 != $LOCAL_COVERAGE ] ; then
109
+ cover -delete
110
+ fi
111
+
112
+ if [[ 1 == $CLEAN_ONLY ]] ; then
113
+ exit 0
114
+ fi
115
+
21
116
check_tools
22
117
23
- ./run.sh || exit 1
24
118
25
- exit 0
119
+ echo " Build test program"
120
+ " $CC " test.c -o test --coverage
121
+ if [ 0 != $? ] ; then
122
+ echo " compile failed"
123
+ exit 1
124
+ fi
125
+
126
+ echo " Run test program"
127
+ ./test
128
+ if [ 0 != $? ] ; then
129
+ echo " test execution failed"
130
+ exit 1
131
+ fi
132
+
133
+ status=0
134
+ for TOOL in " $LCOV_TOOL --capture -d" " $GENINFO_TOOL " ; do
135
+
136
+ : " -----------------------------"
137
+ : " No gcov-tool option"
138
+ : " -----------------------------"
139
+ $COVER $TOOL . -o test.info --verbose
140
+ if [ 0 != $? ] ; then
141
+ echo " failed vanilla"
142
+ status=1
143
+ if [ $KEEP_GOING == 0 ] ; then
144
+ exit $status
145
+ fi
146
+ fi
147
+
148
+ : " -----------------------------"
149
+ : " gcov-tool option without path"
150
+ : " -----------------------------"
151
+ $COVER $TOOL . -o test.info --verbose --gcov-tool " gcov"
152
+ if [ 0 != $? ] ; then
153
+ echo " failed gcov"
154
+ status=1
155
+ if [ $KEEP_GOING == 0 ] ; then
156
+ exit $status
157
+ fi
158
+ fi
159
+
160
+ : " -----------------------------"
161
+ : " gcov-tool option with absolute path"
162
+ : " -----------------------------"
163
+ $COVER $TOOL . -o test.info --verbose --gcov-tool " $PWD /mygcov.sh"
164
+ if [ 0 != $? ] ; then
165
+ echo " failed script"
166
+ status=1
167
+ if [ $KEEP_GOING == 0 ] ; then
168
+ exit $status
169
+ fi
170
+ fi
171
+
172
+ : " -----------------------------"
173
+ : " gcov-tool option with relative path"
174
+ : " -----------------------------"
175
+ $COVER $TOOL . -o test.info --verbose --gcov-tool " ./mygcov.sh"
176
+ if [ 0 != $? ] ; then
177
+ echo " failed relative script"
178
+ status=1
179
+ if [ $KEEP_GOING == 0 ] ; then
180
+ exit $status
181
+ fi
182
+ fi
183
+
184
+ : " -----------------------------"
185
+ : " gcov-tool option specifying nonexistent tool without path"
186
+ : " -----------------------------"
187
+ $COVER $TOOL . -o test.info --verbose --gcov-tool gcov.nonexistent
188
+ if [ 0 == $? ] ; then
189
+ echo " missing tool: should have failed"
190
+ status=1
191
+ if [ $KEEP_GOING == 0 ] ; then
192
+ exit $status
193
+ fi
194
+ fi
195
+
196
+ : " -----------------------------"
197
+ : " gcov-tool option specifying nonexistent tool with absolute path"
198
+ : " -----------------------------"
199
+ $COVER $TOOL . -o test.info --verbose --gcov-tool " /gcov.nonexistent"
200
+ if [ 0 == $? ] ; then
201
+ echo " should have failed absolute path"
202
+ status=1
203
+ if [ $KEEP_GOING == 0 ] ; then
204
+ exit $status
205
+ fi
206
+ fi
207
+
208
+ : " -----------------------------"
209
+ : " gcov-tool option specifying nonexistent tool with relative path"
210
+ : " -----------------------------"
211
+ $COVER $TOOL . -o test.info --verbose --gcov-tool " ./gcov.nonexistent"
212
+ if [ 0 == $? ] ; then
213
+ echo " should have failed relative nonexistent"
214
+ status=1
215
+ if [ $KEEP_GOING == 0 ] ; then
216
+ exit $status
217
+ fi
218
+ fi
219
+ done
220
+
221
+ if [ 0 == $status ] ; then
222
+ echo " Tests passed"
223
+ else
224
+ echo " Tests failed"
225
+ fi
226
+
227
+ if [ " x$COVER " != " x" ] && [ $LOCAL_COVERAGE == 1 ]; then
228
+ cover
229
+ fi
230
+
231
+ exit $status
0 commit comments