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