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 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
|
#!/bin/sh
short_options='ot:p:i:e:k:'
long_options='print-output,trigger:,pin-packages:,run-id:,extra-apt-source:,signing-key:'
usage() {
cat <<EOF
usage: debci test [OPTIONS] srcpkg
Options:
-o, --print-output
print output directory after test finished
-t TRIGGER, --trigger TRIGGER
Records TRIGGER as being the trigger for this test run. The trigger will
be written to a file in the output directory, so that it can be retrieved
later
-p RELEASE=pkgname,src:srcname,...
--pin-packages RELEASE=pkgname,src:srcname,...
Force specific packages to be installed from the given RELEASE. The
format is the same as the --pin-packages option from autopkgtest. RELEASE
will be automatically added to the testbed APT sources.
-i ID, --run-id ID
Use the specific ID as the run id for this test run, instead of
generating one based on the current date.
-e apt-source, --extra-apt-source apt-source
Add the given apt-source to /etc/apt/sources.list.d and update it.
-k KEY, --signing-key KEY
KEY is copied to /etc/apt/trusted.gpg.d/ inside the testbed to authorize secure extra-apt-source.
$@
EOF
}
set -eu
debci_base_dir=$(readlink -f $(dirname $(readlink -f $0))/..)
. $debci_base_dir/lib/environment.sh
. $debci_base_dir/lib/functions.sh
artifacts_too_large() {
cat << EOF
The original file was deleted because the artifacts directory was too large.
Consider adapting your tests to reduce potentially large artifacts to the
minimum required to debug problems, i.e.:
- reduce logs to the last N lines
- avoid too many large files as artifacts
- etc
EOF
}
process_package() {
local pkgname
case "$pkg" in
.*|*/*)
# a local pathname
if [ -d "$pkg" ]; then
pkgname="$(basename $(readlink -f "$pkg"))"
else
echo "E: $pkg is not a valid package"
exit 1
fi
;;
*)
pkgname="$pkg"
;;
esac
# output directory for test-package/autopkgtest
local base_dir="$(autopkgtest_incoming_dir_for_package "$pkgname")"
if [ -n "${run_id:-}" ]; then
adt_out_dir="${base_dir}/${run_id}"
else
run_id=$(date +%Y%m%d_%H%M%S)
adt_out_dir="${base_dir}/${run_id}"
inc=0
orig_run_id="$run_id"
while [ -d "$adt_out_dir" ]; do
# this in *very* unlikely to happen in production, but we need this for the
# test suite
run_id="${orig_run_id}.${inc}"
adt_out_dir="${base_dir}/${run_id}"
done
fi
mkdir -p "$(dirname $adt_out_dir)"
start_timestamp=$(date +%s)
# these variables can be considered as an API by backends/*/test-package and
# debci-autopkgtest
export debci_suite
export debci_arch
export debci_autopkgtest_args
eval ': "${debci_autopkgtest_args_'"$debci_backend"':=}"'
eval "export debci_autopkgtest_args_$debci_backend"
export debci_test_package="$pkgname"
export debci_test_outputdir="$adt_out_dir"
########################################################################
# XXX This is a hack to handle the fact that the --add-apt-source option
# has spaces in it. $options is separated by | with a bogus first item
# (to avoid an empty first argument; it is split on | into "$@", then
# the first item is discarded. "$@" is then used when calling the backend
# test-package command
########################################################################
old_IFS="$IFS"
IFS='|'
set -- $options
shift
IFS="$old_IFS"
########################################################################
if [ "$debci_quiet" = 'true' ]; then
test-package "$@" --output-dir "$adt_out_dir" "$pkg" \
>/dev/null 2>&1 || true
else
test-package "$@" --output-dir "$adt_out_dir" "$pkg" || true
fi
if [ ! -d "$adt_out_dir" ]; then
return
fi
finish_timestamp=$(date +%s)
# remove redundant logs
rm -f "${adt_out_dir}"/*-stdout
rm -f "${adt_out_dir}"/*-stderr
# cap main log
log=${adt_out_dir}/log
if [ -f "${log}" ]; then
limit=20 # in MB
limit_bytes=$((limit*1024*1024))
total_size="$(stat --format=%s "${log}")"
if [ "${total_size}" -gt "$limit_bytes" ]; then
mv "${log}" "${log}.orig"
(
# first 1MB
dd bs=1024 if="${log}.orig" count=1024 # first 1 MB
echo
echo "----------------8<----------------8<----------------8<-----------------"
echo ""
echo "WARNING: log file truncated at ${limit} MB (before compression)"
echo " First 1MB is presented above, last $((limit-1)) MB below"
echo ""
echo "----------------8<----------------8<----------------8<-----------------"
echo
# last N-1 MB
dd bs=1024 if="${log}.orig" skip=$((total_size/1024 - (limit-1)*1024))
) > "${log}" 2>/dev/null
rm -f "${log}.orig"
fi
gzip "${log}"
fi
# limit size of the artifacts directory
artifacts=${adt_out_dir}/artifacts
if [ -d "${artifacts}" ]; then
limit=100 # in MB
while [ "$(du -sm "${artifacts}" | awk '{print($1)}')" -gt "${limit}" ]; do
# remove largest artifact
largest=$(find "${artifacts}" -type f -printf '%s %h/%f\n' | sort -r -n | head -1 | awk '{print($2)}')
if [ -z "${largest}" ]; then
break
fi
rm -f "${largest}"
artifacts_too_large > "${largest}.removed.txt"
done
fi
if [ -d "${adt_out_dir}/tests-tree" ]; then
log_error "W: removing leftover ${adt_out_dir}/tests-tree"
rm -rf "${adt_out_dir}/tests-tree"
fi
if [ -f "${adt_out_dir}/duration".in ]; then
cp "${adt_out_dir}/duration".in "${adt_out_dir}/duration"
else
echo $(($finish_timestamp - $start_timestamp)) > "$adt_out_dir/duration"
fi
if [ -n "$trigger" ]; then
echo "$trigger" > "$adt_out_dir/trigger"
fi
if [ -n "$print_output" ]; then
echo "$adt_out_dir"
fi
}
# defaults
index=''
print_output=''
trigger=''
options=':'
has_extra_apt_sources=false
for opt in $@; do
case "$opt" in
-e|--extra-apt-source)
has_extra_apt_sources=true
;;
esac
done
added_releases=
keydir=$(mktemp -d)
trap cleanup INT TERM EXIT
cleanup() {
rm -rf "${keydir}"
}
key=0
while true; do
opt="$1"
shift
case "$opt" in
-o|--print-output)
print_output=true
;;
-t|--trigger)
trigger="$1"
shift
;;
-p|--pin-packages)
pin="$1"
shift
release=$(echo "$pin" | cut -d = -f 1)
if [ "$has_extra_apt_sources" = false ]; then
release_added=no
for entry in $added_releases; do
if [ "${entry}" = "${release}" ]; then
release_added=yes
fi
done
if [ "${release_added}" = no ]; then
options="$options|--add-apt-release=$release"
added_releases="${added_releases} ${release}"
fi
fi
options="$options|--pin-packages=$pin"
;;
-i|--run-id)
run_id="$1"
if echo "$run_id" | grep -q -e '^[0-9]\{8\}_[0-9]\{6\}$' -e '^[0-9]*$' ; then
: ok
else
echo "E: invalid run-id: $run_id (format needs to be YYYYMMDD_HHMMSS)"
exit 1
fi
shift
;;
-e|--extra-apt-source)
extra_apt_source=`echo -n "$1" | base64 -d`
options="$options|--add-apt-source=$extra_apt_source"
shift
;;
-k|--signing-key)
key=$((key+1))
key_file="${keydir}/${key}.asc"
echo -n "$1" | base64 -d > $key_file
options="$options|--copy=${key_file}:/etc/apt/trusted.gpg.d/${key}.asc"
shift
;;
--)
break
;;
esac
done
if [ $# -eq 1 ]; then
pkg="$1"
process_package
else
usage
exit 1
fi
|