Skip to content

Commit

Permalink
Eliminate the need for explicit RPMTEST_INIT
Browse files Browse the repository at this point in the history
Add a new RPMTEST_SETUP_RW macro for setting up a test with a
writable snapshot, use everywhere as needed and eliminate the now
unnecessary RPMTEST_INIT and thus a whole lot of boilerplate across
the test-suite. Many tests were using RPMTEST_INIT unnecessarily,
and there still are many tests that could actually use a read-only
environment but that's another story.

Of particular note is RPMTEST_SKIP_IF which becomes necessary here:
if AT_SKIP_IF decides to skip a test, it exits without no chance for
cleanup, and if this happens in a test using RPMTEST_SETUP_RW, we'd
leave a mount behind and get warnings about busy mountpoints in the
test-suite.
  • Loading branch information
pmatilai committed Jan 29, 2025
1 parent d0a94d5 commit c9f0ef7
Show file tree
Hide file tree
Showing 26 changed files with 397 additions and 851 deletions.
17 changes: 12 additions & 5 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ For the typical structure of a single test, consult GNU Autotest's
[documentation](https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.71/autoconf.html#Writing-Testsuites)
as well as the existing tests. Below are the specifics of RPM's test-suite:

* Use `RPMTEST_SETUP` instead of `AT_SETUP`
* Use `RPMTEST_CHECK` instead of `AT_CHECK`
* Use `RPMTEST_CLEANUP` instead of `AT_CLEANUP`
* Use `RPMTEST_SKIP_IF` instead of `AT_SKIP_IF`
* Use `RPMTEST_INIT` to create a mutable snapshot (optional)
* Use `RPMTEST_SETUP` instead of `AT_SETUP` to setup a test in an immutable
system image with writable `.` and `/tmp`.
* Use `RPMTEST_SETUP_RW` instead of `AT_SETUP` to prepare the use of a mutable
snapshot of the system image. To be used when the test needs to modify
the system image itself - to install a package, import keys and so on.
* The absolute path to the snapshot's root is stored in the `$RPMTEST`
environment variable, modify the directory tree as you wish
* To run RPM inside the snapshot, use the `runroot` prefix, e.g. `runroot
Expand All @@ -149,6 +149,11 @@ as well as the existing tests. Below are the specifics of RPM's test-suite:
environment with only a handful of variables preset. To pass your own
variable(s), use `--setenv` (once for each variable), e.g. `runroot
--setenv FOO "foo" rpm ...`
* Due to historical reasons, a mutable snapshot is currently needed for
merely building packages as well.
* Use `RPMTEST_CHECK` instead of `AT_CHECK`
* Use `RPMTEST_CLEANUP` instead of `AT_CLEANUP`
* Use `RPMTEST_SKIP_IF` instead of `AT_SKIP_IF`
* Use `RPMTEST_USER` to create a regular UNIX user in a mutable snapshot
* The username is stored in the `$RPMUSER` environment variable
* To run a binary as `$RPMUSER` inside the snapshot, use `runroot_user`
Expand All @@ -157,6 +162,8 @@ as well as the existing tests. Below are the specifics of RPM's test-suite:
to the macro, e.g. `RPMTEST_USER([user1, user2])`. Then, use
`runroot_user -n <name>` to run a binary as a specific user
* Use `RPMDB_RESET` to reinitialize a snapshot to an empty rpmdb (avoid this)
* Use `RPMTEST_SNAPSHOT_MOUNT` create a mutable snapshot inside an immutable
test (not normally needed, use RPMTEST_SETUP_RW instead)
* If no snapshot was used, just call the RPM binaries normally
* Store any working files in the current directory (it's always writable)

Expand Down
20 changes: 13 additions & 7 deletions tests/local.at
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ m4_define([RPMTEST_SETUP],[
AT_SETUP($1)
])

m4_define([RPMTEST_SETUP_RW],[
RPMTEST_SETUP($1)
RPMTEST_SNAPSHOT_MOUNT
])

m4_define([RPMTEST_SNAPSHOT_MOUNT],[[
export RPMTEST="${PWD}/tree"
export HOME="${RPMTEST}/root"
Expand All @@ -19,10 +24,6 @@ if [ -d "$RPMTEST" ]; then
fi
]])

m4_define([RPMTEST_INIT],[
RPMTEST_SNAPSHOT_MOUNT
])

m4_define([RPMDB_RESET],[
rm -rf "${RPMTEST}"`rpm --eval '%_dbpath'`
runroot rpm --initdb
Expand All @@ -46,7 +47,13 @@ LD_PRELOAD=${ASANLIB} ASAN_OPTIONS=detect_leaks=0 ${PYTHON} test.py
]])

m4_define([RPMTEST_SKIP_IF],[
AT_SKIP_IF($1)
AT_CHECK([
if $1; then
RPMTEST_SNAPSHOT_UMOUNT
# autotest's documented "skip this" code
exit 77
fi
])
])

m4_define([RPMTEST_CHECK],[
Expand All @@ -73,7 +80,7 @@ RPMTEST_CHECK_UNQUOTED(
])

m4_define([RPMPY_CHECK],[
RPMTEST_SKIP_IF([$PYTHON_DISABLED])
AT_SKIP_IF([$PYTHON_DISABLED])
RPMTEST_CHECK([RPMPY_RUN([$1])], [], [$2], [$3])
])

Expand All @@ -86,7 +93,6 @@ RPMTEST_CLEANUP
])

m4_define([RPMTEST_USER],[
RPMTEST_INIT
[[ $# != 0 ]] && export RPMUSER=$1
useradd -m -R $RPMTEST $RPMUSER
])
Expand Down
Loading

0 comments on commit c9f0ef7

Please sign in to comment.