2016-12-03 02:07:08 +03:00
#!/bin/bash
2016-12-09 01:31:20 +03:00
set -euo pipefail
2016-12-03 02:07:08 +03:00
dn=$(cd $(dirname $0) && pwd)
2016-12-22 20:39:28 +03:00
export topsrcdir=$(cd $dn/.. && pwd)
2018-01-08 22:54:10 +03:00
. ${dn}/common/libtest-core.sh
2018-09-10 02:45:02 +03:00
. ${dn}/common/libtestrepos.sh
2016-12-22 20:39:28 +03:00
2017-01-06 17:52:57 +03:00
# avoid refetching yum metadata everytime
export RPMOSTREE_USE_CACHED_METADATA=1
2018-07-31 17:57:31 +03:00
export LOGDIR=${LOGDIR:-$(pwd)/test-compose-logs}
2018-01-08 22:54:10 +03:00
mkdir -p ${LOGDIR}
2016-12-09 01:31:20 +03:00
colour_print() {
colour=$1; shift
[ ! -t 1 ] || echo -en "\e[${colour}m"
echo -n "$@"
[ ! -t 1 ] || echo -en "\e[0m"
echo
}
pass_print() {
colour_print 32 "$@" # green
}
fail_print() {
colour_print 31 "$@" # red
}
skip_print() {
colour_print 34 "$@" # blue
}
2016-12-03 02:07:08 +03:00
uid=$(id -u)
test_compose_datadir=/var/tmp/rpmostree-compose-cache-${uid}
export test_compose_datadir
mkdir -p ${test_compose_datadir}
datadir_owner=$(stat -c '%u' ${test_compose_datadir})
test ${uid} = ${datadir_owner}
2017-11-30 22:32:49 +03:00
# Create a consistent cache of the RPMs
2018-07-19 20:45:12 +03:00
echo "Preparing compose tests... $(date)"
2017-11-30 22:32:49 +03:00
tmp_repo=${test_compose_datadir}/tmp-repo
if test -z "${RPMOSTREE_COMPOSE_CACHEONLY:-}"; then
setup_rpmmd_repos ${dn}/composedata
ostree --repo=${tmp_repo} init --mode=bare-user
2019-03-23 21:41:27 +03:00
# Ensure all subsequent tests have the RPMs
mkdir -p ${test_compose_datadir}/{fedora-local,cache}
rpm-ostree compose --repo=${tmp_repo} tree --download-only-rpms --cachedir=${test_compose_datadir}/cache ${dn}/composedata/fedora-base.json
find ${test_compose_datadir}/cache/ -name '*.rpm' | while read f; do
mv $f ${test_compose_datadir}/fedora-local
done
(cd ${test_compose_datadir}/fedora-local && createrepo_c .)
2017-08-30 16:32:58 +03:00
fi
2018-07-19 20:45:12 +03:00
echo "Done preparing compose tests! $(date)"
2017-11-30 22:32:49 +03:00
rm ${tmp_repo} -rf
2016-12-09 01:31:20 +03:00
total=0
pass=0
fail=0
skip=0
2018-01-08 22:54:10 +03:00
all_tests="$(cd ${dn}/compose-tests && ls test-*.sh | sort)"
2018-08-09 19:14:01 +03:00
if [ "${RPMOSTREE_COMPOSE_TEST_FILTER:-}" == odd ]; then
# https://superuser.com/a/101760/237392
all_tests="$(sed -n 'p;n' <<< ${all_tests})"
elif [ "${RPMOSTREE_COMPOSE_TEST_FILTER:-}" == even ]; then
all_tests="$(sed -n 'n;p' <<< ${all_tests})"
fi
2018-01-08 22:54:10 +03:00
tests=""
if [ -n "${TESTS+ }" ]; then
for tf in ${all_tests}; do
2016-12-09 01:31:20 +03:00
tfbn=$(basename "$tf" .sh)
tfbn=" ${tfbn#test-} "
if [[ " $TESTS " != *$tfbn* ]]; then
2018-01-08 22:54:10 +03:00
echo "Skipping: ${tf}"
2016-12-09 01:31:20 +03:00
continue
fi
2018-01-08 22:54:10 +03:00
tests="${tests} ${tf}"
done
else
tests="${all_tests}"
fi
2016-12-09 01:31:20 +03:00
2018-01-08 22:54:10 +03:00
if test -z "${tests}"; then
fatal "error: No tests match ${TESTS}"
fi
2016-12-03 02:07:08 +03:00
2018-01-08 22:54:10 +03:00
echo "Compose tests starting: $(date)"
echo "Executing: ${tests}"
echo "Writing logs to ${LOGDIR}"
(for tf in ${tests}; do echo $tf; done) | \
2018-07-31 17:57:31 +03:00
parallel -v -j +1 --progress --halt soon,fail=1 \
--results ${LOGDIR}/parallel --quote /bin/sh -c "${dn}/compose-tests/run-test.sh {}"
2018-01-08 22:54:10 +03:00
echo "$(date): All tests passed"