2
1
# common.sh - common defs for all tests -*- sh -*-
3
# Copyright (C) 2004 Free Software Foundation, Inc.
2
# Copyright (C) 2004, 2008 Free Software Foundation, Inc.
5
4
# This file is part of GnuPG.
7
6
# GnuPG is free software; you can redistribute it and/or modify
8
7
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2 of the License, or
8
# the Free Software Foundation; either version 3 of the License, or
10
9
# (at your option) any later version.
12
11
# GnuPG is distributed in the hope that it will be useful,
15
14
# GNU General Public License for more details.
17
16
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
17
# along with this program; if not, see <http://www.gnu.org/licenses/>.
21
19
# reset some environment variables because we do not want to test locals
27
[ "$VERBOSE" = yes ] && set -x
23
export LANG LANGUAGE LC_ALL
27
if [ "$1" = "--debug" ]; then
28
33
[ -z "$srcdir" ] && srcdir="."
29
34
[ -z "$top_srcdir" ] && top_srcdir=".."
30
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"
33
45
if [ "$GNUPGHOME" != "`pwd`" ]; then
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.
45
69
#--------------------------------
46
70
#------ utility functions -------
67
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
71
105
echo "$pgmname: fatal:" $* >&2
106
if [ "$silent" != "yes" ]; then
107
echo "$section_out ERROR: $* (fatal)"
76
113
echo "$pgmname:" $* >&2
114
if [ "$silent" != "yes" ]; then
115
echo "$section_out ERROR: $*"
81
122
echo "$pgmname:" $* >&2
123
if [ "$silent" != "yes" ]; then
124
echo "$section_out ____ $*"
85
$echo_n "$pgmname:" $* >&2
130
echo_n "$pgmname:" $* >&2
89
135
echo "PASS: " $* >&2
90
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)"
94
148
echo "FAIL: " $* >&2
95
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)"
99
174
echo "UNRESOLVED: " $* >&2
100
175
unresolved_count=`expr ${unresolved_count} + 1`
104
echo "UNSUPPORTED: " $* >&2
105
unsupported_count=`expr ${unsupported_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)"
109
186
final_result () {
187
section=$first_section_set
110
188
[ $pass_count = 0 ] || info "$pass_count tests passed"
111
189
[ $fail_count = 0 ] || info "$fail_count tests failed"
190
[ $skip_count = 0 ] || info "$unsupported_count tests skipped"
112
191
[ $unresolved_count = 0 ] || info "$unresolved_count tests unresolved"
113
[ $unsupported_count = 0 ] || info "$unsupported_count tests unsupported"
192
[ -z "$debug" -a -f "$SCRATCH" ] && rm "$SCRATCH"
114
193
if [ $fail_count = 0 ]; then
115
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
123
pgmname=`basename $0`
127
261
unresolved_count=0
266
# User settable variables
131
271
#trap cleanup SIGHUP SIGINT SIGQUIT
132
exec 2> ${pgmname}.log
272
[ -z "$debug" ] && exec 2> ${pgmname}.log