• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#! /bin/sh
2
3# This is a script for the use of PCRE2 maintainers. It configures and rebuilds
4# PCRE2 with a variety of configuration options, and in each case runs the
5# tests to ensure that all goes well. Every possible combination would take far
6# too long, so we use a representative sample. This script should be run in the
7# PCRE2 source directory.
8
9# While debugging, it is sometimes useful to be able to cut out some of the
10# tests, in order to run those that are giving errors. The following options
11# do this:
12#
13# -noasan         skip the test that uses -fsanitize=address
14# -nousan         skip the test that uses -fsanitize=undefined
15# -nodebug        skip the test that uses --enable-debug
16# -nojit          skip all JIT tests
17# -nojitmain      skip non-valgrind JIT tests
18# -nojitvalgrind  skip JIT tests with valgrind
19# -nomain         skip all the main (non-JIT) set of tests
20# -nomainvalgrind skip the main (non-JIT) valgrind tests
21# -notmp          skip the test in a temporary directory
22# -novalgrind     skip all the valgrind tests
23
24# Alternatively, if any of those names are given with '+' instead of '-no',
25# only those groups named with '+' are run (e.g. +jit). If -dummy is given,
26# no tests are actually run - this provides a means of testing the selectors.
27
28# The -v option causes a call to 'pcre2test -C' to happen for each
29# configuration.
30
31useasan=1
32useusan=1
33usedebug=1
34usejit=1
35usejitvalgrind=1
36usemain=1
37usemainvalgrind=1
38usetmp=1
39usevalgrind=1
40
41dummy=0
42seenplus=0
43verbose=0
44
45while [ $# -gt 0 ] ; do
46  case $1 in
47    +*) if [ $seenplus -eq 0 ]; then
48          useasan=0
49          useusan=0
50          usedebug=0
51          usejit=0
52          usejitvalgrind=0
53          usemain=0
54          usemainvalgrind=0
55          usetmp=0
56          seenplus=1
57        fi;;
58  esac
59
60  case $1 in
61    -dummy)          dummy=1;;
62    -v)              verbose=1;;
63    -noasan)         useasan=0;;
64    -nousan)         useusan=0;;
65    -nodebug)        usedebug=0;;
66    -nojit)          usejit=0; usejitvalgrind=0;;
67    -nojitmain)      usejit=0;;
68    -nojitvalgrind)  usejitvalgrind=0;;
69    -nomain)         usemain=0; usemainvalgrind=0;;
70    -nomainvalgrind) usemainvalgrind=0;;
71    -notmp)          usetmp=0;;
72    -novalgrind)     usevalgrind=0;;
73    +asan)           useasan=1;;
74    +usan)           useusan=1;;
75    +debug)          usedebug=1;;
76    +jit)            usejit=1; usejitvalgrind=1;;
77    +jitmain)        usejit=1;;
78    +jitvalgrind)    usejitvalgrind=1;;
79    +main)           usemain=1; usemainvalgrind=1;;
80    +mainvalgrind)   usemainvalgrind=1;;
81    +tmp)            usetmp=1;;
82    +valgrind)       usevalgrind=1; usejitvalgrind=1; usemainvalgrind=1;;
83    *)               echo "Unknown option '$1'"; exit 1;;
84  esac
85  shift
86done
87
88if [ $usejitvalgrind -eq 0 -a $usemainvalgrind -eq 0 ] ; then
89  usevalgrind=0
90fi
91
92# This is in case the caller has set aliases (as I do - PH)
93
94unset cp ls mv rm
95
96# This is a temporary directory for testing out-of-line builds
97
98tmp=/tmp/pcre2testing
99
100# Don't bother with compiler optimization for most tests; it just slows down
101# compilation a lot (and running the tests themselves is quick). However, one
102# special test turns optimization on, because it can provoke some compiler
103# warnings.
104
105CFLAGS="-g"
106OFLAGS="-O0"
107ISGCC=0
108
109# If the compiler is gcc, add a lot of warning switches.
110
111cc --version >/tmp/pcre2ccversion 2>/dev/null
112if [ $? -eq 0 ] && grep GCC /tmp/pcre2ccversion >/dev/null; then
113  ISGCC=1
114  CFLAGS="$CFLAGS -Wall"
115  CFLAGS="$CFLAGS -Wno-overlength-strings"
116  CFLAGS="$CFLAGS -Wpointer-arith"
117  CFLAGS="$CFLAGS -Wwrite-strings"
118  CFLAGS="$CFLAGS -Wundef -Wshadow"
119  CFLAGS="$CFLAGS -Wmissing-field-initializers"
120  CFLAGS="$CFLAGS -Wunused-parameter"
121  CFLAGS="$CFLAGS -Wextra -Wformat"
122  CFLAGS="$CFLAGS -Wbad-function-cast"
123  CFLAGS="$CFLAGS -Wmissing-declarations"
124  CFLAGS="$CFLAGS -Wnested-externs"
125  CFLAGS="$CFLAGS -pedantic"
126  CFLAGS="$CFLAGS -Wuninitialized"
127  CFLAGS="$CFLAGS -Wmaybe-uninitialized"
128  CFLAGS="$CFLAGS -Wmissing-prototypes"
129  CFLAGS="$CFLAGS -Wstrict-prototypes"
130fi
131rm -f /tmp/pcre2ccversion
132
133# This function runs a single test with the set of configuration options that
134# are in $opts. The source directory must be set in srcdir. The function must
135# be defined as "runtest()" not "function runtest()" in order to run on
136# Solaris.
137
138runtest()
139  {
140  rm -f $srcdir/pcre2test $srcdir/pcre2grep $srcdir/pcre2_jit_test
141  testcount=`expr $testcount + 1`
142
143  if [ "$opts" = "" ] ; then
144    echo "[$testcount/$testtotal] Configuring with: default settings"
145  else
146    echo "[$testcount/$testtotal] Configuring with:"
147    echo "  $opts"
148  fi
149
150  if [ $dummy -eq 1 ]; then return; fi
151
152  CFLAGS="$CFLAGS" \
153    $srcdir/configure $opts >/dev/null 2>teststderrM
154  if [ $? -ne 0 ]; then
155    echo " "
156    echo "******** Error while configuring ********"
157    cat teststderrM
158    exit 1
159  fi
160
161# There is an infelicity in the Autotools world (as of October 2015) which
162# causes the message
163#
164# ar: `u' modifier ignored since `D' is the default (see `U')
165#
166# to be output while linking. This triggers an unwanted error report from this
167# script, because it expects no stderr output while making. To get round this
168# we filter the stderr output through sed, removing all occurrences of the
169# above lines. Just for paranoia, check that sed is available before doing
170# this.
171
172  echo "Making"
173  make -j >/dev/null 2>teststderrM
174  makeRC=$?
175  if command -v sed >/dev/null 2>&1 ; then
176    sed "/\`u' modifier ignored since \`D' is the default/ d" \
177      teststderrM > teststderrMM
178    mv -f teststderrMM teststderrM
179  fi
180  if [ $makeRC -ne 0 -o -s teststderrM ]; then
181    echo " "
182    echo "******** Errors or warnings while making ********"
183    echo " "
184    cat teststderrM
185    exit 1
186  fi
187
188  if [ $verbose -eq 1 ]; then
189    ./pcre2test -C
190  fi
191
192  ./pcre2test -C jit >/dev/null
193  jit=$?
194  ./pcre2test -C pcre2-8 >/dev/null
195  pcre2_8=$?
196
197  echo "Running PCRE2 library tests $withvalgrind"
198  $srcdir/RunTest $valgrind >teststdoutM 2>teststderrM
199
200  if [ $? -ne 0 -o -s teststderrM ]; then
201    echo " "
202    echo "**** Test failed ****"
203    if [ -s teststderrM ] ; then
204      cat teststderrM
205    else
206      cat teststdoutM
207    fi
208    exit 1
209  fi
210
211  if [ $pcre2_8 -gt 0 ]; then
212    echo "Running pcre2grep tests $withvalgrind"
213    $srcdir/RunGrepTest $valgrind >teststdoutM 2>teststderrM
214    if [ $? -ne 0 -o -s teststderrM ]; then
215      echo " "
216      echo "**** Test failed ****"
217      cat teststderrM
218      cat teststdoutM
219      exit 1
220    fi
221  else
222    echo "Skipping pcre2grep tests: 8-bit library not compiled"
223  fi
224
225  if [ "$jit" -gt 0 ]; then
226    echo "Running JIT regression tests $withvalgrind"
227    $jrvalgrind $srcdir/pcre2_jit_test >teststdoutM 2>teststderrM
228    if [ $? -ne 0 -o -s teststderrM ]; then
229      echo " "
230      echo "**** Test failed ****"
231      cat teststderrM
232      cat teststdoutM
233      exit 1
234    fi
235  else
236    echo "Skipping JIT regression tests: JIT is not enabled"
237  fi
238  }
239
240# Update the total count whenever a new test is added; it is used to show
241# progess as each test is run.
242
243testtotal=`expr 17 \* $usemain + \
244  1 \* $usemain \* $usedebug + \
245  1 \* $usetmp + \
246  1 \* $ISGCC \* $usemain + \
247  1 \* $ISGCC \* $usemain \* $useasan + \
248  1 \* $ISGCC \* $usemain \* $useusan + \
249  13 \* $usejit + \
250  2 \* $usemainvalgrind + \
251  2 \* $usejitvalgrind`
252
253testcount=0
254
255if [ $testtotal -eq 0 ] ; then
256  echo "** No tests selected"
257  exit 1
258fi
259
260valgrind=
261jrvalgrind=
262withvalgrind=
263srcdir=.
264export srcdir
265
266if [ $usejit -ne 0 ]; then
267  enable_jit=--enable-jit
268else
269  enable_jit=
270fi
271
272# If gcc is in use, run a maximally configured test with -O2, because that can
273# throw up warnings that are not detected with -O0. Then run a second test with
274# -fsanitize=address, which also may throw up new warnings as well as checking
275# things at runtime. Finally, run another test using -fsanitize=undefined
276# -std-gnu99 to check for runtime actions that are not well defined. However,
277# we also use -fno-sanitize=shift to avoid warnings for shifts of negative
278# numbers, which occur in src/pcre2_jit_compile.c.
279
280if [ $ISGCC -ne 0 -a $usemain -ne 0 ]; then
281  echo "---------- Maximally configured test with -O2 ----------"
282  SAVECFLAGS="$CFLAGS"
283  CFLAGS="-O2 $CFLAGS"
284  echo "CFLAGS=$CFLAGS"
285  opts="--disable-shared $enable_jit --enable-pcre2-16 --enable-pcre2-32"
286  runtest
287  if [ $useasan -ne 0 ]; then
288    echo "---------- Maximally configured test with -fsanitize=address ----------"
289# Following a kernel change, sanitize address doesn't work unless the extra
290# PIE options are also set.
291    CFLAGS="$OFLAGS $SAVECFLAGS -no-pie -fno-PIE -fsanitize=address"
292    echo "CFLAGS=$CFLAGS"
293    opts="--disable-shared $enable_jit --enable-pcre2-16 --enable-pcre2-32"
294    runtest
295  fi
296# This also seems to be the case for sanitize undefined.
297  if [ $useusan -ne 0 ]; then
298    echo "------- Maximally configured test with -fsanitize=undefined -fno-sanitize=shift -fno-sanitize=alignment -std=gnu99 -------"
299    CFLAGS="$OFLAGS $SAVECFLAGS -no-pie -fno-PIE -fsanitize=undefined -fno-sanitize=shift -fno-sanitize=alignment -std=gnu99"
300    echo "CFLAGS=$CFLAGS"
301    opts="--disable-shared $enable_jit --enable-pcre2-16 --enable-pcre2-32"
302    runtest
303  fi
304  CFLAGS="$OFLAGS $SAVECFLAGS"
305fi
306
307# This set of tests builds PCRE2 and runs the tests with a variety of configure
308# options, in the current (source) directory. The empty configuration builds
309# with all the default settings. As well as testing that these options work, we
310# use --disable-shared or --disable-static except for the default test (which
311# builds both) to save a bit of time by building only one version of the
312# library for the subsequent tests.
313
314echo "---------- CFLAGS for the remaining tests ----------"
315echo "CFLAGS=$CFLAGS"
316
317if [ $usemain -ne 0 ]; then
318  if [ $usedebug -ne 0 ]; then
319    echo "---------- Maximally configured test with --enable-debug ----------"
320    opts="--disable-shared $enable_jit --enable-pcre2-16 --enable-pcre2-32 --enable-debug"
321    runtest
322  fi
323
324  echo "---------- Non-JIT tests in the current directory ----------"
325  for opts in \
326    "" \
327    "--disable-static" \
328    "--disable-shared" \
329    "--disable-unicode --disable-shared --enable-never-backslash-C" \
330    "--with-link-size=3 --disable-shared --disable-pcre2grep-callout" \
331    "--disable-unicode --enable-rebuild-chartables --disable-shared" \
332    "--disable-unicode --enable-newline-is-any --disable-shared" \
333    "--disable-unicode --enable-newline-is-cr --disable-shared" \
334    "--disable-unicode --enable-newline-is-crlf --disable-shared" \
335    "--disable-unicode --enable-newline-is-anycrlf --enable-bsr-anycrlf --disable-shared" \
336    "--enable-newline-is-any --disable-static" \
337    "--disable-unicode --enable-pcre2-16" \
338    "--enable-pcre2-16 --disable-shared" \
339    "--disable-unicode --enable-pcre2-32" \
340    "--enable-pcre2-32 --disable-shared" \
341    "--disable-unicode --enable-pcre2-32 --enable-pcre2-16 --disable-shared" \
342    "--disable-unicode --enable-pcre2-32 --enable-pcre2-16 --disable-pcre2-8 --disable-shared"
343  do
344    runtest
345  done
346fi
347
348# Now run the JIT tests unless disabled
349
350if [ $usejit -ne 0 ]; then
351  echo "---------- JIT tests in the current directory ----------"
352  for opts in \
353    "--disable-unicode --enable-jit --disable-shared" \
354    "--enable-jit --disable-shared" \
355    "--enable-jit --with-link-size=3 --disable-shared" \
356    "--enable-jit --enable-pcre2-16 --disable-shared" \
357    "--disable-unicode --enable-jit --enable-pcre2-16 --disable-pcre2-8 --disable-shared" \
358    "--enable-jit --enable-pcre2-16 --disable-pcre2-8 --disable-shared" \
359    "--enable-jit --enable-pcre2-16 --with-link-size=3 --disable-shared" \
360    "--enable-jit --enable-pcre2-16 --with-link-size=4 --disable-shared" \
361    "--enable-jit --enable-pcre2-32 --disable-shared" \
362    "--disable-unicode --enable-jit --enable-pcre2-32 --disable-pcre2-8 --disable-shared" \
363    "--enable-jit --enable-pcre2-32 --disable-pcre2-8 --disable-shared" \
364    "--enable-jit --enable-pcre2-32 --with-link-size=4 --disable-shared" \
365    "--enable-jit --enable-pcre2-32 --enable-pcre2-16 --disable-pcre2-8 --enable-newline-is-anycrlf --enable-bsr-anycrlf --disable-shared"
366  do
367    runtest
368  done
369fi
370
371# Now re-run some of the tests under valgrind.
372
373if [ $usevalgrind -ne 0 ]; then
374  echo "---------- Tests in the current directory using valgrind ----------"
375  valgrind=valgrind
376  withvalgrind="with valgrind"
377
378  if [ $usemainvalgrind -ne 0 ]; then
379    for opts in \
380      "--disable-shared" \
381      "--with-link-size=3 --enable-pcre2-16 --enable-pcre2-32 --disable-shared"
382    do
383      opts="--enable-valgrind $opts"
384      runtest
385    done
386  fi
387
388  if [ $usejitvalgrind -ne 0 ]; then
389    jrvalgrind="valgrind --tool=memcheck -q --smc-check=all-non-file --suppressions=$srcdir/testdata/valgrind-jit.supp"
390    for opts in \
391      "--enable-jit --disable-shared" \
392      "--enable-jit --enable-pcre2-16 --enable-pcre2-32"
393    do
394      opts="--enable-valgrind $opts"
395      runtest
396    done
397  fi
398fi
399
400valgrind=
401jrvalgrind=
402withvalgrind=
403
404# Clean up the distribution and then do at least one build and test in a
405# directory other than the source directory. It doesn't work unless the
406# source directory is cleaned up first.
407
408if [ -f Makefile ]; then
409  echo "Running 'make distclean'"
410  make distclean >/dev/null 2>&1
411  if [ $? -ne 0 ]; then
412    echo "** 'make distclean' failed"
413    exit 1
414  fi
415fi
416
417echo "---------- End of tests in the source directory ----------"
418echo "Removing teststdoutM and teststderrM"
419rm -rf teststdoutM teststderrM
420
421if [ $usetmp -ne 0 ]; then
422  echo "---------- Tests in the $tmp directory ----------"
423  srcdir=`pwd`
424  export srcdir
425
426  if [ ! -e $tmp ]; then
427    mkdir $tmp
428  fi
429
430  if [ ! -d $tmp ]; then
431    echo "** Failed to create $tmp or it is not a directory"
432    exit 1
433  fi
434
435  cd $tmp
436  if [ $? -ne 0 ]; then
437    echo "** Failed to cd to $tmp"
438    exit 1
439  fi
440
441  for opts in \
442    "--disable-shared"
443  do
444    runtest
445  done
446
447  echo "Removing $tmp"
448  rm -rf $tmp
449fi
450
451echo "---------- All done ----------"
452
453# End
454