diff options
Diffstat (limited to 'test/integration/framework')
-rw-r--r-- | test/integration/framework | 154 |
1 files changed, 97 insertions, 57 deletions
diff --git a/test/integration/framework b/test/integration/framework index d9bacef83..8e401cb5f 100644 --- a/test/integration/framework +++ b/test/integration/framework @@ -101,7 +101,11 @@ runapt() { msgdebug "Executing: ${CCMD}$*${CDEBUG} " local CMD="$1" shift - MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG="$(getaptconfig)" LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$CMD "$@" + case $CMD in + sh|aptitude|*/*) ;; + *) CMD="${BUILDDIRECTORY}/$CMD";; + esac + MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG="$(getaptconfig)" LD_LIBRARY_PATH=${BUILDDIRECTORY} $CMD "$@" } aptconfig() { runapt apt-config "$@"; } aptcache() { runapt apt-cache "$@"; } @@ -111,24 +115,19 @@ aptftparchive() { runapt apt-ftparchive "$@"; } aptkey() { runapt apt-key "$@"; } aptmark() { runapt apt-mark "$@"; } apt() { runapt apt "$@"; } -apthelper() { - APT_CONFIG="$(getaptconfig)" LD_LIBRARY_PATH=${APTHELPERBINDIR} ${APTHELPERBINDIR}/apt-helper "$@"; -} -aptwebserver() { - LD_LIBRARY_PATH=${APTWEBSERVERBINDIR} ${APTWEBSERVERBINDIR}/aptwebserver "$@"; -} +apthelper() { runapt "${APTHELPERBINDIR}/apt-helper" "$@"; } +aptwebserver() { runapt "${APTWEBSERVERBINDIR}/aptwebserver" "$@"; } +aptitude() { runapt aptitude "$@"; } + dpkg() { command dpkg --root=${TMPWORKINGDIRECTORY}/rootdir --force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log "$@" } -aptitude() { - APT_CONFIG="$(getaptconfig)" LD_LIBRARY_PATH=${BUILDDIRECTORY} command aptitude "$@" +dpkgcheckbuilddeps() { + command dpkg-checkbuilddeps --admindir=${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg "$@" } gdb() { echo "gdb: run »$*«" - APT_CONFIG="$(getaptconfig)" LD_LIBRARY_PATH=${BUILDDIRECTORY} command gdb ${BUILDDIRECTORY}/$1 --args "$@" -} -http() { - LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/methods/http + APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${LIBRARYPATH} command gdb ${BUILDDIRECTORY}/$1 --args "$@" } gpg() { # see apt-key for the whole trickery. Setup is done in setupenvironment @@ -173,6 +172,7 @@ setupenvironment() { # allow overriding the default BUILDDIR location BUILDDIRECTORY=${APT_INTEGRATION_TESTS_BUILD_DIR:-"${TESTDIRECTORY}/../../build/bin"} + LIBRARYPATH=${APT_INTEGRATION_TESTS_LIBRARY_PATH:-"${BUILDDIRECTORY}"} METHODSDIR=${APT_INTEGRATION_TESTS_METHODS_DIR:-"${BUILDDIRECTORY}/methods"} APTHELPERBINDIR=${APT_INTEGRATION_TESTS_LIBEXEC_DIR:-"${BUILDDIRECTORY}"} APTWEBSERVERBINDIR=${APT_INTEGRATION_TESTS_WEBSERVER_BIN_DIR:-"${BUILDDIRECTORY}"} @@ -184,11 +184,12 @@ setupenvironment() { mkdir rootdir aptarchive keys cd rootdir mkdir -p etc/apt/apt.conf.d etc/apt/sources.list.d etc/apt/trusted.gpg.d etc/apt/preferences.d - mkdir -p var/cache var/lib var/log tmp + mkdir -p var/cache var/lib/apt var/log tmp mkdir -p var/lib/dpkg/info var/lib/dpkg/updates var/lib/dpkg/triggers touch var/lib/dpkg/available mkdir -p usr/lib/apt ln -s ${METHODSDIR} usr/lib/apt/methods + ln -s ${BUILDDIRECTORY}/../../debian/apt.conf.autoremove etc/apt/apt.conf.d/01autoremove cd .. local PACKAGESFILE=$(echo "$(basename $0)" | sed -e 's/^test-/Packages-/' -e 's/^skip-/Packages-/') if [ -f "${TESTDIRECTORY}/${PACKAGESFILE}" ]; then @@ -217,8 +218,6 @@ setupenvironment() { echo 'quiet::NoUpdate "true";' >> aptconfig.conf echo "Acquire::https::CaInfo \"${TESTDIR}/apt.pem\";" > rootdir/etc/apt/apt.conf.d/99https echo "Apt::Cmd::Disable-Script-Warning \"1\";" > rootdir/etc/apt/apt.conf.d/apt-binary - export LC_ALL=C.UTF-8 - export PATH="${PATH}:/usr/local/sbin:/usr/sbin:/sbin" configcompression '.' 'gz' #'bz2' 'lzma' 'xz' # gpg needs a trustdb to function, but it can't be invalid (not even empty) @@ -234,6 +233,12 @@ setupenvironment() { # newer gpg versions are fine without it, but play it safe for now gpg --quiet --check-trustdb --secret-keyring $SECRETKEYRING --keyring $SECRETKEYRING >/dev/null 2>&1 + # cleanup the environment a bit + export PATH="${PATH}:/usr/local/sbin:/usr/sbin:/sbin" + export LC_ALL=C.UTF-8 + unset LANGUAGE APT_CONFIG + unset GREP_OPTIONS DEB_BUILD_PROFILES + msgdone "info" } @@ -254,6 +259,10 @@ getarchitectures() { echo "$(aptconfig dump | grep APT::Architecture | cut -d'"' -f 2 | sed '/^$/ d' | sort | uniq | tr '\n' ' ')" } +getarchitecturesfromcommalist() { + echo "$1" | sed -e 's#,#\n#g' | sed -e "s/^native\$/$(getarchitecture 'native')/" +} + configarchitecture() { { echo "APT::Architecture \"$(getarchitecture $1)\";" @@ -427,7 +436,7 @@ Package: $NAME" >> ${BUILDDIR}/debian/control # fi done - for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do + for arch in $(getarchitecturesfromcommalist "$ARCH"); do rm -rf ${BUILDDIR}/debian/tmp mkdir -p ${BUILDDIR}/debian/tmp/DEBIAN ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME} ${BUILDDIR}/debian/tmp/usr/bin cp ${BUILDDIR}/debian/copyright ${BUILDDIR}/debian/changelog ${BUILDDIR}/FEATURES ${BUILDDIR}/debian/tmp/usr/share/doc/${NAME} @@ -582,7 +591,7 @@ insertpackage() { something went horribly wrong! They are autogenerated und used only by testcases and surf no other propose…"}" local ARCHS="" - for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do + for arch in $(getarchitecturesfromcommalist "$ARCH"); do if [ "$arch" = 'all' -o "$arch" = 'none' ]; then ARCHS="$(getarchitectures)" else @@ -644,7 +653,7 @@ insertinstalledpackage() { local FILE='rootdir/var/lib/dpkg/status' local INFO='rootdir/var/lib/dpkg/info' - for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do + for arch in $(getarchitecturesfromcommalist "$ARCH"); do echo "Package: $NAME Status: $STATUS Priority: $PRIORITY @@ -850,18 +859,16 @@ signreleasefiles() { webserverconfig() { msgtest "Set webserver config option '${1}' to" "$2" - downloadfile "http://localhost:8080/_config/set/${1}/${2}" '/dev/null' >/dev/null - local DOWNLOG='download-testfile.log' - rm -f "$DOWNLOG" - local STATUS="${TMPWORKINGDIRECTORY}/rootdir/tmp/webserverconfig.status" - downloadfile "http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" - if [ "$(cat "$STATUS")" = '200' ]; then + local DOWNLOG='rootdir/tmp/download-testfile.log' + local STATUS='rootdir/tmp/webserverconfig.status' + rm -f "$STATUS" "$DOWNLOG" + if downloadfile "http://localhost:8080/_config/set/${1}/${2}" "$STATUS" > "$DOWNLOG"; then msgpass else - cat >&2 "$DOWNLOG" - msgfail "Statuscode was $(cat "$STATUS")" + cat "$DOWNLOG" "$STATUS" + msgfail fi - rm "$STATUS" + testwebserverlaststatuscode '200' } rewritesourceslist() { @@ -919,23 +926,29 @@ connect = 8080 changetocdrom() { mkdir -p rootdir/media/cdrom/.disk local CD="$(readlink -f rootdir/media/cdrom)" - echo "acquire::cdrom::mount \"${CD}\";" > rootdir/etc/apt/apt.conf.d/00cdrom - echo 'acquire::cdrom::autodetect 0;' >> rootdir/etc/apt/apt.conf.d/00cdrom + echo "acquire::cdrom::mount \"${CD}\"; +acquire::cdrom::${CD}/::mount \"mv ${CD}-unmounted ${CD}\"; +acquire::cdrom::${CD}/::umount \"mv ${CD} ${CD}-unmounted\"; +acquire::cdrom::autodetect 0;" > rootdir/etc/apt/apt.conf.d/00cdrom echo -n "$1" > ${CD}/.disk/info if [ ! -d aptarchive/dists ]; then msgdie 'Flat file archive cdroms can not be created currently' return 1 fi - mv aptarchive/dists $CD + mv aptarchive/dists "$CD" ln -s "$(readlink -f ./incoming)" $CD/pool find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list' -delete + # start with an unmounted disk + mv "${CD}" "${CD}-unmounted" + # we don't want the disk to be modifiable + addtrap 'prefix' "chmod -f -R +w $PWD/rootdir/media/cdrom/dists/ $PWD/rootdir/media/cdrom-unmounted/dists/ || true;" + chmod -R -w rootdir/media/cdrom-unmounted/dists } downloadfile() { - PROTO="$(echo "$1" | cut -d':' -f 1)" - apthelper -o Acquire::https::CaInfo=${TESTDIR}/apt.pem \ - -o Debug::Acquire::${PROTO}=1 \ - download-file "$1" "$2" 2>&1 + local PROTO="$(echo "$1" | cut -d':' -f 1 )" + apthelper -o Debug::Acquire::${PROTO}=1 \ + download-file "$1" "$2" 2>&1 || true # only if the file exists the download was successful if [ -e "$2" ]; then return 0 @@ -947,8 +960,8 @@ downloadfile() { checkdiff() { local DIFFTEXT="$(command diff -u "$@" | sed -e '/^---/ d' -e '/^+++/ d' -e '/^@@/ d')" if [ -n "$DIFFTEXT" ]; then - echo - echo "$DIFFTEXT" + echo >&2 + echo >&2 "$DIFFTEXT" return 1 else return 0 @@ -997,11 +1010,17 @@ testequalor2() { shift 2 msgtest "Test for equality OR of" "$*" $* >$COMPAREAGAINST 2>&1 || true - (checkdiff $COMPAREFILE1 $COMPAREAGAINST 1> /dev/null || - checkdiff $COMPAREFILE2 $COMPAREAGAINST 1> /dev/null) && msgpass || - ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \ - "\n${CINFO}Diff against OR 2${CNORMAL}" "$(checkdiff $COMPAREFILE2 $COMPAREAGAINST)" && - msgfail ) + if checkdiff $COMPAREFILE1 $COMPAREAGAINST >/dev/null 2>&1 || \ + checkdiff $COMPAREFILE2 $COMPAREAGAINST >/dev/null 2>&1 + then + msgpass + else + echo -n "\n${CINFO}Diff against OR 1${CNORMAL}" + checkdiff $COMPAREFILE1 $COMPAREAGAINST || true + echo -n "${CINFO}Diff against OR 2${CNORMAL}" + checkdiff $COMPAREFILE2 $COMPAREAGAINST || true + msgfail + fi } testshowvirtual() { @@ -1027,24 +1046,24 @@ testnopackage() { msgtest "Test for non-existent packages" "apt-cache show $*" local SHOWPKG="$(aptcache show "$@" 2>&1 | grep '^Package: ')" if [ -n "$SHOWPKG" ]; then - echo - echo "$SHOWPKG" + echo >&2 + echo >&2 "$SHOWPKG" msgfail - return 1 + else + msgpass fi - msgpass } testdpkginstalled() { msgtest "Test for correctly installed package(s) with" "dpkg -l $*" local PKGS="$(dpkg -l "$@" 2>/dev/null | grep '^i' | wc -l)" if [ "$PKGS" != $# ]; then - echo $PKGS - dpkg -l "$@" | grep '^[a-z]' + echo >&2 $PKGS + dpkg -l "$@" | grep '^[a-z]' >&2 msgfail - return 1 + else + msgpass fi - msgpass } testdpkgnotinstalled() { @@ -1052,11 +1071,11 @@ testdpkgnotinstalled() { local PKGS="$(dpkg -l "$@" 2> /dev/null | grep '^i' | wc -l)" if [ "$PKGS" != 0 ]; then echo - dpkg -l "$@" | grep '^[a-z]' + dpkg -l "$@" | grep '^[a-z]' >&2 msgfail - return 1 + else + msgpass fi - msgpass } testmarkedauto() { @@ -1081,8 +1100,8 @@ testsuccess() { if $@ >${OUTPUT} 2>&1; then msgpass else - echo - cat $OUTPUT + echo >&2 + cat >&2 $OUTPUT msgfail fi } @@ -1095,14 +1114,35 @@ testfailure() { fi local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" if $@ >${OUTPUT} 2>&1; then - echo - cat $OUTPUT + echo >&2 + cat >&2 $OUTPUT msgfail else msgpass fi } +testwebserverlaststatuscode() { + local DOWNLOG='rootdir/tmp/webserverstatus-testfile.log' + local STATUS='rootdir/tmp/webserverstatus-statusfile.log' + rm -f "$DOWNLOG" "$STATUS" + msgtest 'Test last status code from the webserver was' "$1" + downloadfile "http://localhost:8080/_config/find/aptwebserver::last-status-code" "$STATUS" > "$DOWNLOG" + if [ "$(cat "$STATUS")" = "$1" ]; then + msgpass + else + echo >&2 + if [ -n "$2" ]; then + shift + echo >&2 '#### Additionally provided output files contain:' + cat >&2 "$@" + fi + echo >&2 '#### Download log of the status code:' + cat >&2 "$DOWNLOG" + msgfail "Status was $(cat "$STATUS")" + fi +} + pause() { echo "STOPPED execution. Press enter to continue" local IGNORE |