]> git.saurik.com Git - apt.git/blobdiff - test/integration/framework
dereference redirect in Vcs-Browser URI to cgit
[apt.git] / test / integration / framework
index 908b56c030296d25d10fed0370ca344db93f689b..3bf6012bad70f211548b642d2e1e798eb0e963ce 100644 (file)
@@ -64,19 +64,26 @@ msgninfo() { msgprintf "${CINFO}I: %s" '%s' "${CNORMAL}" "$@"; }
 msgndebug() { msgprintf "${CDEBUG}D: %s" '%s' "${CNORMAL}" "$@"; }
 msgtest() { msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@"; }
 msgpass() { printf "${CPASS}PASS${CNORMAL}\n"; }
-msgskip() {
+msgreportheader() {
        if [ -n "$MSGTEST_MSG" ]; then
+               test "$1" != 'msgfailoutput' || echo
+               if [ -n "$MSGTEST_MSGMSG" ]; then
+                       echo "$MSGTEST_MSGMSG"
+               fi
+               if [ -n "$MSGTEST_GRP" ] && [ "$MSGTEST_GRP" != 'NEXT' ] && [ "$MSGTEST_GRP" != "$MSGTEST_MSG" ]; then
+                       echo "${CFAIL}Part of the test group: $MSGTEST_GRP"
+               fi
                echo -n "$MSGTEST_MSG"
                unset MSGTEST_MSG
        fi
+}
+msgskip() {
+       msgreportheader 'msgskip'
        if [ $# -gt 0 ]; then printf "${CWARNING}SKIP: $*${CNORMAL}\n" >&2;
        else printf "${CWARNING}SKIP${CNORMAL}\n" >&2; fi
 }
 msgfail() {
-       if [ -n "$MSGTEST_MSG" ]; then
-               echo -n "$MSGTEST_MSG"
-               unset MSGTEST_MSG
-       fi
+       msgreportheader 'msgfail'
        if [ $# -gt 0 ] && [ -n "$1" ]; then printf "${CFAIL}FAIL: $*${CNORMAL}\n" >&2;
        else printf "${CFAIL}FAIL${CNORMAL}\n" >&2; fi
        if [ -n "$APT_DEBUG_TESTS" ]; then
@@ -84,6 +91,20 @@ msgfail() {
        fi
        EXIT_CODE=$((EXIT_CODE+1));
 }
+MSGGROUP_LEVEL=0
+msggroup() {
+       if [ -n "$1" ]; then
+               if [ $MSGGROUP_LEVEL = 0 ]; then
+                       MSGTEST_GRP='NEXT'
+               fi
+               MSGGROUP_LEVEL=$((MSGGROUP_LEVEL+1));
+       else
+               MSGGROUP_LEVEL=$((MSGGROUP_LEVEL-1));
+               if [ $MSGGROUP_LEVEL = 0 ]; then
+                       unset MSGTEST_GRP
+               fi
+       fi
+}
 
 # enable / disable Debugging
 if [ $MSGLEVEL -le 0 ]; then
@@ -94,9 +115,16 @@ if [ $MSGLEVEL -le 1 ]; then
        msgnwarn() { true; }
 fi
 if [ $MSGLEVEL -le 2 ]; then
-       msgmsg() { true; }
+       msgmsg() {
+               MSGTEST_MSGMSG="$(msgprintf "${CMSG}%s" '%s' "${CNORMAL}" "$@")"
+       }
        msgnmsg() { true; }
-       msgtest() { MSGTEST_MSG="$(msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@")"; }
+       msgtest() {
+               MSGTEST_MSG="$(msgprintf "${CINFO}%s" "${CCMD}%s${CINFO}" "…${CNORMAL} " "$@")"
+               if [ "$MSGTEST_GRP" = 'NEXT' ]; then
+                       MSGTEST_GRP="$MSGTEST_MSG"
+               fi
+       }
        msgpass() { printf " ${CPASS}P${CNORMAL}"; }
 fi
 if [ $MSGLEVEL -le 3 ]; then
@@ -171,10 +199,14 @@ gdb() {
        aptmark) CMD="apt-mark";;
        apthelper) CMD="apt-helper";;
        aptftparchive) CMD="apt-ftparchive";;
+       dpkg) shift; runapt ${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg "$@"; return;;
        *) CMD="$1";;
        esac
        shift
-       runapt command gdb --quiet -ex run "${BUILDDIRECTORY}/$CMD" --args "${BUILDDIRECTORY}/$CMD" "$@"
+       if [ "${CMD##*/}" = "$CMD" ]; then
+               CMD="${BUILDDIRECTORY}/${CMD}"
+       fi
+       runapt command gdb --quiet -ex run "$CMD" --args "$CMD" "$@"
 }
 
 exitwithstatus() {
@@ -294,11 +326,25 @@ if [ -r "${TMPWORKINGDIRECTORY}/noopchroot.so" ]; then
                export LD_PRELOAD="${TMPWORKINGDIRECTORY}/noopchroot.so"
        fi
 fi
-exec fakeroot dpkg --root="${TMPWORKINGDIRECTORY}/rootdir" \\
+exec fakeroot ${DPKG:-dpkg} --root="${TMPWORKINGDIRECTORY}/rootdir" \\
        --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log \\
        --force-not-root --force-bad-path "\$@"
 EOF
-       chmod +x "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg"
+       cat << EOF > "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg"
+#!/bin/sh
+set -e
+if [ -r "${TMPWORKINGDIRECTORY}/noopchroot.so" ]; then
+       if [ -n "\$LD_PRELOAD" ]; then
+               export LD_PRELOAD="${TMPWORKINGDIRECTORY}/noopchroot.so \${LD_PRELOAD}"
+       else
+               export LD_PRELOAD="${TMPWORKINGDIRECTORY}/noopchroot.so"
+       fi
+fi
+exec fakeroot gdb --quiet -ex run "${DPKG:-dpkg}" --args "${DPKG:-dpkg}" --root="${TMPWORKINGDIRECTORY}/rootdir" \\
+       --log=${TMPWORKINGDIRECTORY}/rootdir/var/log/dpkg.log \\
+       --force-not-root --force-bad-path "\$@"
+EOF
+       chmod +x "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg" "${TMPWORKINGDIRECTORY}/rootdir/usr/bin/gdb-dpkg"
        echo "Dir::Bin::dpkg \"${TMPWORKINGDIRECTORY}/rootdir/usr/bin/dpkg\";" > rootdir/etc/apt/apt.conf.d/99dpkg
 
        {
@@ -830,6 +876,9 @@ Architecture: $ARCH" >> $FILE
        echo "Files:
  $(echo -n "$DSCFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) $DSCFILE
  $(echo -n "$TARFILE" | md5sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) $TARFILE
+Checksums-Sha256:
+ $(echo -n "$DSCFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$DSCFILE" | wc -c) $DSCFILE
+ $(echo -n "$TARFILE" | sha256sum | cut -d' ' -f 1) $(echo -n "$TARFILE" | wc -c) $TARFILE
 " >> $FILE
 }
 
@@ -1216,7 +1265,21 @@ checkdiff() {
        fi
 }
 
+testoutputequal() {
+       local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testoutputequal.output"
+       local COMPAREFILE="$1"
+       shift
+       if "$@" 2>&1 | checkdiff $COMPAREFILE - >"$OUTPUT" 2>&1; then
+               msgpass
+       else
+               echo "=== content of file we compared with (${COMPAREFILE}) ===" >>"${OUTPUT}"
+               cat "$COMPAREFILE" >>"${OUTPUT}"
+               msgfailoutput '' "$OUTPUT" "$@"
+       fi
+}
+
 testfileequal() {
+       msggroup 'testfileequal'
        local MSG='Test for correctness of file'
        if [ "$1" = '--nomsg' ]; then
                MSG=''
@@ -1229,32 +1292,28 @@ testfileequal() {
        fi
        local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfileequal.output"
        if [ -z "$*" ]; then
-               if echo -n "" | checkdiff - $FILE >"$OUTPUT" 2>&1; then
-                       msgpass
-               else
-                       msgfailoutput '' "$OUTPUT"
-               fi
+               testoutputequal "$FILE" echo -n ''
        else
-               if echo "$*" | checkdiff - $FILE >"$OUTPUT" 2>&1; then
-                       msgpass
-               else
-                       msgfailoutput '' "$OUTPUT"
-               fi
+               testoutputequal "$FILE" echo "$*"
        fi
+       msggroup
 }
 
 testempty() {
+       msggroup 'testempty'
        msgtest "Test for no output of" "$*"
        local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testempty.comparefile"
-       if "$@" >$COMPAREFILE 2>&1 && test ! -s $COMPAREFILE; then
+       if ("$@" >$COMPAREFILE 2>&1 || true) && test ! -s $COMPAREFILE; then
                msgpass
        else
-               msgfailoutput '' "$COMPAREFILE"
+               msgfailoutput '' "$COMPAREFILE" "$@"
        fi
        aptautotest 'testempty' "$@"
+       msggroup
 }
 
 testequal() {
+       msggroup 'testequal'
        local MSG='Test of equality of'
        if [ "$1" = '--nomsg' ]; then
                MSG=''
@@ -1268,16 +1327,13 @@ testequal() {
        if [ -n "$MSG" ]; then
                msgtest "$MSG" "$*"
        fi
-       local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequal.output"
-       if "$@" 2>&1 | checkdiff $COMPAREFILE - >"$OUTPUT" 2>&1; then
-               msgpass
-       else
-               msgfailoutput '' "$OUTPUT"
-       fi
+       testoutputequal "$COMPAREFILE" "$@"
        aptautotest 'testequal' "$@"
+       msggroup
 }
 
 testequalor2() {
+       msggroup 'testequalor2'
        local COMPAREFILE1="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
        local COMPAREFILE2="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
        local COMPAREAGAINST="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
@@ -1299,9 +1355,11 @@ testequalor2() {
                msgfailoutput '' "$OUTPUT"
        fi
        aptautotest 'testequalor2' "$@"
+       msggroup
 }
 
 testshowvirtual() {
+       msggroup 'testshowvirtual'
        local VIRTUAL="N: Can't select versions from package '$1' as it is purely virtual"
        local PACKAGE="$1"
        shift
@@ -1318,14 +1376,12 @@ N: No packages found"
        local ARCH="$(getarchitecture 'native')"
        echo "$VIRTUAL" | sed -e "s/:$ARCH//" -e 's/:all//' >"$COMPAREFILE"
        local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testshowvirtual.output"
-       if aptcache show -q=0 "$PACKAGE" 2>&1 | checkdiff "$COMPAREFILE" - >"$OUTPUT" 2>&1; then
-               msgpass
-       else
-               msgfailoutput '' "$OUTPUT"
-       fi
+       testoutputequal "$COMPAREFILE" aptcache show -q=0 "$PACKAGE"
+       msggroup
 }
 
 testnopackage() {
+       msggroup 'testnopackage'
        msgtest "Test for non-existent packages" "apt-cache show $*"
        local SHOWPKG="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
        if [ -n "$SHOWPKG" ]; then
@@ -1335,9 +1391,11 @@ testnopackage() {
        else
                msgpass
        fi
+       msggroup
 }
 
 testdpkgstatus() {
+       msggroup 'testdpkgstatus'
        local STATE="$1"
        local NR="$2"
        shift 2
@@ -1351,17 +1409,23 @@ testdpkgstatus() {
        else
                msgpass
        fi
+       msggroup
 }
 
 testdpkginstalled() {
+       msggroup 'testdpkginstalled'
        testdpkgstatus 'ii' "$#" "$@"
+       msggroup
 }
 
 testdpkgnotinstalled() {
+       msggroup 'testdpkgnotinstalled'
        testdpkgstatus 'ii' '0' "$@"
+       msggroup
 }
 
 testmarkedauto() {
+       msggroup 'testmarkedauto'
        local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
        if [ -n "$1" ]; then
                msgtest 'Test for correctly marked as auto-installed' "$*"
@@ -1370,14 +1434,11 @@ testmarkedauto() {
                msgtest 'Test for correctly marked as auto-installed' 'no package'
                echo -n > $COMPAREFILE
        fi
-       local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.output"
-       if aptmark showauto 2>&1 | checkdiff $COMPAREFILE - >"$OUTPUT" 2>&1; then
-               msgpass
-       else
-               msgfailoutput '' "$OUTPUT"
-       fi
+       testoutputequal "$COMPAREFILE" aptmark showauto
+       msggroup
 }
 testmarkedmanual() {
+       msggroup 'testmarkedmanual'
        local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile"
        if [ -n "$1" ]; then
                msgtest 'Test for correctly marked as manually installed' "$*"
@@ -1386,20 +1447,12 @@ testmarkedmanual() {
                msgtest 'Test for correctly marked as manually installed' 'no package'
                echo -n > $COMPAREFILE
        fi
-       local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.output"
-       if aptmark showmanual 2>&1 | checkdiff $COMPAREFILE - >"$OUTPUT" 2>&1; then
-               msgpass
-       else
-               msgfailoutput '' "$OUTPUT"
-       fi
+       testoutputequal "$COMPAREFILE" aptmark showmanual
+       msggroup
 }
 
 msgfailoutput() {
-       if [ -n "$MSGTEST_MSG" ]; then
-               echo
-               echo -n "$MSGTEST_MSG"
-               unset MSGTEST_MSG
-       fi
+       msgreportheader 'msgfailoutput'
        local MSG="$1"
        local OUTPUT="$2"
        shift 2
@@ -1417,6 +1470,10 @@ msgfailoutput() {
                        if expr match "$1" "$FILEFLAGS" >/dev/null; then
                                echo "#### stat(2) of file: $2 ####"
                                stat "$2" || true
+                               if test -e "$2"; then
+                                       echo "#### Complete file: $2 ####"
+                                       cat >&2 "$2" || true
+                               fi
                        fi
                }
                msgfailoutputstatfile "$2" "$3"
@@ -1431,6 +1488,7 @@ msgfailoutput() {
 }
 
 testsuccess() {
+       msggroup 'testsuccess'
        if [ "$1" = '--nomsg' ]; then
                shift
        else
@@ -1463,8 +1521,10 @@ testsuccess() {
                msgfailoutput "exitcode $EXITCODE" "$OUTPUT" "$@"
        fi
        aptautotest 'testsuccess' "$@"
+       msggroup
 }
 testwarning() {
+       msggroup 'testwarning'
        if [ "$1" = '--nomsg' ]; then
                shift
        else
@@ -1490,8 +1550,10 @@ testwarning() {
                msgfailoutput "exitcode $EXITCODE" "$OUTPUT" "$@"
        fi
        aptautotest 'testwarning' "$@"
+       msggroup
 }
 testfailure() {
+       msggroup 'testfailure'
        if [ "$1" = '--nomsg' ]; then
                shift
        else
@@ -1527,45 +1589,48 @@ testfailure() {
                fi
        fi
        aptautotest 'testfailure' "$@"
+       msggroup
 }
 
 testsuccessequal() {
+       msggroup 'testsuccessequal'
        local CMP="$1"
        shift
        testsuccess "$@"
        testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/testsuccess.output" "$CMP"
+       msggroup
 }
 testwarningequal() {
+       msggroup 'testwarningequal'
        local CMP="$1"
        shift
        testwarning "$@"
        testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/testwarning.output" "$CMP"
+       msggroup
 }
 testfailureequal() {
+       msggroup 'testfailureequal'
        local CMP="$1"
        shift
        testfailure "$@"
        testfileequal "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" "$CMP"
+       msggroup
 }
 
 testfailuremsg() {
+       msggroup 'testfailuremsg'
        local CMP="$1"
        shift
        testfailure "$@"
        msgtest 'Check that the output of the previous failed command has expected' 'failures and warnings'
        local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.comparefile"
        grep '^\(W\|E\):' "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" > "$COMPAREFILE" 2>&1 || true
-       local OUTPUT="${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailuremsg.output"
-       if echo "$CMP" | checkdiff - "${COMPAREFILE}" >"$OUTPUT" 2>&1; then
-               msgpass
-       else
-               echo '### Complete output ###' >"$OUTPUT"
-               cat "${TMPWORKINGDIRECTORY}/rootdir/tmp/testfailure.output" >"$OUTPUT"
-               msgfailoutput '' "$OUTPUT"
-       fi
+       testoutputequal "$COMPAREFILE" echo "$CMP"
+       msggroup
 }
 
 testfilestats() {
+       msggroup 'testfilestats'
        msgtest "Test that file $1 has $2 $3" "$4"
        if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
                msgpass
@@ -1578,12 +1643,16 @@ testfilestats() {
                } >"$OUTPUT" 2>&1
                msgfailoutput '' "$OUTPUT"
        fi
+       msggroup
 }
 testaccessrights() {
+       msggroup 'testaccessrights'
        testfilestats "$1" '%a' '=' "$2"
+       msggroup
 }
 
 testwebserverlaststatuscode() {
+       msggroup 'testwebserverlaststatuscode'
        local DOWNLOG='rootdir/tmp/webserverstatus-testfile.log'
        local STATUS='downloaded/webserverstatus-statusfile.log'
        rm -f "$DOWNLOG" "$STATUS"
@@ -1603,6 +1672,7 @@ testwebserverlaststatuscode() {
                } >"$OUTPUT" 2>&1
                msgfailoutput "Status was $(cat "$STATUS")" "$OUTPUT"
        fi
+       msggroup
 }
 
 pause() {