sbcl: update to 2.5.1
[oi-userland.git] / components / print / ghostscript / tests / run
blobffd7c8919d24dbc0ee3b5aa134f2a459c93d0e10
1 #!/bin/sh
3 # Copyright (c) 2020, Oracle and/or its affiliates.
6 # check verify gs specified by ${GS} or the one in current directory
7 # system_check verify system gs
8 # generate generate data for tests
10 # GS variable selects gs tree
11 # DEBUG variable is more verbose
14 AWK=gawk
15 ECHO=gecho
16 SED=gsed
19 TMPDIR=$(mktemp -d) || {
20 echo Cannot create temp dir. >&2
21 exit 1
23 trap "rm -rf \"$TMPDIR\"" 0 1 2 3 6
25 TEST_DIR=$(dirname "$0"); [ -z "$TEST_DIR" ] && TEST_DIR=.
26 if [ "$1" = system-check ]; then
27 GS_BIN=$(which gs)
28 echo "Using system gs."
29 else
30 GS=${GS:-.}
31 GS_BIN=$GS/bin/gs
32 GS_RESPATH="$GS/Resource/Init:$GS/lib:$GS/Resource/Font"
33 echo "Using $GS_BIN -I \"$GS_RESPATH\"."
36 [ ! -x "$GS_BIN" ] && {
37 echo "Cannot find gs executable $GS_BIN." >&2
38 exit 1
41 GS_BIN_BITS=$(file "$GS_BIN" | "$SED" -e 's/^.*ELF \([[:digit:]]*\)-bit.*$/\1/')
43 IN="$TEST_DIR/input.ps"
44 OUT=$TMPDIR/testout
46 [ ! -f "$IN" ] && {
47 echo "Cannot find test data $IN." >&2
48 exit 1
51 TEST1_GENERATE_FILTER="bbox|cif|devicen|display|ijs|nullpage|oprp|opvp|plib|plibc|plibg|plibk|plibm|rinkj|tiffsep1|uniprint|x11|x11alpha|x11cmyk|x11cmyk2|x11cmyk4|x11cmyk8|x11gray2|x11gray4|x11mono|x11rg16x|x11rg32x"
53 TEST2_DEVS="bjccmyk cdeskjet cdj1600 cdj500 cdj550 cdj670 cdj850 cdj880 cdj890 cdjcolor chp2200 mj500c mj6000c mj700v2c mj8000c npdl photoex picty180 stcolor txtwrite"
54 TEST2_GENERATE_TRIES=3
55 TEST2_EXPECTED="$TEST_DIR/test2-$(uname -p)-$GS_BIN_BITS"
56 TEST2_CKSUM=$TMPDIR/cksum
58 GS() {
59 dev=$1
60 in=$2
61 out=$3
63 cmd="$GS_BIN -I \"$GS_RESPATH\" -q -dNOPAUSE -dBATCH -sDEVICE=\"$dev\" -sOutputFile=\"$out\" \"$in\""
64 [ -n "$DEBUG" ] && echo "\$ $cmd"
66 eval "$cmd"; ret=$?
67 [ -n "$DEBUG" ] && echo "\$?=$ret"
69 return $ret
72 test1() {
73 $ECHO This is test1.
75 GS_DEVICES=$($GS_BIN -h | $AWK -vFILTER="$TEST1_GENERATE_FILTER" 'END {print devices}
76 $0 == "Available devices:" {gather=1; next}
77 $0 == "Search path:" {gather=0}
78 gather == 1 {for(i=1; i<=NF; i++){if(!(match($i, FILTER))) devices=devices " " $i}}')
80 for dev in $GS_DEVICES; do
81 status=pass
82 target="$TMPDIR/$dev"
83 GS "$dev" "$IN" "$target" || status=fail
84 [ ! -s "$target" ] && status="fail (zero size)"
85 [ $ret -eq 0 -a "$status" != pass ] && ret=1
87 $ECHO $dev $status
88 done
91 test2_find_deterministic() {
92 dev=$1
94 target="$TMPDIR/$dev"
96 GS "$dev" "$IN" "$target" >/dev/null 2>&1 || return 1
97 [ ! -f "$target" ] && return 1
98 for n in $(seq 2 $TEST2_GENERATE_TRIES); do
99 $ECHO -n "$n "
100 GS "$dev" "$IN" "$OUT" >/dev/null 2>&1 || return 1
101 cmp -s "$target" "$OUT" || return 1
102 done
103 (cd $(dirname "$target") && cksum "$dev" >"$TEST2_CKSUM")
106 # Generate function tries to find devices with deterministic output and saves it for testing.
107 test2_generate() {
108 # disable x11 devices
109 unset DISPLAY
111 mkdir -p "$TEST2_EXPECTED"
113 for dev in $TEST2_DEVS; do
114 $ECHO -n "$dev "
115 test2_find_deterministic $dev
116 if [ $? -eq 0 ]; then
117 target="$TEST2_EXPECTED/$dev"
118 if [ -s "$target" ]; then
119 status=same
120 cmp "$target" "$TEST2_CKSUM" || status=changed
121 else
122 status=new
125 [ "$status" = new -o "$status" = changed ] && mv "$TEST2_CKSUM" "$target"
126 $ECHO "keep ($status)"
127 else
128 $ECHO disable
129 rm -f "$TEST2_EXPECTED/$dev"
131 done
134 # generates output for all devices, compare with expected
135 test2() {
136 $ECHO This is test2.
138 for dev in $TEST2_DEVS; do
139 status=pass
140 target="$TMPDIR/$dev"
141 GS "$dev" "$IN" "$target" || status=fail
142 [ "$status" = pass ] && {
143 (cd $(dirname "$target") && cksum $(basename "$target") >"$TEST2_CKSUM")
144 cmp "$TEST2_CKSUM" "$TEST2_EXPECTED/$dev" || status=fail
147 [ $ret -eq 0 -a $status != pass ] && ret=1
149 $ECHO $dev $status
150 done
153 check() {
154 test1
155 echo
156 test2
159 generate() {
160 test2_generate
163 case "$1" in
164 check|system-check)
165 ret=0
166 check
167 exit $ret
169 generate)
170 generate
173 $ECHO "Argument must be either 'check', 'system-check' or 'generate'." >&2
174 exit 1
176 esac