1 # common.sh - common defs for all tests -*- sh -*-
2 # Copyright (C) 2004, 2008 Free Software Foundation, Inc.
4 # This file is part of GnuPG.
6 # GnuPG is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # GnuPG is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, see <http://www.gnu.org/licenses/>.
19 # reset some environment variables because we do not want to test locals
23 export LANG LANGUAGE LC_ALL
27 if [ "$1" = "--debug" ]; then
33 [ -z "$srcdir" ] && srcdir
="."
34 [ -z "$top_srcdir" ] && top_srcdir
=".."
35 [ -z "$GPGSM" ] && GPGSM
="../../sm/gpgsm"
36 [ -z "$silent" ] && silent
=no
39 SCRATCH
="scratch.$$.tmp"
41 # We use this as the faked system time for certain tests.
42 MYTIME
="20080508T120000"
45 if [ "$GNUPGHOME" != "`/bin/pwd`" ]; then
46 echo "inittests: please set GNUPGHOME to the tests/pkits directory" >&2
50 if [ -n "$GPG_AGENT_INFO" ]; then
51 echo "inittests: please unset GPG_AGENT_INFO" >&2
55 if [ -f PKITS_data.
tar.bz2
]; then
58 if [ "$pgmname" = "import-all-certs" ]; then
59 if [ "$silent" = "yes" ]; then tmp1
="Note: "; tmp2
=' '
60 else tmp1
="- ____ "; tmp2
="$tmp1"
62 echo "${tmp1}PKITS_data.tar.bz2 is not installed"
63 echo "${tmp2}All tests will be skipped (this is not an error)"
65 # Exit code 77 is used by the Makefile for skipping a tests.
69 #--------------------------------
70 #------ utility functions -------
71 #--------------------------------
75 if test "$echo_n_init" = "no"; then
76 if (echo "testing\c"; echo 1,2,3) |
grep c
>/dev
/null
; then
77 if (echo -n testing
; echo 1,2,3) |
sed s
/-n/xn
/ |
grep xn
>/dev
/null
; then
91 echo $echo_n_n "${1}$echo_n_c"
95 if [ -z "$first_section_set" ]; then
96 first_section_set
=$section
98 section_out
="$(echo $section)"
99 if [ -z "$section_out" ]; then
105 echo "$pgmname: fatal:" $
* >&2
106 if [ "$silent" != "yes" ]; then
107 echo "$section_out ERROR: $* (fatal)"
113 echo "$pgmname:" $
* >&2
114 if [ "$silent" != "yes" ]; then
115 echo "$section_out ERROR: $*"
122 echo "$pgmname:" $
* >&2
123 if [ "$silent" != "yes" ]; then
124 echo "$section_out ____ $*"
130 echo_n
"$pgmname:" $
* >&2
136 pass_count
=`expr ${pass_count} + 1`
137 if [ "$silent" != "yes" ]; then
138 echo_n
"$section_out PASS"
139 if [ -n "$1" ]; then echo_n
" $1"
140 elif [ -n "$description" ]; then echo_n
" ($description)"
149 fail_count
=`expr ${fail_count} + 1`
150 if [ "$silent" != "yes" ]; then
151 echo_n
"$section_out FAIL"
152 if [ -n "$1" ]; then echo_n
" $1"
153 elif [ -n "$description" ]; then echo_n
" ($description)"
162 skip_count
=`expr ${skip_count} + 1`
163 if [ "$silent" != "yes" ]; then
164 echo_n
"$section_out SKIP"
165 if [ -n "$1" ]; then echo_n
" $1"
166 elif [ -n "$description" ]; then echo_n
" ($description)"
174 echo "UNRESOLVED: " $
* >&2
175 unresolved_count
=`expr ${unresolved_count} + 1`
176 if [ "$silent" != "yes" ]; then
177 echo_n
"$section_out UNRESOLVED"
178 if [ -n "$1" ]; then echo_n
" $1"
179 elif [ -n "$description" ]; then echo_n
" ($description)"
187 section
=$first_section_set
188 [ $pass_count = 0 ] || info
"$pass_count tests passed"
189 [ $fail_count = 0 ] || info
"$fail_count tests failed"
190 [ $skip_count = 0 ] || info
"$unsupported_count tests skipped"
191 [ $unresolved_count = 0 ] || info
"$unresolved_count tests unresolved"
192 [ -z "$debug" -a -f "$SCRATCH" ] && rm "$SCRATCH"
193 if [ $fail_count = 0 ]; then
194 info
"all tests passed"
202 [ -f pubring.kbx
] && rm pubring.kbx
203 if [ -d private-keys-v1.d
]; then
204 rm private-keys-v1.d
/* 2>/dev
/null || true
205 rmdir private-keys-v1.d
213 echo "BEGIN TEST $section ($description)" >&2
217 case "$test_status" in
218 none
) skip
"($description) - test not implemented";;
219 pass
) pass
"($description)";;
220 fail
) fail
"($description)";;
221 setup
) fail
"($description) - setup failed";;
222 ns
) skip
"($description) - not supported";;
223 nys
) skip
"($description) - not yet supported";;
224 *) unresolved
"$(description)";;
226 echo "END TEST $section" >&2
230 if [ "$test_status" = "none" ]; then
236 if [ "$2" = "--import-anyway" ]; then
237 if ! ${GPGSM} -q --debug-no-chain-validation --import certs
/$1.crt
242 if ! ${GPGSM} -q --import certs
/$1.crt
; then
249 # CRL are not yet implemented
266 # User settable variables
271 #trap cleanup SIGHUP SIGINT SIGQUIT
272 [ -z "$debug" ] && exec 2> ${pgmname}.log