Testing
A framework that promises a game will run on 17 targets has to check it, and the rule it holds itself to is strict: anything that can be tested is tested, and a test asserts what actually happened, not that a command exited 0. A green check that ran nothing is worse than a red one, so every gate is also shown failing on the thing it was written to catch.
This page says what is tested and how it holds. To add a test of your own, of any kind, Contributing says how.
Everything below runs with rmp test in
the framework's repository, stage by stage, and in its CI on every push. The last section is what
the same command runs in a game.
Unit tests, with no window#
The unit tests use doctest and run without a window, a GPU or a display. They cover the scene stack and its order of events, objects, handles,
behaviors and the catalogue, collision against objects and against maps, the camera, input, the
asset table, sprite animation, the LDtk and Tiled readers, saves and rmp::Value, the
diagnostics, and the random generator,
and the fix the framework carries in raylib's software renderer, read at the edges of a
texture,
and the terminal a DRM/KMS game hands back however it ends, from a program made to die each way
on a pseudo-terminal. Every file called tests/*_test.cpp is picked up by the
build, so a new test needs no change to CMake.
They run twice. Once in the order they are written, and once shuffled with a fixed seed, so a test that only passes because an earlier one left something behind is found, and found again the next time.
Both
runs are a debug build of the framework, so both run under the
sanitizers, and the build is configured with RMP_WERROR: a
compiler warning in the framework or in a test is an error there.
The
same stage then builds and runs tests/game/, the tests every game is given, against
the small game in the framework's own src/ — the copy every game starts from — so a
test a new game would fail on its first day fails here first. Below is
what they are.
Two kinds of test need something real underneath, and get it:
- Locales. A save has to read back the same on a machine whose decimal point is not a dot. The test run builds two locales from source for it — one with a comma, one with the Arabic decimal separator, which is two bytes long — and points the tests at them, and CI fails if they cannot be built rather than skipping the tests that need them.
- The sound device. One suite opens the real audio device at a master volume of 0 and reads back what the mixer produced, to check that a sound plays where it should between the speakers. On a CI runner with no sound card it runs against the audio library's null backend. It runs once, not in the shuffled pass.
What
makes all of this possible without a window is the seam: time, input and randomness enter the
framework through a few functions a test replaces — one clock, which the game and the UI both read,
the game's input sampler and the UI's own, and one random generator.
Time is a parameter explains it, and
tools/seam_check.sh fails if any other file starts reading them on its own. The files it
allows are the seams themselves, and the list only gets shorter: a file on it that stops reading the
real thing fails until its line goes. The UI's text field is not on it. What it types — the
characters and Backspace — comes through the UI's own seam like the rest of its input, which is how
the layout test types into it, and its caret blinks on the game's clock like the rest of the UI.
The UI, laid out headless#
The UI's layout
engine is pure computation, so with the text measurement and the pointer replaced by stubs and a
viewport injected, a whole menu can be laid out with no window at all.
tests/ui_layout_test.cpp checks what a person would check by hand once and never again:
that the menu is centred, that it stays centred when the window changes, that buttons do not
overlap, that the scale behaves at the extremes, and that a focused button can be pressed from the
keyboard;
that a pointer landing on a button is the interface's before the frame's interface has run, and
that a list scrolls to keep the focus in view.
A frame, in software#
Booting proves the window opened and the assets loaded, and nothing more. A broken shader or a
draw call that silently does nothing still boots and still exits cleanly. So the render stage
builds the game a second time against raylib's software renderer, which draws into plain memory —
no GPU, no window, no display server — and runs it for ten frames. It asserts three things from
the log: the game booted with every asset loaded, a frame was read back and had something on it,
and the run reached the end of its frames instead of dying on the way out. It also checks that the
window was asked for the vertical sync the .toml says.
Before any of that, it reads how the game ended. The markers are printed before the process exits, and two things come after them: a crash while the game shuts down, and LeakSanitizer's report of the memory nobody freed, which a sanitized debug build prints at exit. So a report from a sanitizer anywhere in the log fails the stage, with the first forty lines of it, and so does an exit status other than 0.
In the framework,
the frame is also hashed and compared with tests/fixtures/render_hash.txt. Software
rendering involves no driver, so the same frame comes out byte for byte on Linux x86-64 and on
macOS on Apple Silicon, and one golden hash covers both. A change to the frame that was meant is
recorded with rmp test render-update.
The frame is read back by the framework itself, between the last draw and
EndDrawing() — the only place it can be: before the batch is flushed the frame holds
nothing but the clear colour, and after it the frame may already be gone.
One frame has the detail.
Booting the game#
The smoke
stage builds the game the ordinary way and runs it with a budget of ten frames
(RAY_TEST_MAX_FRAMES=10), after which it exits by itself. It passes only if no
sanitizer reported anything, the game exited with status 0, and it printed
RAY_TEST_BOOT_OK assets_failed=0 and RAY_TEST_RENDER_OK. Otherwise it
prints the log, or the report, and says which: a sanitizer reported the run above (exit
…), the game exited with status …, the game did not boot, or an asset
failed to load, or the game booted and drew nothing.
And
it holds the game to no mistake the framework reports. A mistake in the game that the framework says
once in the log — a widget outside begin()/end(), an action nobody
defined — is counted, and the last frame prints the count, RAY_TEST_REPORTS=0 when
there was none. Anything else fails the stage, with the warnings it counted: the framework
reported a mistake in the game (the WARNING lines above, said once each). That holds in a game
rmp new makes as much as in the framework; a game in plain C has no framework to report
anything, and prints no count.
The
count in assets_failed is of every load that gave nothing usable: a name with nothing
behind it, and a file that is there and does not decode — a picture, a sound, a song or a font cut
short. A corrupt file would otherwise leave a blank texture, silence or a stand-in font, and a boot
that looked clean.
The boot marker is a gate and not a message, which is a distinction worth stating: it is printed only when a window really exists. A boot marker that is always printed passes a game whose platform failed to start, and every job that reads the log would agree.
Under the same frame budget the game also writes a small save to the platform's real save folder, reads it back, compares and deletes it before it reports the boot. Where saves go is different on every platform, and this is how each one's folder is exercised at all.
In
CI the same markers are read on every target a runner can start, each in the most honest
place available, and every one of those checks wants assets_failed=0 on the boot
line, never the marker alone: a game with every texture missing still opens its window. A test
reads every workflow, script and tool and fails on a check that looks for the marker without
it. The Linux desktop builds boot under a virtual X display. The musl builds boot on Alpine, in
an image of the framework's own pinned by its digest and with the network off: a software-rendered
build of the game, and the binary the archive ships, under a virtual X display. What a musl binary
needs from the system is read out of it rather than proven by a boot — below.
The DRM build boots on a virtual kernel display,
and on the same display rmp run, started as on a Linux console with no desktop, has
to choose DRM/KMS by itself, build the game and boot it. The RISC-V build is started as its archive
ships it on a RISC-V board — RISE's, or Cloud-V's for a private repository — in the riscv64 build
image, and, when the board fails or none comes, under QEMU's emulation of a RISC-V processor,
inside the build image.
Windows boots on its runner with its save folder under a path that is not ASCII, the kind a player
called José has, and with the compiler off PATH, so that a DLL the runner has and a
player does not cannot be found. macOS and the BSDs run the render stage under the software renderer. The web build
is loaded in a headless browser that checks the canvas really has pixels on it. iOS is built for
the simulator, where booting it and reading the markers is a step a repository switches on.
Android is the exception: no CI job
reads its markers. When a project is configured for it, the debug APK is started in Firebase Test Lab, by
default on MediumPhone.arm, an Arm virtual device, under a Robo test, which explores the app with no test code of its own and has
no log to read the markers from. It proves the game starts on that device without crashing, and
no more. The robot taps whatever is on the screen,
and the debug build shows Google's test ads whatever ids the .toml carries, so none
of its taps lands on a real ad.
A
release is also started the way a player starts it: from somewhere other than its own folder. A
production build reads ./resources/, and a boot started from the folder where
resources/ happens to be passes whether or not the game finds its files on its own.
So tools/shipped_check.sh builds the release under the software renderer and starts
it twice, and each start must boot with assets_failed=0. First where it was built,
from the project folder, with no resources/ next to the executable: only a
resources/ beside it may move a release, so this one has to stay where it was started
and read the project's. Then laid out as the archive ships it, from another folder. The macOS and
BSD jobs run it, and so does the job that makes a game in plain C, whose own main()
does the moving instead of the framework's entry point. Linux x64, arm64 and RISC-V start the
unzipped archive from another folder, Windows starts the .exe from one, and the musl and DRM
containers start the game from /. On NetBSD and OpenBSD, which cannot say where an
executable is, the check starts the shipped release from its own folder and wants the line that
says so.
Every
container a workflow starts a game in — the musl boots on Alpine, the DRM boot and
rmp run on the virtual display — has an init as its first process, which Docker's
--init puts there. A program that is a container's first process ignores a SIGTERM it
has no handler for, so a game there that hung could not be ended by the step's timeout, and held
its job until the job's own limit ran out. A test reads every workflow and fails on a container that
starts a game — one that sets RAY_TEST_MAX_FRAMES, runs xvfb-run or runs
./rmp run — without one.
What ships, read out of the binary#
A boot on a CI runner proves the game starts on that runner, and a runner is a developer's
machine with everything installed. What a player's machine has to give the game is invisible from
there and written in the binary itself, and so is what a release was linked with, so CI reads them
out of it with tools/binary_check.py, which needs nothing but Python's standard
library:
- What a Windows
.exeimports. Both Windows jobs read the import table and the delay-load table of the.exethey ship, before booting it, and fail on any DLL that is not part of every Windows 10. A dynamically linked compiler runtime is named, with how to link it in instead. With--require-iconit also wants the icon group in the resources, which is what Explorer shows. - Which macOS each slice needs. The macOS job reads the deployment target back out of the CMake cache, then the minimum macOS out of every slice of the universal binary, and fails on a slice that asks for more — allowing 11.0 for arm64, which the toolchain raises any lower target to.
- How a Linux binary was linked. Every Linux job reads its release before UPX packs it: the relocated data read-only once the loader is done (RELRO), every symbol bound at start (BIND_NOW), a stack that is not executable, and — the release being linked position-independent — an executable ASLR can move. A flag a toolchain ignored was never there, and this is where that shows.
- What a musl
binary asks the system for. With
--musl, its interpreter has to be musl's loader and the one library it names musl'slibc.so, or it has to be static and name neither. A boot cannot say this: the Alpine it boots on has what the shipped binary needs, and a static binary would boot on any Linux.
The
readers are tested by the binaries stage, tests/binary_check_test.py,
against binaries it builds byte by byte rather than commits: an .exe with an import
table, a delay-load table and an icon group, a universal Mach-O with a minimum per slice, and ELF
files with and without each of the things the Linux reader asks for. Among
them are the shapes a broken build really has — a MinGW build that imports
libstdc++-6.dll, an MSVC one with the dynamic runtime that imports
VCRUNTIME140.dll, a Mac binary that asks for its build machine's macOS in both slices —
so the gate is seen red before it is trusted green.
Every example, booted#
The
29 examples are tests too. rmp test examples — kept out of the plain
rmp test, because it compiles all of them — runs one script, the one CI runs,
in
its two halves: boot, the first five steps below, and e2e, the sixth,
which CI runs in two jobs side by side.
- Every
C++ example has the shape of an entry point that works on every platform: its own
int main(), or a loop onWindowShouldClose(), compiles everywhere and does not run on the web or iOS, so it is refused. The one exception is the plain C example, which writes its ownmain()and loop on purpose; it is allowed only while its own comment keeps saying which platforms that rules out and why. - Every example directory became a build target, and the number of targets is the number of directories — a pattern that stops matching would otherwise look exactly like a folder where everything passes.
- Every example with an entry point is built against the software renderer, booted for a budget of frames, and required to boot with no asset missing, draw, exit cleanly, leave a screenshot and make no mistake the framework reports. The plain C example is booted like the rest: it calls the C smoke-test hooks the entry point calls for every other example, and has no framework to report anything.
- At the design size every
[window] stretchdraws the same picture, so the stretch example is booted twice more, in a window taller than it is wide and in one wider than 16:9, letterboxed, and its last frame read back: the bars are its clear colour, the world reaches every edge of the area between them, and the court's lines are centred in the window. - The
platformer is played to the end — below — and
tests/input_play.cppdrives one program through the real desktop runner with keys pressed through the input seam, once with a hook that reads the input itself and once with a scene underframe(), and each press has to be seen exactly once. - Every
example with a script in
tests/e2e/is played from it, and every picture the script takes is compared with the one recorded for it — below. As many scripts were found as were built and as were played, or the step fails. They are played side by side, as many at once as the machine has processors — or asCMAKE_BUILD_PARALLEL_LEVELsays, when it is set, because each is a sanitized program of a few hundred megabytes — the one with the most frames first. Each has a folder of its own, and a frame is a sixtieth of a second however busy the machine is, so playing them together changes how long the step waits and nothing a script draws. A script still playing after ten minutes is stopped, and fails; macOS has notimeout, and there nothing stops it.
The screenshots are kept, because looking at a picture of every example is how most visual mistakes are found.
Every
one of these is a debug build of the framework, at -O0 and under the
sanitizers, and a frame drawn by raylib's software renderer is slow that
way. So this build, and only this one, compiles the three files of raylib a frame spends its time
in — rcore.c, which carries the rasteriser, rshapes.c and
rtext.c — at -O2 -ffp-contract=off, still under the sanitizers.
A
frame costs about a fifth of what it did: measured in the build image, Pong's script plays in 17
seconds instead of 85.
Turning
off contraction is what keeps the pixels: at -O2 a compiler may fuse a multiply and an
add into one instruction that rounds once instead of twice, and every picture is compared byte for
byte. It was adopted only once every picture the scripts take came out identical to the ones
-O0 draws.
The
rest of raylib stays at -O0: the image, model and sound loaders are where a malformed
file finds a memory bug, and an optimiser drops a read whose value nothing uses, which
AddressSanitizer then cannot see.
So
does every other build of raylib for the software renderer: the render stage's golden frame is
drawn at -O0 wherever it is compared.
The platformer, played#
Thirty
frames of a title screen prove that the title screen draws. A game in
examples/games has to be playable from start to finish —
win, lose, play again — so one of them is played. tests/platformer_play.cpp drives
the platformer through its real loop with a bot
that presses keys through the same seams a player's keyboard goes through and reads only what a
player can see: where things are. It plays a whole game at 60 frames a second, from the title
through every level to the flag, keeps the best run on disk, plays again and dies three times to
reach the game over screen; it jumps from the moving platform at 60 and at 240 frames a second;
and it plays to the flag again at 240. A game that can be won at one frame rate and not another is
not finished.
Examples played from a script#
A
bot that reads positions is one way to play a game. The other is a script of what a player
presses, frame by frame, with what the screen has to show at the frames that matter. Three
moments of tests/e2e/games/01_pong.e2e: the first serve, the end of the first game,
and the last frame of the script:
1 press KEY_DOWN
19 release KEY_DOWN
19 shot arrows_move_red_only
639 expect scene PongScene
640 expect scene OverScene
641 shot red_wins
# Play again, from the keyboard: the button has the focus.
1430 tap KEY_ENTER
1430 expect scene PongScene
1432 shot again
1432 endEach
line starts with the frame it happens on. press and release hold a key
down and let it go, and tap holds it for one frame; the same three press the first
gamepad's buttons, by raylib's names for them — tap GAMEPAD_BUTTON_RIGHT_FACE_DOWN is
the bottom face button pressed once. A script has the gamepad's buttons and not its sticks, which
stay at rest. click x y presses the left mouse button for one frame at a point of the
window. shot takes the picture that frame drew, expect scene names the
scene that has to be on top once the frame is over, and end is the last frame. The
grammar refuses, with the line, a script that cannot mean what it says: input on frame 0, which has
nothing to compare a key with and so sees no press; a key or a button pressed again before it came
up; a shot name used twice; a script with no end, or one that checks nothing.
The
game that plays it is the example exactly as it ships — its own main.cpp and its own
entry point — built against the software renderer with tests/e2e/driver.cpp beside
it, which installs itself before main() through the framework's seams.
The driver, the script
reader and the comparison are compiled once, into a library every played example links; what one
of them plays — its script, its pictures, the folder a failure goes to — is four strings in a file
the build writes for it. Every frame
is exactly a sixtieth of a second and rmp::random starts from seed 1, so the run is the
same run every time — the menus included, since the
UI reads the game's clock. The script's keys, buttons and clicks reach rmp::input
and the UI's own navigation and pointer —
the
navigation through the same two functions that turn a real keyboard and gamepad into it, so what a
player navigates with and what a script presses cannot drift apart. Saves go to a fresh
folder, so last run's best score cannot change this one, and there is no sound device.
A
script can only press what the game reads through rmp::input or
rmp::ui: under the software renderer raylib's own keyboard and mouse never change, so
a game that asks raylib about a key directly never sees it go down.
On every frame, whatever the script checks, the driver also looks for a control the example has put where nobody can reach it: one that takes the focus, is not wholly inside the window, and is in no scroll area that could bring it in. Nobody could see that control or click it, and no shot would say so unless the script happened to look there, so the script fails, naming the control, the frame and the size of the window.
And
a mistake of the game's that the framework reports during the run — a widget outside
begin()/end(), an action nobody defined, a number that is not one — fails
the script at its end, one line each, in the log's own words. An example is what people
copy, and it makes none.
Every
shot is compared with the picture recorded for it — shot red_wins with
tests/e2e/golden/games/01_pong/red_wins.png — exactly, pixel for
pixel: the pictures are drawn by raylib's software renderer with a fixed step and a fixed seed, so
the same script gives the same bytes, and a tolerance would only be somewhere for a real change to
hide. A shot that differs fails the script with its line —
E2E FAIL <line>: <reason> — and leaves three pictures in
build/examples-check/e2e/: the one expected, the one drawn, and the expected one
darkened with every pixel that differs in red. The e2e job uploads them. A script fails as
well when the game stops before end, exits with a status other than 0, or a sanitizer
reports anything: it is a debug build of the framework, like every example.
Exact
means one compiler, one maths library and one renderer, so the comparison is enforced inside the
pinned build image, where CI runs it, and only reported anywhere else. The pictures are recorded
there too, and nowhere else: rmp test e2e-update refuses to run outside the image and
says how to run it inside, and every picture it changed is looked at before it is committed.
A
test holds the arrangement together. Every example in examples/games/,
examples/ui/, examples/scenes/ and examples/input/ has a
script, or a line in tests/e2e/pending.txt — a list that may only get shorter, and has
nothing left in it.
Every
other area of examples/ is named in the test with the reason it is not played — an ad
shows only on Android; the loading example's keys only play a sound, in a run with no sound
device; the platform examples are Android's own API, or never run at all; and the plain C example
has none of the seams the driver plays a game through — so a new area is a decision and not a
gap. Every shot has its picture and every picture a shot that takes it, and the build
refuses a script that plays no example.
Every script plays a way through and a way to fail: Pong lost and then won, and started again once with the mouse and once from the keyboard; Breakout's three balls lost, then its wall cleared; the platformer's world played to the flag, then every life lost to a fall; every screen of the menu example, with the keyboard, the gamepad and the mouse.
A script that cannot do what a player can is news about the example, and these have found what
no boot could.
Pong's
arrow keys moved both paddles.
Breakout
could not be won: its ball sped up 3 % a bounce and was four times its serve by the thirtieth
brick, faster than the paddle could follow, so its speed_up is 1.01.
In
Space Invaders the formation sped up without limit as it thinned, and the last alien came down
before a ship could get under it; it stops at four times the pace it starts at.
Drawing
the platformer's bats under the sanitizers — its bot plays the levels without drawing them — found
raylib's software renderer reading one texel past a texture at its far edge, which the framework
fixes in its copy of raylib.
The interface examples' scripts found the settings screen's Apply button and half of the style page below the bottom of their own window, a list whose focus walked out of sight, a tap on a button that reached the game underneath as well, and the menu and inventory examples reading Escape and the mouse from raylib, where no script and no gamepad could press them.
Sanitizers#
A
test asserts what it can see, and undefined behaviour is what a test cannot see: a signed overflow
that wraps to a harmless number, a read one past the end that finds a zero. So every debug build of
the framework — the library, every example and every test — runs under AddressSanitizer and
UndefinedBehaviorSanitizer, with LeakSanitizer on Linux, because the framework's own
[dev] sanitize lists both;
every report is fatal. The unit tests, the layout test, the render stage and the smoke stage all
run that way, and the boots read the report as well as the exit status. In CI those jobs set
RMP_REQUIRE_SANITIZERS=1, so a runner whose compiler cannot instrument the build fails
it instead of testing nothing in silence.
That
run is clang's, the framework's development compiler. rmp test sanitize builds the unit
tests and the headless layout test again with gcc, in a build directory of their own and with
warnings as errors: the second compiler instruments differently and warns about other things.
In
CI it is a step of the deep job, below. The clang builds leave alone what
cmake/sanitize_ignore.txt lists, each line with its reason, and the list may only name
vendored code, never the framework's. tests/sanitize_test.cpp holds the whole
arrangement to what it promises: it runs a small program that leaks, overflows a buffer and
overflows an integer on request, and each one has to be reported.
What the tests reach#
A
test that never runs a line cannot find what is wrong with it. rmp test coverage —
kept out of the plain rmp test, because it builds every test again — builds the unit
tests, the headless layout test and tests/input_play.cpp, the one program that drives
the real desktop runner, with clang's source-based coverage, in a debug build of their own and
without the sanitizers, which say nothing about which lines ran. It runs them and reads, line by
line, which lines of src/rmp/ ran.
The
tests link the whole framework library for this, and not only the parts they call, so a file no
test reaches is in the report at 0% instead of missing from it.
Two lists hold the result, and each moves one way only:
- A floor per file, which only rises
tools/coverage_floor.txthas the share of each file's lines the tests run, rounded down. A file below its line fails. A file two points or more above it fails too, until the line is raised in the commit that earned it: a ratchet nobody has to remember to turn is one that does not stall. A file ofsrc/rmp/with no line fails, and so does a source file the report does not hold, unless it has no code of its own. The floors run from 39 —src/rmp/ui/render.cpp, which draws through raylib, where the headless tests do not look — to 100.- The public functions no test calls, a list that only shrinks
tools/untested_api.txtnames every function ofinclude/rmp/a game can call and no test does — one,rmp::Object::_draw(). clang reads the headers to find them, and a template counts as called when any instance of it runs. A new public function no test calls fails: write the test. A listed one a test calls, or one that is gone, fails until its line is removed.
Which
lines a compiler counts, and which tests a machine can run, differ between machines, so both lists
were measured inside the pinned build image and are gates only there; anywhere else they are
printed. Inside it, the tests that skip on a machine without a sound device or the test locales may
not skip. bash tools/coverage_check.sh --update, in the image, raises the floors and
drops what is called; it never lowers a floor or adds a function, which is an edit somebody writes
by hand and a reviewer reads. Lines no test can run — a GPU, a store — go between two comment lines
and are counted apart, and the first of them has to say why:
// RMP_COVERAGE_OFF(<why>)
...
// RMP_COVERAGE_ONBefore any of that, the script builds, runs and reads back a program of two functions, one called and one not, and fails — never skips — when clang's profile runtime is missing or its tools come from another release of LLVM: a coverage run that measured nothing would print every floor as a note and pass.
The gates#
The rest of rmp test is checks on the repository itself — each one written after
a mistake that could be described precisely enough for a machine to reject it:
| Stage | Fails when |
|---|---|
fmt | a file is not formatted the way .clang-format says |
config | the .toml is invalid, a pinned version disagrees with the file that controls it, or a vendored component's licence is not on record |
repo | something a build produced is tracked by git |
seam | a file of the framework reads the clock, the input devices, the screen size or raylib's random state on its own |
workflows | a reusable CI workflow asks for a permission its caller does not grant, or a step throws a build's output away, which is where the compiler's error is printed |
portable | a script uses something macOS's old bash or the BSDs do not have, or the BSD jobs' inline script is not plain ASCII |
shell | a script writes A && B || C, which runs C when B fails |
naming | a name breaks the naming rules in any branch of any #if |
style | a rule of the style guide that clang-tidy cannot see is broken in any branch of any #if: a C cast, NULL, a TODO, something newer than the oldest compiler a game is built with, a user-defined literal, i++ where ++i says the same |
ownership | the framework allocates or frees memory by hand, or calls a raylib Load* or Unload* outside the file that owns what it makes |
pointers | a declaration a game can name has a raw pointer or a C string in it — Pointers and RAII says what goes there instead |
cppcheck | cppcheck, a second static analyser with its own reading of the code, finds anything in src/rmp, or a suppression of one has no reason or no longer matches anything |
headers | a public header does not compile on its own, or lacks the .toml values |
cost | a public header's preprocessed size moved away from its budget |
gates | a check above stops failing on the mistake it exists for — each runs on a copy of the tree with one planted in it |
configure | tools/configure.py accepts something it should refuse, or the other way round, or the suite itself leaves a file the checkout generated changed |
rmp | the rmp command itself misbehaves — including when a file the framework tracks has not been classified as part of a new game or not |
binaries | the readers that judge a shipped .exe and Mac binary misread one — above |
size | tools/size_budget.txt lacks a line for a binary an enabled target ships, has one for a binary nothing ships, or gives a packed size where [upx] packs nothing, or the other way round; or the reader behind it misjudges a size — Continuous integration says what the budget holds |
Commands has the full list of stages with the
summary rmp help test prints for each.
In CI#
A push to the framework runs every stage of rmp test that checks something — all but
the two that record a golden, and the one that takes hours — in its lint job, or in a
job of its own: examples, which builds and boots every example, e2e, which
plays the ones with a script — the two halves of rmp test examples —
coverage, which measures what the tests reach, and deep, the short runs
of the deep tests:
the
properties of rmp test property, RapidCheck's at a fixed seed and Hypothesis's
derandomized; rmp test fuzz, every input committed for a fuzz target replayed under
the sanitizers; and rmp test sanitize, above.
The
one that takes hours is rmp test mutation, Mull over the C++ and mutmut over the
Python, each module against a floor that only rises,
which
.github/workflows/deep.yml runs every Sunday, a job a module.
A
test of the command checks each stage, and each half of one, against the job that runs it.
clang-tidy,
which is rmp lint and not a stage, has a job of its own too, tidy.
What
a push runs of the deep tests is the same on every run — the same seeds, the same inputs — so that
a red is the commit's and never the dice's. The search is deep.yml's: every night it
fuzzes each target for ten minutes and runs the properties at a random seed, and what it finds
becomes an issue labelled nightly-finding, one per signature, with the command that
plays it again.
Like
the canary, it runs only in the framework's own repository.
Each
of these starts as soon as the configuration is read, beside the others and beside the platform
builds, so the run takes as long as its longest job rather than their sum. The same push
makes a new game with rmp new and runs that game's own checks, follows the recipe at
the top of examples/plain_c/src/main.c in a copy of that game, boots the result and
starts its release from the project folder and from another, checks this documentation site
against the commit, and builds the fast lane: Linux x64, the web, Android and Windows x64. A
release tag builds every target, and so can a run started by hand.
A
release of the framework waits for all of it: clang-tidy, the examples and their scripts, the new
game, the coverage, the short runs of the deep tests and the documentation as well as every
platform. The Linux jobs run
inside a build image pinned by digest, with every compiler and tool already in it, so a build does
not depend on a download succeeding.
The framework's own changes are checked in three sizes of run. They are pushed two pieces of work at a time, so that one fast lane covers both. When that run is red, the fix is checked on a debug lane: a run started by hand for exactly the platforms involved — Linux, Windows and macOS, with Android or iOS only when the bug is there — and every one of the framework's own jobs beside them:
gh workflow run ci.yml -f targets=linux-x64-glibc,windows-x64,macosThe full matrix of every target, about twenty minutes, runs once, when a whole piece of work is done — and on every release tag. A failure on a BSD after a green fast lane is a bug of that platform, fixed on its own.
The sanitized debug builds CI boots are drawn by raylib's software renderer, which links no window system and no graphics driver — all but one. The smoke stage runs once more in the job that boots the examples, under a virtual X display with Mesa's software OpenGL: a sanitized debug build that opens a real window, where LeakSanitizer meets the system's own libraries when the game exits.
The BSD builds run inside virtual machines, and a script that stops early can still exit 0 in one. So the check that ends the script writes a file once it has reached its verdict, and the step after it fails if the file is not there: nothing inside a script can catch its own early exit.
In your game#
A
game made with rmp new has the same command, and runs the stages that make sense for
a game:
rmp test
rmp test unit
rmp test smokeconfig- The game's
.tomlthroughconfigure.py --check, the pinned versions, and the licence record: a library added tothirdparty/without its row inTHIRD_PARTY_LICENSES.mdfails here. See Licences. unit- The game's own tests, in
tests/game/, built with the game and run with no window: below. With no.cppin that folder the stage has nothing to check, and says skip nothing matches tests/game/*.cpp instead of failing. render- The game built against the software renderer, booted for ten frames, and checked for a clean boot, pixels on the screen and a clean exit. A game has no golden hash: its title screen is its author's to change.
smoke- The game built the ordinary way and booted with a frame budget, which must report every asset loaded and a frame drawn, and exit with status 0.
Both are debug builds, and a game's [dev] sanitize is [] until it lists
a sanitizer: with one listed, a report fails the stage the way it does in the framework. See
Configuration.
A game's CI runs the same stages in its own lint job, and builds its targets the
way the framework's does. The framework's own tests stay with the framework: they test the
framework, and a game is built on one that has passed them.
The game's own tests#
A
game made with rmp new has a folder for tests of its own, tests/game/,
and starts with one in it. Every .cpp there is built, with doctest, together with
every .cpp and .c under the game's src/ but
main.cpp and the framework's src/rmp/, into one program,
game_test, linked to the framework library. main.cpp stays out because
RMP_GAME there is the game's main(), and doctest brings its own: a test
file holds test cases and nothing else, and includes a scene the way src/main.cpp
does.
// ---------------------------------------------------------------------------
// Your game's own tests. Every .cpp in tests/game/ is one, and holds
// TEST_CASEs and nothing else: doctest brings the main(). `rmp test unit`
// builds them with your src/ -- every file in it but main.cpp -- and runs them
// with no window, and CI runs them on every push. Delete tests/game/ and
// neither asks for them again.
//
// rmp test unit build them and run them
// ./build/debug/game_test -tc="*menu*" one case, by name
//
// With no window there is no GPU: a texture comes back empty and a frame
// draws nothing, while files still load and your code still runs. What a test
// drives is what the framework takes in through a seam -- time is the delta
// you hand a hook, the dice are rmp::random::seed(), the devices are
// rmp::input::detail::DeviceState -- and what it reads is what your code
// keeps. Drawing is the boot's to check: `rmp test smoke`.
// ---------------------------------------------------------------------------
#include <doctest.h>
#include <rmp/assets.h>
#include "scenes/main_menu.h"
TEST_CASE("the main menu finds every file it loads") {
// A file renamed in resources/ and not in the code is a hole in the
// picture rather than a crash, so a game that boots can still be missing
// one. rmp::assets counts what it was asked for and what it could not
// read, and a scene's _ready() is where it asks.
const int asked = rmp::assets::requested_loads();
const int failed = rmp::assets::failed_loads();
MainMenuScene menu;
menu._ready();
CHECK(rmp::assets::failed_loads() == failed);
// A menu of yours that loads no file has nothing for this test to check:
// it says so, and passes. Test what your menu does instead.
WARN_MESSAGE(rmp::assets::requested_loads() > asked,
"the main menu loaded no file, so this test checked nothing");
}
It runs with no window, so there is no GPU: a texture comes back empty and a frame draws
nothing, while files still load and the game's code still runs. What a test drives is what the
framework takes in through its seams — the delta handed to a hook, the seed of
rmp::random, the input devices — and what it reads is what the game keeps. Drawing is
the boot's to check, in render and smoke.
rmp test unit
./build/debug/game_test -tc="*menu*"rmp test unit builds the program and runs every case; the program itself takes
doctest's options, such as one case by name. The game's CI runs the same program in its
lint job. Delete tests/game/ and neither asks for it again: the stage
and the job both say there is nothing to run, and pass.