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