~ubuntu-branches/ubuntu/karmic/gnupg2/karmic-updates

« back to all changes in this revision

Viewing changes to tests/pkits/common.sh

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Viehmann
  • Date: 2008-10-04 10:25:53 UTC
  • mfrom: (5.1.15 intrepid)
  • Revision ID: james.westby@ubuntu.com-20081004102553-fv62pp8dsitxli47
Tags: 2.0.9-3.1
* Non-maintainer upload.
* agent/gpg-agent.c: Deinit the threading library before exec'ing
  the command to run in --daemon mode. And because that still doesn't
  restore the sigprocmask, do that manually. Closes: #499569

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/sh
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.
4
3
#
5
4
# This file is part of GnuPG.
6
5
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.
11
10
12
11
# GnuPG is distributed in the hope that it will be useful,
15
14
# GNU General Public License for more details.
16
15
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/>.
20
18
 
21
19
# reset some environment variables because we do not want to test locals
22
 
export LANG=C
23
 
export LANGUAGE=C
24
 
export LC_ALL=C
25
 
 
26
 
 
27
 
[ "$VERBOSE" = yes ] && set -x
 
20
LANG=C
 
21
LANGUAGE=C
 
22
LC_ALL=C
 
23
export LANG LANGUAGE LC_ALL
 
24
 
 
25
pgmname=`basename $0`
 
26
 
 
27
if [ "$1" = "--debug" ]; then
 
28
  debug=yes
 
29
  set -x
 
30
else
 
31
  debug=
 
32
fi
28
33
[ -z "$srcdir" ] && srcdir="."
29
34
[ -z "$top_srcdir" ] && top_srcdir=".."
30
35
[ -z "$GPGSM" ] && GPGSM="../../sm/gpgsm"
 
36
[ -z "$silent" ] && silent=no
 
37
 
 
38
AWK=awk
 
39
SCRATCH="scratch.$$.tmp"
 
40
 
 
41
# We use this as the faked system time for certain tests.
 
42
MYTIME="20080508T120000"
31
43
 
32
44
 
33
45
if [ "$GNUPGHOME" != "`pwd`" ]; then
40
52
    exit 1
41
53
fi
42
54
 
43
 
 
 
55
if [ -f PKITS_data.tar.bz2 ]; then
 
56
  :
 
57
else
 
58
    if [ "$pgmname" = "import-all-certs" ]; then
 
59
        if [ "$silent" = "yes" ]; then tmp1="Note: "; tmp2='      '
 
60
        else tmp1="- ____ "; tmp2="$tmp1"
 
61
        fi
 
62
        echo "${tmp1}PKITS_data.tar.bz2 is not installed"
 
63
        echo "${tmp2}All tests will be skipped (this is not an error)"
 
64
    fi
 
65
    # Exit code 77 is used by the Makefile for skipping a tests.
 
66
    exit 77
 
67
fi
44
68
 
45
69
#--------------------------------
46
70
#------ utility functions -------
67
91
  echo $echo_n_n "${1}$echo_n_c"
68
92
}
69
93
 
 
94
setup_output () {
 
95
  if [ -z "$first_section_set" ]; then
 
96
      first_section_set=$section
 
97
  fi
 
98
  section_out="$(echo $section)"
 
99
  if [ -z "$section_out" ]; then
 
100
      section_out="-"
 
101
  fi
 
102
}
 
103
 
70
104
fatal () {
71
105
    echo "$pgmname: fatal:" $* >&2
 
106
    if [ "$silent" != "yes" ]; then
 
107
        echo "$section_out ERROR: $* (fatal)"
 
108
    fi
72
109
    exit 1;
73
110
}
74
111
 
75
112
error () {
76
113
    echo "$pgmname:" $* >&2
 
114
    if [ "$silent" != "yes" ]; then
 
115
        echo "$section_out ERROR: $*"
 
116
    fi
77
117
    exit 1
78
118
}
79
119
 
80
120
info () {
 
121
    setup_output
81
122
    echo "$pgmname:" $* >&2
 
123
    if [ "$silent" != "yes" ]; then
 
124
        echo "$section_out ____ $*"
 
125
    fi
82
126
}
83
127
 
84
128
info_n () {
85
 
    $echo_n "$pgmname:" $* >&2
 
129
    setup_output
 
130
    echo_n "$pgmname:" $* >&2
86
131
}
87
132
 
88
133
pass () {
 
134
    setup_output
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)"
 
141
        fi
 
142
        echo
 
143
    fi
91
144
}
92
145
 
93
146
fail () {
 
147
    setup_output
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)"
 
154
        fi
 
155
        echo
 
156
    fi
 
157
}
 
158
 
 
159
skip () {
 
160
    setup_output
 
161
    echo "SKIP: " $* >&2
 
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)"
 
167
        fi
 
168
        echo
 
169
    fi
96
170
}
97
171
 
98
172
unresolved () {
 
173
    setup_output
99
174
    echo "UNRESOLVED: " $* >&2
100
175
    unresolved_count=`expr ${unresolved_count} + 1`
101
 
}
102
 
 
103
 
unsupported () {
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)"
 
180
        fi
 
181
        echo
 
182
    fi
106
183
}
107
184
 
108
185
 
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"
116
195
    else
118
197
    fi
119
198
}
120
199
 
 
200
 
 
201
clean_homedir () {
 
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
 
206
    fi
 
207
}
 
208
 
 
209
start_test () {
 
210
    section="$1"
 
211
    description="$2"
 
212
    test_status=none
 
213
    echo "BEGIN TEST $section ($description)" >&2
 
214
}
 
215
 
 
216
end_test () {
 
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)";; 
 
225
   esac
 
226
   echo "END TEST $section" >&2
 
227
}
 
228
 
 
229
set_status () {
 
230
    if [ "$test_status" = "none" ]; then
 
231
        test_status=$1
 
232
    fi
 
233
}
 
234
 
 
235
need_cert () {
 
236
    if [ "$2" = "--import-anyway" ]; then
 
237
        if ! ${GPGSM} -q --debug-no-chain-validation --import certs/$1.crt
 
238
          then 
 
239
            set_status setup
 
240
        fi
 
241
    else
 
242
        if ! ${GPGSM} -q --import certs/$1.crt; then 
 
243
            set_status setup
 
244
        fi
 
245
    fi
 
246
}
 
247
 
 
248
need_crl () {
 
249
    # CRL are not yet implemented
 
250
    #set_status setup
 
251
    :
 
252
}
 
253
 
 
254
 
 
255
 
121
256
set -e
122
257
 
123
 
pgmname=`basename $0`
124
 
 
125
258
pass_count=0
126
259
fail_count=0
 
260
skip_count=0
127
261
unresolved_count=0
128
 
unsupported_count=0
 
262
first_section_set=""
 
263
section_out=""
 
264
test_status=none
 
265
 
 
266
# User settable variables
 
267
section=""
 
268
description=""
129
269
 
130
270
 
131
271
#trap cleanup SIGHUP SIGINT SIGQUIT
132
 
exec 2> ${pgmname}.log
 
272
[ -z "$debug" ] && exec 2> ${pgmname}.log
133
273
 
134
274
:
135
275
# end