Testing
Focused local feedback
For ordinary development, including AI agent work, run the smallest set of cases that covers the change. Do not routinely bootstrap or run full suites; documentation-only edits need no compiler build or tests.
graft task dev # prepare out/dev-jihoo; no tests and no runner build
graft task dev -- tests/run/basics.jh tests/fail/borrow_mut_twice.jh
# In an open graft develop shell, skip starting another shell:
python3 scripts/dev.py tests/run/basics.jh
The task builds out/dev-jihoo from the seed when needed, and builds
out/dev-runner only if tests are requested. Both builds use -O0
and the seed’s single-unit clang backend. Selected cases use the new compiler’s
ordinary runtime checks, ownership checks and effect attributes.
Name exact paths relative to the checkout: direct
tests/{run,test,fail}/*.jh and examples/*.jh files, or lib/ files
with #[test] functions. Helper modules, UEFI cases, and suite-wide checks
aren’t supported. The task runs with --cache in a deliberately clean,
pinned runtime environment; use the direct runner if you need specialized
environment settings. Runs are serialized per checkout, reuse private local
artifacts, and default to one allowed CPU (JIHOO_THREADS overrides the limit).
CI uses out/jihoo and doesn’t share the local task’s cache or CPU settings.
For a syntax, type, and borrow check without building a compiler:
graft develop -c jihoo check compiler/main.jh
Explicit suite and release validation
Run the direct runner from the checkout in the dev shell, where jihoo is
the seed and JIHOO_PATH is the checkout’s lib. The environment comes from
graft: Debian 13 packages and LLVM 23’s
release tarball (graft.graft, pinned for x86_64 and
aarch64 by graft.lock).
graft develop # the dev shell: `jihoo` is the seed, UEFI tools on x86_64
graft task bootstrap # seed -> stage 1 -> stage 2 (out/jihoo), same IR
graft task test # tests/runner.jh against out/jihoo, every suite
graft task test -- check fail # only checking and diagnostics suites
graft task test -- format # formatting and syntax preservation
graft lock --arch x86_64 --arch aarch64 # after changing graft.graft
For targeted use of the direct runner, JIHOO_TEST=maps filters by a
substring of the case path (unlike the local task’s exact paths), and
JIHOO_TEST_OPT=-O0 sets the optimization level for run cases. For example:
JIHOO_TEST=maps JIHOO_COMPILER=out/dev-jihoo jihoo run tests/runner.jh -- run
CI
.github/workflows/test.yml runs in the same environment, in two tiers:
- core, on every pull request: on x86_64, the bootstrap and the suites format, check, run, test, fail and lsp; with the seed, release, and dev script tests, a few minutes. This is what a pull request waits for.
- full, on every push to main and on pull requests with the
full-cilabel: on x86_64 and aarch64, every suite (examples, backend, selfhost and, on x86_64, uefi), and the benchmarks’ deterministic checks. A failure there after merging is fixed by a following pull request. Label pull requests that change the backend, the targets, threads, UEFI or the seed.
The runner
tests/runner.jh tests a compiler:
JIHOO_COMPILER, else compiler/main.jh built by the jihoo that runs
the runner. Its suites:
- format:
tests/format.pyformats the compiler, standard library, examples, tests and benchmarks into a temporary tree. It checks exact comment bytes, syntax trees with positions removed, idempotence, golden output,fmt --checkand rejection of invalid syntax. Emitted LLVM IR must agree before and after formatting on both targets for the compiler, runtime corpus and examples. Profile cases also check that spaces, line breaks and leading block comments do not change the freestanding attribute’s meaning.--external ../bananaadditionally checks that project’s source files and compares its entry point’s IR. Source files in the checkout and external project are read without modification. The files ofcompiler/andlib/must already be formatted (fmt --check); replace a file the suite names with the output ofout/jihoo fmt. Wrapping cases cover narrow widths, nested lists, comments, tuple and enum forms, and deterministic generated lists. A separate syntax-comparison fixture checks that return, call and index newlines and parameter modes remain distinct when positions are omitted. A 40-column golden and IR comparisons check the parameter, array and field layout together. - run: every file in
tests/run/is built and run, and its output compared.//> textlines are the expected standard output in order,// exit: Nthe exit status (default 0; a trap is 132),// args: a bthe program’s arguments, and// link: tests/ffi/native.cadds link inputs relative to the checkout. Thentests/differential.pyruns its fixed seeds. - check: every file in
tests/run/andexamples/passesjihoo checkwith LLVM, C compiler, linker and backend settings pointing to unavailable tools. Success is silent. Additional cases cover both targets, modules withoutmain, unresolved externals, rejected output/link/run options, and absence of generated files.tests/diagnostics.pyuses Python’s JSON parser to validate structured errors against the negative corpus and text diagnostics, checking both ends of source ranges, related notes, Unicode, invalid UTF-8, escaping and truncation. Python is supplied by the dev shell, not required by the installed compiler. - test:
jihoo testruns every file intests/test/, with the directives oftests/run: the expected output is the list of tests, failures and the summary, and// args:holds--and names. Modules they import are intests/test/lib. Every file oflib/with#[test]functions must then passjihoo test. The suite also runs the compiler unit tests withjihoo test -O1 compiler/main.jh. - fail: every file in
tests/fail/must not compile, and each// error: textmust appear in the error message and no// no-error: textmay. Checkedemit-mirandcheckmust report the same diagnostics, including whencheckruns withJIHOO_NO_ELABset. - examples: the programs in
examples/build and run. - backend: the C ABI (
tests/run/ffi.jhandffi_aggregates.jh) at-O0to-O3with both backends; an object withoutmain(emit-obj --lib) that C links, statically and as a shared library, with aggregate and 128-bit signatures; objects cross-compiled with no C compiler; link errors; and a missing LLVM. - selfhost: the compiler builds
compiler/main.jh, and the compiler it builds writes the sameemit-llvmoutput, errors included, for every.jhfile in the checkout on both targets (Self-hosting). - uefi: the programs of
tests/uefi, and those oftests/runthat need nothing UEFI lacks (files, processes, threads, arguments, dynamic libraries), are built as#![uefi]programs for x86_64, with their C link inputs compiled by clang forx86_64-unknown-windows, and checked to be PE images for the machine; some are also built for aarch64. GivenJIHOO_QEMU,JIHOO_OVMFandJIHOO_UEFI_SHELL, one QEMU boot runs them all: the UEFI shell runs astartup.nshthat writes each program’s standard output, standard error and%lasterror%to files, and the runner compares them with the//>lines and// exit:. Without those variables the programs are only built.
On x86_64 the dev shell sets them (QEMU, OVMF and the UEFI shell from Debian):
graft task test -- uefi
Unit tests of the standard library are #[test] functions at the end of
its files (out/dev-jihoo test lib/std/string.jh).
Add a tests/run program for every feature and every bug fixed, and a
tests/fail one for every error the compiler should give, in particular
every way the borrow rules can be broken.
For a tests/run fixture with // run-release, the run suite also compiles
and executes the same fixture with --release.
Incremental local runs
When explicitly using the direct runner outside CI, it also accepts
--cache, for example:
JIHOO_TEST=maps JIHOO_COMPILER=out/dev-jihoo jihoo run tests/runner.jh -- --cache run
--cache or JIHOO_TEST_CACHE=1 stores passing actions under
out/.test-cache. The runner keys an action by the compiler executable,
case and runner inputs, invocation environment, and a freshly resolved manifest. The runner batches cases with the same
loader flags using jihoo deps --manifest-batch, which shares source reads,
parsing, and hashing across those cases. Expected diagnostics can be cached when loading
succeeds. Cases with unresolved dependencies run normally. Explicit link
files are hashed, including the aggregate C fixture’s header.
Execution is eligible for skipping only for cases listed in
tests/cache-pure.txt, with identified toolchain paths. Keep that list
limited to programs with known build and runtime inputs. For listed
run and examples cases without extra link inputs, a matching build key can
reuse a previous pass even when the compiler executable has changed.
That key depends on the fresh LLVM IR and build recipe. The runner also
keys the prior result by the expected outputs, arguments and environment.
With --cache, compiler calls in check, fail, run, test,
and examples use the configured JIHOO_CACHE_DIR, or
out/.jihoo-cache if it is unset. Set it to an empty string to disable
compiler-cache reuse while retaining the runner cache. Fixed diagnostic
and differential checks can reuse passing results when their compiler,
toolchain and local checkout inputs match. This shortcut requires a direct
checkout compiler and JIHOO_PATH pointing to its single checkout library.
The default runner executes every selected case and clears inherited
JIHOO_CACHE_DIR. Backend and selfhost children always run with compiler
caching cleared. An incremental selfhost still builds stage 2, and batches
manifests by stage, target, and loader flags before checking previous passes.
Use the uncached invocation for CI and explicit full validation.
Differential testing
tests/differential.py writes random
programs of integer functions fK(a: i64, b: i64) -> i64: wrapping
arithmetic, bit operations, shifts, division by values that are never
zero (sometimes -1), conversions between every integer type, if,
match on ranges, for loops, arrays, a struct changed in place and
read through a method and a borrowing function, an enum matched with
bindings and a guard, Vec(i64) pushed, changed and iterated, closures
that capture the variables around them, a String grown and read,
generic functions instantiated at every integer type, f64 arithmetic,
%, comparisons and the math builtins (back to integers by a saturating
as or by their bits, every NaN as one value), Option matched,
Result through ?, while loops ended by break, a Map filled in
a loop, trait objects (Vec(dyn Op)) called through a default method,
std.sort, a variable changed through inout arguments, a generic
Pair(T) swapped through inout self, Box, and calls to earlier
functions.
Each function’s results on six inputs are computed three ways that must
agree: by a model of jihoo’s integer semantics in Python, by the
compile-time interpreter (a const table) and by compiled code, given
inputs it cannot know while compiling. Compiled code is built at -O0,
at -O2, at -O2 --release, and for the freestanding profile. Nothing overflows a checked operation, and
calls stay within the interpreter’s step limit. Programs are checked in
parallel. When JIHOO_THREADS is set to an integer, the differential
pool shares that budget across compiler processes.
The run suite checks 12 seeds; more find more:
python3 tests/differential.py --compiler out/jihoo --seed 1000 --count 500 --keep failed
python3 tests/differential.py --print --seed 1007 # the program of a seed
tests/run/float_libc.jh does the same
for float text: 20,000 floats from random bits, written by std.float
with an exponent and with fixed digits, must match glibc’s printf, and
the shortest text must read back through strtod and strtof as the same
value.
--keep saves the programs that fail. It found that the interpreter and
constant folding rejected MIN / -1 and MIN % -1 as overflow, which
compiled code wraps as documented
(tests/run/min_div.jh).
Broken programs
scripts/fuzz_compiler.py checks that
the compiler reports errors in programs rather than crashing on them. It
changes the files of tests/run, tests/fail and
examples at random (a number or an operator replaced, which mostly
keeps a program well formed, or a token deleted, doubled or swapped, or
the file cut short) and runs check and emit-llvm on each. A trap, a
signal, the compiler’s own panic: or a case that does not end within a
minute is a crash; --keep saves those cases.
scripts/fuzz_compiler.py --compiler out/jihoo # 2000 cases
scripts/fuzz_compiler.py --seed 7 --count 20000 --keep crashes
--valgrind tests safety rather than robustness: programs of tests/run
without unsafe, extern, threads, processes or input get one to three
numbers or operators replaced, or a statement swapped with the next,
doubled or deleted (which makes a use follow a move, or a borrow overlap a
change), and each the compiler accepts runs under
valgrind at -O0. A program that compiles without unsafe must not
touch memory it does not own, nor lose memory it allocated (valgrind’s
“definitely lost”: a drop that was skipped); panics and traps are fine,
since what they leave is still reachable.
scripts/fuzz_compiler.py --valgrind --count 500 # valgrind is in the dev shell
--threads does the same for data races: the programs of tests/run that
start threads get those edits, and each the compiler accepts is built with
--sanitize=thread and run; a
ThreadSanitizer report is kept. Safe code must not race.
scripts/fuzz_compiler.py --threads --count 400
Memory
Programs should neither leak nor touch memory they do not own. Build with
-O0 and run them under valgrind:
out/dev-jihoo build -O0 tests/run/maps.jh -o /tmp/maps
valgrind --leak-check=full --error-exitcode=9 /tmp/maps
Banana
scripts/banana_regression.py
checks and tests a checkout of Banana, the sibling terminal, with the
compiler under development: the jihoo commands of Banana’s own
tools/test.sh (checking src/main.jh and its plugin, and running its
terminal parser, selection, style and PTY tests) with --compiler in
place of Banana’s pinned compiler, so the commands follow Banana’s tests
as they change. None needs a display. The ordinary suite does not depend
on it.
scripts/banana_regression.py --banana ../banana --compiler out/jihoo
tests/format.py --external ../banana and scripts/benchmark_compile.py --external cover Banana’s formatting and compilation time.
Other machines
jihoo build --target aarch64 cross-compiles; freestanding programs run
under qemu-aarch64 (graft run debian#qemu-user -p qemu-aarch64 -- ./program). The aggregate C ABI test can
also run without libc on either target; the C oracle only needs Clang’s
freestanding headers:
{ echo '#![freestanding]'; cat tests/run/ffi_aggregates.jh; } > /tmp/ffi-aggregates.jh
clang --target=aarch64-linux-gnu -ffreestanding -fno-stack-protector -O2 \
-c tests/ffi/aggregates.c -o /tmp/ffi-c.o
out/jihoo build --target aarch64 /tmp/ffi-aggregates.jh /tmp/ffi-c.o -o /tmp/ffi-arm
qemu-aarch64 /tmp/ffi-arm
compiler/cabi.jh implements the classification described by the
AMD64 psABI,
AAPCS64
and, for UEFI on x86_64, the
Microsoft x64 convention;
the uefi suite runs ffi_aggregates.jh against the C oracle compiled for
Windows.
A UEFI program for aarch64 runs in qemu-system-aarch64 -M virt with
ARM firmware, such as the edk2-aarch64-code.fd that QEMU ships, whose
internal shell runs startup.nsh from the first FAT disk:
out/jihoo build --target aarch64 examples/uefi.jh -o esp/uefi.efi
printf 'fs0:\r\nuefi.efi\r\nreset -s\r\n' > esp/startup.nsh
qemu-system-aarch64 -M virt -cpu max -nographic \
-bios $QEMU/share/qemu/edk2-aarch64-code.fd \
-drive format=raw,file=fat:rw:esp,if=virtio
The C oracle exercises mixed register classes, homogeneous aggregates, register exhaustion and rollback, stack alignment, independent argument copies, callbacks, dynamic symbols, and variadic promotions and aggregates.
Backend performance
jihoo build -O2 compiler/main.jh -o out/jihoo
python3 scripts/benchmark_backends.py --compiler out/jihoo --selfhost --json /tmp/backends.json
The script builds the same runtime workloads through LLVM’s C API and
clang at -O2 --release, keeps bounds checks, checks their output, warms
up both executables, and alternates run order. It reports median runtime
for recursion, a sieve, matrix multiplication and floating point loops,
and median compilation time. --selfhost also builds the compiler with
each backend and compares its IR and frontend runtime. Runtime regressions
above --max-regression (10% by default) cause failure. Use an idle machine
and the same LLVM/clang version and linker driver for both paths; small
differences need repeated measurements.
Functional pipelines
python3 benchmarks/functional-fusion/run.py --compiler out/jihoo --iterations 128
This compares ordinary higher-order functions, comptime producers, the
public iterator API, eager vectors, a handwritten jihoo loop, and C. It
checks randomized results at O0/O2 with checked/wrapping arithmetic, records
allocations and optimized IR, and measures interleaved runtimes. See the
benchmark for the method,
recorded results, and the filter/fold fusion optimization. The program
suite additionally checks callback order, trap order, ownership,
streaming parsers using take and zip, and compile-time use.
--check-only runs the correctness, allocation and optimized-IR checks
without timing samples or thresholds. CI runs it with the packaged compiler
on x86_64 and aarch64 Linux and keeps out/functional-fusion/results.
Compilation time and memory
jihoo build -O2 compiler/main.jh -o out/jihoo
python3 scripts/benchmark_compile.py --compiler out/jihoo --json /tmp/compile.json \
--baseline benchmarks/compile/baseline-x86_64.json
The script measures each workload twice: jihoo check (loading, types,
compile-time evaluation, moves, drops and borrows) and full compilation
(build at -O2 for the host, emit-obj for another --target or a
module without main). The built-in workloads are the compiler itself,
a compile-time generation program
(tables, maps, sorting and derived code evaluated by the interpreter),
200 calls of std.fmt whose literal
patterns are each checked while compiling, and the fusion benchmark’s
iterator kernels. --external NAME=ENTRY[:INCLUDE...] adds any other
program, such as Banana’s entry point; its revision is recorded too.
Every sample is a new compiler process run through GNU time (in the dev
shell), so peak resident memory belongs to the compiler rather than to the
Python process that started it. Samples of all cases are interleaved. The
report records the compiler’s revision (marked -dirty when compiler/,
lib/ or benchmarks/ differ from it) and version, each case’s command,
target and options, the host, every sample and the medians.
--baseline compares median elapsed time and median peak memory with a
recorded report and fails when either grows by more than 10%
(--max-time-regression, --max-memory-regression); time differences under
20 ms are ignored. Compare only reports taken on the same idle host;
benchmarks/compile/baseline-x86_64.json is one such recording, a reference
for that host rather than a threshold for others. --check-only runs every
case once and checks that it succeeds, that check prints nothing and
creates no files, and that full compilation writes its output, without
thresholds. CI runs it for both targets with the packaged compiler.
--time-passes adds the compiler’s own
phase timings to every sample
and their medians to each case, and prints them; against a baseline that
recorded them too, each phase’s elapsed ratio is printed, without
thresholds. Use it to see which phase a change moved: the totals stay the
measure that --baseline checks.
python3 tests/time_passes.py --compiler out/jihoo
The check suite validates the table, that its phases add up to the total, and that output, objects, statuses and diagnostics are the same without it.
Compile-time resource measurements
python3 tests/comptime_report.py --compiler out/jihoo
The check suite validates the report schema and source spans, accounting totals, unchanged LLVM IR, and step/memory/depth and invalid-memory failures.