Skip to content

Commit 69a2b35

Browse files
committed
Add test for version callback in llvm2lcov
Signed-off-by: Henry Cox <[email protected]>
1 parent 97abf19 commit 69a2b35

File tree

4 files changed

+64
-30
lines changed

4 files changed

+64
-30
lines changed

bin/llvm2lcov

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,16 +147,13 @@ sub parse
147147
}
148148
next;
149149
}
150-
151150
$srcReader->open($filename);
152151

153152
my $fileInfo = $top->data($filename);
154-
if ($lcovutil::compute_file_version &&
155-
@lcovutil::extractVersionScript) {
156-
my $version = lcovutil::extractFileVersion($filename);
157-
$fileInfo->version($version)
158-
if (defined($version) && $version ne "");
159-
}
153+
154+
my $version = lcovutil::extractFileVersion($filename);
155+
$fileInfo->version($version)
156+
if (defined($version) && $version ne "");
160157

161158
my $lineData = $fileInfo->test($testname);
162159
# use branch data to derive MC/DC expression - so need

tests/lcov/mcdc/main.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @file main.cpp
3+
* @author MTK50321 Henry Cox
4+
* @date Fri Dec 13 14:34:31 2024
5+
*
6+
* @brief Check differences between LLVM/GCC regarding MC/DC results.
7+
* split into two files to enable more testing
8+
*/
9+
10+
extern void test(int, int, int);
11+
12+
13+
int main(int ac, char ** av)
14+
{
15+
test(1,1,0);
16+
#ifdef SENS1
17+
test(1,0,0);
18+
#endif
19+
#ifdef SENS2
20+
test(0,1,0);
21+
#endif
22+
return 0;
23+
}
24+

tests/lcov/mcdc/mcdc.sh

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,21 @@ if [ 'x' == "x$GENHTML_TOOL" ] ; then
8383
PERL2LCOV_TOOL=${LCOV_HOME}/bin/perl2lcov
8484
fi
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+
86101
ROOT=`pwd`
87102
PARENT=`(cd .. ; pwd)`
88103

@@ -112,7 +127,7 @@ STATUS=0
112127
function 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

144170
function 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
@@ -184,21 +210,21 @@ fi
184210

185211

186212
if [ "$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
210236
fi
211237

212238
if [ "$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

tests/lcov/mcdc/test.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,3 @@ void test(int a, int b, int c)
1414
printf("not..\n");
1515
}
1616
}
17-
18-
19-
int main(int ac, char ** av)
20-
{
21-
test(1,1,0);
22-
#ifdef SENS1
23-
test(1,0,0);
24-
#endif
25-
#ifdef SENS2
26-
test(0,1,0);
27-
#endif
28-
return 0;
29-
}

0 commit comments

Comments
 (0)