Added some special heap tests

This commit is contained in:
Philip Hazel 2022-07-28 17:58:19 +01:00
parent 1343bdff8f
commit cc5e121c8e
7 changed files with 187 additions and 24 deletions

View File

@ -45,6 +45,10 @@ It is freed with the match data block.
different in different environments and so cannot be included in the standard
tests.
12. Created a test for pcre2_match() heap processing that is not part of the
tests run by 'make check', but can be run manually. The current output is from
a 64-bit system.
Version 10.40 15-April-2022
---------------------------

35
RunTest
View File

@ -17,8 +17,16 @@
# individual test numbers, ranges of tests such as 3-6 or 3- (meaning 3 to the
# end), or a number preceded by ~ to exclude a test. For example, "3-15 ~10"
# runs tests 3 to 15, excluding test 10, and just "~10" runs all the tests
# except test 10. Whatever order the arguments are in, the tests are always run
# in numerical order.
# except test 10. Whatever order the arguments are in, these tests are always
# run in numerical order.
#
# If no specific tests are selected (which is the case when this script is run
# via 'make check') the default is to run all the numbered tests.
#
# There may also be named (as well as numbered) tests for special purposes. At
# present there is just one, called "heap". This test's output contains the
# sizes of heap frames and frame vectors, which depend on the environment. It
# is therefore not run unless explicitly requested.
#
# Inappropriate tests are automatically skipped (with a comment to say so). For
# example, if JIT support is not compiled, test 16 is skipped, whereas if JIT
@ -82,6 +90,7 @@ title24="Test 24: Non-UTF pattern conversion tests"
title25="Test 25: UTF pattern conversion tests"
title26="Test 26: Auto-generated unicode property tests"
maxtest=26
titleheap="Test 'heap': Environment-specific heap tests"
if [ $# -eq 1 -a "$1" = "list" ]; then
echo $title0
@ -111,6 +120,11 @@ if [ $# -eq 1 -a "$1" = "list" ]; then
echo $title24
echo $title25
echo $title26
echo ""
echo $titleheap
echo ""
echo "Numbered tests are automatically run if nothing selected."
echo "Named tests must be explicitly selected."
exit 0
fi
@ -241,6 +255,7 @@ do23=no
do24=no
do25=no
do26=no
doheap=no
while [ $# -gt 0 ] ; do
case $1 in
@ -271,6 +286,7 @@ while [ $# -gt 0 ] ; do
24) do24=yes;;
25) do25=yes;;
26) do26=yes;;
heap) doheap=yes;;
-8) arg8=yes;;
-16) arg16=yes;;
-32) arg32=yes;;
@ -412,8 +428,8 @@ if [ $jit -ne 0 -a "$nojit" != "yes" ] ; then
fi
fi
# If no specific tests were requested, select all. Those that are not
# relevant will be automatically skipped.
# If no specific tests were requested, select all the numbered tests. Those
# that are not relevant will be automatically skipped.
if [ $do0 = no -a $do1 = no -a $do2 = no -a $do3 = no -a \
$do4 = no -a $do5 = no -a $do6 = no -a $do7 = no -a \
@ -421,7 +437,7 @@ if [ $do0 = no -a $do1 = no -a $do2 = no -a $do3 = no -a \
$do12 = no -a $do13 = no -a $do14 = no -a $do15 = no -a \
$do16 = no -a $do17 = no -a $do18 = no -a $do19 = no -a \
$do20 = no -a $do21 = no -a $do22 = no -a $do23 = no -a \
$do24 = no -a $do25 = no -a $do26 = no \
$do24 = no -a $do25 = no -a $do26 = no -a $doheap = no \
]; then
do0=yes
do1=yes
@ -882,6 +898,15 @@ for bmode in "$test8" "$test16" "$test32"; do
fi
fi
# Manually selected heap tests - output may vary in different environments,
# which is why that are not automatically run.
if [ $doheap = yes ] ; then
echo $titleheap
$sim $valgrind ./pcre2test -q $setstack $bmode $testdata/testinputheap testtry
checkresult $? heap-$bits ""
fi
# End of loop for 8/16/32-bit tests
done

View File

@ -1246,19 +1246,19 @@ are supported. */
#define PCRE2_MATCH_DATA_CREATE(a,b,c) \
if (test_mode == PCRE8_MODE) \
G(a,8) = pcre2_match_data_create_8(b,c); \
G(a,8) = pcre2_match_data_create_8(b,G(c,8)); \
else if (test_mode == PCRE16_MODE) \
G(a,16) = pcre2_match_data_create_16(b,c); \
G(a,16) = pcre2_match_data_create_16(b,G(c,16)); \
else \
G(a,32) = pcre2_match_data_create_32(b,c)
G(a,32) = pcre2_match_data_create_32(b,G(c,32))
#define PCRE2_MATCH_DATA_CREATE_FROM_PATTERN(a,b,c) \
if (test_mode == PCRE8_MODE) \
G(a,8) = pcre2_match_data_create_from_pattern_8(G(b,8),c); \
G(a,8) = pcre2_match_data_create_from_pattern_8(G(b,8),G(c,8)); \
else if (test_mode == PCRE16_MODE) \
G(a,16) = pcre2_match_data_create_from_pattern_16(G(b,16),c); \
G(a,16) = pcre2_match_data_create_from_pattern_16(G(b,16),G(c,16)); \
else \
G(a,32) = pcre2_match_data_create_from_pattern_32(G(b,32),c)
G(a,32) = pcre2_match_data_create_from_pattern_32(G(b,32),G(c,32))
#define PCRE2_MATCH_DATA_FREE(a) \
if (test_mode == PCRE8_MODE) \
@ -1766,15 +1766,15 @@ the three different cases. */
#define PCRE2_MATCH_DATA_CREATE(a,b,c) \
if (test_mode == G(G(PCRE,BITONE),_MODE)) \
G(a,BITONE) = G(pcre2_match_data_create_,BITONE)(b,c); \
G(a,BITONE) = G(pcre2_match_data_create_,BITONE)(b,G(c,BITONE)); \
else \
G(a,BITTWO) = G(pcre2_match_data_create_,BITTWO)(b,c)
G(a,BITTWO) = G(pcre2_match_data_create_,BITTWO)(b,G(c,BITTWO))
#define PCRE2_MATCH_DATA_CREATE_FROM_PATTERN(a,b,c) \
if (test_mode == G(G(PCRE,BITONE),_MODE)) \
G(a,BITONE) = G(pcre2_match_data_create_from_pattern_,BITONE)(G(b,BITONE),c); \
G(a,BITONE) = G(pcre2_match_data_create_from_pattern_,BITONE)(G(b,BITONE),G(c,BITONE)); \
else \
G(a,BITTWO) = G(pcre2_match_data_create_from_pattern_,BITTWO)(G(b,BITTWO),c)
G(a,BITTWO) = G(pcre2_match_data_create_from_pattern_,BITTWO)(G(b,BITTWO),G(c,BITTWO))
#define PCRE2_MATCH_DATA_FREE(a) \
if (test_mode == G(G(PCRE,BITONE),_MODE)) \
@ -2074,9 +2074,9 @@ the three different cases. */
#define PCRE2_MAKETABLES(a) a = pcre2_maketables_8(NULL)
#define PCRE2_MATCH(a,b,c,d,e,f,g,h) \
a = pcre2_match_8(G(b,8),(PCRE2_SPTR8)c,d,e,f,G(g,8),h)
#define PCRE2_MATCH_DATA_CREATE(a,b,c) G(a,8) = pcre2_match_data_create_8(b,c)
#define PCRE2_MATCH_DATA_CREATE(a,b,c) G(a,8) = pcre2_match_data_create_8(b,G(c,8))
#define PCRE2_MATCH_DATA_CREATE_FROM_PATTERN(a,b,c) \
G(a,8) = pcre2_match_data_create_from_pattern_8(G(b,8),c)
G(a,8) = pcre2_match_data_create_from_pattern_8(G(b,8),G(c,8))
#define PCRE2_MATCH_DATA_FREE(a) pcre2_match_data_free_8(G(a,8))
#define PCRE2_PATTERN_CONVERT(a,b,c,d,e,f,g) a = pcre2_pattern_convert_8(G(b,8),c,d,(PCRE2_UCHAR8 **)e,f,G(g,8))
#define PCRE2_PATTERN_INFO(a,b,c,d) a = pcre2_pattern_info_8(G(b,8),c,d)
@ -2181,9 +2181,9 @@ the three different cases. */
#define PCRE2_MAKETABLES(a) a = pcre2_maketables_16(NULL)
#define PCRE2_MATCH(a,b,c,d,e,f,g,h) \
a = pcre2_match_16(G(b,16),(PCRE2_SPTR16)c,d,e,f,G(g,16),h)
#define PCRE2_MATCH_DATA_CREATE(a,b,c) G(a,16) = pcre2_match_data_create_16(b,c)
#define PCRE2_MATCH_DATA_CREATE(a,b,c) G(a,16) = pcre2_match_data_create_16(b,G(c,16))
#define PCRE2_MATCH_DATA_CREATE_FROM_PATTERN(a,b,c) \
G(a,16) = pcre2_match_data_create_from_pattern_16(G(b,16),c)
G(a,16) = pcre2_match_data_create_from_pattern_16(G(b,16),G(c,16))
#define PCRE2_MATCH_DATA_FREE(a) pcre2_match_data_free_16(G(a,16))
#define PCRE2_PATTERN_CONVERT(a,b,c,d,e,f,g) a = pcre2_pattern_convert_16(G(b,16),c,d,(PCRE2_UCHAR16 **)e,f,G(g,16))
#define PCRE2_PATTERN_INFO(a,b,c,d) a = pcre2_pattern_info_16(G(b,16),c,d)
@ -2288,9 +2288,9 @@ the three different cases. */
#define PCRE2_MAKETABLES(a) a = pcre2_maketables_32(NULL)
#define PCRE2_MATCH(a,b,c,d,e,f,g,h) \
a = pcre2_match_32(G(b,32),(PCRE2_SPTR32)c,d,e,f,G(g,32),h)
#define PCRE2_MATCH_DATA_CREATE(a,b,c) G(a,32) = pcre2_match_data_create_32(b,c)
#define PCRE2_MATCH_DATA_CREATE(a,b,c) G(a,32) = pcre2_match_data_create_32(b,G(c,32))
#define PCRE2_MATCH_DATA_CREATE_FROM_PATTERN(a,b,c) \
G(a,32) = pcre2_match_data_create_from_pattern_32(G(b,32),c)
G(a,32) = pcre2_match_data_create_from_pattern_32(G(b,32),G(c,32))
#define PCRE2_MATCH_DATA_FREE(a) pcre2_match_data_free_32(G(a,32))
#define PCRE2_PATTERN_CONVERT(a,b,c,d,e,f,g) a = pcre2_pattern_convert_32(G(b,32),c,d,(PCRE2_UCHAR32 **)e,f,G(g,32))
#define PCRE2_PATTERN_INFO(a,b,c,d) a = pcre2_pattern_info_32(G(b,32),c,d)
@ -2784,7 +2784,7 @@ return block;
static void my_free(void *block, void *data)
{
(void)data;
if (show_memory)
if (show_memory && block != NULL)
{
uint32_t i, j;
BOOL found = FALSE;
@ -7318,7 +7318,8 @@ causes a new match data block to be obtained that exactly fits the pattern. */
if (dat_datctl.oveccount == 0)
{
PCRE2_MATCH_DATA_FREE(match_data);
PCRE2_MATCH_DATA_CREATE_FROM_PATTERN(match_data, compiled_code, NULL);
PCRE2_MATCH_DATA_CREATE_FROM_PATTERN(match_data, compiled_code,
general_context);
PCRE2_GET_OVECTOR_COUNT(max_oveccount, match_data);
}
else if (dat_datctl.oveccount <= max_oveccount)
@ -7329,7 +7330,7 @@ else
{
max_oveccount = dat_datctl.oveccount;
PCRE2_MATCH_DATA_FREE(match_data);
PCRE2_MATCH_DATA_CREATE(match_data, max_oveccount, NULL);
PCRE2_MATCH_DATA_CREATE(match_data, max_oveccount, general_context);
}
if (CASTVAR(void *, match_data) == NULL)

13
testdata/testinputheap vendored Normal file
View File

@ -0,0 +1,13 @@
#pattern framesize, memory
/abcd/
abcd\=memory
abcd\=find_limits
/(((((((((((((((((((((((((((((( (^abc|xyz){1,20}$ ))))))))))))))))))))))))))))))/x
abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcX\=memory
abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcX\=find_limits
/ab(cd)/
abcd\=memory
abcd\=memory,ovector=0

40
testdata/testoutputheap-16 vendored Normal file
View File

@ -0,0 +1,40 @@
#pattern framesize, memory
/abcd/
Memory allocation (code space): 26
Frame size for pcre2_match(): 128
abcd\=memory
malloc 20480
0: abcd
abcd\=find_limits
Minimum heap limit = 1
Minimum match limit = 2
Minimum depth limit = 2
0: abcd
/(((((((((((((((((((((((((((((( (^abc|xyz){1,20}$ ))))))))))))))))))))))))))))))/x
Memory allocation (code space): 1294
Frame size for pcre2_match(): 624
abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcX\=memory
malloc 40960
free unremembered block
No match
abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcX\=find_limits
Minimum heap limit = 22
Minimum match limit = 37
Minimum depth limit = 35
No match
/ab(cd)/
Memory allocation (code space): 36
Frame size for pcre2_match(): 144
abcd\=memory
0: abcd
1: cd
abcd\=memory,ovector=0
free 40960
free unremembered block
malloc 128
malloc 20480
0: abcd
1: cd

40
testdata/testoutputheap-32 vendored Normal file
View File

@ -0,0 +1,40 @@
#pattern framesize, memory
/abcd/
Memory allocation (code space): 52
Frame size for pcre2_match(): 128
abcd\=memory
malloc 20480
0: abcd
abcd\=find_limits
Minimum heap limit = 1
Minimum match limit = 2
Minimum depth limit = 2
0: abcd
/(((((((((((((((((((((((((((((( (^abc|xyz){1,20}$ ))))))))))))))))))))))))))))))/x
Memory allocation (code space): 2588
Frame size for pcre2_match(): 624
abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcX\=memory
malloc 40960
free unremembered block
No match
abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcX\=find_limits
Minimum heap limit = 22
Minimum match limit = 37
Minimum depth limit = 35
No match
/ab(cd)/
Memory allocation (code space): 72
Frame size for pcre2_match(): 144
abcd\=memory
0: abcd
1: cd
abcd\=memory,ovector=0
free 40960
free unremembered block
malloc 128
malloc 20480
0: abcd
1: cd

40
testdata/testoutputheap-8 vendored Normal file
View File

@ -0,0 +1,40 @@
#pattern framesize, memory
/abcd/
Memory allocation (code space): 15
Frame size for pcre2_match(): 128
abcd\=memory
malloc 20480
0: abcd
abcd\=find_limits
Minimum heap limit = 1
Minimum match limit = 2
Minimum depth limit = 2
0: abcd
/(((((((((((((((((((((((((((((( (^abc|xyz){1,20}$ ))))))))))))))))))))))))))))))/x
Memory allocation (code space): 855
Frame size for pcre2_match(): 624
abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcX\=memory
malloc 40960
free unremembered block
No match
abcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcabcX\=find_limits
Minimum heap limit = 22
Minimum match limit = 37
Minimum depth limit = 35
No match
/ab(cd)/
Memory allocation (code space): 23
Frame size for pcre2_match(): 144
abcd\=memory
0: abcd
1: cd
abcd\=memory,ovector=0
free 40960
free unremembered block
malloc 128
malloc 20480
0: abcd
1: cd