From 9eefc59220356d1c7a8017ad777aa8f167b0af8e Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Mon, 6 Jun 2016 12:08:29 -0400 Subject: [PATCH] tests: no longer use installed tests For now, we don't remove the ability to install tests (e.g. the necessary blurbs in glib-tap.mk are still there), but we take out all our previously installed tests from the list. All the previously installed tests are then converted to work uninstalled. This also allows us to do some simplifications in the test cases. Also do some cleanups in the Makefile to improve legibility. Closes: #304 Approved by: cgwalters --- Makefile-tests.am | 64 +++++++------------ tests/libtest.sh | 19 ++++-- .../{setup-session.sh.in => setup-session.sh} | 6 +- tests/test-basic.sh | 2 +- tests/test-compose.sh | 8 +-- tests/test-ucontainer.sh | 12 +--- 6 files changed, 48 insertions(+), 63 deletions(-) rename tests/{setup-session.sh.in => setup-session.sh} (90%) diff --git a/Makefile-tests.am b/Makefile-tests.am index 809f2ed9..6d310b78 100644 --- a/Makefile-tests.am +++ b/Makefile-tests.am @@ -3,8 +3,8 @@ include $(top_srcdir)/buildutil/glib-tap.mk AM_TESTS_ENVIRONMENT = UNINSTALLEDTESTS=1 builddir=$(abs_builddir) CLEANFILES += \ - tests/setup-session.sh \ - tests/compose/yum/empty tests/compose/yum/repodata/repomd.xml \ + tests/compose/yum/empty \ + tests/compose/yum/repodata/repomd.xml \ tests/compose/test-repo.repo \ tests/compose/yum/repodata/*.bz2 \ tests/compose/yum/repodata/*.gz \ @@ -16,16 +16,19 @@ tests/compose/yum/empty: tests/compose/yum/empty.c tests/compose/yum/repodata/repomd.xml: tests/compose/yum/empty tests/compose/yum/empty.spec (cd tests/compose/yum && \ - rpmbuild --define "_sourcedir $(shell pwd)/tests/compose/yum" --define "_specdir $(shell pwd)/tests/compose/yum" --define "_builddir $(shell pwd)/tests/compose/yum" \ - --define "_srcrpmdir $(shell pwd)/tests/compose/yum" --define "_rpmdir $(shell pwd)/tests/compose/yum" --define "_buildrootdir $(shell pwd)/tests/compose/yum/.build" \ - -ba empty.spec && rm *.src.rpm && createrepo_c --no-database $(shell pwd)/tests/compose/yum/) + rpmbuild \ + --define "_sourcedir $(abs_top_srcdir)/tests/compose/yum" \ + --define "_specdir $(abs_top_srcdir)/tests/compose/yum" \ + --define "_builddir $(abs_top_srcdir)/tests/compose/yum" \ + --define "_srcrpmdir $(abs_top_srcdir)/tests/compose/yum" \ + --define "_rpmdir $(abs_top_srcdir)/tests/compose/yum" \ + --define "_buildrootdir $(abs_top_srcdir)/tests/compose/yum/.build" \ + -ba empty.spec && \ + rm *.src.rpm && \ + createrepo_c --no-database $(abs_top_srcdir)/tests/compose/yum/) tests/compose/test-repo.repo: tests/compose/test-repo.repo.in tests/compose/yum/repodata/repomd.xml - cat $< | sed -e "s|%WHERE%|$(installed_testdir)|" > $@ - -# A version of the repo that points directly to the srcdir (for uninstalled tests) -tests/compose/test-repo-local.repo: tests/compose/test-repo.repo.in tests/compose/yum/repodata/repomd.xml - cat $< | sed -e "s|%WHERE%|$(shell pwd)|" > $@ + cat $< | sed -e "s|%WHERE%|$(abs_top_srcdir)|" > $@ CLEANFILES += tests/compose/test-repo-local.repo \ tests/compose/yum/empty-1.0-1.src.rpm \ @@ -37,48 +40,27 @@ tests_jsonutil_LDADD = $(PKGDEP_RPMOSTREE_LIBS) librpmostreepriv.la tests/test-compose.sh: tests/compose/test-repo.repo -tests/test-ucontainer.sh: tests/compose/test-repo-local.repo +tests/test-ucontainer.sh: tests/compose/test-repo.repo -installed_test_data = tests/libtest.sh \ - tests/compose/test-repo.repo \ - tests/compose/test-repo.json \ - tests/compose/test-repo-add-files.json \ - tests/compose/test-repo.repo.in \ - $(NULL) - -tests/setup-session.sh: tests/setup-session.sh.in - sed \ - -e "s|[@]installed_testdir[@]|$(installed_testdir)|" \ - -e "s|[@]LIBEXECDIR[@]|$(libexecdir)|" \ - < $< > $@.tmp && mv $@.tmp $@ - -test_installed_extra_scripts = \ - tests/setup-session.sh \ - $(NULL) - -nobase_installed_test_DATA += $(shell find tests/compose/yum/ -type f) \ - $(NULL) - -installed_test_scripts = \ - tests/test-compose.sh \ - tests/test-basic.sh \ - $(NULL) - -test_programs = \ +uninstalled_test_programs = \ tests/jsonutil \ $(NULL) -test_scripts = tests/test-ucontainer.sh +uninstalled_test_scripts = \ + tests/test-basic.sh \ + tests/test-compose.sh \ + tests/test-ucontainer.sh \ + $(NULL) + +uninstalled_test_extra_programs = dbus-run-session -installed_test_PROGRAMS += dbus-run-session dbus_run_session_SOURCES = tests/dbus-run-session.c check-local: @echo " *** NOTE ***" @echo " *** NOTE ***" @echo " \"make check\" only runs a subset of rpm-ostree's tests." - @echo " The other tests use https://live.gnome.org/GnomeGoals/InstalledTests" - @echo " To run them, rpm-ostree must be configured with --enable-installed-tests and installed" + @echo " Use \"make vmcheck\" to run remaining tests in a VM." @echo " *** NOTE ***" @echo " *** NOTE ***" diff --git a/tests/libtest.sh b/tests/libtest.sh index 306783c4..276910a4 100644 --- a/tests/libtest.sh +++ b/tests/libtest.sh @@ -25,9 +25,12 @@ if test -n "${LIBTEST_SH:-}"; then fi LIBTEST_SH=1 +self="$(realpath $0)" + if test -z "${SRCDIR:-}"; then SRCDIR=$(dirname $0) fi + _cleanup_tmpdir () { if test -f ${test_tmpdir}/.test; then rm ${test_tmpdir} -rf @@ -37,7 +40,7 @@ _cleanup_tmpdir () { # If we're running as a local test (i.e. through `make check`), then # UNINSTALLEDTESTS=1. Otherwise (i.e. as an installed test), it's undefined, in # which case we're already in a tmpdir. -if test -n "${UNINSTALLEDTESTS:-}"; then +if test -n "${UNINSTALLEDTESTS:-}" && ! test -f $PWD/.test; then test_tmpdir=$(mktemp -d test.XXXXXX) touch ${test_tmpdir}/.test trap _cleanup_tmpdir EXIT @@ -333,8 +336,16 @@ os_repository_new_commit () check_root_test () { if test "$(id -u)" != "0"; then - echo 1>&2 "$0 can be run only as root" - echo "1..0" - exit 77 + echo "1..0 # requires root" + # don't use 77 to signal skip. TAP driver will already know it's a skip + # from the 1..0 test plan (and would set as fail if exit code != 0). + exit 0 + fi +} + +ensure_dbus () +{ + if test -z "$RPMOSTREE_USE_SESSION_BUS"; then + exec "$SRCDIR/setup-session.sh" "$self" fi } diff --git a/tests/setup-session.sh.in b/tests/setup-session.sh similarity index 90% rename from tests/setup-session.sh.in rename to tests/setup-session.sh index 26ad661a..9cf59156 100755 --- a/tests/setup-session.sh.in +++ b/tests/setup-session.sh @@ -23,7 +23,9 @@ set -e . $(dirname $0)/libtest.sh -exec_binary="@LIBEXECDIR@/rpm-ostreed" +# libtest.sh should have added the builddir which contains rpm-ostreed to our +# path +exec_binary="$(which rpm-ostreed)" mkdir -p sysroot mkdir -p session-services @@ -63,4 +65,4 @@ export RPMOSTREE_USE_SESSION_BUS=1 # easily clean up. export OSTREE_SYSROOT_DEBUG=mutable-deployments -exec @installed_testdir@/dbus-run-session --config-file=${test_tmpdir}/session.conf $@ +exec dbus-run-session --config-file=${test_tmpdir}/session.conf $@ diff --git a/tests/test-basic.sh b/tests/test-basic.sh index cb2ed4b4..85f056dd 100755 --- a/tests/test-basic.sh +++ b/tests/test-basic.sh @@ -21,7 +21,7 @@ set -e . $(dirname $0)/libtest.sh -check_root_test +ensure_dbus echo "1..9" diff --git a/tests/test-compose.sh b/tests/test-compose.sh index 0f3082ae..68280c26 100755 --- a/tests/test-compose.sh +++ b/tests/test-compose.sh @@ -40,22 +40,22 @@ ostree init --repo=repo --mode=archive-z2 echo "ok setup" -rpm-ostree --repo=repo compose --dry-run tree $SRCDIR/test-repo.json +rpm-ostree --repo=repo compose --dry-run tree $SRCDIR/compose/test-repo.json ostree --repo=repo refs >refs.txt assert_file_empty refs.txt rm refs.txt echo "ok dry run" -rpm-ostree --repo=repo compose tree $SRCDIR/test-repo.json +rpm-ostree --repo=repo compose tree $SRCDIR/compose/test-repo.json ostree --repo=repo refs >refs.txt assert_file_has_content refs.txt ${testref} echo "ok compose" # bring them in the current context so we can modify exported_file -ln -s $SRCDIR/test-repo-add-files.json . -ln -s $SRCDIR/test-repo.repo . +ln -s $SRCDIR/compose/test-repo-add-files.json . +ln -s $SRCDIR/compose/test-repo.repo . echo hello > exported_file diff --git a/tests/test-ucontainer.sh b/tests/test-ucontainer.sh index 6156c8fd..906e8891 100755 --- a/tests/test-ucontainer.sh +++ b/tests/test-ucontainer.sh @@ -24,18 +24,8 @@ set -euo pipefail echo "1..2" rpm-ostree container init -if test -d ${SRCDIR}/compose; then - composedatadir=${SRCDIR}/compose -else - composedatadir=${SRCDIR} -fi -REPO=test-repo -if test -n "${UNINSTALLEDTESTS:-}"; then - REPO=test-repo-local -fi - -cp ${composedatadir}/$REPO.repo rpmmd.repos.d +cp ${SRCDIR}/compose/test-repo.repo rpmmd.repos.d cat >empty.conf <