]> git.saurik.com Git - apt.git/blobdiff - test/integration/framework
select kernels to protect from autoremove based on Debian version
[apt.git] / test / integration / framework
index 6cba26c8dcd10685920e6bfb4d481114661b0d22..3bf6012bad70f211548b642d2e1e798eb0e963ce 100644 (file)
@@ -64,31 +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 "Part of the test group: $MSGTEST_GRP"
+                       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
-               if [ -n "$MSGTEST_MSGMSG" ]; then
-                       echo "$MSGTEST_MSGMSG"
-               fi
-               if [ -n "$MSGTEST_GRP" ] && [ "$MSGTEST_GRP" != 'NEXT' ] && [ "$MSGTEST_GRP" != "$MSGTEST_MSG" ]; then
-                       echo "Part of the test group: $MSGTEST_GRP"
-               fi
-               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
@@ -204,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() {
@@ -327,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
 
        {
@@ -1266,7 +1279,7 @@ testoutputequal() {
 }
 
 testfileequal() {
-       msggroup "$0"
+       msggroup 'testfileequal'
        local MSG='Test for correctness of file'
        if [ "$1" = '--nomsg' ]; then
                MSG=''
@@ -1287,10 +1300,10 @@ testfileequal() {
 }
 
 testempty() {
-       msggroup "$0"
+       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" "$@"
@@ -1300,7 +1313,7 @@ testempty() {
 }
 
 testequal() {
-       msggroup "$0"
+       msggroup 'testequal'
        local MSG='Test of equality of'
        if [ "$1" = '--nomsg' ]; then
                MSG=''
@@ -1320,7 +1333,7 @@ testequal() {
 }
 
 testequalor2() {
-       msggroup "$0"
+       msggroup 'testequalor2'
        local COMPAREFILE1="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile1"
        local COMPAREFILE2="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.comparefile2"
        local COMPAREAGAINST="${TMPWORKINGDIRECTORY}/rootdir/tmp/testequalor2.compareagainst"
@@ -1346,7 +1359,7 @@ testequalor2() {
 }
 
 testshowvirtual() {
-       msggroup "$0"
+       msggroup 'testshowvirtual'
        local VIRTUAL="N: Can't select versions from package '$1' as it is purely virtual"
        local PACKAGE="$1"
        shift
@@ -1368,7 +1381,7 @@ N: No packages found"
 }
 
 testnopackage() {
-       msggroup "$0"
+       msggroup 'testnopackage'
        msgtest "Test for non-existent packages" "apt-cache show $*"
        local SHOWPKG="$(aptcache show "$@" 2>&1 | grep '^Package: ')"
        if [ -n "$SHOWPKG" ]; then
@@ -1382,7 +1395,7 @@ testnopackage() {
 }
 
 testdpkgstatus() {
-       msggroup "$0"
+       msggroup 'testdpkgstatus'
        local STATE="$1"
        local NR="$2"
        shift 2
@@ -1400,19 +1413,19 @@ testdpkgstatus() {
 }
 
 testdpkginstalled() {
-       msggroup "$0"
+       msggroup 'testdpkginstalled'
        testdpkgstatus 'ii' "$#" "$@"
        msggroup
 }
 
 testdpkgnotinstalled() {
-       msggroup "$0"
+       msggroup 'testdpkgnotinstalled'
        testdpkgstatus 'ii' '0' "$@"
        msggroup
 }
 
 testmarkedauto() {
-       msggroup "$0"
+       msggroup 'testmarkedauto'
        local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedauto.comparefile"
        if [ -n "$1" ]; then
                msgtest 'Test for correctly marked as auto-installed' "$*"
@@ -1425,7 +1438,7 @@ testmarkedauto() {
        msggroup
 }
 testmarkedmanual() {
-       msggroup "$0"
+       msggroup 'testmarkedmanual'
        local COMPAREFILE="${TMPWORKINGDIRECTORY}/rootdir/tmp/testmarkedmanual.comparefile"
        if [ -n "$1" ]; then
                msgtest 'Test for correctly marked as manually installed' "$*"
@@ -1439,17 +1452,7 @@ testmarkedmanual() {
 }
 
 msgfailoutput() {
-       if [ -n "$MSGTEST_MSG" ]; then
-               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
+       msgreportheader 'msgfailoutput'
        local MSG="$1"
        local OUTPUT="$2"
        shift 2
@@ -1467,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"
@@ -1481,7 +1488,7 @@ msgfailoutput() {
 }
 
 testsuccess() {
-       msggroup "$0"
+       msggroup 'testsuccess'
        if [ "$1" = '--nomsg' ]; then
                shift
        else
@@ -1517,7 +1524,7 @@ testsuccess() {
        msggroup
 }
 testwarning() {
-       msggroup "$0"
+       msggroup 'testwarning'
        if [ "$1" = '--nomsg' ]; then
                shift
        else
@@ -1546,7 +1553,7 @@ testwarning() {
        msggroup
 }
 testfailure() {
-       msggroup "$0"
+       msggroup 'testfailure'
        if [ "$1" = '--nomsg' ]; then
                shift
        else
@@ -1586,7 +1593,7 @@ testfailure() {
 }
 
 testsuccessequal() {
-       msggroup "$0"
+       msggroup 'testsuccessequal'
        local CMP="$1"
        shift
        testsuccess "$@"
@@ -1594,7 +1601,7 @@ testsuccessequal() {
        msggroup
 }
 testwarningequal() {
-       msggroup "$0"
+       msggroup 'testwarningequal'
        local CMP="$1"
        shift
        testwarning "$@"
@@ -1602,7 +1609,7 @@ testwarningequal() {
        msggroup
 }
 testfailureequal() {
-       msggroup "$0"
+       msggroup 'testfailureequal'
        local CMP="$1"
        shift
        testfailure "$@"
@@ -1611,7 +1618,7 @@ testfailureequal() {
 }
 
 testfailuremsg() {
-       msggroup "$0"
+       msggroup 'testfailuremsg'
        local CMP="$1"
        shift
        testfailure "$@"
@@ -1623,7 +1630,7 @@ testfailuremsg() {
 }
 
 testfilestats() {
-       msggroup "$0"
+       msggroup 'testfilestats'
        msgtest "Test that file $1 has $2 $3" "$4"
        if [ "$4" "$3" "$(stat --format "$2" "$1")" ]; then
                msgpass
@@ -1639,13 +1646,13 @@ testfilestats() {
        msggroup
 }
 testaccessrights() {
-       msggroup "$0"
+       msggroup 'testaccessrights'
        testfilestats "$1" '%a' '=' "$2"
        msggroup
 }
 
 testwebserverlaststatuscode() {
-       msggroup "$0"
+       msggroup 'testwebserverlaststatuscode'
        local DOWNLOG='rootdir/tmp/webserverstatus-testfile.log'
        local STATUS='downloaded/webserverstatus-statusfile.log'
        rm -f "$DOWNLOG" "$STATUS"