-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdpkg-runtests.sh
executable file
·152 lines (131 loc) · 3.98 KB
/
dpkg-runtests.sh
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
#!/bin/bash --posix
############################################################################
# Copyright (C) 2007 Lawrence Livermore National Security, LLC
# Produced at Lawrence Livermore National Laboratory.
# Written by Jim Garlick <garlick@llnl.gov>.
# UCRL-CODE-235516
#
# This file is part of dpkg-scripts, a set of utilities for managing
# packages in /usr/local with dpkg.
#
# dpkg-scripts is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# dpkg-scripts is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with dpkg-scripts; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
############################################################################
# A package exports a single executable shell script called 'test' as part
# of its metadata. The test exits with 0=success, 1=notrun, >1=fail.
# It may log to stdout/stderr.
declare -r prog=dpkg-runtests
declare -r dpkgroot=/usr/local
declare -r infodir=${dpkgroot}/dpkg-db/info
declare -r dkwrap=/usr/bin/dpkg-wrap
vopt=0
Vopt=0
die()
{
echo "${prog}: $1" >&2
exit 1
}
runtest()
{
local pkg=$1
local result
echo "start $(date)"
echo "running dpkg -s ${pkg}"
dpkg -s ${pkg}
#echo "running dpkg-verify ${pkg}"
#dpkg-verify ${pkg} && echo "dpkg-verify reports no errors"
if [ -r ${infodir}/${pkg}.dk ] && [ -x ${dkwrap} ]; then
echo "running ${dkwrap} ${pkg} ${infodir}/${pkg}.test"
${dkwrap} ${pkg} ${infodir}/${pkg}.test
else
echo "running ${infodir}/${pkg}.test"
${infodir}/${pkg}.test
fi
result=$?
case ${result} in
0) echo "result: ok"
;;
1) echo "result: notrun"
;;
*) echo "result: fail"
;;
esac
echo "finish $(date)"
return ${result}
}
usage()
{
echo "Usage: dpkg-runtests [-v] pkg [pkg...]" >&2
exit 1
}
##
## MAIN
##
while getopts "?vV" opt; do
case ${opt} in
h|\?) usage ;;
v) vopt=1 ;;
V) Vopt=1; vopt=1 ;;
*) die "bad option: ${opt}" ;;
esac
done
shift $((${OPTIND} - 1))
failures=0
testsrun=0
[ $(id -u) != 0 ] || die "you must not run tests as superuser"
umask 022
packages=$(dpkg-query -Wf '${package} ${status}\n' "$@" \
| awk '$4 == "installed" {print $1}' )
workdir=$(mktemp -d ${TMPDIR:-/tmp}/${prog}.XXXXXXXXXX) || die "mktemp error"
for pkg in ${packages}; do
if ! dpkg -L ${pkg} >/dev/null 2>&1; then
printf "${prog}: %-40s %s\n" ${pkg} "error - no such package" >&2
continue
fi
if ! [ -x ${infodir}/${pkg}.test ]; then
printf "${prog}: %-40s %s\n" ${pkg} "notest"
continue
fi
tmpdir=${workdir}/${pkg}
mkdir ${tmpdir} || die "Failed to create tmpdir ${tmpdir}"
printf "${prog}: %-40s " ${pkg}
pushd ${tmpdir} >/dev/null
runtest ${pkg} >test.log 2>&1
result=$?
popd >/dev/null
case $result in
0) printf "ok\n"
testsrun=$(expr ${testsrun} + 1)
[ $Vopt = 1 ] && cat ${tmpdir}/test.log
rm -rf ${tmpdir}
;;
1) printf "notrun (see %s)\n" ${tmpdir}
[ $vopt = 1 ] && cat ${tmpdir}/test.log
;;
2) printf "failed (see %s)\n" ${tmpdir}
[ $vopt = 1 ] && cat ${tmpdir}/test.log
failures=$(expr ${failures} + 1)
testsrun=$(expr ${testsrun} + 1)
;;
esac
done
rmdir ${workdir} 2>/dev/null
if [ ${failures} = 0 ]; then
echo "${prog}: Summary: all tests passed"
else
echo "${prog}: Summary: ${failures} of ${testsrun} tests failed"
exit 2
fi
exit 0
# vi: expandtab sw=4 ts=4