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
19 TMPDIR
=$
(mktemp
-d) ||
{
20 echo Cannot create temp dir.
>&2
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
28 echo "Using system 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
41 GS_BIN_BITS
=$
(file "$GS_BIN" |
"$SED" -e 's/^.*ELF \([[:digit:]]*\)-bit.*$/\1/')
43 IN
="$TEST_DIR/input.ps"
47 echo "Cannot find test data $IN." >&2
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
63 cmd
="$GS_BIN -I \"$GS_RESPATH\" -q -dNOPAUSE -dBATCH -sDEVICE=\"$dev\" -sOutputFile=\"$out\" \"$in\""
64 [ -n "$DEBUG" ] && echo "\$ $cmd"
67 [ -n "$DEBUG" ] && echo "\$?=$ret"
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
83 GS
"$dev" "$IN" "$target" || status
=fail
84 [ ! -s "$target" ] && status
="fail (zero size)"
85 [ $ret -eq 0 -a "$status" != pass
] && ret
=1
91 test2_find_deterministic
() {
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
100 GS
"$dev" "$IN" "$OUT" >/dev
/null
2>&1 ||
return 1
101 cmp -s "$target" "$OUT" ||
return 1
103 (cd $
(dirname "$target") && cksum "$dev" >"$TEST2_CKSUM")
106 # Generate function tries to find devices with deterministic output and saves it for testing.
108 # disable x11 devices
111 mkdir
-p "$TEST2_EXPECTED"
113 for dev
in $TEST2_DEVS; do
115 test2_find_deterministic
$dev
116 if [ $?
-eq 0 ]; then
117 target
="$TEST2_EXPECTED/$dev"
118 if [ -s "$target" ]; then
120 cmp "$target" "$TEST2_CKSUM" || status
=changed
125 [ "$status" = new
-o "$status" = changed
] && mv "$TEST2_CKSUM" "$target"
126 $ECHO "keep ($status)"
129 rm -f "$TEST2_EXPECTED/$dev"
134 # generates output for all devices, compare with expected
138 for dev
in $TEST2_DEVS; do
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
173 $ECHO "Argument must be either 'check', 'system-check' or 'generate'." >&2