3 ###############################################################################
4 # Run the PCRE2 tests using the pcre2test program. The appropriate tests are
5 # selected, depending on which build-time options were used.
7 # When JIT support is available, all appropriate tests are run with and without
8 # JIT, unless "-nojit" is given on the command line. There are also two tests
9 # for JIT-specific features, one to be run when JIT support is available
10 # (unless "-nojit" is specified), and one when it is not.
12 # Whichever of the 8-, 16- and 32-bit libraries exist are tested. It is also
13 # possible to select which to test by giving "-8", "-16" or "-32" on the
16 # As well as "-nojit", "-8", "-16", and "-32", arguments for this script are
17 # individual test numbers, ranges of tests such as 3-6 or 3- (meaning 3 to the
18 # end), or a number preceded by ~ to exclude a test. For example, "3-15 ~10"
19 # runs tests 3 to 15, excluding test 10, and just "~10" runs all the tests
20 # except test 10. Whatever order the arguments are in, the tests are always run
23 # Inappropriate tests are automatically skipped (with a comment to say so). For
24 # example, if JIT support is not compiled, test 16 is skipped, whereas if JIT
25 # support is compiled, test 15 is skipped.
27 # Other arguments can be one of the words "-valgrind", "-valgrind-log", or
28 # "-sim" followed by an argument to run cross-compiled executables under a
29 # simulator, for example:
31 # RunTest 3 -sim "qemu-arm -s 8388608"
33 # For backwards compatibility, -nojit, -valgrind, -valgrind-log, and -sim may
34 # be given without the leading "-" character.
36 # When PCRE2 is compiled by clang with -fsanitize arguments, some tests need
37 # very much more stack than normal. In environments where the stack can be
38 # set at runtime, -bigstack sets a gigantic stack.
40 # There are two special cases where only one argument is allowed:
42 # If the first and only argument is "ebcdic", the script runs the special
43 # EBCDIC test that can be useful for checking certain EBCDIC features, even
44 # when run in an ASCII environment. PCRE2 must be built with EBCDIC support for
45 # this test to be run.
47 # If the script is obeyed as "RunTest list", a list of available tests is
48 # output, but none of them are run.
49 ###############################################################################
51 # Define test titles in variables so that they can be output as a list. Some
52 # of them are modified (e.g. with -8 or -16) when used in the actual tests.
54 title0="Test 0: Unchecked pcre2test argument tests (to improve coverage)"
55 title1="Test 1: Main non-UTF, non-UCP functionality (compatible with Perl >= 5.10)"
56 title2="Test 2: API, errors, internals and non-Perl stuff"
57 title3="Test 3: Locale-specific features"
59 title4B=" and Unicode property support (compatible with Perl >= 5.10)"
60 title5A="Test 5: API, internals, and non-Perl stuff for UTF"
61 title5B=" and UCP support"
62 title6="Test 6: DFA matching main non-UTF, non-UCP functionality"
63 title7A="Test 7: DFA matching with UTF"
64 title7B=" and Unicode property support"
65 title8="Test 8: Internal offsets and code size tests"
66 title9="Test 9: Specials for the basic 8-bit library"
67 title10="Test 10: Specials for the 8-bit library with UTF-8 and UCP support"
68 title11="Test 11: Specials for the basic 16-bit and 32-bit libraries"
69 title12="Test 12: Specials for the 16-bit and 32-bit libraries UTF and UCP support"
70 title13="Test 13: DFA specials for the basic 16-bit and 32-bit libraries"
71 title14="Test 14: DFA specials for UTF and UCP support"
72 title15="Test 15: Non-JIT limits and other non-JIT tests"
73 title16="Test 16: JIT-specific features when JIT is not available"
74 title17="Test 17: JIT-specific features when JIT is available"
75 title18="Test 18: Tests of the POSIX interface, excluding UTF/UCP"
76 title19="Test 19: Tests of the POSIX interface with UTF/UCP"
77 title20="Test 20: Serialization and code copy tests"
78 title21="Test 21: \C tests without UTF (supported for DFA matching)"
79 title22="Test 22: \C tests with UTF (not supported for DFA matching)"
80 title23="Test 23: \C disabled test"
81 title24="Test 24: Non-UTF pattern conversion tests"
82 title25="Test 25: UTF pattern conversion tests"
85 if [ $# -eq 1 -a "$1" = "list" ]; then
88 echo $title2 "(not UTF or UCP)"
90 echo $title4A $title4B
91 echo $title5A $title5B
93 echo $title7A $title7B
115 # Set up a suitable "diff" command for comparison. Some systems
116 # have a diff that lacks a -u option. Try to deal with this.
119 diff -u /dev/null /dev/null 2>/dev/null && cf="diff -u"
123 if [ -n "$srcdir" -a -d "$srcdir" ] ; then
124 testdata="$srcdir/testdata"
125 elif [ -d "./testdata" ] ; then
127 elif [ -d "../testdata" ] ; then
130 echo "Cannot find the testdata directory"
135 # ------ Function to check results of a test -------
137 # This function is called with three parameters:
139 # $1 the value of $? after a call to pcre2test
140 # $2 the suffix of the output file to compare with
141 # $3 the $opt value (empty, -jit, or -dfa)
143 # Note: must define using name(), not "function name", for Solaris.
147 if [ $1 -ne 0 ] ; then
148 echo "** pcre2test failed - check testtry"
152 -jit) with=" with JIT";;
153 -dfa) with=" with DFA";;
156 $cf $testdata/testoutput$2 testtry
157 if [ $? != 0 ] ; then
159 echo "** Test $2 failed$with"
166 # ------ Function to run and check a special pcre2test arguments test -------
170 $valgrind $vjs ./pcre2test $1 >>testtry
171 if [ $? -ne 0 ] ; then
172 echo "** pcre2test $1 failed - check testtry"
178 # ------ Special EBCDIC Test -------
180 if [ $# -eq 1 -a "$1" = "ebcdic" ]; then
181 $valgrind ./pcre2test -C ebcdic >/dev/null
183 if [ $ebcdic -ne 1 ] ; then
184 echo "Cannot run EBCDIC tests: EBCDIC support not compiled"
187 for opt in "" "-dfa"; do
188 ./pcre2test -q $opt $testdata/testinputEBC >testtry
189 checkresult $? EBC "$opt"
195 # ------ Normal Tests ------
209 # This is in case the caller has set aliases (as I do - PH)
212 # Process options and select which tests to run; for those that are explicitly
213 # requested, check that the necessary optional facilities are available.
242 while [ $# -gt 0 ] ; do
273 bigstack|-bigstack) bigstack=yes;;
274 nojit|-nojit) nojit=yes;;
275 sim|-sim) shift; sim=$1;;
276 valgrind|-valgrind) valgrind="valgrind --tool=memcheck -q --smc-check=all-non-file";;
277 valgrind-log|-valgrind-log) valgrind="valgrind --tool=memcheck --num-callers=30 --leak-check=no --error-limit=no --smc-check=all-non-file --log-file=report.%p ";;
279 if expr "$1" : '~[0-9][0-9]*$' >/dev/null; then
280 skip="$skip `expr "$1" : '~\([0-9]*\)*$'`"
282 echo "Unknown option or test selector '$1'"; exit 1
286 if expr "$1" : '[0-9][0-9]*-[0-9]*$' >/dev/null; then
287 tf=`expr "$1" : '\([0-9]*\)'`
288 tt=`expr "$1" : '.*-\([0-9]*\)'`
289 if [ "$tt" = "" ] ; then tt=$maxtest; fi
290 if expr \( "$tt" ">" "$maxtest" \) >/dev/null; then
291 echo "Invalid test range '$1'"; exit 1
293 while expr "$tf" "<=" "$tt" >/dev/null; do
298 echo "Invalid test range '$1'"; exit 1
301 *) echo "Unknown option or test selector '$1'"; exit 1;;
306 # Find which optional facilities are available.
308 $sim ./pcre2test -C linksize >/dev/null
310 if [ $link_size -lt 2 ] ; then
311 echo "RunTest: Failed to find internal link size"
314 if [ $link_size -gt 4 ] ; then
315 echo "RunTest: Failed to find internal link size"
319 # If it is possible to set the system stack size and -bigstack was given,
320 # set up a large stack.
322 $sim ./pcre2test -S 1 /dev/null /dev/null
323 if [ $? -eq 0 -a "$bigstack" != "" ] ; then
329 # All of 8-bit, 16-bit, and 32-bit character strings may be supported, but only
332 $sim ./pcre2test -C pcre2-8 >/dev/null
334 $sim ./pcre2test -C pcre2-16 >/dev/null
336 $sim ./pcre2test -C pcre2-32 >/dev/null
341 $sim ./pcre2test -C backslash-C >/dev/null
344 # Initialize all bitsizes skipped
350 # If no bitsize arguments, select all that are available
352 if [ "$arg8$arg16$arg32" = "" ] ; then
353 if [ $support8 -ne 0 ] ; then
356 if [ $support16 -ne 0 ] ; then
359 if [ $support32 -ne 0 ] ; then
363 # Otherwise, select requested bit sizes
366 if [ "$arg8" = yes ] ; then
367 if [ $support8 -eq 0 ] ; then
368 echo "Cannot run 8-bit library tests: 8-bit library not compiled"
373 if [ "$arg16" = yes ] ; then
374 if [ $support16 -eq 0 ] ; then
375 echo "Cannot run 16-bit library tests: 16-bit library not compiled"
380 if [ "$arg32" = yes ] ; then
381 if [ $support32 -eq 0 ] ; then
382 echo "Cannot run 32-bit library tests: 32-bit library not compiled"
389 # UTF support is implied by Unicode support, and it always applies to all bit
390 # sizes if both are supported; we can't have UTF-8 support without UTF-16 or
393 $sim ./pcre2test -C unicode >/dev/null
396 # When JIT is used with valgrind, we need to set up valgrind suppressions as
397 # otherwise there are a lot of false positive valgrind reports when the
398 # the hardware supports SSE2.
401 $sim ./pcre2test -C jit >/dev/null
403 if [ $jit -ne 0 -a "$nojit" != "yes" ] ; then
405 if [ "$valgrind" != "" ] ; then
406 vjs="--suppressions=$testdata/valgrind-jit.supp"
410 # If no specific tests were requested, select all. Those that are not
411 # relevant will be automatically skipped.
413 if [ $do0 = no -a $do1 = no -a $do2 = no -a $do3 = no -a \
414 $do4 = no -a $do5 = no -a $do6 = no -a $do7 = no -a \
415 $do8 = no -a $do9 = no -a $do10 = no -a $do11 = no -a \
416 $do12 = no -a $do13 = no -a $do14 = no -a $do15 = no -a \
417 $do16 = no -a $do17 = no -a $do18 = no -a $do19 = no -a \
418 $do20 = no -a $do21 = no -a $do22 = no -a $do23 = no -a \
419 $do24 = no -a $do25 = no \
449 # Handle any explicit skips at this stage, so that an argument list may consist
450 # only of explicit skips.
452 for i in $skip; do eval do$i=no; done
454 # Show which release and which test data
457 echo PCRE2 C library tests using test data from $testdata
458 $sim ./pcre2test /dev/null
461 for bmode in "$test8" "$test16" "$test32"; do
464 -16) if [ "$test8$test32" != "skipskip" ] ; then echo ""; fi
465 bits=16; echo "---- Testing 16-bit library ----"; echo "";;
466 -32) if [ "$test8$test16" != "skipskip" ] ; then echo ""; fi
467 bits=32; echo "---- Testing 32-bit library ----"; echo "";;
468 -8) bits=8; echo "---- Testing 8-bit library ----"; echo "";;
471 # Test 0 is a special test. Its output is not checked, because it will
472 # be different on different hardware and with different configurations.
473 # Running this test just exercises the code.
475 if [ $do0 = yes ] ; then
477 echo '/abc/jit,memory,framesize' >testSinput
478 echo ' abc' >>testSinput
481 checkspecial '--help'
482 checkspecial '-S 1 -t 10 testSinput'
486 # Primary non-UTF test, compatible with JIT and all versions of Perl >= 5.8
488 if [ $do1 = yes ] ; then
490 for opt in "" $jitopt; do
491 $sim $valgrind ${opt:+$vjs} ./pcre2test -q $setstack $bmode $opt $testdata/testinput1 testtry
492 checkresult $? 1 "$opt"
496 # PCRE2 tests that are not Perl-compatible: API, errors, internals
498 if [ $do2 = yes ] ; then
499 echo $title2 "(excluding UTF-$bits)"
500 for opt in "" $jitopt; do
501 $sim $valgrind ${opt:+$vjs} ./pcre2test -q $setstack $bmode $opt $testdata/testinput2 testtry
503 $sim $valgrind ${opt:+$vjs} ./pcre2test -q $bmode $opt -error -70,-62,-2,-1,0,100,101,191,200 >>testtry
504 checkresult $? 2 "$opt"
509 # Locale-specific tests, provided that either the "fr_FR", "fr_CA", "french"
510 # or "fr" locale is available. The first two are Unix-like standards; the
511 # last two are for Windows. Unfortunately, different versions of the French
512 # locale give different outputs for some items. This test passes if the
513 # output matches any one of the alternative output files.
515 if [ $do3 = yes ] ; then
518 # In some environments locales that are listed by the "locale -a"
519 # command do not seem to work with setlocale(). Therefore, we do
520 # a preliminary test to see if pcre2test can set one before going
523 for loc in 'fr_FR' 'french' 'fr' 'fr_CA'; do
524 locale -a | grep "^$loc\$" >/dev/null
525 if [ $? -eq 0 ] ; then
526 echo "/a/locale=$loc" | \
527 $sim $valgrind ./pcre2test -q $bmode | \
528 grep "Failed to set locale" >/dev/null
529 if [ $? -ne 0 ] ; then
531 if [ "$locale" = "fr_FR" ] ; then
532 infile=$testdata/testinput3
533 outfile=$testdata/testoutput3
534 outfile2=$testdata/testoutput3A
535 outfile3=$testdata/testoutput3B
539 outfile2=test3outputA
540 outfile3=test3outputB
541 sed "s/fr_FR/$loc/" $testdata/testinput3 >test3input
542 sed "s/fr_FR/$loc/" $testdata/testoutput3 >test3output
543 sed "s/fr_FR/$loc/" $testdata/testoutput3A >test3outputA
544 sed "s/fr_FR/$loc/" $testdata/testoutput3B >test3outputB
551 if [ "$locale" != "" ] ; then
552 echo $title3 "(using '$locale' locale)"
553 for opt in "" $jitopt; do
554 $sim $valgrind ${opt:+$vjs} ./pcre2test -q $setstack $bmode $opt $infile testtry
557 -jit) with=" with JIT";;
560 if $cf $outfile testtry >teststdout || \
561 $cf $outfile2 testtry >teststdout || \
562 $cf $outfile3 testtry >teststdout
566 echo "** Locale test did not run successfully$with. The output did not match"
567 echo " $outfile, $outfile2 or $outfile3."
568 echo " This may mean that there is a problem with the locale settings rather"
569 echo " than a bug in PCRE2."
576 echo "Cannot test locale-specific features - none of the 'fr_FR', 'fr_CA',"
577 echo "'fr' or 'french' locales can be set, or the \"locale\" command is"
578 echo "not available to check for them."
583 # Tests for UTF and Unicode property support
585 if [ $do4 = yes ] ; then
586 echo ${title4A}-${bits}${title4B}
587 if [ $utf -eq 0 ] ; then
588 echo " Skipped because UTF-$bits support is not available"
590 for opt in "" $jitopt; do
591 $sim $valgrind ${opt:+$vjs} ./pcre2test -q $setstack $bmode $opt $testdata/testinput4 testtry
592 checkresult $? 4 "$opt"
597 if [ $do5 = yes ] ; then
598 echo ${title5A}-${bits}$title5B
599 if [ $utf -eq 0 ] ; then
600 echo " Skipped because UTF-$bits support is not available"
602 for opt in "" $jitopt; do
603 $sim $valgrind ${opt:+$vjs} ./pcre2test -q $setstack $bmode $opt $testdata/testinput5 testtry
604 checkresult $? 5 "$opt"
609 # Tests for DFA matching support
611 if [ $do6 = yes ] ; then
613 $sim $valgrind ./pcre2test -q $setstack $bmode $testdata/testinput6 testtry
617 if [ $do7 = yes ] ; then
618 echo ${title7A}-${bits}$title7B
619 if [ $utf -eq 0 ] ; then
620 echo " Skipped because UTF-$bits support is not available"
622 $sim $valgrind ./pcre2test -q $setstack $bmode $opt $testdata/testinput7 testtry
627 # Test of internal offsets and code sizes. This test is run only when there
628 # is UTF/UCP support. The actual tests are mostly the same as in some of the
629 # above, but in this test we inspect some offsets and sizes. This is a
630 # doublecheck for the maintainer, just in case something changes unexpectely.
631 # The output from this test is different in 8-bit, 16-bit, and 32-bit modes
632 # and for different link sizes, so there are different output files for each
633 # mode and link size.
635 if [ $do8 = yes ] ; then
637 if [ $utf -eq 0 ] ; then
638 echo " Skipped because UTF-$bits support is not available"
640 $sim $valgrind ./pcre2test -q $setstack $bmode $testdata/testinput8 testtry
641 checkresult $? 8-$bits-$link_size ""
645 # Tests for 8-bit-specific features
647 if [ "$do9" = yes ] ; then
649 if [ "$bits" = "16" -o "$bits" = "32" ] ; then
650 echo " Skipped when running 16/32-bit tests"
652 for opt in "" $jitopt; do
653 $sim $valgrind ${opt:+$vjs} ./pcre2test -q $setstack $bmode $opt $testdata/testinput9 testtry
654 checkresult $? 9 "$opt"
659 # Tests for UTF-8 and UCP 8-bit-specific features
661 if [ "$do10" = yes ] ; then
663 if [ "$bits" = "16" -o "$bits" = "32" ] ; then
664 echo " Skipped when running 16/32-bit tests"
665 elif [ $utf -eq 0 ] ; then
666 echo " Skipped because UTF-$bits support is not available"
668 for opt in "" $jitopt; do
669 $sim $valgrind ${opt:+$vjs} ./pcre2test -q $setstack $bmode $opt $testdata/testinput10 testtry
670 checkresult $? 10 "$opt"
675 # Tests for 16-bit and 32-bit features. Output is different for the two widths.
677 if [ $do11 = yes ] ; then
679 if [ "$bits" = "8" ] ; then
680 echo " Skipped when running 8-bit tests"
682 for opt in "" $jitopt; do
683 $sim $valgrind ${opt:+$vjs} ./pcre2test -q $setstack $bmode $opt $testdata/testinput11 testtry
684 checkresult $? 11-$bits "$opt"
689 # Tests for 16-bit and 32-bit features with UTF-16/32 and UCP support. Output
690 # is different for the two widths.
692 if [ $do12 = yes ] ; then
694 if [ "$bits" = "8" ] ; then
695 echo " Skipped when running 8-bit tests"
696 elif [ $utf -eq 0 ] ; then
697 echo " Skipped because UTF-$bits support is not available"
699 for opt in "" $jitopt; do
700 $sim $valgrind ${opt:+$vjs} ./pcre2test -q $setstack $bmode $opt $testdata/testinput12 testtry
701 checkresult $? 12-$bits "$opt"
706 # Tests for 16/32-bit-specific features in DFA non-UTF modes
708 if [ $do13 = yes ] ; then
710 if [ "$bits" = "8" ] ; then
711 echo " Skipped when running 8-bit tests"
713 $sim $valgrind ./pcre2test -q $setstack $bmode $testdata/testinput13 testtry
718 # Tests for DFA UTF and UCP features. Output is different for the different widths.
720 if [ $do14 = yes ] ; then
722 if [ $utf -eq 0 ] ; then
723 echo " Skipped because UTF-$bits support is not available"
725 $sim $valgrind ./pcre2test -q $setstack $bmode $opt $testdata/testinput14 testtry
726 checkresult $? 14-$bits ""
730 # Test non-JIT match and recursion limits
732 if [ $do15 = yes ] ; then
734 $sim $valgrind ./pcre2test -q $setstack $bmode $testdata/testinput15 testtry
738 # Test JIT-specific features when JIT is not available
740 if [ $do16 = yes ] ; then
742 if [ $jit -ne 0 ] ; then
743 echo " Skipped because JIT is available"
745 $sim $valgrind ./pcre2test -q $setstack $bmode $testdata/testinput16 testtry
750 # Test JIT-specific features when JIT is available
752 if [ $do17 = yes ] ; then
754 if [ $jit -eq 0 -o "$nojit" = "yes" ] ; then
755 echo " Skipped because JIT is not available or nojit was specified"
757 $sim $valgrind $vjs ./pcre2test -q $setstack $bmode $testdata/testinput17 testtry
762 # Tests for the POSIX interface without UTF/UCP (8-bit only)
764 if [ $do18 = yes ] ; then
766 if [ "$bits" = "16" -o "$bits" = "32" ] ; then
767 echo " Skipped when running 16/32-bit tests"
769 $sim $valgrind ./pcre2test -q $setstack $bmode $testdata/testinput18 testtry
774 # Tests for the POSIX interface with UTF/UCP (8-bit only)
776 if [ $do19 = yes ] ; then
778 if [ "$bits" = "16" -o "$bits" = "32" ] ; then
779 echo " Skipped when running 16/32-bit tests"
780 elif [ $utf -eq 0 ] ; then
781 echo " Skipped because UTF-$bits support is not available"
783 $sim $valgrind ./pcre2test -q $setstack $bmode $testdata/testinput19 testtry
788 # Serialization tests
790 if [ $do20 = yes ] ; then
792 $sim $valgrind ./pcre2test -q $setstack $bmode $testdata/testinput20 testtry
796 # \C tests without UTF - DFA matching is supported
798 if [ "$do21" = yes ] ; then
800 if [ $supportBSC -eq 0 ] ; then
801 echo " Skipped because \C is disabled"
803 for opt in "" $jitopt -dfa; do
804 $sim $valgrind ${opt:+$vjs} ./pcre2test -q $setstack $bmode $opt $testdata/testinput21 testtry
805 checkresult $? 21 "$opt"
810 # \C tests with UTF - DFA matching is not supported for \C in UTF mode
812 if [ "$do22" = yes ] ; then
814 if [ $supportBSC -eq 0 ] ; then
815 echo " Skipped because \C is disabled"
816 elif [ $utf -eq 0 ] ; then
817 echo " Skipped because UTF-$bits support is not available"
819 for opt in "" $jitopt; do
820 $sim $valgrind ${opt:+$vjs} ./pcre2test -q $setstack $bmode $opt $testdata/testinput22 testtry
821 checkresult $? 22-$bits "$opt"
826 # Test when \C is disabled
828 if [ "$do23" = yes ] ; then
830 if [ $supportBSC -ne 0 ] ; then
831 echo " Skipped because \C is not disabled"
833 $sim $valgrind ./pcre2test -q $setstack $bmode $testdata/testinput23 testtry
838 # Non-UTF pattern conversion tests
840 if [ "$do24" = yes ] ; then
842 $sim $valgrind ./pcre2test -q $setstack $bmode $testdata/testinput24 testtry
846 # UTF pattern conversion tests
848 if [ "$do25" = yes ] ; then
850 if [ $utf -eq 0 ] ; then
851 echo " Skipped because UTF-$bits support is not available"
853 $sim $valgrind ./pcre2test -q $setstack $bmode $testdata/testinput25 testtry
858 # End of loop for 8/16/32-bit tests
861 # Clean up local working files
862 rm -f testSinput test3input testsaved1 testsaved2 test3output test3outputA test3outputB teststdout teststderr testtry