1#!/bin/sh 2 3st=0 # exit status (set to 1 if a test fails) 4skipped= 5fail="**FAIL**" 6skip="**SKIP**" 7success=" SUCCESS" 8TEST(){ 9 # Try to make the log file easier to read: 10 echo "=============== pngtest $* ====================" 11 ./pngtest "$@" 12 status=$? 13 case "$status" in 14 0) test_status="$success";; 15 77) test_status="$skip" 16 skipped=1;; 17 *) test_status="$fail" 18 st="$status";; 19 esac 20 echo "===============$test_status $* ====================" 21 return "$status" 22} 23 24# The "standard" test 25TEST --strict "${srcdir}"/pngtest.png 26 27# Various crashers 28# Use --relaxed because some come from fuzzers that don't maintain CRCs 29TEST --relaxed "${srcdir}"/contrib/testpngs/crashers/badcrc.png 30# Use --xfail because there is no reliable way of disabling these errors 31# (Adler32 checking cannot be switched off on all builds and there is no 32# provision for turning the other checks into warnings.) 33TEST --xfail "${srcdir}"/contrib/testpngs/crashers/badadler.png 34TEST --xfail "${srcdir}"/contrib/testpngs/crashers/bad_iCCP.png 35TEST --xfail "${srcdir}"/contrib/testpngs/crashers/empty_ancillary_chunks.png 36for file in "${srcdir}"/contrib/testpngs/crashers/huge_*_chunk.png 37do 38 TEST --xfail "$file" 39done 40for file in "${srcdir}"/contrib/testpngs/crashers/huge_*safe_to_copy.png 41do 42 TEST --xfail "$file" 43done 44TEST --xfail "${srcdir}"/contrib/testpngs/crashers/huge_IDAT.png 45 46# Regression tests for required warnings (or errors): 47check_stdout(){ 48 # $1: the test file (a bad PNG which must produce a warning, etc) 49 # $2: a string which must occur at the end of line on stdout for success 50 # result: an error message on descriptor 3 if the string is NOT found 51 # 52 # WARNING: when this script is executed on MSYS2 (Windows Cygwin variant) 53 # pngtest outputs lines terminated with <cr><lf> however the MSYS2 shell 54 # expects <lf> (\n) terminated lines so the <cr> ends up in the shell 55 # variable 'line' below. The pattern matching ignores this because of the 56 # '*' at the end of the pattern match. 57 found= 58 skipped= 59 while read line 60 do 61 case "$line" in 62 *"$2"*) found=1;; 63 *"TEST SKIPPED"*) skipped=1;; 64 esac 65 echo "$line" # preserve the original output verbatim 66 done 67 # output the missing warning on descriptor 3: 68 test -z "$found" -a -z "$skipped" && echo "$1: $2" >&3 69} 70# NOTE: traditionally the Bourne shell executed the last element in a pipe 71# sequence in the original shell so it could set variables in the original 72# shell however this is not reliable and doesn't work in bash. 73# 74# It *is* reliable to use the actual exit status of the last command in 75# the pipeline. 76exec 4>&1 # original stdout - the log file 77{ 78 exec 3>&1 # stdout is the pipe at this point 79 fail=" FAIL(EXPECTED)" # runtime scope 80 success=" SUCCESS(UNEXPECTED)" # there should be a write error 81 for file in "${srcdir}"/contrib/testpngs/badpal/*.png 82 do 83 # The exit code is ignored here, the test is that the particular errors 84 # (warnings) are produced. The original output still ends up in the log 85 # file. 86 { 87 TEST "$file" 88 test "$?" -eq 77 && echo "TEST SKIPPED" 89 } | 90 check_stdout "$file" 'IDAT: Read palette index exceeding num_palette' | 91 check_stdout "$file" 'Wrote palette index exceeding num_palette' >&4 92 done 93 exec 3>&- 94} | { 95 # This may not be a sub-shell, if it is 'st' is undefined and the exit 96 # just ends up as 'exit'. 97 while read error 98 do 99 echo "MISSING REPORT: $error" 100 st=1 101 done 102 exit $st 103} || st=$? 104 105test "$st" -gt 0 && exit "$st" 106test -n "$skipped" && exit 77 107exit 0 108