]> git.saurik.com Git - apt.git/blobdiff - test/integration/framework
Merge remote-tracking branch 'upstream/debian/sid' into debian/sid
[apt.git] / test / integration / framework
index d661717837c4334136ca34ae32ad2ce85ddece84..1c6f041b0b3a8544648064721566c12bfbdc6f4d 100644 (file)
@@ -90,18 +90,22 @@ msgdone() {
                echo "${CDONE}DONE${CNORMAL}";
        fi
 }
-
+getaptconfig() {
+       if [ -f ./aptconfig.conf ]; then
+            echo "./aptconfig.conf"
+       elif [ -f ../aptconfig.conf ]; then
+            echo "../aptconfig.conf"
+        fi
+}
 runapt() {
        msgdebug "Executing: ${CCMD}$*${CDEBUG} "
        local CMD="$1"
        shift
-       if [ -f ./aptconfig.conf ]; then
-               MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$CMD "$@"
-       elif [ -f ../aptconfig.conf ]; then
-               MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$CMD "$@"
-       else
-               MALLOC_PERTURB_=21 MALLOC_CHECK_=2 LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$CMD "$@"
-       fi
+       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,33 +115,20 @@ aptftparchive() { runapt apt-ftparchive "$@"; }
 aptkey() { runapt apt-key "$@"; }
 aptmark() { runapt apt-mark "$@"; }
 apt() { runapt apt "$@"; }
-apthelper() { 
-  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 "$@"; }
+aptextracttemplates() { runapt apt-extracttemplates "$@"; }
+
 dpkg() {
        command dpkg --root=${TMPWORKINGDIRECTORY}/rootdir --force-not-root --force-bad-path --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log "$@"
 }
 dpkgcheckbuilddeps() {
        command dpkg-checkbuilddeps --admindir=${TMPWORKINGDIRECTORY}/rootdir/var/lib/dpkg "$@"
 }
-aptitude() {
-       if [ -f ./aptconfig.conf ]; then
-               APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY}  command aptitude "$@"
-       elif [ -f ../aptconfig.conf ]; then
-               APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} command aptitude "$@"
-       else
-               LD_LIBRARY_PATH=${BUILDDIRECTORY}  command aptitude "$@"
-       fi
-}
 gdb() {
        echo "gdb: run »$*«"
-       APT_CONFIG=aptconfig.conf 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
@@ -182,6 +173,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}"}
@@ -193,11 +185,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
@@ -244,7 +237,7 @@ setupenvironment() {
        # cleanup the environment a bit
        export PATH="${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
        export LC_ALL=C.UTF-8
-       unset LANGUAGE
+       unset LANGUAGE APT_CONFIG
        unset GREP_OPTIONS DEB_BUILD_PROFILES
 
        msgdone "info"
@@ -267,6 +260,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)\";"
@@ -440,7 +437,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}
@@ -595,7 +592,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
@@ -657,7 +654,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
@@ -863,18 +860,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() {
@@ -932,23 +927,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
@@ -960,8 +961,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
@@ -1010,7 +1011,9 @@ testequalor2() {
        shift 2
        msgtest "Test for equality OR of" "$*"
        $* >$COMPAREAGAINST 2>&1 || true
-       if checkdiff $COMPAREFILE1 $COMPAREAGAINST 1> /dev/null || checkdiff $COMPAREFILE2 $COMPAREAGAINST 1> /dev/null; then
+       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}"
@@ -1044,24 +1047,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() {
@@ -1069,11 +1072,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() {
@@ -1098,8 +1101,8 @@ testsuccess() {
        if $@ >${OUTPUT} 2>&1; then
                msgpass
        else
-               echo
-               cat $OUTPUT
+               echo >&2
+               cat >&2 $OUTPUT
                msgfail
        fi
 }
@@ -1112,14 +1115,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