Skip to content

Commit 7337f89

Browse files
authored
Chip away at more coverage spots
1 parent ea16201 commit 7337f89

File tree

11 files changed

+577
-65
lines changed

11 files changed

+577
-65
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,8 @@ jobs:
539539
submodules: true
540540

541541
- name: Configure
542+
# We use DEBUG=OFF here in order to suppress the coverage misses due to
543+
# assertions, which obviously always pass.
542544
run: CC="clang -fprofile-instr-generate -fcoverage-mapping" cmake $CMAKE_FLAGS -DCMAKE_BUILD_TYPE=Debug -DPCRE2_DEBUG=OFF -DPCRE2_SUPPORT_JIT=ON -DPCRE2_BUILD_PCRE2_16=ON -DPCRE2_BUILD_PCRE2_32=ON -DPCRE2_SUPPORT_LIBZ=ON -DPCRE2_SUPPORT_LIBBZ2=ON -DPCRE2_SUPPORT_LIBEDIT=ON -DPCRE2_SUPPORT_LIBREADLINE=OFF -B build
543545

544546
- name: Build

RunTest

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,9 @@ checkresult()
197197

198198
checkspecial()
199199
{
200+
expect=${2:-0}
200201
$sim $valgrind $vjs $pcre2test $1 >>testSoutput
201-
if [ $? -ne 0 ] ; then
202+
if [ $? -ne "$expect" ] ; then
202203
echo "** pcre2test $1 failed - check testSoutput"
203204
yield=1
204205
return 1
@@ -538,13 +539,19 @@ for bmode in "$test8" "$test16" "$test32"; do
538539
echo ' abc' >>testSinput
539540
echo '' >testSoutput
540541
saverc=0
541-
checkspecial '-C' || saverc=$?
542+
checkspecial "$bmode -C" || saverc=$?
542543
checkspecial '--help' || saverc=$?
543544
checkspecial "$bmode testSinput" || saverc=$?
544545
checkspecial "$bmode $testdata/testinputheap" || saverc=$?
545546
if [ $support_setstack -eq 0 ] ; then
546547
checkspecial "$bmode -S 1 -t 10 testSinput" || saverc=$?
547548
fi
549+
checkspecial "$bmode reallydoesnotexist" 1 || saverc=$?
550+
checkspecial "$bmode testSinput reallydoesnotexist/outfile" 1 || saverc=$?
551+
checkspecial "$bmode -pattern debug testSinput" || saverc=$?
552+
checkspecial "$bmode -pattern INVALID testSinput" 1 2>/dev/null || saverc=$?
553+
checkspecial "$bmode -subject notempty testSinput" || saverc=$?
554+
checkspecial "$bmode -subject INVALID testSinput" 1 2>/dev/null || saverc=$?
548555
checkspecial -LM || saverc=$?
549556
checkspecial -LP || saverc=$?
550557
checkspecial -LS || saverc=$?

maint/FilterCoverage.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ def scan_exclusions(srcpath):
2727
continue
2828
if in_block:
2929
excl.add(i)
30+
31+
# If line matches '^\s*#(if|endif|else|elif)\b', exclude it.
32+
# For some reason, Clang likes to output coverage for these lines,
33+
# even though they have no executable code.
34+
if re.match(r'^\s*#(if|endif|else|elif|ifdef|ifndef)\b', line):
35+
excl.add(i)
36+
37+
# Similarly, Clang seems to generate DA entries for "}" lines inside
38+
# switch statements. Exclude these too.
39+
if re.match(r'^\s*}\s*(/\*.*?\*/)?$', line):
40+
excl.add(i)
3041
return excl
3142

3243
DA_RE = re.compile(r'^\s*DA:(\d+),(\d+)(,.*)?\s*$')

maint/RunCoverage

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99

1010
set -e
1111

12+
clang_report=0
1213
nomalloc=0
1314

1415
while [ $# -gt 0 ] ; do
1516
case $1 in
1617
nomalloc|-nomalloc) nomalloc=1;;
18+
clang|-clang|clang-report|-clang-report) clang_report=1;;
1719
*) echo "Unknown option or test selector '$1'"; exit 1;;
1820
esac
1921
shift
@@ -44,26 +46,40 @@ PROF_FILES="coverage-*.profraw"
4446
llvm-profdata-$LLVM_VER merge -sparse $PROF_FILES -o coverage.profdata
4547
echo ""
4648

47-
# Output LCOV-compatible output, for downstream tools
48-
echo "== Generating LCOV report =="
49-
llvm-cov-$LLVM_VER export \
50-
-format=lcov \
51-
-instr-profile=coverage.profdata \
52-
./pcre2test -object ./pcre2grep -object ./pcre2posix_test -object ./pcre2_jit_test \
53-
-sources ../src/ ./ \
54-
> ./coverage-lcov.info
55-
echo ""
49+
if [ "$clang_report" -eq 1 ]; then
50+
echo "== Generating Clang coverage report =="
51+
llvm-cov-$LLVM_VER show \
52+
-format=html \
53+
-show-line-counts-or-regions -show-branches=percent \
54+
-instr-profile=coverage.profdata \
55+
./pcre2test -object ./pcre2grep -object ./pcre2posix_test -object ./pcre2_jit_test \
56+
-sources ../src/ ./ \
57+
-output-dir=coverage-html
58+
echo ""
5659

57-
# Filter out lines marked with "LCOV_EXCL_LINE" or "LCOV_EXCL_START"/"LCOV_EXCL_STOP"
58-
echo "== Filtering LCOV report =="
59-
python3 ../maint/FilterCoverage.py ./coverage-lcov.info > ./coverage-lcov.filtered.info
60-
mv ./coverage-lcov.filtered.info ./coverage-lcov.info
61-
echo ""
60+
else
61+
# Output LCOV-compatible output, for downstream tools
62+
echo "== Generating LCOV report =="
63+
llvm-cov-$LLVM_VER export \
64+
-format=lcov \
65+
-instr-profile=coverage.profdata \
66+
./pcre2test -object ./pcre2grep -object ./pcre2posix_test -object ./pcre2_jit_test \
67+
-sources ../src/ ./ \
68+
> ./coverage-lcov.info
69+
echo ""
6270

63-
# Use genhtml to generate an HTML report from the LCOV data
64-
echo "== Generating HTML report =="
65-
mkdir -p coverage-html
66-
genhtml \
67-
--highlight --branch-coverage --legend --title "PCRE2 code coverage report" --num-spaces 2 \
68-
-o coverage-html ./coverage-lcov.info
69-
echo ""
71+
# Filter out lines marked with "LCOV_EXCL_LINE" or "LCOV_EXCL_START"/"LCOV_EXCL_STOP"
72+
echo "== Filtering LCOV report =="
73+
python3 ../maint/FilterCoverage.py ./coverage-lcov.info > ./coverage-lcov.filtered.info
74+
mv ./coverage-lcov.filtered.info ./coverage-lcov.info
75+
echo ""
76+
77+
# Use genhtml to generate an HTML report from the LCOV data
78+
echo "== Generating HTML report =="
79+
mkdir -p coverage-html
80+
genhtml \
81+
--highlight --branch-coverage --legend --title "PCRE2 code coverage report" --num-spaces 2 \
82+
-o coverage-html ./coverage-lcov.info
83+
echo ""
84+
85+
fi

src/pcre2_context.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -502,10 +502,7 @@ return 0;
502502
}
503503

504504
/* These functions became obsolete at release 10.30. The first is kept as a
505-
synonym for backwards compatibility. The second now does nothing. Exclude both
506-
from coverage reports. */
507-
508-
/* LCOV_EXCL_START */
505+
synonym for backwards compatibility. The second now does nothing. */
509506

510507
PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
511508
pcre2_set_recursion_limit(pcre2_match_context *mcontext, uint32_t limit)
@@ -525,8 +522,6 @@ pcre2_set_recursion_memory_management(pcre2_match_context *mcontext,
525522
return 0;
526523
}
527524

528-
/* LCOV_EXCL_STOP */
529-
530525

531526
/* ------------ Convert context ------------ */
532527

src/pcre2_util.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ side-effects. */
7171
} while(0)
7272
#endif
7373

74+
/* LCOV_EXCL_START */
75+
7476
/* PCRE2_UNREACHABLE() can be used to mark locations on the code that
7577
shouldn't be reached. In non debug builds is defined as a hint for
7678
the compiler to eliminate any code after it, so it is useful also for
@@ -107,8 +109,16 @@ the reason and the actions that should be taken if it ever triggers. */
107109

108110
#define PCRE2_DEBUG_UNREACHABLE() PCRE2_UNREACHABLE()
109111

112+
/* LCOV_EXCL_STOP */
113+
110114
#endif /* PCRE2_DEBUG */
111115

116+
#ifndef PCRE2_ASSERT
117+
#define PCRE2_ASSERT(x) do {} while(0)
118+
#endif
119+
120+
/* LCOV_EXCL_START */
121+
112122
#ifndef PCRE2_DEBUG_UNREACHABLE
113123
#define PCRE2_DEBUG_UNREACHABLE() do {} while(0)
114124
#endif
@@ -123,9 +133,7 @@ the reason and the actions that should be taken if it ever triggers. */
123133
#endif
124134
#endif /* !PCRE2_UNREACHABLE */
125135

126-
#ifndef PCRE2_ASSERT
127-
#define PCRE2_ASSERT(x) do {} while(0)
128-
#endif
136+
/* LCOV_EXCL_STOP */
129137

130138
/* We define this fallthrough macro for suppressing -Wimplicit-fallthrough warnings.
131139
Clang only allows this via an attribute, whereas other compilers (eg. GCC) match attributes

src/pcre2posix.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,8 @@ preg->re_erroffset = (size_t)(-1); /* No meaning after successful compile */
331331

332332
if (preg->re_match_data == NULL)
333333
{
334-
/* LCOV_EXCL_START */
335334
pcre2_code_free(preg->re_pcre2_code);
336335
return REG_ESPACE;
337-
/* LCOV_EXCL_STOP */
338336
}
339337

340338
return 0;

src/pcre2test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ static modstruct modlist[] = {
781781
{ "never_callout", MOD_CTC, MOD_OPT, PCRE2_EXTRA_NEVER_CALLOUT, CO(extra_options) },
782782
{ "never_ucp", MOD_PAT, MOD_OPT, PCRE2_NEVER_UCP, PO(options) },
783783
{ "never_utf", MOD_PAT, MOD_OPT, PCRE2_NEVER_UTF, PO(options) },
784-
{ "newline", MOD_CTC, MOD_NL, 0, CO(newline_convention) },
784+
{ "newline", MOD_CTC, MOD_NL, 0, 0 },
785785
{ "no_auto_capture", MOD_PAT, MOD_OPT, PCRE2_NO_AUTO_CAPTURE, PO(options) },
786786
{ "no_auto_possess", MOD_PATP, MOD_OPT, PCRE2_NO_AUTO_POSSESS, PO(options) },
787787
{ "no_bs0", MOD_CTC, MOD_OPT, PCRE2_EXTRA_NO_BS0, CO(extra_options) },

0 commit comments

Comments
 (0)