rpm/tests
Florian Festi 4c1f71ec9e Add error messages for url helper calls
Rpm allows URLs as cli parameters. The files are then automatically
downloaded with %_urlhelper which defaults to curl(1). So far failures
have been ignored right away and error messages are generated later when
the file was not found on disk.

Issue a meaningful error message when the help program is failing or missing
completely. This allows not to ship curl with rpm while still giving the
user a chance to find out what is going on. This is not quite ideal as
the operation continues and creates a second error message later on, but
as good as it gets without redesigning the whole code.

Related: rhbz#2216754
Resolves: #2683
2024-06-14 13:43:37 +03:00
..
data Add a testcase for Lua hook register/call/unregister 2024-06-14 09:29:15 +03:00
pinned Add a deprecation warning for clamp_mtime_to_source_date_epoch 2024-04-05 11:17:06 +02:00
CMakeLists.txt cmake: move os-release parsing into oci branch 2024-05-13 14:48:25 +02:00
Dockerfile Add Dockerfile.fedora 2023-10-31 14:53:29 +02:00
Dockerfile.fedora Switch to C++ for the majority of codebase 2024-04-09 11:00:00 +03:00
README.md Add a note about --setenv to test README 2024-03-25 12:01:38 +01:00
atlocal.in Sanitize awk and find-debuginfo paths in macros 2024-03-14 10:04:47 +01:00
local.at Add a build option for enabling address sanitizer, use for CI 2024-01-31 10:13:08 +02:00
mktree.common Add support for "pinned" tests 2024-01-04 12:37:30 +02:00
mktree.oci Add support for "pinned" tests 2024-01-04 12:37:30 +02:00
mktree.rootfs Exit from mktree on failure 2023-11-01 09:27:05 +02:00
package.m4.in Implement test-suite execution in cmake 2022-10-20 14:10:04 +03:00
rpmbuild.at Avoid special characters from %{VERSION} in %builddir 2024-06-12 17:01:39 +02:00
rpmbuildid.at Drop redundant atconfig 2023-07-06 09:02:11 +03:00
rpmconfig.at Replace AT_CHECK and AT_CLEANUP with RPMTEST_* 2023-07-05 13:41:03 +03:00
rpmconfig2.at Replace AT_CHECK and AT_CLEANUP with RPMTEST_* 2023-07-05 13:41:03 +03:00
rpmconfig3.at Replace AT_CHECK and AT_CLEANUP with RPMTEST_* 2023-07-05 13:41:03 +03:00
rpmconflict.at Replace AT_CHECK and AT_CLEANUP with RPMTEST_* 2023-07-05 13:41:03 +03:00
rpmdb.at Allow building rpm without OpenPGP support 2024-03-20 12:42:33 +02:00
rpmdepmatch.at Rearrange test-suite python helper macros a bit 2011-06-09 13:19:14 +03:00
rpmdeps.at Replace AT_CHECK and AT_CLEANUP with RPMTEST_* 2023-07-05 13:41:03 +03:00
rpmdevel.at Add a build option for enabling address sanitizer, use for CI 2024-01-31 10:13:08 +02:00
rpme.at Fix sbit removal if fchmodat() doesn't support AT_SYMLINK_NOFOLLOW 2023-11-10 11:25:43 +02:00
rpmgeneral.at Add error messages for url helper calls 2024-06-14 13:43:37 +03:00
rpmi.at Adapt tests to current state of the "legacy" parser 2024-04-23 09:42:54 +03:00
rpmio.at Replace AT_CHECK and AT_CLEANUP with RPMTEST_* 2023-07-05 13:41:03 +03:00
rpmmacro.at Add a testcase for Lua hook register/call/unregister 2024-06-14 09:29:15 +03:00
rpmorder.at Ignore non-scriptlet weak dependencies in ordering 2024-04-04 09:50:22 +03:00
rpmpgp.at Allow building rpm without OpenPGP support 2024-03-20 12:42:33 +02:00
rpmpgpcheck.c Fix the OpenPGP parser tests 2022-03-31 09:37:47 +03:00
rpmpgppubkeyfingerprint.c Fix couple of leaks in rpmpgppubkeyfingerprint test prog 2024-01-31 10:13:08 +02:00
rpmpkgfmt.at Add tests for v6 package structure and digests, equal to v4 just now 2024-04-04 13:01:55 +03:00
rpmpython.at Fix test-suite under Fedora 40 modern C rules 2024-05-13 15:25:29 +02:00
rpmquery.at Fix test-suite under Fedora 40 modern C rules 2024-05-13 15:25:29 +02:00
rpmreplace.at Replace AT_CHECK and AT_CLEANUP with RPMTEST_* 2023-07-05 13:41:03 +03:00
rpmscript.at Pass arg2 to file trigger scripts 2024-02-09 10:21:20 +02:00
rpmsigdig.at Adapt tests to current state of the "legacy" parser 2024-04-23 09:42:54 +03:00
rpmspec.at Always create %specpartsdir on build 2024-05-13 10:08:47 +02:00
rpmtests.sh Move snapshot() back to atlocal 2023-10-31 14:53:29 +02:00
rpmvercmp.at Lump version comparison tests into a single test-group 2024-03-27 12:55:13 +02:00
rpmverify.at Avoid unnecessary rebuilding in verifyscript test 2023-12-12 13:13:38 +02:00
rpmvfylevel.at Allow building rpm without OpenPGP support 2024-03-20 12:42:33 +02:00

README.md

Tests

Introduction

This test-suite builds an OCI image matching the host OS with a fresh RPM installation layered on top (with make install), ready to be tested in a container, either automatically by a script (via make check) or in an interactive shell (via make shell).

Prerequisites

To use this test-suite, you need either of:

  1. Podman
  2. Docker

[!IMPORTANT] CMake integration (native mode) is currently only available on Fedora Linux hosts with Podman installed, on other systems a fresh build of RPM will be done as part of a Fedora-based image (non-native mode).

Running all tests

To build the image (if not built yet) and perform automated testing, run:

make check

The number of tests performed depends on features enabled at configure time, at least the CMake option ENABLE_PYTHON=<ON|OFF>. See also the INSTALL file for more information.

If the test-suite is configured in native mode, it may sometimes be useful to verify that everything passes in non-native mode too as that's what our CI uses. To do that, run:

make ci

Selective testing

To run single tests, you can run the commands:

make check TESTOPTS="$NNN $MMM"

where NNN and MMM are the numbers of the tests to be run.

You can also select tests by keywords used in their description by using the command:

 make check TESTOPTS="-k $KEYWORD"

Use multiple -k parameters to have tests with different keywords run. Use -k $KEYWORD1,$KEYWORD2 to execute tests matching both KEYWORD1 and KEYWORD2.

For all available options, see the output of the command:

./rpmtests --help

By default, tests are executed in parallel using all available cores, pass a specific -jN value to limit.

Interactive testing

To drop into an interactive GNU Autotest shell, run:

make atshell

This is like a singular, empty RPMTEST_CHECK with a shell running in it and a writable tree available at the path stored in $RPMTEST. From this shell, you can run the same commands as a normal test would, such as runroot rpm. This can be used to quickly prototype (or debug) a test.

You can also drop straight into the $RPMTEST container like so:

make shell

This is just a shorthand for make atshell followed by runroot_other bash.

To factory-reset the $RPMTEST tree, run:

make reset

To only build the OCI image, use:

make tree

You can also just use Podman or Docker directly to manage containers (the image is named rpm when built). For example, to run a shell:

podman run -it rpm

Understanding the tests

Optimizations

Since the test-suite consists of several hundreds of tests and is meant to be run repeatedly during development, it's optimized for speed.

Instead of running each test in a separate OCI container, all the tests run in a single, immutable OCI container. Mutable, disposable snapshots of its root filesystem are then created on demand for tests that need write access to it (such as those installing or removing packages). These tests perform the desired operation through a lightweight, nested container with the snapshot set as its root directory.

This reduces the number of containers needed while still ensuring that each test operates in a pristine environment, without affecting any other test or the test logic itself. Snapshots are created with OverlayFS and nested containers with Bubblewrap which heavily reduces the startup time of each test when compared to a full-blown OCI runtime.

Since this is done from the immutable OCI container, that container needs to run as --privileged in order to allow the creation of nested namespaces.

Layout

The OCI image is built from a Dockerfile.<osname> where <osname> is the host OS name (e.g. fedora). Currently, we only have Dockerfile.fedora, contributions for other distros are welcome. The Dockerfile symlink points to the file that should be used in non-native mode (see above).

The test script that's executed in the OCI container is written in GNU Autotest and is compiled from the rpmtests.at file. The individual tests are split into several files with the .at suffix, each covering a specific area within RPM, such as package building, transactions or configuration, which are then included by the top-level rpmtests.at script.

Writing tests

For the typical structure of a single test, consult GNU Autotest's documentation as well as the existing tests. Below are the specifics of RPM's test-suite:

  • Use RPMTEST_CHECK instead of AT_CHECK
  • Use RPMTEST_CLEANUP instead of AT_CLEANUP
  • Use RPMTEST_SETUP or RPMDB_INIT to create a mutable snapshot (optional)
    • 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 rpm ...
    • To run any other binary inside the snapshot, use runroot_other instead
    • By default, runroot and runroot_other will operate in a clean 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 ...
  • If no snapshot was used, just call the RPM binaries normally
  • Store any working files in the current directory (it's always writable)