Package apt-xxtra-heavy-load-checkinstall: Scripts

Pre install

set -o pipefail
pushd /usr/share/apt/tests/

# force the target arch for the tests
#
# By default, the packages would be built for the arch detected by rpm-build
# (rpmbuild --eval %_arch). On installation, they would be compared
# by rpm for compatibility with the arch detected by rpm. Currently,
# the mismatch in the detection between rpm and rpm-build can lead to problems,
# at least, on armh. So, we set the target by force to a value that must work.
system_arch="$(rpm -q rpm --qf='%{ARCH}')"
export APT_TEST_TARGET="$system_arch"

# prepare data for rpm --import
APT_TEST_GPGPUBKEY="$PWD"/example-pubkey.asc
gpg-keygen --passphrase '' \
	--name-real 'Some One' --name-email someone@example.com \
	/dev/null "$APT_TEST_GPGPUBKEY"

export APT_TEST_GPGPUBKEY

# Below we run the same tests many times in order to possibly catch
# bad races. (It's more probable to catch a race under heavy load;
# therefore, of the total specified number of tries, we do
# simultaneously as many as reasonable and possibly even more than TRIES.)

# To not run in parallel, build the pkg with --define 'nprocs_for_check %nil'
# Consider multiplying `nproc` by 2 for heavier load.
NPROCS=`nproc`
if ! [ "$NPROCS" -gt 0 ] 2>/dev/null; then
	NPROCS=1
fi

TRIES=2
if [ $TRIES -lt ${NPROCS:-0} ]; then
	TRIES=$NPROCS
fi

already_once=0
for (( try = 0; try < TRIES; )); do
    # all methods (you might want to update the list if there are new ones)
    for method in file cdrom http https; do
	# do the same method several times in parallel (to provoke races)
	for (( repeat = 0; repeat < 2; ++repeat )); do
	    echo "$((try++)):$method"
	    if (( already_once && (try >= TRIES) )); then
		break 2
	    fi
	done
    done
    already_once=1
done |
    xargs -d'\n' -I'{}' ${NPROCS:+-P$NPROCS --process-slot-var=PARALLEL_SLOT} \
	  -- sh -efuo pipefail \
	  -c 'APT_TEST_METHODS={}
              APT_TEST_METHODS="${APT_TEST_METHODS#*:}"
              export APT_TEST_METHODS
              \
		./run-tests -v '${NPROCS:+'|& sed --unbuffered -e "s/^/[$PARALLEL_SLOT {}] /"'}