Skip to content

Commit 500c68b

Browse files
authored
Add testing for malloc() failures (#697)
An additional testing argument, `-malloc` is added to pcre2test and to RunTest. The ManyConfig tests run this now in CI. We exercise each malloc failure in the core code by counting how many mallocs are done, then repeating compilation and matching with a failure on each successive malloc.
1 parent fb3b380 commit 500c68b

File tree

8 files changed

+836
-616
lines changed

8 files changed

+836
-616
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,13 @@ jobs:
358358
run: cd build && make -j3
359359

360360
- name: Test
361-
run: cd build && LLVM_PROFILE_FILE="coverage-%m.profraw" ctest -j1 --output-on-failure
361+
run: |
362+
cd build
363+
echo "== Running all tests with CTest =="
364+
LLVM_PROFILE_FILE="coverage-%m.profraw" ctest -j1 --output-on-failure
365+
echo ""
366+
echo "== Re-running pcre2test with -malloc =="
367+
LLVM_PROFILE_FILE="coverage-%m.profraw" srcdir=.. pcre2test=./pcre2test ../RunTest -malloc
362368
363369
- name: Report
364370
run: |

RunTest

Lines changed: 42 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ checkresult()
195195

196196
checkspecial()
197197
{
198-
$sim $valgrind $vjs $pcre2test $1 >>testSoutput
198+
$sim $valgrind $vjs $pcre2test -q $1 >>testSoutput
199199
if [ $? -ne 0 ] ; then
200200
echo "** pcre2test $1 failed - check testSoutput"
201201
yield=1
@@ -214,10 +214,12 @@ arg16=
214214
arg32=
215215
nojit=
216216
bigstack=
217+
malloc=
217218
sim=
218219
skip=
219220
valgrind=
220221
vjs=
222+
globalopts="-q"
221223
: ${pcre2test:=./pcre2test}
222224

223225
# This is in case the caller has set aliases (as I do - PH)
@@ -300,6 +302,7 @@ while [ $# -gt 0 ] ; do
300302
-16) arg16=yes;;
301303
-32) arg32=yes;;
302304
bigstack|-bigstack) bigstack=yes;;
305+
malloc|-malloc) malloc=yes;;
303306
nojit|-nojit) nojit=yes;;
304307
sim|-sim) shift; sim=$1;;
305308
valgrind|-valgrind) valgrind="valgrind --tool=memcheck -q --smc-check=all-non-file --error-exitcode=70";;
@@ -351,9 +354,13 @@ fi
351354
$sim $pcre2test -S 32 /dev/null /dev/null >/dev/null 2>&1
352355
support_setstack=$?
353356
if [ $support_setstack -eq 0 -a "$bigstack" != "" ] ; then
354-
setstack="-S 32"
355-
else
356-
setstack=""
357+
globalopts="$globalopts -S 32"
358+
fi
359+
360+
# If the malloc option is given, then call pcre2test with -malloc.
361+
362+
if [ "$malloc" != "" ] ; then
363+
globalopts="$globalopts -malloc"
357364
fi
358365

359366
# All of 8-bit, 16-bit, and 32-bit character strings may be supported, but only
@@ -557,7 +564,7 @@ for bmode in "$test8" "$test16" "$test32"; do
557564
if [ $do1 = yes ] ; then
558565
echo $title1
559566
for opt in "" $jitopt; do
560-
$sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $testdata/testinput1 testoutput$bits$opt/testoutput1
567+
$sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput1 testoutput$bits$opt/testoutput1
561568
checkresult $? 1 "$opt"
562569
done
563570
fi
@@ -569,10 +576,10 @@ for bmode in "$test8" "$test16" "$test32"; do
569576
echo $title2 "(excluding UTF-$bits)"
570577
cp $testdata/testbtables .
571578
for opt in "" $jitopt; do
572-
$sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $testdata/testinput2 testoutput$bits$opt/testoutput2
579+
$sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput2 testoutput$bits$opt/testoutput2
573580
saverc=$?
574581
if [ $saverc = 0 ] ; then
575-
$sim $valgrind ${opt:+$vjs} $pcre2test -q $bmode $opt -error -80,-62,-2,-1,0,100,101,191,300 >>testoutput$bits$opt/testoutput2
582+
$sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt -error -80,-62,-2,-1,0,100,101,191,300 >>testoutput$bits$opt/testoutput2
576583
checkresult $? 2 "$opt"
577584
else
578585
checkresult $saverc 2 "$opt"
@@ -628,7 +635,7 @@ for bmode in "$test8" "$test16" "$test32"; do
628635
if [ "$locale" != "" ] ; then
629636
echo $title3 "(using '$locale' locale)"
630637
for opt in "" $jitopt; do
631-
$sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $infile testoutput$bits/testoutput3
638+
$sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $infile testoutput$bits/testoutput3
632639
if [ $? = 0 ] ; then
633640
case "$opt" in
634641
-jit) with=" with JIT";;
@@ -670,7 +677,7 @@ for bmode in "$test8" "$test16" "$test32"; do
670677
echo " Skipped because UTF-$bits support is not available"
671678
else
672679
for opt in "" $jitopt; do
673-
$sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $testdata/testinput4 testoutput$bits$opt/testoutput4
680+
$sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput4 testoutput$bits$opt/testoutput4
674681
checkresult $? 4 "$opt"
675682
done
676683
fi
@@ -682,7 +689,7 @@ for bmode in "$test8" "$test16" "$test32"; do
682689
echo " Skipped because UTF-$bits support is not available"
683690
else
684691
for opt in "" $jitopt; do
685-
$sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $testdata/testinput5 testoutput$bits$opt/testoutput5
692+
$sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput5 testoutput$bits$opt/testoutput5
686693
checkresult $? 5 "$opt"
687694
done
688695
fi
@@ -692,7 +699,7 @@ for bmode in "$test8" "$test16" "$test32"; do
692699

693700
if [ $do6 = yes ] ; then
694701
echo $title6
695-
$sim $valgrind $pcre2test -q $setstack $bmode $testdata/testinput6 testoutput$bits/testoutput6
702+
$sim $valgrind $pcre2test $globalopts $bmode $testdata/testinput6 testoutput$bits/testoutput6
696703
checkresult $? 6 ""
697704
fi
698705

@@ -701,7 +708,7 @@ for bmode in "$test8" "$test16" "$test32"; do
701708
if [ $utf -eq 0 ] ; then
702709
echo " Skipped because UTF-$bits support is not available"
703710
else
704-
$sim $valgrind $pcre2test -q $setstack $bmode $testdata/testinput7 testoutput$bits/testoutput7
711+
$sim $valgrind $pcre2test $globalopts $bmode $testdata/testinput7 testoutput$bits/testoutput7
705712
checkresult $? 7 ""
706713
fi
707714
fi
@@ -725,7 +732,7 @@ for bmode in "$test8" "$test16" "$test32"; do
725732
if [ $utf -eq 0 ] ; then
726733
echo " Skipped because UTF-$bits support is not available"
727734
else
728-
$sim $valgrind $pcre2test -q $setstack $bmode $testdata/testinput8 testoutput$bits/testoutput8-$bits-$bits_link_size
735+
$sim $valgrind $pcre2test $globalopts $bmode $testdata/testinput8 testoutput$bits/testoutput8-$bits-$bits_link_size
729736
checkresult $? 8-$bits-$bits_link_size ""
730737
fi
731738
fi
@@ -738,7 +745,7 @@ for bmode in "$test8" "$test16" "$test32"; do
738745
echo " Skipped when running 16/32-bit tests"
739746
else
740747
for opt in "" $jitopt; do
741-
$sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $testdata/testinput9 testoutput$bits$opt/testoutput9
748+
$sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput9 testoutput$bits$opt/testoutput9
742749
checkresult $? 9 "$opt"
743750
done
744751
fi
@@ -754,7 +761,7 @@ for bmode in "$test8" "$test16" "$test32"; do
754761
echo " Skipped because UTF-$bits support is not available"
755762
else
756763
for opt in "" $jitopt; do
757-
$sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $testdata/testinput10 testoutput$bits$opt/testoutput10
764+
$sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput10 testoutput$bits$opt/testoutput10
758765
checkresult $? 10 "$opt"
759766
done
760767
fi
@@ -768,7 +775,7 @@ for bmode in "$test8" "$test16" "$test32"; do
768775
echo " Skipped when running 8-bit tests"
769776
else
770777
for opt in "" $jitopt; do
771-
$sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $testdata/testinput11 testoutput$bits$opt/testoutput11-$bits
778+
$sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput11 testoutput$bits$opt/testoutput11-$bits
772779
checkresult $? 11-$bits "$opt"
773780
done
774781
fi
@@ -785,7 +792,7 @@ for bmode in "$test8" "$test16" "$test32"; do
785792
echo " Skipped because UTF-$bits support is not available"
786793
else
787794
for opt in "" $jitopt; do
788-
$sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $testdata/testinput12 testoutput$bits$opt/testoutput12-$bits
795+
$sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput12 testoutput$bits$opt/testoutput12-$bits
789796
checkresult $? 12-$bits "$opt"
790797
done
791798
fi
@@ -798,7 +805,7 @@ for bmode in "$test8" "$test16" "$test32"; do
798805
if [ "$bits" = "8" ] ; then
799806
echo " Skipped when running 8-bit tests"
800807
else
801-
$sim $valgrind $pcre2test -q $setstack $bmode $testdata/testinput13 testoutput$bits/testoutput13
808+
$sim $valgrind $pcre2test $globalopts $bmode $testdata/testinput13 testoutput$bits/testoutput13
802809
checkresult $? 13 ""
803810
fi
804811
fi
@@ -810,7 +817,7 @@ for bmode in "$test8" "$test16" "$test32"; do
810817
if [ $utf -eq 0 ] ; then
811818
echo " Skipped because UTF-$bits support is not available"
812819
else
813-
$sim $valgrind $pcre2test -q $setstack $bmode $testdata/testinput14 testoutput$bits/testoutput14-$bits
820+
$sim $valgrind $pcre2test $globalopts $bmode $testdata/testinput14 testoutput$bits/testoutput14-$bits
814821
checkresult $? 14-$bits ""
815822
fi
816823
fi
@@ -819,7 +826,7 @@ for bmode in "$test8" "$test16" "$test32"; do
819826

820827
if [ $do15 = yes ] ; then
821828
echo $title15
822-
$sim $valgrind $pcre2test -q $setstack $bmode $testdata/testinput15 testoutput$bits/testoutput15
829+
$sim $valgrind $pcre2test $globalopts $bmode $testdata/testinput15 testoutput$bits/testoutput15
823830
checkresult $? 15 ""
824831
fi
825832

@@ -830,7 +837,7 @@ for bmode in "$test8" "$test16" "$test32"; do
830837
if [ $jit -ne 0 ] ; then
831838
echo " Skipped because JIT is available"
832839
else
833-
$sim $valgrind $pcre2test -q $setstack $bmode $testdata/testinput16 testoutput$bits/testoutput16
840+
$sim $valgrind $pcre2test $globalopts $bmode $testdata/testinput16 testoutput$bits/testoutput16
834841
checkresult $? 16 ""
835842
fi
836843
fi
@@ -842,7 +849,7 @@ for bmode in "$test8" "$test16" "$test32"; do
842849
if [ $jit -eq 0 -o "$nojit" = "yes" ] ; then
843850
echo " Skipped because JIT is not available or nojit was specified"
844851
else
845-
$sim $valgrind $vjs $pcre2test -q $setstack $bmode $testdata/testinput17 testoutput$bits/testoutput17
852+
$sim $valgrind $vjs $pcre2test $globalopts $bmode $testdata/testinput17 testoutput$bits/testoutput17
846853
checkresult $? 17 ""
847854
fi
848855
fi
@@ -854,7 +861,7 @@ for bmode in "$test8" "$test16" "$test32"; do
854861
if [ "$bits" = "16" -o "$bits" = "32" ] ; then
855862
echo " Skipped when running 16/32-bit tests"
856863
else
857-
$sim $valgrind $pcre2test -q $setstack $bmode $testdata/testinput18 testoutput$bits/testoutput18
864+
$sim $valgrind $pcre2test $globalopts $bmode $testdata/testinput18 testoutput$bits/testoutput18
858865
checkresult $? 18 ""
859866
fi
860867
fi
@@ -868,7 +875,7 @@ for bmode in "$test8" "$test16" "$test32"; do
868875
elif [ $utf -eq 0 ] ; then
869876
echo " Skipped because UTF-$bits support is not available"
870877
else
871-
$sim $valgrind $pcre2test -q $setstack $bmode $testdata/testinput19 testoutput$bits/testoutput19
878+
$sim $valgrind $pcre2test $globalopts $bmode $testdata/testinput19 testoutput$bits/testoutput19
872879
checkresult $? 19 ""
873880
fi
874881
fi
@@ -877,7 +884,7 @@ for bmode in "$test8" "$test16" "$test32"; do
877884

878885
if [ $do20 = yes ] ; then
879886
echo $title20
880-
$sim $valgrind $pcre2test -q $setstack $bmode $testdata/testinput20 testoutput$bits/testoutput20
887+
$sim $valgrind $pcre2test $globalopts $bmode $testdata/testinput20 testoutput$bits/testoutput20
881888
checkresult $? 20 ""
882889
fi
883890

@@ -889,7 +896,7 @@ for bmode in "$test8" "$test16" "$test32"; do
889896
echo " Skipped because \C is disabled"
890897
else
891898
for opt in "" $jitopt -dfa; do
892-
$sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $testdata/testinput21 testoutput$bits$opt/testoutput21
899+
$sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput21 testoutput$bits$opt/testoutput21
893900
checkresult $? 21 "$opt"
894901
done
895902
fi
@@ -905,7 +912,7 @@ for bmode in "$test8" "$test16" "$test32"; do
905912
echo " Skipped because UTF-$bits support is not available"
906913
else
907914
for opt in "" $jitopt; do
908-
$sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $testdata/testinput22 testoutput$bits$opt/testoutput22-$bits
915+
$sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput22 testoutput$bits$opt/testoutput22-$bits
909916
checkresult $? 22-$bits "$opt"
910917
done
911918
fi
@@ -918,7 +925,7 @@ for bmode in "$test8" "$test16" "$test32"; do
918925
if [ $supportBSC -ne 0 ] ; then
919926
echo " Skipped because \C is not disabled"
920927
else
921-
$sim $valgrind $pcre2test -q $setstack $bmode $testdata/testinput23 testoutput$bits/testoutput23
928+
$sim $valgrind $pcre2test $globalopts $bmode $testdata/testinput23 testoutput$bits/testoutput23
922929
checkresult $? 23 ""
923930
fi
924931
fi
@@ -927,7 +934,7 @@ for bmode in "$test8" "$test16" "$test32"; do
927934

928935
if [ "$do24" = yes ] ; then
929936
echo $title24
930-
$sim $valgrind $pcre2test -q $setstack $bmode $testdata/testinput24 testoutput$bits/testoutput24
937+
$sim $valgrind $pcre2test $globalopts $bmode $testdata/testinput24 testoutput$bits/testoutput24
931938
checkresult $? 24 ""
932939
fi
933940

@@ -938,7 +945,7 @@ for bmode in "$test8" "$test16" "$test32"; do
938945
if [ $utf -eq 0 ] ; then
939946
echo " Skipped because UTF-$bits support is not available"
940947
else
941-
$sim $valgrind $pcre2test -q $setstack $bmode $testdata/testinput25 testoutput$bits/testoutput25
948+
$sim $valgrind $pcre2test $globalopts $bmode $testdata/testinput25 testoutput$bits/testoutput25
942949
checkresult $? 25 ""
943950
fi
944951
fi
@@ -951,7 +958,7 @@ for bmode in "$test8" "$test16" "$test32"; do
951958
echo " Skipped because UTF-$bits support is not available"
952959
else
953960
for opt in "" $jitopt; do
954-
$sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $testdata/testinput26 testoutput$bits$opt/testoutput26
961+
$sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput26 testoutput$bits$opt/testoutput26
955962
checkresult $? 26 "$opt"
956963
done
957964
fi
@@ -965,7 +972,7 @@ for bmode in "$test8" "$test16" "$test32"; do
965972
echo " Skipped because UTF-$bits support is not available"
966973
else
967974
for opt in "" $jitopt; do
968-
$sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $testdata/testinput27 testoutput$bits$opt/testoutput27
975+
$sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput27 testoutput$bits$opt/testoutput27
969976
checkresult $? 27 "$opt"
970977
done
971978
fi
@@ -979,7 +986,7 @@ for bmode in "$test8" "$test16" "$test32"; do
979986
echo " Skipped when not targetting EBCDIC"
980987
else
981988
for opt in "" $jitopt "-dfa"; do
982-
$sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $testdata/testinput28 testoutput$bits$opt/testoutput28
989+
$sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput28 testoutput$bits$opt/testoutput28
983990
checkresult $? 28 "$opt"
984991
done
985992
fi
@@ -995,7 +1002,7 @@ for bmode in "$test8" "$test16" "$test32"; do
9951002
echo " Skipped because EBCDIC newline is not 0x25"
9961003
else
9971004
for opt in "" $jitopt "-dfa"; do
998-
$sim $valgrind ${opt:+$vjs} $pcre2test -q $setstack $bmode $opt $testdata/testinput29 testoutput$bits$opt/testoutput29
1005+
$sim $valgrind ${opt:+$vjs} $pcre2test $globalopts $bmode $opt $testdata/testinput29 testoutput$bits$opt/testoutput29
9991006
checkresult $? 29 "$opt"
10001007
done
10011008
fi
@@ -1006,7 +1013,7 @@ for bmode in "$test8" "$test16" "$test32"; do
10061013

10071014
if [ $doheap = yes ] ; then
10081015
echo $titleheap
1009-
$sim $valgrind $pcre2test -q $setstack $bmode $testdata/testinputheap testoutput$bits/testoutputheap-$bits
1016+
$sim $valgrind $pcre2test $globalopts $bmode $testdata/testinputheap testoutput$bits/testoutputheap-$bits
10101017
checkresult $? heap-$bits ""
10111018
fi
10121019

doc/html/pcre2test.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,12 @@ <h1>pcre2test man page</h1>
318318
the total times for all compiles and matches are output.
319319
</p>
320320
<p>
321+
<b>-malloc</b>
322+
Exercise malloc() failures, by first counting the number of calls made to malloc
323+
during pattern compilation and matching, then re-running the compilation and
324+
matching that many times, exercising a failure of each malloc() call.
325+
</p>
326+
<p>
321327
<b>-version</b>
322328
Output the PCRE2 version number and then exit.
323329
</p>

doc/pcre2test.1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ compile phase.
265265
These behave like \fB-t\fP and \fB-tm\fP, but in addition, at the end of a run,
266266
the total times for all compiles and matches are output.
267267
.TP 10
268+
\fB-malloc\fP
269+
Exercise malloc() failures, by first counting the number of calls made to malloc
270+
during pattern compilation and matching, then re-running the compilation and
271+
matching that many times, exercising a failure of each malloc() call.
272+
.TP 10
268273
\fB-version\fP
269274
Output the PCRE2 version number and then exit.
270275
.

0 commit comments

Comments
 (0)