Skip to content

Attributes ​

All attributes live in sparkles.test_runner.attributes and are plain marker types — a test annotated with them remains an ordinary unittest block for any other runner. Import them unconditionally (not under version (unittest)): unittest UDAs are resolved even in builds that do not compile the unittest bodies.

@betterC ​

The test is -betterC-compatible (no GC, exceptions, TypeInfo, druntime).

  • Runs normally under dub test.
  • --better-c extracts it into a standalone druntime-free program.
  • The body may only use the module's public symbols. Its own module is compiled in by default, so ordinary functions work; other modules are opted in with --include-import.
  • @betterC(selfContained: true) keeps the module out entirely, limiting the body to templates/CTFE-able code — which is what lets a module that cannot compile under -betterC still host such a test.

@ctfe ​

The test runs at compile time instead of runtime.

  • Evaluated through CTFE by a runner-generated probe compiled with -o- -unittest (semantic analysis only) after -i/-e filtering — so filters control which tests execute, and --help/--list work even when an @ctfe test would fail.
  • Reported as ⚙ … (compile time) on success, ✗ … (compile time) plus the compiler's CTFE error trail on failure; never executed at runtime.
  • The body must be CTFE-able; needs a D compiler on PATH (or $DC / --compiler) at run time.
  • Named after (and forward-compatible with) DMD 2.113's @__ctfe function attribute.

@wasm ​

The test is WebAssembly-compatible.

  • Runs normally under dub test.
  • --wasm compiles it for wasm32-unknown-wasip1 with the full druntime and Phobos of an LDC that has the WASI runtime, and runs it under wasmtime.
  • --wasm-bare compiles it for bare wasm32 with -betterC instead; there all @betterC constraints apply.
  • @wasm(selfContained: true) keeps the test's own module out of the extracted program.

@benchmark / @benchmark(iterations: N) ​

The test is a benchmark whose body is the measured unit.

  • Skipped by normal runs (counted in the summary); measured by --bench.
  • iterations pins the per-sample iteration count; 0 (default) auto-scales.
  • The whole body is measured. To keep setup out of the timing, register the measured part as a benchCase from a @benchCases test instead (a BenchTiming.batched case is timed the way a whole body is). blackBox is the optimizer barrier.
  • Calling benchCase from a @benchmark body fails the test's registration: a matrix is @benchCases.
  • --perf adds hardware-counter columns to the --bench table: Linux perf_event (IPC, instructions/iter, cache/branch miss rates) or macOS proc_pid_rusage fixed counters (IPC + instructions/iter, process-wide).

@benchCases / @benchCases(iterations: N) ​

The test registers its rows with benchCase — a matrix, or one case that keeps setup out of the timing (case structs the runner owns, with Metric throughput columns) — and its body is never measured itself.

  • Skipped by normal runs; measured by --bench, case by case. --list shows it with the @benchmark marker, which is the runner's word for "measured by --bench".
  • iterations runs exactly N timed calls per per-call case, one sample each, and pins a BenchTiming.batched case's per-sample count; 0 (default) samples until the time budget is met.
  • A body that registers no case fails with "<test> registered no cases", unless it called skipTest (an environment filter left nothing to measure), which leaves the test skipped with no rows.

@workload / @workload(reps: N) ​

The test is a workload, measured under the window model — the counterpart to @benchmark's per-iteration statistics.

  • Skipped by normal runs (counted in the summary); measured by --bench in a single pass: the body runs once (reps times for the measured window content; 0 is treated as 1), and the runner reports each open counter source's deltas across the window plus a wall-clock decomposition (on-CPU user/kernel from rusage, runqueue wait from schedstat, and a clamped other residual — locks/sleeps are never attributed to a fabricated cause). The body is never re-run for counting, so expensive or non-idempotent workloads are safe.
  • The whole body is the window by default. From sparkles.test_runner.workload, workloadWindow(dg) / workloadWindow(name, dg) measures only the closure (× reps); each call is one row in the workloads table. Outside --bench the closure runs exactly once, inertly.
  • --perf / --syscalls / --metrics open the same sources for windows; the table shows a fixed summary column set per source (full totals in --bench-json's windows array).
  • On Linux the decomposition is thread-scoped (the driving thread); rusage's user/kernel split is tick-sampled, so windows should be long (tens of milliseconds up) for the split to be signal rather than quantization.
  • @workload(regime: CacheRegime.cold) (or warm) sets the page-cache regime workloadFiles(paths...) establishes and verifies for the files the body names — see the how-to's regime section.

See Measure workloads.

@slow ​

The test takes minutes rather than milliseconds — a sweep over a whole corpus, say.

  • Runs normally under dub test.
  • --skip-slow leaves it out (the summary counts it: 5 slow (run with --only-slow)); --only-slow runs nothing else. The two exclude each other, and both combine with -i/-e.
  • ci test passes --skip-slow; CI runs each slow test as a job of its own through ci test --slow, which selects it by name. So a slow test needs a @("name"), and @slow goes on the unittest itself, not on a @slow: label or block: ci finds slow tests by reading the source, and fails a job whose test binary lists slow tests the source scan did not.

@serial / @serial(threadAffinity: ThreadAffinity.mainThread) ​

The test must not run beside other tests: it uses process-wide state, say. Whatever -t asks for, the default mode runs every other test first, on the workers, then the @serial ones, one at a time.

  • threadAffinity (a ThreadAffinity) says which thread runs them:
    • none (the default, and a bare @serial): any thread; the runner uses one worker for all of them.
    • mainThread: the main thread of the process that runs them — the worker's, or the binary's own in the fallback — after the none ones. For a library confined to the thread that initialized it: sparkles:nix's tests use it, because the Nix evaluator registers only the thread that called initNix with its garbage collector, and evaluating on another thread crashes.
  • The main thread runs its tests under the same stack budget as a worker (a 384 KiB watermark), so a test that passes there also fits a worker.
  • --list shows @serial or @serial(mainThread); it combines with every other attribute.

Combining ​

Attributes compose freely — e.g. @betterC @wasm opts one test into both extra environments; @("name") string UDAs keep naming the test. The exclusions: @benchmark and @benchCases declare different roles for a body, and either with @workload names different measurement models for the same body, and combining them is a discovery-time error.