X-Git-Url: https://git.saurik.com/apt.git/blobdiff_plain/a0975c8d97f06ac116c5cea9a98993817ced0e86..83b880c6505a20247239d897b7387bba37942993:/test/integration/framework?ds=sidebyside

diff --git a/test/integration/framework b/test/integration/framework
index bf6fa0218..8e401cb5f 100644
--- a/test/integration/framework
+++ b/test/integration/framework
@@ -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,19 @@ 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 "$@"; }
+
 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 +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}"}
@@ -193,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
@@ -244,7 +236,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 +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)\";"
@@ -440,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}
@@ -595,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
@@ -657,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
@@ -863,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() {
@@ -952,10 +946,9 @@ acquire::cdrom::autodetect 0;" > rootdir/etc/apt/apt.conf.d/00cdrom
 }
 
 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
@@ -967,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
@@ -1017,7 +1010,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}"
@@ -1051,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() {
@@ -1076,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() {
@@ -1105,8 +1100,8 @@ testsuccess() {
 	if $@ >${OUTPUT} 2>&1; then
 		msgpass
 	else
-		echo
-		cat $OUTPUT
+		echo >&2
+		cat >&2 $OUTPUT
 		msgfail
 	fi
 }
@@ -1119,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