eBPF-based security platform
docs: describe the test tiers and how tests are numbered
Daniel Borkmann69d996a7620e
diff --git a/AGENTS.md b/AGENTS.mdindex 9285f881..7d0c7f02 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -60,6 +60,7 @@ remote-management or transport layers.| `Documentation/requirements.rst` | Kernel options, operator toolchain, target runtime. || `Documentation/getting-started.rst` | Quickstart: build, sign, initialise a target, load and unload, publish and install packages. || `Documentation/telemetry.rst` | OTLP export of map snapshots and status keepalives, the signed Lua decoders, and collector integration (OpenTelemetry Collector, ClickHouse, Splunk, custom). |+| `Documentation/testing.rst` | The test tiers (unit, functional, end-to-end), the test numbers, running the tests and the test VM. Read it before adding or moving a test. || `Documentation/coding-style.rst` | The kernel's coding style, applied to all C here. || `Documentation/contributing.rst` | Commit message form, the mandatory `Signed-off-by:` and the kernel's attribution tags. Read it before crafting a commit. |@@ -344,6 +345,10 @@ one usually still compiles and passes tests.- `sudo make -C testing test-tgt` always boots the dm-verity runtime and signedconfig from a dracut initrd. CI runs that same required suite through`.github/scripts/target-tests.sh`; the old root-only installer suite is gone.+- `util/<m>.c` is unit tested by `testing/unit/<m>.c`: a change to a util+ function adds or updates its cases there. A shell test is named+ `t<F><K><NN>`, family, host (0) or target (1), and order, and lives in+ its family's directory; `Documentation/testing.rst` has the families.- `make -C testing fuzz [FUZZ_SECONDS=60]` runs the libFuzzer targets in`testing/fuzz/` for the parsers of input from outside the host, underASan and UBSan, on their seed corpora; CI runs them too. A parser thatdiff --git a/Documentation/index.rst b/Documentation/index.rstindex 39526c6a..1783b615 100644--- a/Documentation/index.rst+++ b/Documentation/index.rst@@ -100,6 +100,10 @@ Reading or writing a ``.upatch```upatch-spec <upatch-spec.rst>`__ is the byte-level reference forthe signed artifact.+Testing+ `testing <testing.rst>`__ describes the test tiers, how tests are+ numbered and grouped, how to run them, and the test VM.+Contributing`contributing <contributing.rst>`__ covers commit messages, themandatory ``Signed-off-by:`` and the kernel's tags.diff --git a/Documentation/testing.rst b/Documentation/testing.rstnew file mode 100644index 00000000..fce16e02--- /dev/null+++ b/Documentation/testing.rst@@ -0,0 +1,168 @@+..+ SPDX-License-Identifier: BSD-2-Clause+ Copyright (c) 2026 Authors of shirudo++Testing shirudo+===============++shirudo is tested in tiers, each under its own directory of ``testing/``:+unit tests for the functions of ``util/``, functional tests for one command+or mechanism at a time, end-to-end tests for whole delivery paths, tests of+the scripts CI runs, and libFuzzer targets for the parsers of input from+outside the host. A change comes with a test in the lowest tier that can+show it works. See `requirements <requirements.rst>`__ for what the test+hosts need and `contributing <contributing.rst>`__ for what to run before+sending a change.++1) The layout+-------------++::++ testing/+ unit/ unit tests, util/<m>.c by unit/<m>.c+ ghchecks/ the scripts under .github/scripts+ functional/<family>/ one command or mechanism at a time+ e2e/ whole delivery paths on a test VM+ fuzz/ libFuzzer targets and seed corpora+ fixtures/ BPF programs, decoders and configs the+ tests build from+ helper/ C and Python helpers the tests run+ vm/ the test VM: kernel, bundle, guest+ test-lib.sh the TAP harness of the shell tests+ integration-lib.sh shared setup of the target tests+ run-tests.sh the unit and host tests+ run-target-tests.sh one family's target tests, in its VM++Each ``functional/`` family may carry a ``test.plan.md`` that maps the cases+it must cover to the tests that do, and says which are not covered yet.++2) Test numbers+---------------++A shell test is named ``t<F><K><NN>-<what>.sh``, the way git numbers its+test families:++* ``F`` is the family, and with it the directory;+* ``K`` is ``0`` for a host test, which needs no root, kernel or TPM of its+ own, and ``1`` for a target test, which runs as root in the test VM+ against an initialised target;+* ``NN`` orders the tests of a family, and is the order they run in.++=== ============================ ==========================================+F Directory What it covers+=== ============================ ==========================================+0 ``ghchecks/`` DCO, SPDX, style, commit range, SBOM+1 ``functional/build/`` dispatch, static target, packaging,+ initrd installer, the test VM scripts+2 ``functional/signing/`` keys, signatures, the trusted set+3 ``functional/upatch/`` the container, build metadata, load,+ unload, serializers+4 ``functional/tpm/`` the register, eventlog, attestation and+ initrd binding+5 ``functional/image/`` runtime and config images, activation,+ revocation, interruption+6 ``functional/tamperproof/`` attacks on the LSM, the seal, the+ keyrings, bpffs and the TPM path+7 ``functional/bpm/`` packages, repositories, the upatch tree+8 ``functional/otel/`` map export, status, TLS policy+9 ``e2e/`` the kernel-obs package, delivery paths+=== ============================ ==========================================++A new test takes the next free number of its family and kind; a number is+not reused for a different test. A file under ``testing/`` that is not a+test does not take a name of this form.++3) Running the tests+--------------------++``make -C testing test-unit``+ Builds and runs the unit tests.++``make -C testing test-op``+ Builds shirudo, the helpers and the unit tests, then runs the unit+ tests and every host test in number order. ``SANITIZE=address,undefined``+ builds all of it under ASan and UBSan, as CI does.++``make -C testing test-tgt``+ Runs the target tests, one VM per family, booted from one bundle+ through the production path: the dm-verity runtime and the signed+ config from a dracut initrd. ``register`` runs the TPM register tests+ before ``init``, without the production initrd. ``T="<family> ..."``+ selects families, ``make -C testing test-tgt-<family>`` runs one, and+ ``make -j`` boots several side by side. A VM that passed keeps its+ logs and drops its disks; one that failed is kept under+ ``build/test-vm/vms/`` for inspection. Needs root.++``make -C testing fuzz [FUZZ_SECONDS=60]``+ Runs every libFuzzer target on its seed corpus under ASan and UBSan.++``make -C testing vm``+ Boots an interactive VM with a prepared shirudo, for running a test by+ hand; ``make -C testing help`` lists the rest.++The ``ghchecks/`` tests run with the host tests and need no build.++4) Unit tests+-------------++``testing/unit/<m>.c`` tests the functions of ``util/<m>.c``. It calls them+directly and checks the results with the assertions of ``unit.h``:+``EXPECT_*`` records a failure and goes on, ``ASSERT_*`` ends the case.+Each case is a ``static void`` function named for what it shows, and the+file lists its cases in one table that ends with an empty entry::++ static void decode_refuses_non_hex(void)+ {+ __u8 out[1];++ EXPECT_EQ(hex_decode("zz", out, 1), -EINVAL);+ }++ static const struct unit_case cases[] = {+ UNIT_CASE(decode_refuses_non_hex),+ {}+ };++ UNIT_SUITE(hex, cases);++A case left out of the table is an unused static function, which the+build refuses. Each case runs in a child of its own, so a crash, a+sanitizer report or a hang fails that case alone; the case's stderr comes+back as TAP diagnostics when it fails, and ``unit_skip()`` skips it with a+reason. The tests link the util objects from an archive, so a test pulls+in only what its module needs and needs no build rule of its own.++A change to a function of ``util/`` adds or updates its cases. What needs+the command line, root, the TPM simulator, the kernel or an implementation+written apart from shirudo to compare against is a functional test.++5) Functional and end-to-end tests+----------------------------------++A shell test starts in ``testing/``, sources ``test-lib.sh``, and runs its+cases with ``test_expect_success``; ``test_skip_all`` skips the whole script+when a prerequisite is missing. It works in a scratch directory of its own+and writes nothing into the tree.++A target test also sources ``integration-lib.sh`` and calls+``target_guard``. Its family's VM was booted for that family alone, so it+finds loaded only what its family loaded; ``require_loaded <name>`` loads a+signed fixture of the bundle that a test needs. A target test that skips+as a whole fails its family, since every one of them is required.++The end-to-end tests in ``e2e/`` run a shipped package against real kernel+activity and follow it out through the export path.++6) The test VM+--------------++``testing/vm/`` builds and runs the target side. ``build-kernel.sh``+builds the test kernel from bpf-next or a release tag with the slim+configuration and the patches under ``kernel/``. ``build-bundle.sh``+builds the operator side: shirudo, the helpers, the signed upatch fixtures,+the dm-verity runtime image and the signed config images, which+``image-fixtures.sh`` and ``bundle-images.sh`` produce. ``run.sh`` boots a+guest with a software TPM and the bundle and, in test mode, has+``guest.sh`` run one family's tests in it. ``testing/swtpm.sh`` runs a+software TPM on the host for development without a VM.