about summary refs log tree commit diff
path: root/test/Execute-Tests
blob: 39fab58c8670140a6714f74d4f8332cfba420db2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#! /bin/bash

# Confirm that PBM_TESTPREFIX is set.
# PBM_TESTPREFIX is the directory with the Netpbm programs you want to
# test.  If set to null, executables will be sought from the default
# execution path ($PATH).  Usually you should explicitly set this.
#
# You can set it here by de-commenting and modifying the next line:
#export PBM_TESTPREFIX="/usr/local/bin/"

if [ -z $PBM_TESTPREFIX ]
  then
  echo "Warning: PBM_TESTPREFIX is not set."
  echo "Programs in the default execution path:"
  echo $PATH
  echo "will be tested."
elif [ ! -d $PBM_TESTPREFIX ]
  then
  echo "Error: No directory named $PBM_TESTPREFIX"
  exit 1
else
  # append "/" to end of string if necessary
  export PBM_TESTPREFIX=$(echo $PBM_TESTPREFIX | sed '/\/$/!s@$@/@')
fi

# Set PBM_BINPREFIX.
# PBM_BINPREFIX is the directory where Netpbm programs which play
# auxiliary roles in tests (such as image generators for producing
# test images, analyzers to summarize output and so forth).
#
# If testing a fresh install, this should be the same as PBM_TESTPREFIX.
# If you are developing a single Netpbm program, you may want to
# set this to a directory with stable executables.  (Final "/" is
# mandatory.)
# If set to null, executables in the default execution path will
# be used.

# export PBM_BINPREFIX="/usr/local/bin/"
# export PBM_BINPREFIX=""
export PBM_BINPREFIX=${PBM_TESTPREFIX}

# Add PBM_BINPREFIX to PATH.
# This is necessary for Netpbm programs (mosly scripts) that call
# other Netpbm programs.

if [ ! -z $PBM_BINPREFIX ]
  then
  export PATH=${PBM_BINPREFIX}:$PATH
fi

# Set srcdir, which is the directory which contains Execute-Tests
# (this script), Test-Order *.test and *.ok files.

srcdir=$(dirname $0)

# Provision to run programs under valgrind.
# export PBM_TESTPREFIX="valgrind --log-fd=4 "${PBM_TESTPREFIX}

# Set tmpdir, which is used in some of the test scripts.  By default
# this is created by mktemp.  The user can override and specify tmpdir,
# but in this case it must be an existing directory and must not be
# either $srcdir or current work.

if [ -z $tmpdir ]
  then
    tmpdir_created=$(mktemp -d) || exit 1;
  export tmpdir=${tmpdir_created}
  else
  tmpdir_created="";
  if [ ! -d ${tmpdir} ]
     then echo "Specified temporary directory $tmpdir does not exist."
     exit 1;
  elif [ ${tmpdir} -ef ${srcdir} ]
     then echo "Temporary directory must not be $srcdir."
     exit 1;
  elif [ ${tmpdir} -ef $PWD ]
     then echo "Temporary directory must not be current directory."
     exit 1;
  fi
fi


# If necessary set the RGBDEF environment variable.
#export RGBDEF=/etc/rgb.txt
#export RGBDEF=/usr/local/netpbm/lib/rgb.txt
#export RGBDEF=/usr/share/emacs/*/etc/rgb.txt

# Declare arrays used to count and report test results.
# For now only "SUCCESS" and "FAILURE" are used.
declare -a array=(0 0 0 0 0 0)
declare -a status=("SUCCESS" "FAILURE" "UNEXPECTED SUCCESS"
                   "EXPECTED FAILURE" "NOT SUPPORTED" "TOTAL SUPPORTED")

# Copy test files to the current work directory

if [ ! -f ./testgrid.pbm ]
  then cp -v ${srcdir}/testgrid.pbm ./testgrid.pbm
fi

if [ ! -f ./testimg.ppm ]
  then cp -v ${srcdir}/testimg.ppm  ./testimg.ppm 
fi

# Execute the tests, as described in the "Test-Order" file.
#
# Each test outputs a ".out" file, which is compared against a
# corresponding ".ok" file.  For example the output from "pbmmake.test"
# is "pbmmake.out" and when this matches "pbmmake.ok" we declare the
# test a success.
# In the error case the ".out" file is retained in the current work
# directory.
#
# All tests are self-contained.
#
# By default the tests are executed in the order described in the
# file Test-Order.  Copy this file from the source directory
# to the work directory.
# 
# The --no-clobber version comes useful when the user wants a modified
# (pared-down) version of Test-Order.

cp ${srcdir}/Test-Order ./Test-Order
#cp --no-clobber ${srcdir}/Test-Order ./Test-Order

for t in `grep -v "^#" ./Test-Order | fgrep ".test"`
do
echo == $t ==
${srcdir}/$t >  ${t%.test}.out ; let result=$?
case $result in
0)   cmp -s ${t%.test}.out ${srcdir}/${t%.test}.ok ;
     if [ $? -eq 0 ]
        then let result=0;  rm  ${t%.test}.out ;
        else let result=1;
     fi
     let supported=1 ;;
80) let result=4 ; let supported=0;;
*)  let result=1 ; let supported=1;;
esac

# Report whether a single test succeeded or failed.
# Increment counters.

echo $t: ${status[${result}]}; echo
let array[${result}]=${array[${result}]}+1
let array[5]=${array[5]}+$supported

done


# Erase temporary directory and its contents, if it was created.

if [ -n $tmpdir_created ]
    then rm -rf $tmpdir_created
fi


# Erase test image files in the current (work) directory.
# (Do not erase them if we are working from the source directory.)

if [ ! $PWD -ef ${srcdir} ]
    then rm ./testimg.ppm ./testgrid.pbm
fi


# Calculate success / failure totals and print a summary report.
# Report date and time of completion.

echo "Test summary:"
echo ==================

for s in 0 1 2 3 4 5
  do
    if [[ ${array[${s}]} -gt 0 || s -eq 1 ]]
    then echo ${status[${s}]} ${array[${s}]}
    fi
  done

echo ==================
echo "All tests done."
date -R -u


# Exit with status 0 if all supported tests succeeded, 1 otherwise.

if [[ ${array[0]} -eq ${array[5]} ]]
then exit 0
else exit 1
fi