Blame RunTest

Packit 504f36
#! /bin/sh
Packit 504f36
Packit 504f36
###############################################################################
Packit 504f36
# Run the PCRE2 tests using the pcre2test program. The appropriate tests are
Packit 504f36
# selected, depending on which build-time options were used.
Packit 504f36
#
Packit 504f36
# When JIT support is available, all appropriate tests are run with and without
Packit 504f36
# JIT, unless "-nojit" is given on the command line. There are also two tests
Packit 504f36
# for JIT-specific features, one to be run when JIT support is available
Packit 504f36
# (unless "-nojit" is specified), and one when it is not.
Packit 504f36
#
Packit 504f36
# Whichever of the 8-, 16- and 32-bit libraries exist are tested. It is also
Packit 504f36
# possible to select which to test by giving "-8", "-16" or "-32" on the
Packit 504f36
# command line.
Packit 504f36
#
Packit 504f36
# As well as "-nojit", "-8", "-16", and "-32", arguments for this script are
Packit 504f36
# individual test numbers, ranges of tests such as 3-6 or 3- (meaning 3 to the
Packit 504f36
# end), or a number preceded by ~ to exclude a test. For example, "3-15 ~10"
Packit 504f36
# runs tests 3 to 15, excluding test 10, and just "~10" runs all the tests
Packit 504f36
# except test 10. Whatever order the arguments are in, the tests are always run
Packit 504f36
# in numerical order.
Packit 504f36
#
Packit 504f36
# Inappropriate tests are automatically skipped (with a comment to say so). For
Packit 504f36
# example, if JIT support is not compiled, test 16 is skipped, whereas if JIT
Packit 504f36
# support is compiled, test 15 is skipped.
Packit 504f36
#
Packit 504f36
# Other arguments can be one of the words "-valgrind", "-valgrind-log", or
Packit 504f36
# "-sim" followed by an argument to run cross-compiled executables under a
Packit 504f36
# simulator, for example:
Packit 504f36
#
Packit 504f36
# RunTest 3 -sim "qemu-arm -s 8388608"
Packit 504f36
#
Packit 504f36
# For backwards compatibility, -nojit, -valgrind, -valgrind-log, and -sim may
Packit 504f36
# be given without the leading "-" character.
Packit 504f36
#
Packit 504f36
# When PCRE2 is compiled by clang with -fsanitize arguments, some tests need
Packit 504f36
# very much more stack than normal. In environments where the stack can be
Packit 504f36
# set at runtime, -bigstack sets a gigantic stack.
Packit 504f36
#
Packit 504f36
# There are two special cases where only one argument is allowed:
Packit 504f36
#
Packit 504f36
# If the first and only argument is "ebcdic", the script runs the special
Packit 504f36
# EBCDIC test that can be useful for checking certain EBCDIC features, even
Packit 504f36
# when run in an ASCII environment. PCRE2 must be built with EBCDIC support for
Packit 504f36
# this test to be run.
Packit 504f36
#
Packit 504f36
# If the script is obeyed as "RunTest list", a list of available tests is
Packit 504f36
# output, but none of them are run.
Packit 504f36
###############################################################################
Packit 504f36
Packit 504f36
# Define test titles in variables so that they can be output as a list. Some
Packit 504f36
# of them are modified (e.g. with -8 or -16) when used in the actual tests.
Packit 504f36
Packit 504f36
title0="Test 0: Unchecked pcre2test argument tests (to improve coverage)"
Packit 504f36
title1="Test 1: Main non-UTF, non-UCP functionality (compatible with Perl >= 5.10)"
Packit 504f36
title2="Test 2: API, errors, internals and non-Perl stuff"
Packit 504f36
title3="Test 3: Locale-specific features"
Packit 504f36
title4A="Test 4: UTF"
Packit 504f36
title4B=" and Unicode property support (compatible with Perl >= 5.10)"
Packit 504f36
title5A="Test 5: API, internals, and non-Perl stuff for UTF"
Packit 504f36
title5B=" and UCP support"
Packit 504f36
title6="Test 6: DFA matching main non-UTF, non-UCP functionality"
Packit 504f36
title7A="Test 7: DFA matching with UTF"
Packit 504f36
title7B=" and Unicode property support"
Packit 504f36
title8="Test 8: Internal offsets and code size tests"
Packit 504f36
title9="Test 9: Specials for the basic 8-bit library"
Packit 504f36
title10="Test 10: Specials for the 8-bit library with UTF-8 and UCP support"
Packit 504f36
title11="Test 11: Specials for the basic 16-bit and 32-bit libraries"
Packit 504f36
title12="Test 12: Specials for the 16-bit and 32-bit libraries UTF and UCP support"
Packit 504f36
title13="Test 13: DFA specials for the basic 16-bit and 32-bit libraries"
Packit 504f36
title14="Test 14: DFA specials for UTF and UCP support"
Packit 504f36
title15="Test 15: Non-JIT limits and other non-JIT tests"
Packit 504f36
title16="Test 16: JIT-specific features when JIT is not available"
Packit 504f36
title17="Test 17: JIT-specific features when JIT is available"
Packit 504f36
title18="Test 18: Tests of the POSIX interface, excluding UTF/UCP"
Packit 504f36
title19="Test 19: Tests of the POSIX interface with UTF/UCP"
Packit 504f36
title20="Test 20: Serialization and code copy tests"
Packit 504f36
title21="Test 21: \C tests without UTF (supported for DFA matching)"
Packit 504f36
title22="Test 22: \C tests with UTF (not supported for DFA matching)"
Packit 504f36
title23="Test 23: \C disabled test"
Packit 504f36
title24="Test 24: Non-UTF pattern conversion tests"
Packit 504f36
title25="Test 25: UTF pattern conversion tests"
Packit 504f36
maxtest=25
Packit 504f36
Packit 504f36
if [ $# -eq 1 -a "$1" = "list" ]; then
Packit 504f36
  echo $title0
Packit 504f36
  echo $title1
Packit 504f36
  echo $title2 "(not UTF or UCP)"
Packit 504f36
  echo $title3
Packit 504f36
  echo $title4A $title4B
Packit 504f36
  echo $title5A $title5B
Packit 504f36
  echo $title6
Packit 504f36
  echo $title7A $title7B
Packit 504f36
  echo $title8
Packit 504f36
  echo $title9
Packit 504f36
  echo $title10
Packit 504f36
  echo $title11
Packit 504f36
  echo $title12
Packit 504f36
  echo $title13
Packit 504f36
  echo $title14
Packit 504f36
  echo $title15
Packit 504f36
  echo $title16
Packit 504f36
  echo $title17
Packit 504f36
  echo $title18
Packit 504f36
  echo $title19
Packit 504f36
  echo $title20
Packit 504f36
  echo $title21
Packit 504f36
  echo $title22
Packit 504f36
  echo $title23
Packit 504f36
  echo $title24
Packit 504f36
  echo $title25
Packit 504f36
  exit 0
Packit 504f36
fi
Packit 504f36
Packit 504f36
# Set up a suitable "diff" command for comparison. Some systems
Packit 504f36
# have a diff that lacks a -u option. Try to deal with this.
Packit 504f36
Packit 504f36
cf="diff"
Packit 504f36
diff -u /dev/null /dev/null 2>/dev/null && cf="diff -u"
Packit 504f36
Packit 504f36
# Find the test data
Packit 504f36
Packit 504f36
if [ -n "$srcdir" -a -d "$srcdir" ] ; then
Packit 504f36
  testdata="$srcdir/testdata"
Packit 504f36
elif [ -d "./testdata" ] ; then
Packit 504f36
  testdata=./testdata
Packit 504f36
elif [ -d "../testdata" ] ; then
Packit 504f36
  testdata=../testdata
Packit 504f36
else
Packit 504f36
  echo "Cannot find the testdata directory"
Packit 504f36
  exit 1
Packit 504f36
fi
Packit 504f36
Packit 504f36
Packit 504f36
# ------ Function to check results of a test -------
Packit 504f36
Packit 504f36
# This function is called with three parameters:
Packit 504f36
#
Packit 504f36
#  $1 the value of $? after a call to pcre2test
Packit 504f36
#  $2 the suffix of the output file to compare with
Packit 504f36
#  $3 the $opt value (empty, -jit, or -dfa)
Packit 504f36
#
Packit 504f36
# Note: must define using name(), not "function name", for Solaris.
Packit 504f36
Packit 504f36
checkresult()
Packit 504f36
  {
Packit 504f36
  if [ $1 -ne 0 ] ; then
Packit 504f36
    echo "** pcre2test failed - check testtry"
Packit 504f36
    exit 1
Packit 504f36
  fi
Packit 504f36
  case "$3" in
Packit 504f36
    -jit) with=" with JIT";;
Packit 504f36
    -dfa) with=" with DFA";;
Packit 504f36
    *)    with="";;
Packit 504f36
  esac
Packit 504f36
  $cf $testdata/testoutput$2 testtry
Packit 504f36
  if [ $? != 0 ] ; then
Packit 504f36
    echo ""
Packit 504f36
    echo "** Test $2 failed$with"
Packit 504f36
    exit 1
Packit 504f36
  fi
Packit 504f36
  echo "  OK$with"
Packit 504f36
  }
Packit 504f36
Packit 504f36
Packit 504f36
# ------ Function to run and check a special pcre2test arguments test -------
Packit 504f36
Packit 504f36
checkspecial()
Packit 504f36
  {
Packit 504f36
  $valgrind  $vjs ./pcre2test $1 >>testtry
Packit 504f36
  if [ $? -ne 0 ] ; then
Packit 504f36
    echo "** pcre2test $1 failed - check testtry"
Packit 504f36
    exit 1
Packit 504f36
  fi
Packit 504f36
  }
Packit 504f36
Packit 504f36
Packit 504f36
# ------ Special EBCDIC Test -------
Packit 504f36
Packit 504f36
if [ $# -eq 1 -a "$1" = "ebcdic" ]; then
Packit 504f36
  $valgrind ./pcre2test -C ebcdic >/dev/null
Packit 504f36
  ebcdic=$?
Packit 504f36
  if [ $ebcdic -ne 1 ] ; then
Packit 504f36
    echo "Cannot run EBCDIC tests: EBCDIC support not compiled"
Packit 504f36
    exit 1
Packit 504f36
  fi
Packit 504f36
  for opt in "" "-dfa"; do
Packit 504f36
    ./pcre2test -q $opt $testdata/testinputEBC >testtry
Packit 504f36
    checkresult $? EBC "$opt"
Packit 504f36
  done
Packit 504f36
exit 0
Packit 504f36
fi
Packit 504f36
Packit 504f36
Packit 504f36
# ------ Normal Tests ------
Packit 504f36
Packit 504f36
# Default values
Packit 504f36
Packit 504f36
arg8=
Packit 504f36
arg16=
Packit 504f36
arg32=
Packit 504f36
nojit=
Packit 504f36
bigstack=
Packit 504f36
sim=
Packit 504f36
skip=
Packit 504f36
valgrind=
Packit 504f36
vjs=
Packit 504f36
Packit 504f36
# This is in case the caller has set aliases (as I do - PH)
Packit 504f36
unset cp ls mv rm
Packit 504f36
Packit 504f36
# Process options and select which tests to run; for those that are explicitly
Packit 504f36
# requested, check that the necessary optional facilities are available.
Packit 504f36
Packit 504f36
do0=no
Packit 504f36
do1=no
Packit 504f36
do2=no
Packit 504f36
do3=no
Packit 504f36
do4=no
Packit 504f36
do5=no
Packit 504f36
do6=no
Packit 504f36
do7=no
Packit 504f36
do8=no
Packit 504f36
do9=no
Packit 504f36
do10=no
Packit 504f36
do11=no
Packit 504f36
do12=no
Packit 504f36
do13=no
Packit 504f36
do14=no
Packit 504f36
do15=no
Packit 504f36
do16=no
Packit 504f36
do17=no
Packit 504f36
do18=no
Packit 504f36
do19=no
Packit 504f36
do20=no
Packit 504f36
do21=no
Packit 504f36
do22=no
Packit 504f36
do23=no
Packit 504f36
do24=no
Packit 504f36
do25=no
Packit 504f36
Packit 504f36
while [ $# -gt 0 ] ; do
Packit 504f36
  case $1 in
Packit 504f36
    0) do0=yes;;
Packit 504f36
    1) do1=yes;;
Packit 504f36
    2) do2=yes;;
Packit 504f36
    3) do3=yes;;
Packit 504f36
    4) do4=yes;;
Packit 504f36
    5) do5=yes;;
Packit 504f36
    6) do6=yes;;
Packit 504f36
    7) do7=yes;;
Packit 504f36
    8) do8=yes;;
Packit 504f36
    9) do9=yes;;
Packit 504f36
   10) do10=yes;;
Packit 504f36
   11) do11=yes;;
Packit 504f36
   12) do12=yes;;
Packit 504f36
   13) do13=yes;;
Packit 504f36
   14) do14=yes;;
Packit 504f36
   15) do15=yes;;
Packit 504f36
   16) do16=yes;;
Packit 504f36
   17) do17=yes;;
Packit 504f36
   18) do18=yes;;
Packit 504f36
   19) do19=yes;;
Packit 504f36
   20) do20=yes;;
Packit 504f36
   21) do21=yes;;
Packit 504f36
   22) do22=yes;;
Packit 504f36
   23) do23=yes;;
Packit 504f36
   24) do24=yes;;
Packit 504f36
   25) do25=yes;;
Packit 504f36
   -8) arg8=yes;;
Packit 504f36
  -16) arg16=yes;;
Packit 504f36
  -32) arg32=yes;;
Packit 504f36
   bigstack|-bigstack) bigstack=yes;;
Packit 504f36
   nojit|-nojit) nojit=yes;;
Packit 504f36
   sim|-sim) shift; sim=$1;;
Packit 504f36
   valgrind|-valgrind) valgrind="valgrind --tool=memcheck -q --smc-check=all-non-file";;
Packit 504f36
   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 ";;
Packit 504f36
   ~*)
Packit 504f36
     if expr "$1" : '~[0-9][0-9]*$' >/dev/null; then
Packit 504f36
       skip="$skip `expr "$1" : '~\([0-9]*\)*$'`"
Packit 504f36
     else
Packit 504f36
       echo "Unknown option or test selector '$1'"; exit 1
Packit 504f36
     fi
Packit 504f36
   ;;
Packit 504f36
   *-*)
Packit 504f36
     if expr "$1" : '[0-9][0-9]*-[0-9]*$' >/dev/null; then
Packit 504f36
       tf=`expr "$1" : '\([0-9]*\)'`
Packit 504f36
       tt=`expr "$1" : '.*-\([0-9]*\)'`
Packit 504f36
       if [ "$tt" = "" ] ; then tt=$maxtest; fi
Packit 504f36
       if expr \( "$tt" ">" "$maxtest" \) >/dev/null; then
Packit 504f36
         echo "Invalid test range '$1'"; exit 1
Packit 504f36
       fi
Packit 504f36
       while expr "$tf" "<=" "$tt" >/dev/null; do
Packit 504f36
         eval do${tf}=yes
Packit 504f36
         tf=`expr $tf + 1`
Packit 504f36
       done
Packit 504f36
     else
Packit 504f36
       echo "Invalid test range '$1'"; exit 1
Packit 504f36
     fi
Packit 504f36
   ;;
Packit 504f36
   *) echo "Unknown option or test selector '$1'"; exit 1;;
Packit 504f36
  esac
Packit 504f36
  shift
Packit 504f36
done
Packit 504f36
Packit 504f36
# Find which optional facilities are available.
Packit 504f36
Packit 504f36
$sim ./pcre2test -C linksize >/dev/null
Packit 504f36
link_size=$?
Packit 504f36
if [ $link_size -lt 2 ] ; then
Packit 504f36
  echo "RunTest: Failed to find internal link size"
Packit 504f36
  exit 1
Packit 504f36
fi
Packit 504f36
if [ $link_size -gt 4 ] ; then
Packit 504f36
  echo "RunTest: Failed to find internal link size"
Packit 504f36
  exit 1
Packit 504f36
fi
Packit 504f36
Packit 504f36
# If it is possible to set the system stack size and -bigstack was given,
Packit 504f36
# set up a large stack.
Packit 504f36
Packit 504f36
$sim ./pcre2test -S 1 /dev/null /dev/null
Packit 504f36
if [ $? -eq 0 -a "$bigstack" != "" ] ; then
Packit 504f36
  setstack="-S 64"
Packit 504f36
else
Packit 504f36
  setstack=""
Packit 504f36
fi
Packit 504f36
Packit 504f36
# All of 8-bit, 16-bit, and 32-bit character strings may be supported, but only
Packit 504f36
# one need be.
Packit 504f36
Packit 504f36
$sim ./pcre2test -C pcre2-8 >/dev/null
Packit 504f36
support8=$?
Packit 504f36
$sim ./pcre2test -C pcre2-16 >/dev/null
Packit 504f36
support16=$?
Packit 504f36
$sim ./pcre2test -C pcre2-32 >/dev/null
Packit 504f36
support32=$?
Packit 504f36
Packit 504f36
# \C may be disabled
Packit 504f36
Packit 504f36
$sim ./pcre2test -C backslash-C >/dev/null
Packit 504f36
supportBSC=$?
Packit 504f36
Packit 504f36
# Initialize all bitsizes skipped
Packit 504f36
Packit 504f36
test8=skip
Packit 504f36
test16=skip
Packit 504f36
test32=skip
Packit 504f36
Packit 504f36
# If no bitsize arguments, select all that are available
Packit 504f36
Packit 504f36
if [ "$arg8$arg16$arg32" = "" ] ; then
Packit 504f36
  if [ $support8 -ne 0 ] ; then
Packit 504f36
    test8=-8
Packit 504f36
  fi
Packit 504f36
  if [ $support16 -ne 0 ] ; then
Packit 504f36
    test16=-16
Packit 504f36
  fi
Packit 504f36
  if [ $support32 -ne 0 ] ; then
Packit 504f36
    test32=-32
Packit 504f36
  fi
Packit 504f36
Packit 504f36
# Otherwise, select requested bit sizes
Packit 504f36
Packit 504f36
else
Packit 504f36
  if [ "$arg8" = yes ] ; then
Packit 504f36
    if [ $support8 -eq 0 ] ; then
Packit 504f36
      echo "Cannot run 8-bit library tests: 8-bit library not compiled"
Packit 504f36
      exit 1
Packit 504f36
    fi
Packit 504f36
    test8=-8
Packit 504f36
  fi
Packit 504f36
  if [ "$arg16" = yes ] ; then
Packit 504f36
    if [ $support16 -eq 0 ] ; then
Packit 504f36
      echo "Cannot run 16-bit library tests: 16-bit library not compiled"
Packit 504f36
      exit 1
Packit 504f36
    fi
Packit 504f36
    test16=-16
Packit 504f36
  fi
Packit 504f36
  if [ "$arg32" = yes ] ; then
Packit 504f36
    if [ $support32 -eq 0 ] ; then
Packit 504f36
      echo "Cannot run 32-bit library tests: 32-bit library not compiled"
Packit 504f36
      exit 1
Packit 504f36
    fi
Packit 504f36
    test32=-32
Packit 504f36
  fi
Packit 504f36
fi
Packit 504f36
Packit 504f36
# UTF support is implied by Unicode support, and it always applies to all bit
Packit 504f36
# sizes if both are supported; we can't have UTF-8 support without UTF-16 or
Packit 504f36
# UTF-32 support.
Packit 504f36
Packit 504f36
$sim ./pcre2test -C unicode >/dev/null
Packit 504f36
utf=$?
Packit 504f36
Packit 504f36
# When JIT is used with valgrind, we need to set up valgrind suppressions as
Packit 504f36
# otherwise there are a lot of false positive valgrind reports when the
Packit 504f36
# the hardware supports SSE2.
Packit 504f36
Packit 504f36
jitopt=
Packit 504f36
$sim ./pcre2test -C jit >/dev/null
Packit 504f36
jit=$?
Packit 504f36
if [ $jit -ne 0 -a "$nojit" != "yes" ] ; then
Packit 504f36
  jitopt=-jit
Packit 504f36
  if [ "$valgrind" != "" ] ; then
Packit 504f36
    vjs="--suppressions=$testdata/valgrind-jit.supp"
Packit 504f36
  fi
Packit 504f36
fi
Packit 504f36
Packit 504f36
# If no specific tests were requested, select all. Those that are not
Packit 504f36
# relevant will be automatically skipped.
Packit 504f36
Packit 504f36
if [ $do0  = no -a $do1  = no -a $do2  = no -a $do3  = no -a \
Packit 504f36
     $do4  = no -a $do5  = no -a $do6  = no -a $do7  = no -a \
Packit 504f36
     $do8  = no -a $do9  = no -a $do10 = no -a $do11 = no -a \
Packit 504f36
     $do12 = no -a $do13 = no -a $do14 = no -a $do15 = no -a \
Packit 504f36
     $do16 = no -a $do17 = no -a $do18 = no -a $do19 = no -a \
Packit 504f36
     $do20 = no -a $do21 = no -a $do22 = no -a $do23 = no -a \
Packit 504f36
     $do24 = no -a $do25 = no \
Packit 504f36
   ]; then
Packit 504f36
  do0=yes
Packit 504f36
  do1=yes
Packit 504f36
  do2=yes
Packit 504f36
  do3=yes
Packit 504f36
  do4=yes
Packit 504f36
  do5=yes
Packit 504f36
  do6=yes
Packit 504f36
  do7=yes
Packit 504f36
  do8=yes
Packit 504f36
  do9=yes
Packit 504f36
  do10=yes
Packit 504f36
  do11=yes
Packit 504f36
  do12=yes
Packit 504f36
  do13=yes
Packit 504f36
  do14=yes
Packit 504f36
  do15=yes
Packit 504f36
  do16=yes
Packit 504f36
  do17=yes
Packit 504f36
  do18=yes
Packit 504f36
  do19=yes
Packit 504f36
  do20=yes
Packit 504f36
  do21=yes
Packit 504f36
  do22=yes
Packit 504f36
  do23=yes
Packit 504f36
  do24=yes
Packit 504f36
  do25=yes
Packit 504f36
fi
Packit 504f36
Packit 504f36
# Handle any explicit skips at this stage, so that an argument list may consist
Packit 504f36
# only of explicit skips.
Packit 504f36
Packit 504f36
for i in $skip; do eval do$i=no; done
Packit 504f36
Packit 504f36
# Show which release and which test data
Packit 504f36
Packit 504f36
echo ""
Packit 504f36
echo PCRE2 C library tests using test data from $testdata
Packit 504f36
$sim ./pcre2test /dev/null
Packit 504f36
echo ""
Packit 504f36
Packit 504f36
for bmode in "$test8" "$test16" "$test32"; do
Packit 504f36
  case "$bmode" in
Packit 504f36
    skip) continue;;
Packit 504f36
    -16)  if [ "$test8$test32" != "skipskip" ] ; then echo ""; fi
Packit 504f36
          bits=16; echo "---- Testing 16-bit library ----"; echo "";;
Packit 504f36
    -32)  if [ "$test8$test16" != "skipskip" ] ; then echo ""; fi
Packit 504f36
          bits=32; echo "---- Testing 32-bit library ----"; echo "";;
Packit 504f36
    -8)   bits=8; echo "---- Testing 8-bit library ----"; echo "";;
Packit 504f36
  esac
Packit 504f36
Packit 504f36
  # Test 0 is a special test. Its output is not checked, because it will
Packit 504f36
  # be different on different hardware and with different configurations.
Packit 504f36
  # Running this test just exercises the code.
Packit 504f36
Packit 504f36
  if [ $do0 = yes ] ; then
Packit 504f36
    echo $title0
Packit 504f36
    echo '/abc/jit,memory,framesize' >testSinput
Packit 504f36
    echo '   abc' >>testSinput
Packit 504f36
    echo '' >testtry
Packit 504f36
    checkspecial '-C'
Packit 504f36
    checkspecial '--help'
Packit 504f36
    checkspecial '-S 1 -t 10 testSinput'
Packit 504f36
    echo "  OK"
Packit 504f36
  fi
Packit 504f36
Packit 504f36
  # Primary non-UTF test, compatible with JIT and all versions of Perl >= 5.8
Packit 504f36
Packit 504f36
  if [ $do1 = yes ] ; then
Packit 504f36
    echo $title1
Packit 504f36
    for opt in "" $jitopt; do
Packit 504f36
      $sim $valgrind ${opt:+$vjs} ./pcre2test -q $setstack $bmode $opt $testdata/testinput1 testtry
Packit 504f36
      checkresult $? 1 "$opt"
Packit 504f36
    done
Packit 504f36
  fi
Packit 504f36
Packit 504f36
  # PCRE2 tests that are not Perl-compatible: API, errors, internals
Packit 504f36
Packit 504f36
  if [ $do2 = yes ] ; then
Packit 504f36
    echo $title2 "(excluding UTF-$bits)"
Packit 504f36
    for opt in "" $jitopt; do
Packit 504f36
      $sim $valgrind ${opt:+$vjs} ./pcre2test -q $setstack $bmode $opt $testdata/testinput2 testtry
Packit 504f36
      if [ $? = 0 ] ; then
Packit 504f36
        $sim $valgrind ${opt:+$vjs} ./pcre2test -q $bmode $opt -error -70,-62,-2,-1,0,100,101,191,200 >>testtry
Packit 504f36
        checkresult $? 2 "$opt"
Packit 504f36
      fi
Packit 504f36
    done
Packit 504f36
  fi
Packit 504f36
Packit 504f36
  # Locale-specific tests, provided that either the "fr_FR", "fr_CA", "french"
Packit 504f36
  # or "fr" locale is available. The first two are Unix-like standards; the
Packit 504f36
  # last two are for Windows. Unfortunately, different versions of the French
Packit 504f36
  # locale give different outputs for some items. This test passes if the
Packit 504f36
  # output matches any one of the alternative output files.
Packit 504f36
Packit 504f36
  if [ $do3 = yes ] ; then
Packit 504f36
    locale=
Packit 504f36
Packit 504f36
    # In some environments locales that are listed by the "locale -a"
Packit 504f36
    # command do not seem to work with setlocale(). Therefore, we do
Packit 504f36
    # a preliminary test to see if pcre2test can set one before going
Packit 504f36
    # on to use it.
Packit 504f36
Packit 504f36
    for loc in 'fr_FR' 'french' 'fr' 'fr_CA'; do
Packit 504f36
      locale -a | grep "^$loc\$" >/dev/null
Packit 504f36
      if [ $? -eq 0 ] ; then
Packit 504f36
        echo "/a/locale=$loc" | \
Packit 504f36
          $sim $valgrind ./pcre2test -q $bmode | \
Packit 504f36
            grep "Failed to set locale" >/dev/null
Packit 504f36
        if [ $? -ne 0 ] ; then
Packit 504f36
          locale=$loc
Packit 504f36
          if [ "$locale" = "fr_FR" ] ; then
Packit 504f36
            infile=$testdata/testinput3
Packit 504f36
            outfile=$testdata/testoutput3
Packit 504f36
            outfile2=$testdata/testoutput3A
Packit 504f36
            outfile3=$testdata/testoutput3B
Packit 504f36
          else
Packit 504f36
            infile=test3input
Packit 504f36
            outfile=test3output
Packit 504f36
            outfile2=test3outputA
Packit 504f36
            outfile3=test3outputB
Packit 504f36
            sed "s/fr_FR/$loc/" $testdata/testinput3 >test3input
Packit 504f36
            sed "s/fr_FR/$loc/" $testdata/testoutput3 >test3output
Packit 504f36
            sed "s/fr_FR/$loc/" $testdata/testoutput3A >test3outputA
Packit 504f36
            sed "s/fr_FR/$loc/" $testdata/testoutput3B >test3outputB
Packit 504f36
          fi
Packit 504f36
          break
Packit 504f36
        fi
Packit 504f36
      fi
Packit 504f36
    done
Packit 504f36
Packit 504f36
    if [ "$locale" != "" ] ; then
Packit 504f36
      echo $title3 "(using '$locale' locale)"
Packit 504f36
      for opt in "" $jitopt; do
Packit 504f36
        $sim $valgrind ${opt:+$vjs} ./pcre2test -q $setstack $bmode $opt $infile testtry
Packit 504f36
        if [ $? = 0 ] ; then
Packit 504f36
          case "$opt" in
Packit 504f36
            -jit) with=" with JIT";;
Packit 504f36
            *)    with="";;
Packit 504f36
          esac
Packit 504f36
          if $cf $outfile testtry >teststdout || \
Packit 504f36
             $cf $outfile2 testtry >teststdout || \
Packit 504f36
             $cf $outfile3 testtry >teststdout
Packit 504f36
          then
Packit 504f36
            echo "  OK$with"
Packit 504f36
          else
Packit 504f36
            echo "** Locale test did not run successfully$with. The output did not match"
Packit 504f36
            echo "   $outfile, $outfile2 or $outfile3."
Packit 504f36
            echo "   This may mean that there is a problem with the locale settings rather"
Packit 504f36
            echo "   than a bug in PCRE2."
Packit 504f36
            exit 1
Packit 504f36
          fi
Packit 504f36
        else exit 1
Packit 504f36
        fi
Packit 504f36
      done
Packit 504f36
    else
Packit 504f36
      echo "Cannot test locale-specific features - none of the 'fr_FR', 'fr_CA',"
Packit 504f36
      echo "'fr' or 'french' locales can be set, or the \"locale\" command is"
Packit 504f36
      echo "not available to check for them."
Packit 504f36
      echo " "
Packit 504f36
    fi
Packit 504f36
  fi
Packit 504f36
Packit 504f36
  # Tests for UTF and Unicode property support
Packit 504f36
Packit 504f36
  if [ $do4 = yes ] ; then
Packit 504f36
    echo ${title4A}-${bits}${title4B}
Packit 504f36
    if [ $utf -eq 0 ] ; then
Packit 504f36
      echo "  Skipped because UTF-$bits support is not available"
Packit 504f36
    else
Packit 504f36
      for opt in "" $jitopt; do
Packit 504f36
        $sim $valgrind ${opt:+$vjs} ./pcre2test -q $setstack $bmode $opt $testdata/testinput4 testtry
Packit 504f36
        checkresult $? 4 "$opt"
Packit 504f36
      done
Packit 504f36
    fi
Packit 504f36
  fi
Packit 504f36
Packit 504f36
  if [ $do5 = yes ] ; then
Packit 504f36
    echo ${title5A}-${bits}$title5B
Packit 504f36
    if [ $utf -eq 0 ] ; then
Packit 504f36
      echo "  Skipped because UTF-$bits support is not available"
Packit 504f36
    else
Packit 504f36
      for opt in "" $jitopt; do
Packit 504f36
        $sim $valgrind ${opt:+$vjs} ./pcre2test -q $setstack $bmode $opt $testdata/testinput5 testtry
Packit 504f36
        checkresult $? 5 "$opt"
Packit 504f36
      done
Packit 504f36
    fi
Packit 504f36
  fi
Packit 504f36
Packit 504f36
  # Tests for DFA matching support
Packit 504f36
Packit 504f36
  if [ $do6 = yes ] ; then
Packit 504f36
    echo $title6
Packit 504f36
    $sim $valgrind ./pcre2test -q $setstack $bmode $testdata/testinput6 testtry
Packit 504f36
    checkresult $? 6 ""
Packit 504f36
  fi
Packit 504f36
Packit 504f36
  if [ $do7 = yes ] ; then
Packit 504f36
    echo ${title7A}-${bits}$title7B
Packit 504f36
    if [ $utf -eq 0 ] ; then
Packit 504f36
      echo "  Skipped because UTF-$bits support is not available"
Packit 504f36
    else
Packit 504f36
      $sim $valgrind ./pcre2test -q $setstack $bmode $opt $testdata/testinput7 testtry
Packit 504f36
      checkresult $? 7 ""
Packit 504f36
    fi
Packit 504f36
  fi
Packit 504f36
Packit 504f36
  # Test of internal offsets and code sizes. This test is run only when there
Packit 504f36
  # is UTF/UCP support. The actual tests are mostly the same as in some of the
Packit 504f36
  # above, but in this test we inspect some offsets and sizes. This is a
Packit 504f36
  # doublecheck for the maintainer, just in case something changes unexpectely.
Packit 504f36
  # The output from this test is different in 8-bit, 16-bit, and 32-bit modes
Packit 504f36
  # and for different link sizes, so there are different output files for each
Packit 504f36
  # mode and link size.
Packit 504f36
Packit 504f36
  if [ $do8 = yes ] ; then
Packit 504f36
    echo $title8
Packit 504f36
    if [ $utf -eq 0 ] ; then
Packit 504f36
      echo "  Skipped because UTF-$bits support is not available"
Packit 504f36
    else
Packit 504f36
      $sim $valgrind ./pcre2test -q $setstack $bmode $testdata/testinput8 testtry
Packit 504f36
      checkresult $? 8-$bits-$link_size ""
Packit 504f36
    fi
Packit 504f36
  fi
Packit 504f36
Packit 504f36
  # Tests for 8-bit-specific features
Packit 504f36
Packit 504f36
  if [ "$do9" = yes ] ; then
Packit 504f36
    echo $title9
Packit 504f36
    if [ "$bits" = "16" -o "$bits" = "32" ] ; then
Packit 504f36
      echo "  Skipped when running 16/32-bit tests"
Packit 504f36
    else
Packit 504f36
      for opt in "" $jitopt; do
Packit 504f36
        $sim $valgrind ${opt:+$vjs} ./pcre2test -q $setstack $bmode $opt $testdata/testinput9 testtry
Packit 504f36
        checkresult $? 9 "$opt"
Packit 504f36
      done
Packit 504f36
    fi
Packit 504f36
  fi
Packit 504f36
Packit 504f36
  # Tests for UTF-8 and UCP 8-bit-specific features
Packit 504f36
Packit 504f36
  if [ "$do10" = yes ] ; then
Packit 504f36
    echo $title10
Packit 504f36
    if [ "$bits" = "16" -o "$bits" = "32" ] ; then
Packit 504f36
      echo "  Skipped when running 16/32-bit tests"
Packit 504f36
    elif [ $utf -eq 0 ] ; then
Packit 504f36
      echo "  Skipped because UTF-$bits support is not available"
Packit 504f36
    else
Packit 504f36
      for opt in "" $jitopt; do
Packit 504f36
        $sim $valgrind ${opt:+$vjs} ./pcre2test -q $setstack $bmode $opt $testdata/testinput10 testtry
Packit 504f36
        checkresult $? 10 "$opt"
Packit 504f36
      done
Packit 504f36
    fi
Packit 504f36
  fi
Packit 504f36
Packit 504f36
  # Tests for 16-bit and 32-bit features. Output is different for the two widths.
Packit 504f36
Packit 504f36
  if [ $do11 = yes ] ; then
Packit 504f36
    echo $title11
Packit 504f36
    if [ "$bits" = "8" ] ; then
Packit 504f36
      echo "  Skipped when running 8-bit tests"
Packit 504f36
    else
Packit 504f36
      for opt in "" $jitopt; do
Packit 504f36
        $sim $valgrind ${opt:+$vjs} ./pcre2test -q $setstack $bmode $opt $testdata/testinput11 testtry
Packit 504f36
        checkresult $? 11-$bits "$opt"
Packit 504f36
      done
Packit 504f36
    fi
Packit 504f36
  fi
Packit 504f36
Packit 504f36
  # Tests for 16-bit and 32-bit features with UTF-16/32 and UCP support. Output
Packit 504f36
  # is different for the two widths.
Packit 504f36
Packit 504f36
  if [ $do12 = yes ] ; then
Packit 504f36
    echo $title12
Packit 504f36
    if [ "$bits" = "8" ] ; then
Packit 504f36
      echo "  Skipped when running 8-bit tests"
Packit 504f36
    elif [ $utf -eq 0 ] ; then
Packit 504f36
      echo "  Skipped because UTF-$bits support is not available"
Packit 504f36
    else
Packit 504f36
      for opt in "" $jitopt; do
Packit 504f36
        $sim $valgrind ${opt:+$vjs} ./pcre2test -q $setstack $bmode $opt $testdata/testinput12 testtry
Packit 504f36
        checkresult $? 12-$bits "$opt"
Packit 504f36
      done
Packit 504f36
    fi
Packit 504f36
  fi
Packit 504f36
Packit 504f36
  # Tests for 16/32-bit-specific features in DFA non-UTF modes
Packit 504f36
Packit 504f36
  if [ $do13 = yes ] ; then
Packit 504f36
    echo $title13
Packit 504f36
    if [ "$bits" = "8" ] ; then
Packit 504f36
      echo "  Skipped when running 8-bit tests"
Packit 504f36
    else
Packit 504f36
      $sim $valgrind ./pcre2test -q $setstack $bmode $testdata/testinput13 testtry
Packit 504f36
      checkresult $? 13 ""
Packit 504f36
    fi
Packit 504f36
  fi
Packit 504f36
Packit 504f36
  # Tests for DFA UTF and UCP features. Output is different for the different widths.
Packit 504f36
Packit 504f36
  if [ $do14 = yes ] ; then
Packit 504f36
    echo $title14
Packit 504f36
    if [ $utf -eq 0 ] ; then
Packit 504f36
      echo "  Skipped because UTF-$bits support is not available"
Packit 504f36
    else
Packit 504f36
      $sim $valgrind ./pcre2test -q $setstack $bmode $opt $testdata/testinput14 testtry
Packit 504f36
      checkresult $? 14-$bits ""
Packit 504f36
    fi
Packit 504f36
  fi
Packit 504f36
Packit 504f36
  # Test non-JIT match and recursion limits
Packit 504f36
Packit 504f36
  if [ $do15 = yes ] ; then
Packit 504f36
    echo $title15
Packit 504f36
    $sim $valgrind ./pcre2test -q $setstack $bmode $testdata/testinput15 testtry
Packit 504f36
    checkresult $? 15 ""
Packit 504f36
  fi
Packit 504f36
Packit 504f36
  # Test JIT-specific features when JIT is not available
Packit 504f36
Packit 504f36
  if [ $do16 = yes ] ; then
Packit 504f36
    echo $title16
Packit 504f36
    if [ $jit -ne 0 ] ; then
Packit 504f36
      echo "  Skipped because JIT is available"
Packit 504f36
    else
Packit 504f36
      $sim $valgrind ./pcre2test -q $setstack $bmode $testdata/testinput16 testtry
Packit 504f36
      checkresult $? 16 ""
Packit 504f36
    fi
Packit 504f36
  fi
Packit 504f36
Packit 504f36
  # Test JIT-specific features when JIT is available
Packit 504f36
Packit 504f36
  if [ $do17 = yes ] ; then
Packit 504f36
    echo $title17
Packit 504f36
    if [ $jit -eq 0 -o "$nojit" = "yes" ] ; then
Packit 504f36
      echo "  Skipped because JIT is not available or nojit was specified"
Packit 504f36
    else
Packit 504f36
      $sim $valgrind $vjs ./pcre2test -q $setstack $bmode $testdata/testinput17 testtry
Packit 504f36
      checkresult $? 17 ""
Packit 504f36
    fi
Packit 504f36
  fi
Packit 504f36
Packit 504f36
  # Tests for the POSIX interface without UTF/UCP (8-bit only)
Packit 504f36
Packit 504f36
  if [ $do18 = yes ] ; then
Packit 504f36
    echo $title18
Packit 504f36
    if [ "$bits" = "16" -o "$bits" = "32" ] ; then
Packit 504f36
      echo "  Skipped when running 16/32-bit tests"
Packit 504f36
    else
Packit 504f36
      $sim $valgrind ./pcre2test -q $setstack $bmode $testdata/testinput18 testtry
Packit 504f36
      checkresult $? 18 ""
Packit 504f36
    fi
Packit 504f36
  fi
Packit 504f36
Packit 504f36
  # Tests for the POSIX interface with UTF/UCP (8-bit only)
Packit 504f36
Packit 504f36
  if [ $do19 = yes ] ; then
Packit 504f36
    echo $title19
Packit 504f36
    if [ "$bits" = "16" -o "$bits" = "32" ] ; then
Packit 504f36
      echo "  Skipped when running 16/32-bit tests"
Packit 504f36
    elif [ $utf -eq 0 ] ; then
Packit 504f36
      echo "  Skipped because UTF-$bits support is not available"
Packit 504f36
    else
Packit 504f36
      $sim $valgrind ./pcre2test -q $setstack $bmode $testdata/testinput19 testtry
Packit 504f36
      checkresult $? 19 ""
Packit 504f36
    fi
Packit 504f36
  fi
Packit 504f36
Packit 504f36
  # Serialization tests
Packit 504f36
Packit 504f36
  if [ $do20 = yes ] ; then
Packit 504f36
    echo $title20
Packit 504f36
    $sim $valgrind ./pcre2test -q $setstack $bmode $testdata/testinput20 testtry
Packit 504f36
    checkresult $? 20 ""
Packit 504f36
  fi
Packit 504f36
Packit 504f36
  # \C tests without UTF - DFA matching is supported
Packit 504f36
Packit 504f36
  if [ "$do21" = yes ] ; then
Packit 504f36
    echo $title21
Packit 504f36
    if [ $supportBSC -eq 0 ] ; then
Packit 504f36
      echo "  Skipped because \C is disabled"
Packit 504f36
    else
Packit 504f36
      for opt in "" $jitopt -dfa; do
Packit 504f36
        $sim $valgrind ${opt:+$vjs} ./pcre2test -q $setstack $bmode $opt $testdata/testinput21 testtry
Packit 504f36
        checkresult $? 21 "$opt"
Packit 504f36
      done
Packit 504f36
    fi
Packit 504f36
  fi
Packit 504f36
Packit 504f36
  # \C tests with UTF - DFA matching is not supported for \C in UTF mode
Packit 504f36
Packit 504f36
  if [ "$do22" = yes ] ; then
Packit 504f36
    echo $title22
Packit 504f36
    if [ $supportBSC -eq 0 ] ; then
Packit 504f36
      echo "  Skipped because \C is disabled"
Packit 504f36
    elif [ $utf -eq 0 ] ; then
Packit 504f36
      echo "  Skipped because UTF-$bits support is not available"
Packit 504f36
    else
Packit 504f36
      for opt in "" $jitopt; do
Packit 504f36
        $sim $valgrind ${opt:+$vjs} ./pcre2test -q $setstack $bmode $opt $testdata/testinput22 testtry
Packit 504f36
        checkresult $? 22-$bits "$opt"
Packit 504f36
      done
Packit 504f36
    fi
Packit 504f36
  fi
Packit 504f36
Packit 504f36
  # Test when \C is disabled
Packit 504f36
Packit 504f36
  if [ "$do23" = yes ] ; then
Packit 504f36
    echo $title23
Packit 504f36
    if [ $supportBSC -ne 0 ] ; then
Packit 504f36
      echo "  Skipped because \C is not disabled"
Packit 504f36
    else
Packit 504f36
      $sim $valgrind ./pcre2test -q $setstack $bmode $testdata/testinput23 testtry
Packit 504f36
      checkresult $? 23 ""
Packit 504f36
    fi
Packit 504f36
  fi
Packit 504f36
Packit 504f36
  # Non-UTF pattern conversion tests
Packit 504f36
Packit 504f36
  if [ "$do24" = yes ] ; then
Packit 504f36
    echo $title24
Packit 504f36
    $sim $valgrind ./pcre2test -q $setstack $bmode $testdata/testinput24 testtry
Packit 504f36
    checkresult $? 24 ""
Packit 504f36
  fi
Packit 504f36
Packit 504f36
  # UTF pattern conversion tests
Packit 504f36
Packit 504f36
  if [ "$do25" = yes ] ; then
Packit 504f36
    echo $title25
Packit 504f36
    if [ $utf -eq 0 ] ; then
Packit 504f36
      echo "  Skipped because UTF-$bits support is not available"
Packit 504f36
    else
Packit 504f36
      $sim $valgrind ./pcre2test -q $setstack $bmode $testdata/testinput25 testtry
Packit 504f36
      checkresult $? 25 ""
Packit 504f36
    fi
Packit 504f36
  fi
Packit 504f36
Packit 504f36
# End of loop for 8/16/32-bit tests
Packit 504f36
done
Packit 504f36
Packit 504f36
# Clean up local working files
Packit 504f36
rm -f testSinput test3input testsaved1 testsaved2 test3output test3outputA test3outputB teststdout teststderr testtry
Packit 504f36
Packit 504f36
# End