@@ -83,6 +83,21 @@ if [ 'x' == "x$GENHTML_TOOL" ] ; then
8383 PERL2LCOV_TOOL=${LCOV_HOME} /bin/perl2lcov
8484fi
8585
86+ if [ -f $LCOV_HOME /scripts/getp4version ] ; then
87+ SCRIPT_DIR=$LCOV_HOME /scripts
88+ else
89+ # running test from lcov install
90+ SCRIPT_DIR=$LCOV_HOME /share/lcov/support-scripts
91+ fi
92+ # is this git or P4?
93+ git -C . rev-parse > /dev/null 2>&1
94+ if [ 0 == $? ] ; then
95+ # this is git
96+ GET_VERSION=${SCRIPT_DIR} /gitversion.pm
97+ else
98+ GET_VERSION=${SCRIPT_DIR} /P4version.pm,--local-edit,--md5
99+ fi
100+
86101ROOT=` pwd`
87102PARENT=` (cd .. ; pwd)`
88103
@@ -112,7 +127,7 @@ STATUS=0
112127function runClang()
113128(
114129 # runClang exeName srcFile flags
115- clang++ -fprofile-instr-generate -fcoverage-mapping -fcoverage-mcdc -o $1 $2 $3
130+ clang++ -fprofile-instr-generate -fcoverage-mapping -fcoverage-mcdc -o $1 main.cpp test.cpp $2
116131 if [ $? != 0 ] ; then
117132 echo " ERROR from clang++ $1 "
118133 return 1
@@ -128,23 +143,34 @@ function runClang()
128143 echo " ERROR from llvm-cov $1 "
129144 return 1
130145 fi
131- $COVER $LLVM2LCOV_TOOL --branch --mcdc -o $1 .info $1 .jsn
146+ $COVER $LLVM2LCOV_TOOL --branch --mcdc -o $1 .info $1 .jsn --version-script $GET_VERSION
132147 if [ $? != 0 ] ; then
133148 echo " ERROR from llvm2lcov $1 "
134149 return 1
135150 fi
136- $COVER $GENHTML_TOOL --flat --branch --mcdc -o $1 _rpt $1 .info
151+ $COVER $GENHTML_TOOL --flat --branch --mcdc -o $1 _rpt $1 .info --version-script $GET_VERSION
137152 if [ $? != 0 ] ; then
138153 echo " ERROR from genhtml $1 "
139154 return 1
140155 fi
156+ # run again, excluding 'main.cpp'
157+ $COVER $LLVM2LCOV_TOOL --branch --mcdc -o $1 .excl.info $1 .jsn --version-script $GET_VERSION --exclude ' */main.cpp'
158+ if [ $? != 0 ] ; then
159+ echo " ERROR from llvm2lcov --exclude $1 "
160+ return 1
161+ fi
162+ COUNT=` grep -c SF: $1 .excl.info`
163+ if [ 1 != " $COUNT " ] ; then
164+ echo " ERROR llvm2lcov --exclude $1 didn't work"
165+ return 1
166+ fi
141167 rm -f * .profraw * .profdata
142168)
143169
144170function runGcc()
145171{
146172 # runGcc exeName srcFile flags
147- g++ --coverage -fcondition-coverage -o $1 $2 $3
173+ g++ --coverage -fcondition-coverage -o $1 main.cpp test.cpp $2
148174 if [ $? != 0 ] ; then
149175 echo " ERROR from g++ $1 "
150176 return 1
184210
185211
186212if [ " $ENABLE_MCDC " == 1 ] ; then
187- runGcc gccTest1 test.cpp
213+ runGcc gccTest1
188214 if [ $? != 0 ] ; then
189215 STATUS=1
190216 if [ $KEEP_GOING == 0 ] ; then
191217 exit 1
192218 fi
193219 fi
194- runGcc gccTest2 test.cpp -DSENS1
220+ runGcc gccTest2 -DSENS1
195221 if [ $? != 0 ] ; then
196222 STATUS=1
197223 if [ $KEEP_GOING == 0 ] ; then
198224 exit 1
199225 fi
200226 fi
201- runGcc gccTest3 test.cpp -DSENS2
227+ runGcc gccTest3 -DSENS2
202228 if [ $? != 0 ] ; then
203229 STATUS=1
204230 if [ $KEEP_GOING == 0 ] ; then
@@ -210,21 +236,21 @@ else
210236fi
211237
212238if [ " $ENABLE_LLVM " == 1 ] ; then
213- runClang clangTest1 test.cpp
239+ runClang clangTest1
214240 if [ $? != 0 ] ; then
215241 STATUS=1
216242 if [ $KEEP_GOING == 0 ] ; then
217243 exit 1
218244 fi
219245 fi
220- runClang clangTest2 test.cpp -DSENS1
246+ runClang clangTest2 -DSENS1
221247 if [ $? != 0 ] ; then
222248 STATUS=1
223249 if [ $KEEP_GOING == 0 ] ; then
224250 exit 1
225251 fi
226252 fi
227- runClang clangTest3 test.cpp -DSENS2
253+ runClang clangTest3 -DSENS2
228254 if [ $? != 0 ] ; then
229255 STATUS=1
230256 if [ $KEEP_GOING == 0 ] ; then
0 commit comments