Testing
The C code is tested by programs under tests/ and shell scripts under
tests/integration/, the Go modules by go test. The table lists what
runs them; the CI jobs that do so are in Continuous integration.
Command |
Runs |
|---|---|
|
the C unit tests, the integration scripts and the cross-language
checks, after |
|
that module's Go tests |
|
|
|
unit tests and command-line paths under valgrind memcheck |
|
the store and session tests against a live Postgres |
|
|
|
the agent's IOMMU and TPM self-tests, as root |
|
the C fuzz targets (Fuzzing) |
|
the micro-benchmarks (Performance) |
Unit and integration tests
make test-unit builds all and every test program, then runs:
every program built from
tests/test_*.c, except those listed inTEST_MANUAL(Tests that need a live system). The loop stops at the first program that exits non-zero.the scripts under
tests/integration/that run without root or a running agent. A script whose tool is missing (openssl,python3,go,clang,pkg-config,sphinx-build,softhsm2-util) is not run, and the target printsSKIP:with the reason.two cross-language checks.
tests/cross_lang/test_gen.gosigns a token with the Go server SDK andtest_cross_lang_verifyverifies it with the C one.test_cross_lang_report_genwrites an attestation report with the agent's serializer andtests/cross_lang/report_verify.goparses it with the verifier's. Both needgo.
The Go tests are not part of make test-unit.
A script reads the build directory from LOTA_BUILD_DIR, which the make
recipe exports. A script that drives one binary also takes its path from the
environment, such as LOTA_INSTALL_BIN for lota-install or
LOTA_TRUST_PONG for the trust_pong example.
Adding a C test
The Makefile builds every tests/test_*.c into
$(BUILD_DIR)/test_<name>. A test that needs more than its own source
declares it in the test section:
$(BUILD_DIR)/test_foo: $(AGENT_DIR)/foo.c
$(BUILD_DIR)/test_foo: TEST_CFLAGS := -DFOO
$(BUILD_DIR)/test_foo: TEST_LDLIBS := -lcrypto
-DLOTA_INTERNAL_TESTS exposes the agent's test entry points
(src/agent/agent_internal.h).
A new test is run by make test-unit unless it is added to
TEST_MANUAL, and under valgrind only once it is added to
VALGRIND_UNIT_BINS.
Tests that need a live system
TEST_MANUAL lists the programs the loop leaves out: test_sdk_ipc,
test_ipc_client, test_ipc_dos, demo_sdk and test_tls_verify,
which need a server, and hook_preload_target,
test_cross_lang_report_gen and test_cross_lang_verify, which other
tests run.
When
/run/lota/lota.sockexists,make test-unitalso runstest_sdk_ipc,test_ipc_client statusanddemo_sdkagainst the agent behind it.make test-sdkprints how to start an agent with--test-ipcfor them.test_ipc_dosopens more than 64 connections to such an agent and is only run by hand.test_tls_verifyneedsopenssl s_serveron port 9443 with a certificate whose only SAN isDNS:localhost.make test-unitruns it whenLOTA_RUN_TLS_TESTSis set, or when/tmp/lota-tls-test/ca.pemexists and a server listens on 9443. The program takes another CA file as its argument.make test-hardwarerunslota-agent --test-iommuandlota-agent --test-tpm(Command line), as root.tests/integration/test_bpf_gates.shdrives the BPF LSM gates scoped to protected processes against an agent enforcing with BPF attached. It needs root andmake all examples, and no make target runs it.
Sanitizers and valgrind
SANITIZE=<list> adds -fsanitize=<list> to the compile and link flags
of the host C code, not the BPF object, with
-fno-sanitize-recover=all, so a finding aborts the process and fails the
test. CI runs make test-unit with SANITIZE=address,undefined, under
gcc and clang, and with SANITIZE=thread.
make sanitizer-build builds all, the examples, the C benchmark,
lota-bench and the syzkaller loader under address,undefined and runs
nothing.
make valgrind-unit runs the programs in VALGRIND_UNIT_BINS under
$(VALGRIND) (default valgrind) with:
--error-exitcode=1 --leak-check=full
--errors-for-leak-kinds=definite,indirect --track-origins=yes -q
test_hardening is left out: valgrind cannot run its seccomp filters.
make valgrind-smoke runs lota-agent --help with an empty
configuration file, and --help of the demo_anticheat and
trust_pong examples when they are built, with the same flags.
Go tests
Each Go module (src/verifier, src/attestca, sdk/server,
src/crl, src/fleetctl and the two example modules) is tested on its
own with go test ./... in its directory.
Postgres-backed tests
The verifier's Postgres store and session code is tested only under the
pg_integration build tag, against a live server named by
LOTA_TEST_PG_DSN:
$ podman run -d -e POSTGRES_USER=lota -e POSTGRES_PASSWORD=lota \
> -e POSTGRES_DB=lota -p 55432:5432 docker.io/library/postgres:16-alpine
$ cd src/verifier
$ LOTA_TEST_PG_DSN="postgres://lota:lota@127.0.0.1:55432/lota?sslmode=disable" \
> go test -tags pg_integration -p 1 -count=1 ./store/ ./verify/
-p 1 is needed: both packages truncate the tables of the one database.
Without LOTA_TEST_PG_DSN the tests skip.
Two variables enable more cases; without them those cases skip, and CI sets neither:
LOTA_TEST_PG_SHARD_DSNS: two databases, comma separated, for the sharded store tests, which check which database answered.LOTA_TEST_PG_EMPTY_DSN: a database no verifier has built, for the read-only open refusal.
Go coverage ratchet
scripts/check-go-coverage.sh runs go test -cover ./... in
src/verifier, src/attestca, sdk/server, src/crl and
src/fleetctl and compares each package with its floor in
.github/go-coverage-baseline, or the file given as its argument. It
exits 1 when a package falls below its floor, or when a package with a
non-zero floor reports no coverage, and 2 when the baseline file is
missing.
With LOTA_TEST_PG_DSN set it adds -tags pg_integration -p 1 for
src/verifier. The floors of the store and verify packages
assume those tests ran; without the variable both fall below them. The
floors are raised as tests land and never lowered.
Tree gates
These targets check the tree as a whole. scripts/check-patch runs each
when a patch touches its inputs (Patch checks).
Include hygiene
make check-includes runs scripts/check-includes.sh. It builds a
compile database at build/compile_commands.json with bear over
make -B -k of all, examples, test-bins, fuzz-all,
bench-c, lota-bench and syzkaller-fuzz-loader, and keeps the
first entry of a file compiled twice. It then runs
clang-include-cleaner over every C file in the database except
src/bpf/, and fails on each include the tool reports as unused. A header
reached only through another include is not reported.
Some headers are exempt, because the tool reports them wrongly:
<errno.h>,<sys/types.h>,<unistd.h>,<getopt.h>,<termios.h>,<sys/time.h>and<sys/socket.h>, whose symbols it credits to the glibc and kernel uapi implementation headers.SDL*.h: SDL's public header is<SDL.h>, and the others are implementation detail.<systemd/sd-bus-protocol.h>, whose symbols systemd moves between it and<systemd/sd-bus.h>across releases.
scripts/fix-includes.sh [file.c ...] rewrites the include lists with
include-what-you-use, over the whole database when given no file. The
mapping files under scripts/iwyu/ keep the SDL and TSS2 umbrella
headers. The tool does not see a symbol used only through a macro or under
conditional compilation, so review the diff and rebuild; an include needed
that way carries // IWYU pragma: keep, as in tests/test_seal_aik.c.
The gate needs clang-include-cleaner (clang-tools-extra) and bear,
and exits 1 without them. The fixer needs include-what-you-use,
iwyu_tool.py, fix_includes.py and bear.
Package manifests
Packages are described twice: by the nfpm configs under packaging/nfpm,
which make packages and the release workflow build, and by
packaging/rpm/lota.spec, which COPR builds
(RPM packages). make check-package-manifests runs
scripts/check-package-manifests.sh, which fails when:
the two manifests ship different installed paths for a package. A directory that only holds other listed paths is dropped from both sides, so a directory shipped empty is still compared. Modes and ownership are not compared.
their Requires differ by name, apart from those rpmbuild derives from sonames, which the nfpm config lists by hand.
a sibling is pinned to one build (
=) in one manifest and not in the other.an nfpm config's
pkgconfig(<name>)provides and its shipped.pcfiles differ. rpmbuild derives the provides from the files and nfpm does not.a package's
Summaryis not the first line of its nfpm description, or its%descriptionis not the rest.the spec's
Versionor newest%changelogentry is not the@VERSION@or@CHANGELOG@placeholder thatmake srpmfills fromVERSION.the spec ships a file
make installwrites only when it exists, and no target the spec's%buildruns produces it.a path under
/var/lib/lota,/etc/lota,/usr/lib/lotaor/usr/share/lotahas no parent directory a package owns.a shipped unit is not stopped by both
%systemd_preunand the nfpm pre-remove script.the packages ship a file under
/usr/share/lotathatmake installdoes not place.LOTA_REPO_BASEURLor alota.repoorRPM-GPG-KEY-lotaaddress in a page is not under<site>/rpm, where<site>is_siteinDocumentation/conf.py.
A file added to a package is therefore added to the Makefile install
rule, the nfpm config and the spec's %files.
The player page's build in a clean Fedora
A development host already has every package an earlier build needed, so it
cannot show a package the player page leaves out.
make check-player-build runs scripts/check-player-build.sh. It
starts registry.fedoraproject.org/fedora:44 (LOTA_PLAYER_IMAGE
overrides it) and runs the commands of the Building it yourself section
of Documentation/player/index.rst, read from the page. A copy of the
tree under test replaces the git clone, and sudo is dropped, since
the container runs as root.
A failing step prints its number and the last 20 lines of its output. After
the last step the script checks that /usr/bin/lota-install,
/usr/bin/lota-steam-setup, /usr/bin/lota-proton-hook and both
liblota_wine_hook.so.1 builds, under /usr/lib64 and /usr/lib,
are installed. A missing 32-bit package makes the build skip the 32-bit
hook, and make install then refuses the tree on x86_64.
The script needs podman and network access. With
LOTA_PLAYER_IN_CONTAINER=1 it runs in place, from LOTA_PLAYER_SRC
(default /src), as the CI job does inside a Fedora 44 image.