Skip to content

Testing ​

A miscompile rarely crashes. More often it makes a bubble pass through a wall in round 37, and only sometimes. That is why dampf compares everything it builds with a reference from the start: this page shows how its code is checked against what clang computes on the PC, which test layers do it, what each one catches, and how you run them.

The principle ​

Every test program has a reference result: the same C source compiled by clang on the PC and run there, the PC build. dampf's result must match it bit for bit, because that is the promise dampf makes: the same source behaves the same on both sides. gcc and clang give the same results for the subset on x86-64, so clang's result is gcc's as well; the tests take clang because gcc's bounds sanitizer reported indexes that a program never computes.

Each program is built for the SNES twice, once by the naive code generator and once by the code generator from MIR. Both ROMs run, and both must give the PC's values. The naive code generator does almost everything in 32-bit int, as C's promotions say, and has none of the optimizer's cleverness; it stays in dampf as an independent reference, so a difference between the two points at the optimization that caused it.

The program also runs on the level of MIR in between: dampf's MIR interpreter (dampf.mir.Interpreter) executes it once straight after the lowering from the AST and once after all the optimizer's passes. A wrong lowering or a wrong pass shows up there, before any 65816 code exists. The verifier (dampf.mir.Verifier) checks the MIR after the lowering and, in the optimized run, after every pass. Every value the interpreter computes, and every parameter's value on entry to its function, must lie within the value range dampf inferred for it (Ranges.checker). A DAMPF_RANGE hint that does not hold stops the interpreter with "a hint does not hold", and a load or store outside the global or frame slot its address is based on stops it with "an access outside its object".

On the PC side, clang builds the program twice. The first build uses UBSan, the undefined behaviour sanitizer: extra checks in the code that stop the program when it overflows a signed int, shifts too far, indexes outside an array or divides by zero. It is built with -O0 -fsanitize=undefined -fno-sanitize-recover=all and must run without a report. The second build, with -O1 and without the sanitizer, gives the values. Without the check, a test program whose result depends on undefined behaviour could pass by chance on the PC and fail on the SNES, or the other way round; with it, such a program fails the test.

What is compared are the globals after the entry function has returned. The runtime writes to $21FB at that point, and the test reads every global from memory. Arrays and structs are flattened into their scalar elements (a[2], s.x), and each must have the same value on both sides. Pointers are left out, because their values are addresses that differ between PC and SNES, and so are constant objects in ROM.

The layers ​

Execution tests are small C programs in compiler/src/test/resources/exec/, each written to exercise one area: 8-bit wrap-around, calls, pointers, banks, 32-bit arithmetic, tables in ROM. ExecutionTest runs each one on the PC with clang, in the MIR interpreter before and after the passes, and as two ROMs in dampf's emulator, one per code generator. When Mesen is available, the ROM of the naive code generator also runs there. Every run must give the PC's globals.

Three of the programs test C in interrupt handlers (DAMPF_INTERRUPT): an NMI handler, run at the start of every vertical blank, and an IRQ handler, run at a line the program sets, while the main code computes (interrupts.c); helpers called from the main code and from both handlers, which dampf compiles once for each (context_copies.c); and the data a tick publishes for interrupt code (published.c). On the PC, which has no interrupts, the program calls its handlers itself. Such a program skips the MIR interpreter, which has no interrupts and no hardware registers, and in Mesen its ROM from MIR runs too, since an interrupt can come at any instruction.

The ROM of the code generator from MIR also checks dampf's static timing. dampf computes a best and a worst case in CPU cycles for every function, and in the emulator test_main as a whole, and every call of every function and runtime routine on the way, must take between the two (Timing.check). A call is measured from its first instruction to the instruction after the JSL that called it, without the cycles of interrupts that came meanwhile; each interrupt is measured against bounds of its own, from the moment it is taken to the end of its RTI. A third ROM from MIR lays the blocks out by arbitrary block counts (a third of the blocks "never ran", as --block-counts would take them from a profile); it must give the same globals and keep the timing too, since a profile may change only the order of the blocks.

Random programs come from two generators that write programs within the subset. The programs are free of undefined behaviour by construction: divisors are made odd, shift counts are masked, wide arithmetic is done in uint32_t, where overflow wraps. Values at the edges of the types, such as -32768, 255 and 65536, are chosen often, because that is where sign and overflow handling go wrong.

  • RandomProgram (version 1) writes ten global variables of the six integer types from int8_t to uint32_t, and thirty statements of assignments, if, short for loops and expressions with every operator. Every build runs seeds 1 to 50, always the same programs.
  • RandomLoopProgram (version 2) writes what the optimizer's loop and pointer passes work on: global arrays of bytes, words and a small struct, and a local array; counted loops with every counter type, up and down, steps 1 to 5, the tests <, <=, >, >= and !=, as for, while and do, with up to 300 rounds, constant, global and local bounds, break and continue, nested, and pair loops; helper functions, small ones that are inlined and large ones that are not, with pointer parameters that get one array or one of two; pointer walks and switch. A loop is made from the values its counter takes, so it always ends and its counter never wraps; an index is a counter shifted into the array's bounds or an expression taken modulo its length; calls are whole statements, so no result depends on the order in which C evaluates operands. Every build runs 50 seeds starting at LocalDate.now().toEpochDay() * 1000, so every day tries new programs.

RandomProgramTest runs both with the same steps as the execution tests, the timing check included, but without the ROM laid out by block counts and in dampf's emulator only. A failure names its seed and the command that runs that program alone (-PrandomSeed=S -Prandom=1), and prints the program. dev/bisect_passes.sh with that command names the pass that broke it. Before a release, dev/random_soak.sh runs 5,000 programs of each generator, in shares that run at once.

The preprocessor of dampf is checked against clang's. PreprocessTest has the examples of the C standard (C99 6.10.3.5), the arithmetic of #if, includes, line markers and the features the subset rejects. OracleTest runs every C file dampf compiles in the repository (the test programs, the examples, lib/snes) through dampf's preprocessor and through clang -E: both must give the same tokens, each at the same file and line. RandomMacrosTest does the same with 300 random macro programs from RandomMacros in every build: macros calling macros, macro names as arguments, self-reference, # and ## with empty arguments, variadic macros, invocations over several lines, #if with defined. There a token may stand at a later line than clang's, because after an invocation or a comment over several lines clang keeps the rest of the line where it began, while dampf, like gcc, puts each token at its own line.

The examples are the small games of the dev kit in examples/. ExamplesTest builds each one for the SNES with the code generator from MIR and plays the input of its check.txt in dampf's emulator, through the kit's own main loop. Where raylib was fetched, the same input is played on the desktop as well, on Rachael with gcc's code. After every tick both sides compute a checksum of the game's state: the bytes the game names with sdevkit_dbg_hash from the end of one game_tick to the end of the next. The kit names nothing itself, so each example names its sprite table and what its next picture depends on. The two lists must be the same, so dampf's code and gcc's, lib/snes and Rachael computed the same game tick for tick; the test names the first tick that differs. On the SNES the call only writes the address and size of the memory to a port ($21FC), and the emulator reads and hashes it, so the check costs the game about 80 cycles a call. The sound is compared too: what game_init uploaded into the audio RAM, and every write to the sound chip's DSP that the kit's driver made in the emulator must be the one Rachael's DSP got, in the same tick.

Where Emscripten's emcc runs, raylib was fetched for the web and Playwright is installed in tools/web_check, each example is also built for the web and its check played in headless Chromium. The web's main takes --check like the desktop's; tools/web_check/web_check.js writes check.txt into the page's file system, runs main and copies the results into the example's build/web-check. The test compares them with the SNES's as it compares the desktop's, so emcc's WebAssembly, with its 32-bit pointers and long, computed the same game as gcc and dampf. The check has no window: the browser's frames and the clock that steps the game by them are not part of it. The web takes about two of the five minutes the examples take.

Two programs of the kit's tests, not examples, are played the same way on all three. PublishedDataTest plays dev/publish_check, whose tick publishes data for interrupt code (sdevkit/publish.h); on the SNES the kit's NMI and an IRQ that comes on every line of the vertical blank and the tick in turn read that data and check it. Its checksums name what the interrupts found, so they match the desktop's and the web's, which have no interrupts, only when no interrupt on the SNES ever found torn data. IrqCheckTest plays dev/irq_check, whose IRQ splits the screen twice with values the tick publishes, with short ticks, long ones and ones longer than two frames. Where Mesen and the desktop's build are there, it also plays the ROM in Mesen and compares its pictures with the desktop's pixel for pixel: a register the handler writes too late shows a torn row on the SNES only. Two altered copies of the game must fail the desktop's check: one whose handler writes before sdevkit_irq_wait_hblank, and one whose vertical blank changes something when the NMI runs it again during a long tick.

ModesPictureTest does the same for the example examples/modes, which shows every picture mode Rachael draws: modes 0, 2, 3 and 4, offsets per tile, direct colour, mosaic, mode 7's EXTBG, and VRAM, CGRAM and OAM read back. Where Mesen and the desktop's build are there, its eleven pictures in Mesen must be the desktop's pixel for pixel. A mode drawn wrong shows there only, since dampf's emulator draws no picture.

The emulator's run also writes the frames per tick to the example's build/emu-check/frames.txt (on average and over the slowest 60 ticks) and the master cycles of every tick to ticks.txt there. They come close to Mesen's figures but are not equal: dampf's emulator charges a general DMA its 8 master cycles a byte, but HDMA nothing. A line budget T1 T2 in check.txt turns this into a measured budget: the test fails when a tick from T1 to T2 - 1 took more than a frame. Er-Tüp's budget covers its busiest waves. To see where that time goes, dampf.emu.ExampleProfile plays the same input in dampf's emulator and charges the cycles of a range of ticks to the functions of the ROM, and, with the ROM's .dbg file beside it, to its C lines, including the lines of functions dampf inlined.

Recordings. Every session in the desktop's window is recorded: the joypad and the checksum of every tick. F11 saves it in the format of check.txt, with mark and hash lines that the other players skip, so a bug seen on the desktop can be played again: in the window with --replay, which pauses at the marks and at the first tick whose checksum is not the recorded one, and on the SNES side, with dev/replay.sh in dampf's emulator for any ROM and with dev/replay_example.sh for an example, in dampf's emulator and in Mesen. Given two more file names, dev/replay.sh also writes the ROM's checksums and sound in the formats of the desktop's --check, so a game can compare them with its desktop build using the kit alone. When the ROM from MIR differs and the naive one does not, dampf.emu.RomDiff good.sfc bad.sfc recording.txt plays both and names, tick by tick, the globals that differ. ExamplesTest writes every example's check as a recording too (--record), on the desktop and on the web, and requires the same buttons and the SNES's checksum for every tick in it.

The static timing on the examples is checked by ExamplesTimingTest. It builds every example with the code generator from MIR and runs it for 3,000 frames without input in dampf's emulator: the titles' demos play, Mandelbrot computes, Schach plays. Every call of every function is measured, from its first instruction to the instruction after the JSL that called it, and each must lie between the best and the worst case dampf computes for that function, as the execution tests do for their programs. The test fails as well when an example makes fewer than 1,000 calls in that time. It takes about 20 seconds.

The reference functions are hand-written assembly versions of functions of the examples, in reference/, kept as the yardstick for dampf's code: today Er-Tüp's random16 and sine. ReferenceFunctionsTest builds each example that has some with the code generator from MIR and all its reference functions linked in place of the compiled ones (--replace). That build runs each of them against its C body as dampf compiles it, the check every function written in assembly with DAMPF_ASM gets, and the test prints the cycles of a call, by hand and by dampf. Then the example plays its check.txt in dampf's emulator, and every tick's checksum must be the one of the example's normal build. The check itself is tested too: the execution test asm_functions.c calls functions written in assembly with 8-, 16- and 32-bit and pointer parameters in both code generators, and AsmDeclarationTest makes sure the check finds a wrong result, a wrong write to memory and a loop bound in a comment (; dampf: at most N) set too low.

The examples' benchmark (dev/bench_examples.sh) builds every example that has a check.txt, with the options you give it for dampf build, plays the check in dampf's emulator (dampf.emu.ExampleBench) and measures the work of each tick: its master cycles without the time the main loop spends waiting for the next frame. An example that does the same work every tick, such as Mandelbrot, so shows a faster compiler as less work, not as fewer frames. The work includes the DMAs the game starts, at 8 master cycles a byte; until 2026-11-25 a DMA took no time in the emulator, and the kit's copy of the whole sprite table in every vertical blank went uncounted. The table has one line per example: the work per tick on average and in the busiest 60 ticks, and the share of it in dampf's runtime routines (multiplication, division, shifts by a variable). With BASELINE= and an earlier table it adds the ratio to that table per example and their geometric mean, so an optimization or a tuned parameter is judged on all examples, not on one program. On 2026-11-20, before the runtime's multiplication moved to the CPU's multiplier, the naive code generator did three times the work on the geometric mean, between 1.3 times (Mandelbrot, whose time was the runtime's multiplication) and 6.4 times (Er-Tüp). A game outside the repository measures itself the same way, with dampf.emu.ExampleBench rom.sfc rom.lbl recording.txt. With a fourth argument, work.txt, it also writes the work of every tick, one line tick cycles each.

Two scripts play the examples in Mesen, which has the SNES's graphics chip (the PPU) that dampf's emulator lacks. dev/check_example.sh plays an example headless with the input of its check.txt, saves screenshots and the checksum of every tick, and counts every byte written to VRAM, CGRAM or OAM outside a vertical blank, the pause between two pictures. The PPU drops such a byte, so the script fails when the count is not 0. dev/compare_example.sh plays an example in Mesen and on the desktop with the same input and compares the checksums of every tick and the screenshots, pixel for pixel.

Until 2026-11-19 a copy of Blubber Blasen's code was a layer of its own, with its benchmark, its recorded games and the static timing checked on every call of the benchmark; the examples took those jobs over when it left the repository.

Next to these layers are tests of single parts: front-end tests such as ParserTest and AstBuilderTest, and pass tests written as MIR text, such as NarrowTest, GvnTest and InlineTest. The text format they use is described on MIR. MirTextTest prints the MIR of every execution program and of every example, parses it back and checks that it verifies and prints to the same text.

BackendOutputTest freezes the output of the back end. It keeps a hash of the assembly and of the static timing for every execution test, 20 random programs and every example, with both code generators, and once more for Er-Tüp with its reference functions linked in. A change that only moves code must keep every hash; one that changes the code on purpose records new hashes with -PbackendOutput=update, which also keeps a copy of the assembly in build/backend-output-ref/ to compare against. Beside the hashes the same update writes the static worst case of every function of every example to compiler/src/test/resources/cost-baseline.txt: a hash says that the code changed, the diff of that file says which functions got slower. The same test reads every assembly file back as LIR, dampf's low-level representation (65816 code in basic blocks, written as ca65 source): printed again, it must give the same text, and the LIR verifier must pass. And it builds every ROM twice, with ca65 and ld65, the assembler and linker of the cc65 suite, and with dampf's own assembler and linker. The two images must match byte for byte, the label files must name the same addresses, and the debug files must say the same, whatever ids and order each file uses: the bytes of every line, the symbols, segments, scopes and C symbols (DbgMeaning). This is why you need ca65 and ld65 to develop dampf, but not to use it. LirTest checks the blocks, printer, parser and verifier of LIR on small hand-written pieces.

StyleGuideTest measures the speed rules of the C style guide, lib/C_STYLE.md. Each rule is a C file in compiler/src/test/resources/style/, named after the rule, with a pair of functions that compute the same thing two ways and a first comment that states the claim, such as claim: sum_u8_counter slower sum_u16_counter. The relation is slower, faster or same, where same means within 5 %. The test builds each file with the code generator from MIR and compares the worst cases of the two functions in the timing report. The program must also give the PC's globals in dampf's emulator, so a fast form that changes the meaning cannot get in, and the measured cycles must lie within the static timing. A claim that no longer holds fails the build: the rule changes or goes in the same commit as the change to dampf that broke it. The table of measurements in the guide must be what the test measures.

SpellingTest checks that the same work, written the ways a programmer would write it, costs the same. Each file in compiler/src/test/resources/spelling/ is a family: its functions without parameters are its members, with an optional setup and check. A generated test_main runs every member on the PC and on the SNES, and every member must give the same result. Then the test measures the CPU cycles of one call of each member in dampf's emulator: a member may cost at most the family's tolerance (in percent) more than its cheapest member, unless a gap: line names it with the cause and the step of the plan that should close it. A change that closes a gap fails the test until its line is removed, so the list of gaps only shrinks.

Three more tests keep the documents of the dev kit true. LibCostTest builds a program that calls every function of the console API, the calls a game makes to the dev kit's library, and checks their best and worst cases against the table in lib/README.md. SnesHardwareGuideTest checks the feature table of the guide to the SNES hardware, lib/SNES_HARDWARE.md, against lib/snes and against Rachael in lib/rachael. RachaelTest checks that Rachael counts the register writes she does not draw and the writes the SNES would get while the picture is drawn, that her ports remap VRAM addresses and read VRAM, CGRAM and OAM back by DMA as the SNES does, and runs her renderer's tests in C: small scenes, rendered and checked pixel by pixel. Like StyleGuideTest, each fails when its document is no longer true.

SplashTest checks the course of the splash screen every game of the dev kit starts with, the same code on every platform (lib/splash/splash.h). Without a button it fades in for 31 frames, stays for three seconds (180 frames) and fades out for 31. A button pressed while it fades in or stays ends it once it has faded in, without the fade out. The test builds a small program on Rachael with gcc that presses A in a given frame and checks how many frames the splash lasted and the brightness of its last frame: a press in frame 5 ends it after 31 frames at full brightness, a press in frame 212, when the fade out has begun, changes nothing.

dampf's emulator and Mesen ​

The SNES side of the tests runs in dampf.emu, a 65816 emulator in Java with LoROM and work RAM, the SPC700's boot protocol and the kit's sound driver, the time a DMA takes but not what it copies, and no graphics or sound output. Of the picture it has only the timing that the kit's main loop polls: the line counter, the vertical blank flag and the automatic joypad read, and it has the joypads. It has the interrupts: the NMI at the vertical blank and the timer IRQ at its line or dot, with their registers NMITIMEN, HTIME, VTIME, RDNMI and TIMEUP (InterruptTest). It counts the cycles spent inside interrupts apart, so the timing checks can leave them out. It also has the CPU's multiplier and divider. The multiplier adds one bit of its second factor per CPU cycle, lowest first, as on the console, so code that reads the product before the eighth cycle gets a partial product and fails here too (MultiplierTest).

The emulator exists for two reasons. It runs inside the JVM, so a test needs no external program and runs much faster than a ROM started in Mesen; that is what makes 100 random programs on every build affordable. And it counts master cycles with the memory speeds of the SNES (work RAM and SlowROM 8 per access, I/O 6, internal cycles 6, DRAM refresh 40 per scanline), so the same run that checks the results also measures the speed.

An emulator written for the tests is only worth something if it is right. It is checked in two ways:

  • The CPU against the SingleStepTests 65816 suite. For each of the 256 opcodes the suite holds random starting states, each followed by one instruction and the state after it. CpuSingleStepTest runs 300 of them per opcode in native mode and compares registers, flags, memory, the number of CPU cycles and the number of memory accesses. Emulation mode is modelled only as far as the start-up needs it.
  • The whole machine against Mesen. On Blubber Blasen's benchmark, while the game's code was here, both gave the same checksums on all 3,610 ticks and the same master cycles per tick within a few cycles out of millions. On the check of every example they give the same checksum after every tick. For the multiplier, the runtime's multiplication with one cycle less of waiting gives wrong products in both. On exec/interrupts.c, whose handlers check the line they run on, both take the interrupts on the same lines; Mesen showed that a write of VTIME that makes the current line the IRQ's fires it at once.

In the Gradle tests, Mesen runs only for the execution tests and for the pictures of IrqCheckTest and ModesPictureTest, and only when it is there: when .mesen/ in the repository holds one (it is not in git) or -Pmesen names one. dev/fetch_mesen.sh puts MesenCE there, the Linux build Mesen and the Windows build Mesen.exe, both portable and with the settings the tests need; Gradle takes .mesen/Mesen when it exists, else .mesen/Mesen.exe. MesenRunner starts it headless (--testrunner) with a Lua script that waits for the write to $21FB, reads the globals and writes them to a file. It works with the Linux build, whose libraries it takes from .mesen/lib when that folder exists, and from WSL with the Windows build. IrqCheckTest and ModesPictureTest play their ROMs there with dev/check_example.sh. On the SNES side, the random programs, the examples, their timing and reference functions, and the examples' benchmark run in dampf's emulator only.

The scripts dev/check_example.sh and dev/compare_example.sh start Mesen themselves. Each takes the Mesen that MESEN names, else .mesen/Mesen, else .mesen/Mesen.exe (dev/mesen.sh).

Running the tests ​

./gradlew build compiles dampf and runs every test that needs no property: the unit tests, the execution tests (in Mesen too, when .mesen/ exists), 50 random programs of each generator, the preprocessor's tests with 300 random macro programs, the examples, the static timing on the examples, the reference functions, the check of the back end's output and the tests of the guides. The rest is switched on with Gradle properties:

CallWhat it does
./gradlew buildbuild and run the default tests
./gradlew testthe default tests only
./gradlew test --tests dampf.exec.ExecutionTestone test class
./gradlew test --tests dampf.exec.ExecutionTest -Pexec=<name>only the execution test of <name>.c
./gradlew test -Pmesen=<path to Mesen>execution tests and the pictures of IrqCheckTest and ModesPictureTest also in this Mesen instead of the one in .mesen/
./gradlew test -Prandom=<N>N random programs of each generator instead of 50
./gradlew test -PrandomSeed=<S>random programs of both generators from seed S on (default 1, and today's for RandomLoopProgram)
./gradlew test -PppRandom=<N>N random macro programs instead of 300
./gradlew test -PppSeed=<S>random macro programs from seed S on (default 1)
./gradlew test -PoptLimit=<n>at most n pass applications (dampf.util.PassLimit); the variable DAMPF_OPT_LIMIT does the same
./gradlew test -PtestForks=<n>n test JVMs at once instead of one per core and at most 4; 1 runs the classes one after the other
./gradlew test --tests '*BackendOutputTest' -PbackendOutput=updaterecords new hashes of the back end's output and copies its assembly to build/backend-output-ref/
STYLE_GUIDE=update ./gradlew test --tests dampf.exec.StyleGuideTestwrites today's measurements into the table of lib/C_STYLE.md
LIB_COSTS=update ./gradlew test --tests '*LibCostTest'writes today's best and worst cases into the table of lib/README.md
./gradlew test -PcpuTestsalso the emulator against SingleStepTests, 300 tests per opcode
./gradlew test -PcpuTests=<N>the same with N tests per opcode
./gradlew test -Pcoveragealso measures code coverage with JaCoCo; the report is in build/reports/jacoco/test/html/index.html (and as XML), without the parser ANTLR generates
./gradlew pmdMain pmdTestPMD's checks with the rules in config/pmd/ruleset.xml; reports in build/reports/pmd/; findings do not fail the build
./gradlew cpdcopied code in compiler/src/main/java (PMD's CPD), from 100 tokens on; report in build/reports/cpd/main.txt
./gradlew cpd -PcpdTokens=<N>the same from N tokens on
dev/random_soak.sh [count] [first seed]a long run of random programs, 5,000 of each generator by default, in shares at once (JOBS=n: at most n)
dev/bisect_passes.sh <command>runs a check command with smaller and smaller pass limits and names the pass application that breaks it
dev/bench_examples.sh [options]the examples' benchmark: the work per tick of every example, built with these options for dampf build
BASELINE=<table> dev/bench_examples.shthe same, and the ratio to an earlier table, per example and as the geometric mean
dev/check_example.sh <name>an example in Mesen: lost bytes, screenshots, checksums of every tick
dev/compare_example.sh <name>an example in Mesen and on the desktop: checksums of every tick and screenshots compared
dev/replay_example.sh <name> <recording>a recording of the desktop on the SNES side, in dampf's emulator (WITH_MESEN=1: in Mesen too): the first tick whose checksum differs

The first run with -PcpuTests downloads the start of each opcode's file of the suite, about 50 MB, into ~/.cache/dampf/65816-tests; later runs use the copy. Without a property, the tests that need one are skipped, not failed. A random program that failed runs alone with the command its message names, such as ./gradlew :compiler:test --tests 'dampf.exec.RandomProgramTest.loopProgramsMatchGcc' -PrandomSeed=<S> -Prandom=1. With a pass limit, the tests' emulator allows 6,000 frames, since code without the passes is up to ten times slower, and the execution tests pass with any limit.

Coverage, PMD and CPD are not part of ./gradlew build. JaCoCo is off by default because it slows down the tests that run the emulator, and PMD's findings are there to be read, not to stop a build. All scripts in dev/, with their arguments and variables, are listed in dev/README.md in the repository.

The test classes run in several JVMs at once, one per core and at most 4, since each may take 2 GB of memory. So a test class that writes files writes them where no other class does: into a temporary folder of its own, or into a folder only it uses, such as build/backend-output or an example's build/timing/ and build/reference/. The one exception is an example's build/gen/, which every class that compiles an example converts again: the conversions replace each file atomically (superdevkit.AtomicWrite), so a class compiling from it never reads a file half written.

Every pull request is built on GitHub Actions (.github/workflows/build.yml), and it is merged only when that build passes. The build runs ./gradlew build on Ubuntu with JDK 25, the runner's C compiler, clang, Python 3 and Node.js, and ca65 and ld65 from Ubuntu's cc65 for BackendOutputTest. Mesen, raylib, Emscripten and Playwright are not there, so the execution tests run in dampf's emulator only, ExamplesTest plays the SNES side only, and the tests that need the desktop's or the web's build skip, such as DesktopIsolationTest.

Adding an execution test ​

An execution test is a C file in compiler/src/test/resources/exec/ with globals and a function test_main, which is the entry function on both sides. It needs no output and no assertions: the globals it leaves behind are the result. A comment at the top says what it tests. A test of 8-bit wrap-around could look like this:

c
/* An 8-bit counter wraps at 256; the sum keeps counting in 16 bits. */
#include <stdint.h>

uint8_t lives = 250;
uint16_t score;

void test_main(void)
{
    uint8_t i;
    for (i = 0; i < 10; i++) {
        lives++;
        score += lives;
    }
}

ExecutionTest picks up every .c file in the folder by itself. For the PC side it writes a small harness that includes the file, calls test_main and prints every global, and compiles it with clang twice: clang -std=c99 -O0 -Wall with UBSan for the check, and clang -std=c99 -O1 -Wall for the values. It adds dampf's header directory with -idirafter, so a test can include <dampf.h>; clang searches that directory after its own, so <stdint.h> still comes from the PC. Both sides also find the kit's public headers in lib/include, so a test can include "sdevkit/publish.h", as published.c does. Here the PC prints lives 4 and score 1275, and the test passes when the MIR interpreter, both ROMs in dampf's emulator and, if present, Mesen all end with these values, and every call in the ROM from MIR stays within its static timing.

A test is only useful if its result depends on what it tests: a global that nothing writes stays at its initial value whatever dampf does. Deliberately broken code generation must make a test fail. Once it did not: a 32-bit arithmetic shift had high bits that no test looked at, and a test was added for them.

When something hangs ​

A test must fail, not wait forever. Every program test runs under a hard time limit (assertTimeoutPreemptively): 3 minutes per execution test, 2 per random program and 2 per MIR round trip, because JUnit's default timeouts do not cover the dynamic tests these are built from; StyleGuideTest has 5 for all its rules, and SpellingTest 5 per family. External programs (the C compilers, the PC builds, and ca65 and ld65 where the tests use them) run through dampf.util.Processes with a time limit and are killed when it runs out. The emulator stops after 600 frames in the execution tests, after 2,000 for a random program, whose naive code may need more, after 40 frames per tick of the check plus 2,000 in the examples' checks, and after 200,000 frames in dampf bench; the MIR interpreter counts its steps. The Gradle test task has an overall limit of 2 hours as a last resort. A program that loops forever fails in about a minute with "did not finish within 60 s and was stopped (does it hang?)".

Why it works this way ​

The naive code generator stays. dampf could have dropped its first code generator once the one from MIR was better. It keeps it as a reference that shares only the front end with the optimized path: when the two disagree, the difference points to the optimization at fault. The cost is a second code generator to maintain and every test program built twice (docs/testing.md, The principle).

An emulator of its own. Mesen is a complete SNES emulator and runs the execution tests where it is installed, but it is an external program and much slower to run a ROM in. dampf's emulator runs inside the JVM, so the random programs and the examples run on every build and the examples' benchmark runs without Mesen, and every run counts master cycles at the same time. The cost is a second emulator that has to be proved right, against the SingleStepTests suite and against Mesen (docs/testing.md, Supporting pieces).

clang with UBSan on the PC side. Without the sanitizer, a test program with undefined behaviour could give the PC's answer by luck, and a later change on either side would break it for no visible reason. With it, such a program fails at once, and the random program generators have to avoid undefined behaviour by construction. The tests used gcc until its bounds check reported an index a random loop program never computed, which failed every build of that day. Keeping gcc for the values and clang only for the check was turned down: it would mean two compilers where one does both jobs. The cost is that developing the kit needs clang; using it does not (docs/testing.md, The principle; ADR-6FD2DGP0 in docs/adr/).