]> git.saurik.com Git - apt.git/blobdiff - test/integration/framework
Merge remote-tracking branch 'upstream/debian/sid' into feature/upgrade-with-new
[apt.git] / test / integration / framework
index 31b12e8bfb90985310c65f531765c46763456fc4..4003d932cfffa8b25ff40a547d4fd42500799abf 100644 (file)
@@ -38,7 +38,11 @@ msgtest() {
 }
 msgpass() { echo "${CPASS}PASS${CNORMAL}" >&2; }
 msgskip() { echo "${CWARNING}SKIP${CNORMAL}" >&2; }
-msgfail() { echo "${CFAIL}FAIL${CNORMAL}" >&2; EXIT_CODE=$((EXIT_CODE+1)); }
+msgfail() {
+       if [ $# -gt 0 ]; then echo "${CFAIL}FAIL: $*${CNORMAL}" >&2;
+       else echo "${CFAIL}FAIL${CNORMAL}" >&2; fi
+       EXIT_CODE=$((EXIT_CODE+1));
+}
 
 # enable / disable Debugging
 MSGLEVEL=${MSGLEVEL:-3}
@@ -56,9 +60,9 @@ if [ $MSGLEVEL -le 2 ]; then
        msgpass() { echo -n " ${CPASS}P${CNORMAL}" >&2; }
        msgskip() { echo -n " ${CWARNING}S${CNORMAL}" >&2; }
        if [ -n "$CFAIL" ]; then
-               msgfail() { echo -n " ${CFAIL}FAIL${CNORMAL}" >&2; }
+               msgfail() { echo -n " ${CFAIL}FAIL${CNORMAL}" >&2; EXIT_CODE=$((EXIT_CODE+1)); }
        else
-               msgfail() { echo -n " ###FAILED###" >&2; }
+               msgfail() { echo -n " ###FAILED###" >&2; EXIT_CODE=$((EXIT_CODE+1)); }
        fi
 fi
 if [ $MSGLEVEL -le 3 ]; then
@@ -84,11 +88,11 @@ msgdone() {
 runapt() {
        msgdebug "Executing: ${CCMD}$*${CDEBUG} "
        if [ -f ./aptconfig.conf ]; then
-               APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
-        elif [ -f ../aptconfig.conf ]; then
-                APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
+               MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
+       elif [ -f ../aptconfig.conf ]; then
+               MALLOC_PERTURB_=21 MALLOC_CHECK_=2 APT_CONFIG=../aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
        else
-               LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
+               MALLOC_PERTURB_=21 MALLOC_CHECK_=2 LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/$*
        fi
 }
 aptconfig() { runapt apt-config $*; }
@@ -114,6 +118,9 @@ gdb() {
        echo "gdb: run »$*«"
        APT_CONFIG=aptconfig.conf LD_LIBRARY_PATH=${BUILDDIRECTORY} $(which gdb) ${BUILDDIRECTORY}/$1
 }
+http() {
+       LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/methods/http
+}
 
 exitwithstatus() {
         # error if we about to overflow, but ...
@@ -124,9 +131,23 @@ exitwithstatus() {
         exit $((EXIT_CODE <= 255 ? EXIT_CODE : 255));
 }
 
+shellsetedetector() {
+       local exit_status=$?
+       if [ "$exit_status" != '0' ]; then
+               echo >&2 "${CERROR}E: Looks like the testcases ended prematurely with exitcode: ${exit_status}${CNORMAL}"
+               if [ "$EXIT_CODE" = '0' ]; then
+                       EXIT_CODE="$exit_status"
+               fi
+       fi
+}
+
 addtrap() {
-       CURRENTTRAP="$CURRENTTRAP $1"
-       trap "$CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
+       if [ "$1" = 'prefix' ]; then
+               CURRENTTRAP="$2 $CURRENTTRAP"
+       else
+               CURRENTTRAP="$CURRENTTRAP $1"
+       fi
+       trap "shellsetedetector; $CURRENTTRAP exitwithstatus;" 0 HUP INT QUIT ILL ABRT FPE SEGV PIPE TERM
 }
 
 setupenvironment() {
@@ -135,8 +156,7 @@ setupenvironment() {
        msgninfo "Preparing environment for ${CCMD}$(basename $0)${CINFO} in ${TMPWORKINGDIRECTORY}… "
        BUILDDIRECTORY="${TESTDIRECTORY}/../../build/bin"
        test -x "${BUILDDIRECTORY}/apt-get" || msgdie "You need to build tree first"
-       local OLDWORKINGDIRECTORY=$(pwd)
-       addtrap "cd /; rm -rf $TMPWORKINGDIRECTORY; cd $OLDWORKINGDIRECTORY;"
+       addtrap "cd /; rm -rf $TMPWORKINGDIRECTORY;"
        cd $TMPWORKINGDIRECTORY
        mkdir rootdir aptarchive keys
        cd rootdir
@@ -167,13 +187,14 @@ setupenvironment() {
        echo "DPKG::options:: \"--root=${TMPWORKINGDIRECTORY}/rootdir\";" >> aptconfig.conf
        echo "DPKG::options:: \"--force-not-root\";" >> aptconfig.conf
        echo "DPKG::options:: \"--force-bad-path\";" >> aptconfig.conf
-       if ! $(which dpkg) --assert-multi-arch 2>&1 > /dev/null; then
+       if ! $(which dpkg) --assert-multi-arch >/dev/null 2>&1; then
                echo "DPKG::options:: \"--force-architecture\";" >> aptconfig.conf # Added to test multiarch before dpkg is ready for it…
        fi
        echo "DPKG::options:: \"--log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log\";" >> aptconfig.conf
        echo 'quiet::NoUpdate "true";' >> aptconfig.conf
        export LC_ALL=C
        export PATH="${PATH}:/usr/local/sbin:/usr/sbin:/sbin"
+       configcompression '.' 'gz' #'bz2' 'lzma' 'xz'
        msgdone "info"
 }
 
@@ -215,12 +236,18 @@ configdpkg() {
                        echo -n > rootdir/var/lib/dpkg/status
                fi
        fi
-       if $(which dpkg) --assert-multi-arch 2>&1 > /dev/null; then
+       if $(which dpkg) --assert-multi-arch >/dev/null 2>&1; then
                local ARCHS="$(getarchitectures)"
                if echo "$ARCHS" | grep -E -q '[^ ]+ [^ ]+'; then
                        DPKGARCH="$(dpkg --print-architecture)"
                        for ARCH in ${ARCHS}; do
-                               if [ "${ARCH}" != "${DPKGARCH}" ]; then dpkg --add-architecture ${ARCH}; fi
+                               if [ "${ARCH}" != "${DPKGARCH}" ]; then
+                                       if ! dpkg --add-architecture ${ARCH}; then
+                                               # old-style used e.g. in Ubuntu-P – and as it seems travis
+                                               echo "DPKG::options:: \"--foreign-architecture\";" >> aptconfig.conf
+                                               echo "DPKG::options:: \"${ARCH}\";" >> aptconfig.conf
+                                       fi
+                               fi
                        done
                        if [ "0" = "$(dpkg -l dpkg 2> /dev/null | grep '^i' | wc -l)" ]; then
                                # dpkg doesn't really check the version as long as it is fully installed,
@@ -231,6 +258,20 @@ configdpkg() {
        fi
 }
 
+configcompression() {
+       while [ -n "$1" ]; do
+               case "$1" in
+               '.') echo ".\t.\tcat";;
+               'gz') echo "gzip\tgz\tgzip";;
+               'bz2') echo "bzip2\tbz2\tbzip2";;
+               'lzma') echo "lzma\tlzma\txz --format=lzma";;
+               'xz') echo "xz\txz\txz";;
+               *) echo "$1\t$1\t$1";;
+               esac
+               shift
+       done > ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf
+}
+
 setupsimplenativepackage() {
        local NAME="$1"
        local ARCH="$2"
@@ -401,6 +442,8 @@ buildaptarchive() {
 }
 
 createaptftparchiveconfig() {
+       local COMPRESSORS="$(cut -d'    ' -f 1 ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | tr '\n' ' ')"
+       COMPRESSORS="${COMPRESSORS%* }"
        local ARCHS="$(find pool/ -name '*.deb' | grep -oE '_[a-z0-9-]+\.deb$' | sort | uniq | sed -e '/^_all.deb$/ d' -e 's#^_\([a-z0-9-]*\)\.deb$#\1#' | tr '\n' ' ')"
        if [ -z "$ARCHS" ]; then
                # the pool is empty, so we will operate on faked packages - let us use the configured archs
@@ -418,10 +461,10 @@ createaptftparchiveconfig() {
        echo -n '";
 };
 Default {
-       Packages::Compress ". gzip bzip2 lzma xz";
-       Sources::Compress ". gzip bzip2 lzma xz";
-       Contents::Compress ". gzip bzip2 lzma xz";
-       Translation::Compress ". gzip bzip2 lzma xz";
+       Packages::Compress "'"$COMPRESSORS"'";
+       Sources::Compress "'"$COMPRESSORS"'";
+       Contents::Compress "'"$COMPRESSORS"'";
+       Translation::Compress "'"$COMPRESSORS"'";
        LongDescription "false";
 };
 TreeDefault {
@@ -483,6 +526,7 @@ insertpackage() {
        local VERSION="$4"
        local DEPENDENCIES="$5"
        local PRIORITY="${6:-optional}"
+       local DESCRIPTION="${7}"
        local ARCHS=""
        for arch in $(echo "$ARCH" | sed -e 's#,#\n#g' | sed -e "s#^native\$#$(getarchitecture 'native')#"); do
                if [ "$arch" = 'all' -o "$arch" = 'none' ]; then
@@ -504,11 +548,16 @@ Maintainer: Joe Sixpack <joe@example.org>" >> $FILE
                        echo "Version: $VERSION
 Filename: pool/main/${NAME}/${NAME}_${VERSION}_${arch}.deb" >> $FILE
                        test -z "$DEPENDENCIES" || echo "$DEPENDENCIES" >> $FILE
-                       echo "Description: an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
+                       echo -n 'Description: ' >> $FILE
+                       if [ -z "$DESCRIPTION" ]; then
+                               echo "an autogenerated dummy ${NAME}=${VERSION}/${RELEASE}
  If you find such a package installed on your system,
  YOU did something horribly wrong! They are autogenerated
- und used only by testcases for APT and surf no other propose…
-" >> $FILE
+ und used only by testcases for APT and surf no other propose…" >> $FILE
+                       else
+                               echo "$DESCRIPTION" >> $FILE
+                       fi
+                       echo >> $FILE
                done
        done
 }
@@ -585,13 +634,25 @@ buildaptarchivefromfiles() {
        msginfo "Build APT archive for ${CCMD}$(basename $0)${CINFO} based on prebuild files…"
        find aptarchive -name 'Packages' -o -name 'Sources' | while read line; do
                msgninfo "\t${line} file… "
-               cat ${line} | gzip > ${line}.gz
-               cat ${line} | bzip2 > ${line}.bz2
-               cat ${line} | xz --format=lzma > ${line}.lzma
-               cat ${line} | xz > ${line}.xz
+               compressfile "$line" "$1"
                msgdone "info"
        done
-       generatereleasefiles
+       generatereleasefiles "$@"
+}
+
+compressfile() {
+       cat ${TMPWORKINGDIRECTORY}/rootdir/etc/testcase-compressor.conf | while read compressor extension command; do
+               if [ "$compressor" = '.' ]; then
+                       if [ -n "$2" ]; then
+                               touch -d "$2" "$1"
+                       fi
+                       continue
+               fi
+               cat "$1" | $command > "${1}.${extension}"
+               if [ -n "$2" ]; then
+                       touch -d "$2" "${1}.${extension}"
+               fi
+       done
 }
 
 # can be overridden by testcases for their pleasure
@@ -683,36 +744,76 @@ setupaptarchive() {
                setupflataptarchive
        fi
        signreleasefiles
-       msgninfo "\tSync APT's cache with the archive… "
-       aptget update -qq
-       msgdone "info"
+       if [ "$1" != '--no-update' ]; then
+               msgninfo "\tSync APT's cache with the archive… "
+               aptget update -qq
+               msgdone "info"
+       fi
 }
 
 signreleasefiles() {
        local SIGNER="${1:-Joe Sixpack}"
+       local GPG="gpg --batch --yes --no-default-keyring --trustdb-name rootdir/etc/apt/trustdb.gpg"
        msgninfo "\tSign archive with $SIGNER key… "
-       local SECKEYS=""
+       local REXKEY='keys/rexexpired'
+       local SECEXPIREBAK="${REXKEY}.sec.bak"
+       local PUBEXPIREBAK="${REXKEY}.pub.bak"
+       if [ "${SIGNER}" = 'Rex Expired' ]; then
+               # the key is expired, so gpg doesn't allow to sign with and the --faked-system-time
+               # option doesn't exist anymore (and using faketime would add a new obscure dependency)
+               # therefore we 'temporary' make the key not expired and restore a backup after signing
+               cp ${REXKEY}.sec $SECEXPIREBAK
+               cp ${REXKEY}.pub $PUBEXPIREBAK
+               local SECUNEXPIRED="${REXKEY}.sec.unexpired"
+               local PUBUNEXPIRED="${REXKEY}.pub.unexpired"
+               if [ -f "$SECUNEXPIRED" ] && [ -f "$PUBUNEXPIRED" ]; then
+                       cp $SECUNEXPIRED ${REXKEY}.sec
+                       cp $PUBUNEXPIRED ${REXKEY}.pub
+               else
+                       printf "expire\n1w\nsave\n" | $GPG --keyring ${REXKEY}.pub --secret-keyring ${REXKEY}.sec --command-fd 0 --edit-key "${SIGNER}" >/dev/null 2>&1 || true
+                       cp ${REXKEY}.sec $SECUNEXPIRED
+                       cp ${REXKEY}.pub $PUBUNEXPIRED
+               fi
+       fi
        for KEY in $(find keys/ -name '*.sec'); do
-               SECKEYS="$SECKEYS --secret-keyring $KEY"
+               GPG="$GPG --secret-keyring $KEY"
        done
-       local PUBKEYS=""
        for KEY in $(find keys/ -name '*.pub'); do
-               PUBKEYS="$PUBKEYS --keyring $KEY"
+               GPG="$GPG --keyring $KEY"
        done
        for RELEASE in $(find aptarchive/ -name Release); do
-               gpg --yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" -abs -o ${RELEASE}.gpg ${RELEASE}
-               gpg --yes --no-default-keyring $SECKEYS $PUBKEYS --default-key "$SIGNER" --clearsign -o "$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')" $RELEASE
+               $GPG --default-key "$SIGNER" --armor --detach-sign --sign --output ${RELEASE}.gpg ${RELEASE}
+               local INRELEASE="$(echo "${RELEASE}" | sed 's#/Release$#/InRelease#')"
+               $GPG --default-key "$SIGNER" --clearsign --output $INRELEASE $RELEASE
+               # we might have set a specific date for the Release file, so copy it
+               touch -d "$(stat --format "%y" ${RELEASE})" ${RELEASE}.gpg ${INRELEASE}
        done
+       if [ -f "$SECEXPIREBAK" ] && [ -f "$PUBEXPIREBAK" ]; then
+               mv -f $SECEXPIREBAK ${REXKEY}.sec
+               mv -f $PUBEXPIREBAK ${REXKEY}.pub
+       fi
        msgdone "info"
 }
 
 changetowebserver() {
-       if which weborf > /dev/null; then
-               weborf -xb aptarchive/ 2>&1 > /dev/null &
+       local LOG='/dev/null'
+       if test -x ${BUILDDIRECTORY}/aptwebserver; then
+               cd aptarchive
+               LD_LIBRARY_PATH=${BUILDDIRECTORY} ${BUILDDIRECTORY}/aptwebserver -o aptwebserver::fork=1 "$@" >$LOG 2>&1
+               local PID="$(cat aptwebserver.pid)"
+               if [ -z "$PID" ]; then
+                       msgdie 'Could not fork aptwebserver successfully'
+               fi
+               addtrap "kill $PID;"
+               cd - > /dev/null
+       elif [ $# -gt 0 ]; then
+               msgdie 'Need the aptwebserver when passing arguments for the webserver'
+       elif which weborf > /dev/null; then
+               weborf -xb aptarchive/ >$LOG 2>&1 &
                addtrap "kill $!;"
        elif which gatling > /dev/null; then
                cd aptarchive
-               gatling -p 8080 -F -S 2>&1 > /dev/null &
+               gatling -p 8080 -F -S >$LOG 2>&1 &
                addtrap "kill $!;"
                cd - > /dev/null
        elif which lighttpd > /dev/null; then
@@ -720,11 +821,10 @@ changetowebserver() {
 server.port = 8080
 server.stat-cache-engine = \"disable\"" > lighttpd.conf
                lighttpd -t -f lighttpd.conf >/dev/null || msgdie 'Can not change to webserver: our lighttpd config is invalid'
-               lighttpd -D -f lighttpd.conf 2>/dev/null >/dev/null &
+               lighttpd -D -f lighttpd.conf >$LOG 2>&1 &
                addtrap "kill $!;"
        else
-               msgdie 'You have to install weborf or lighttpd first'
-               return 1
+               msgdie 'You have to build aptwerbserver or install a webserver'
        fi
        local APTARCHIVE="file://$(readlink -f ./aptarchive)"
        for LIST in $(find rootdir/etc/apt/sources.list.d/ -name 'apt-test-*.list'); do
@@ -793,7 +893,7 @@ testequalor2() {
        echo "$2" > $COMPAREFILE2
        shift 2
        msgtest "Test for equality OR of" "$*"
-       $* 2>&1 1> $COMPAREAGAINST
+       $* >$COMPAREAGAINST 2>&1
        (checkdiff $COMPAREFILE1 $COMPAREAGAINST 1> /dev/null ||
                checkdiff $COMPAREFILE2 $COMPAREAGAINST 1> /dev/null) && msgpass ||
                ( echo "\n${CINFO}Diff against OR 1${CNORMAL}" "$(checkdiff $COMPAREFILE1 $COMPAREAGAINST)" \
@@ -870,6 +970,40 @@ testmarkedauto() {
        aptmark showauto 2>&1 | checkdiff $COMPAREFILE - && msgpass || msgfail
 }
 
+testsuccess() {
+       if [ "$1" = '--nomsg' ]; then
+               shift
+       else
+               msgtest 'Test for successful execution of' "$*"
+       fi
+       local OUTPUT=$(mktemp)
+       addtrap "rm $OUTPUT;"
+       if $@ >${OUTPUT} 2>&1; then
+               msgpass
+       else
+               echo
+               cat $OUTPUT
+               msgfail
+       fi
+}
+
+testfailure() {
+       if [ "$1" = '--nomsg' ]; then
+               shift
+       else
+               msgtest 'Test for failure in  execution of' "$*"
+       fi
+       local OUTPUT=$(mktemp)
+       addtrap "rm $OUTPUT;"
+       if $@ >${OUTPUT} 2>&1; then
+               echo
+               cat $OUTPUT
+               msgfail
+       else
+               msgpass
+       fi
+}
+
 pause() {
        echo "STOPPED execution. Press enter to continue"
        local IGNORE