Skip to content

cocotb and the Celox CLI ​

Celox can compile a Veryl or SystemVerilog design into a native executable that runs ordinary cocotb tests through VPI. The generated executable contains the compiled design and the Celox runtime; it does not need the HDL sources when it runs.

Install the CLI ​

Install the celox command from crates.io:

sh
cargo install celox

cargo binstall celox downloads prebuilt binaries instead of compiling them. Each GitHub Release has them as celox-<target> archives for Linux, macOS and Windows. The command supports x86-64 and AArch64 hosts. To use the CLI of a Celox source tree instead, build it with cargo build --release -p celox --bin celox, which creates target/release/celox.

The installation also provides veryl-celox, so that Veryl 0.20.3 or later runs the command as a Veryl subcommand: veryl celox run ... is the same as celox run ..., and veryl --list shows celox.

The run command below needs no Python installation. For VPI tests, install cocotb into the Python environment you want to use:

sh
python3 -m pip install cocotb

The repository dev container already includes cocotb 2.0.1 and Verilator.

Run an HDL testbench directly ​

Use the same command for a SystemVerilog testbench and a Veryl native #[test] module:

sh
celox run src/types.sv src/Dut.sv test/Top.sv --top Top
celox run test/Top.veryl --top Top

For SystemVerilog, pass .sv or .v sources in compilation order. The list can also contain .svh, .vh or .h headers, including a header before the first module source. The command uses two-state simulation by default and runs until $finish or no scheduled events remain. Use --four-state or four_state = true in celox.toml to retain X/Z values. For Veryl, pass one project entry file: Celox discovers Veryl.toml and collects the project's sources and dependencies. A standalone Veryl file also works. Both languages default to two-state simulation. Select the native testbench module with --top. Veryl uses the existing native testbench executor; a test may also complete by falling through its initial blocks.

The command uses the existing frontends' supported language subsets; unsupported constructs produce compilation diagnostics. -O O0, -O O1, and -O O2 select the existing compiler optimization levels. Both languages default to O2, including dead store elimination; signals read by the HDL testbench are retained automatically. An explicit -O overrides the default.

Successful completion returns status 0. Compilation errors, runtime errors, assertion failures, $error, $fatal, lost runtime events, and exhausted execution limits return status 1. SV $stop also returns status 1 because this command has no interactive debugger. Invalid command arguments return status 2. SV $display/$write output goes to stdout; the existing Veryl native testbench executor sends its HDL output to stderr.

--max-steps N sets a positive execution limit (default: 1000000). It counts scheduler steps for SV and testbench ticks for Veryl. Reaching the Veryl tick limit before completion fails the command. This limit does not bound compilation or work within a single step/tick; use an external process timeout when a wall clock limit is needed. --unlimited removes the step/tick limit. Source languages cannot be mixed in one invocation.

For a SystemVerilog testbench, a positional argument starting with + (or --plusarg +ARG, repeatable) is a plusarg, not a source: $test$plusargs and $value$plusargs see them in command-line order, on every backend.

sh
celox run tb.v --top tb +iterations=9 --plusarg +trace

A SystemVerilog design that imports C functions through DPI-C names the shared libraries that provide them with --dpi-lib PATH (repeatable), or with dpi_libs = ["lib/model.so"] at the root or in a target of celox.toml. An import is linked to the first library that defines its C name: the root's libraries, then the target's, then those of the command line. Building the library from C sources is left to the project's build; svdpi.h is not shipped with Celox. See DPI-C imports for the supported argument types.

sh
cc -shared -fPIC -o model.so model.c
celox run tb.sv --top tb --dpi-lib model.so

--coverage-report FILE writes the coverage of the design's covergroups (IEEE 1800-2023 clause 19) to FILE as JSON once a SystemVerilog run ends, after its output: the report of Simulation::coverage(), with camelCase field names (see Coverage). A run that started writes it however it ends: on completion or $finish, on an illegal bin hit or $error, on $fatal, at --max-steps, or when a CDSP client leaves. A run that does not start writes none: invalid arguments (status 2), a compilation error, a checkpoint that --restore-checkpoint cannot restore, a --save-state-on signal that does not exist, or a --cdsp port that cannot be opened. The command never deletes a file, so after such a failure an existing FILE is left as it was: it is the report of an earlier run, and the nonzero exit status says that this run wrote none. FILE must not be a file that the run reads or writes otherwise: a source of the design (from the command line, a file list or the project), the project manifest (given with --project or found), a file list (given with -f, named by the project or by another file list), --dpi-lib libraries, --restore-checkpoint, --save-state-dir, --vcd, --fst, --settle-profile, --activation-profile or --dump-settle-plan; the command rejects it before compiling. A design without covergroups writes {"coverage": 100.0, "covergroups": []}. Failing to write the file fails the command with status 1. Nothing is printed: stdout stays the design's output. Veryl runs reject the option.

sh
celox run tb.sv --top tb --coverage-report coverage.json

Select execution and collect measurements ​

celox run accepts --threads N (1–64, default 1) and --four-state for both languages. Both languages support --backend native|tiered|interpreter|cranelift|wasm (default: tiered; native when --compile-only, a native image, --build-cache-dir or an IR dump is requested). Tiered starts interpreted and adopts compiled code at a scheduler safe point while preserving pending events. The default --jit auto selects hotspot JIT for native x86-64 and AArch64 tiered runs with one simulation thread and no force targets or native block profiling. It compiles frequently executed groups and keeps cold work interpreted. Other configurations retain whole-image tiering.

Use --jit whole-image to select the previous compilation strategy, or --jit hotspot to require a supported hotspot configuration. The existing --hotspot-jit flag is an alias for --jit hotspot. Rust builders also default to hotspot JIT on the tiered backend (SimulatorBuilder::hotspot_jit(false) selects whole-image tiering). For example:

sh
celox run test/Top.sv --top Top --backend tiered --threads 4

Signal checkpoints ​

On Unix, celox run installs a SIGUSR1 handler by default for SystemVerilog. After the SIGUSR1 checkpoint ready message, request a checkpoint with:

sh
kill -USR1 "$sim_pid"
celox run top.sv --top Top --restore-checkpoint "signal-${sim_pid}-1.checkpoint"

The signal handler only sets a flag. At the next complete simulation time step, the CLI saves its system checkpoint and continues running. Requests arriving before that boundary coalesce; blocking host I/O and a non-advancing time slot are not interrupted. Files are signal-<PID>-<N>.checkpoint in --save-state-dir (the current directory by default). Publication is atomic and never overwrites an existing file. Save failures are reported on stderr and do not terminate the run. Use --no-checkpoint-on-signal to disable the handler.

The CLI container combines core execution state with its file-effect handler state, source-driven waveform controls, and the CLI's accumulated assertion/error outcome. A run that already reported a failure remains failed after resume. The container also retains pending scheduled-save requests, the counted signal, cycle count and its previous level. Resume uses that saved schedule, including when the original --save-state-at* flags are repeated or omitted; it does not reissue consumed requests or restart cycle numbering. --save-state-dir and signal-handler registration come from the resumed invocation. Restore builds the target with declaration and combinational initialization deferred, so it does not repeat initialization effects before installing the checkpoint.

The handler keeps a disk-backed working view of files encountered by the run, preserving file contents, handle positions, EOF and scan lookahead across restore. Writes publish that working view to the requested host path immediately. Restore reconstructs the saved working view without undoing already delivered external output; subsequent writes publish the restored branch's contents. Closed working files retain their disk contents without retaining OS descriptors; operations reopen them temporarily. Active output streams retain their host handle until close, so renaming or unlinking a file does not redirect ordinary writes. After restore, output streams reconnect to their recorded paths lazily; OS handles themselves are not persisted. Working files are keyed by normalized paths (absolute paths with existing symlinks resolved). Different paths, including hard links to the same host file, have independent working views. The caller is responsible for coordinating such aliases; the CLI does not infer file identity. A write-only append target does not require read permission: its inaccessible existing prefix stays external, while appended bytes and positions are checkpointed. Resuming retains that prefix and replaces only the known suffix on the next write; the host prefix must still exist and be at least as long as when captured. Standard streams, named pipes and devices remain live external channels. Their already consumed input and delivered output are not rewound. No handler state enters the core checkpoint.

Source-driven $dumpfile/$dumpvars recording resumes in a new, uniquely named <original-name>.resume-<id>.<ext> beside the original file, keeping its extension and format; the CLI reports its path. The original trace is neither truncated nor appended to. Each segment has its own header and starts at the restored time with the saved signal selections and $dumpoff/$dumpon state. $dumplimit retains its configured per-file limit with a fresh byte budget for the new segment. Later dump controls continue to work. Waveform configuration lives in the CLI container, not the core checkpoint. Rust hosts can compose source_waveform_state() with their core checkpoint and use restore_source_waveform() to supply their own new output file.

Resume with the same sources, top, options and a compatible Celox build. --restore-checkpoint loads a trusted artifact, like a native image; do not use it on files from an untrusted producer. This resumes the CLI simulation, not VPI plugins or Python coroutines. Scheduled .state saves below remain the portable inspection format.

Save state files during a SystemVerilog run ​

To compare two runs or two simulators, celox run can save state files for celox state dump and celox state diff:

OptionsPurpose
--save-state-on SIGNALCount the cycles of SIGNAL, a hierarchical path such as tb.clk (the top module's name may be left out). A cycle is a time step at whose end the signal is 1 while it was not at the end of the previous time step.
--save-state-at N[,M...]Save the state after cycles N, M, ... of --save-state-on, counted from 1, as <SIGNAL>-<N>.state. The file is written right after that time step, with every region of the time done, so its nonblocking updates are included.
--save-state-at-time T[,U...]Save the state after everything due at times up to T, before the run advances past T, as time-<T>.state. T is in units of the design's global time precision.
--save-state-dir DIRWrite the files to DIR (default: the current directory).

A cycle that the run never reaches is an error. These options are available for SystemVerilog testbenches on every backend, including designs with file I/O or VCD tasks. The saved file contains HDL state; external resources are excluded under the snapshot contract.

sh
celox run c906.v --top tb --save-state-on tb.clk --save-state-at 1000,2000 --save-state-dir states
celox state diff states/tb.clk-1000.state other/tb.clk-1000.state

For Veryl native testbenches it also provides:

OptionsPurpose
--reportEmit machine-readable CELOX_* configuration, timing, tiered statistics and result records on stdout.
--require-compiledWith --report --backend tiered, require generated code to be exercised in a completed run. Normal tiered runs can finish on the interpreter.
--compile-onlyCompile native, Cranelift or WASM code without executing the testbench.
--build-cache-dir DIRCache native compilation for a Veryl.toml project in a trusted local directory.
--native-image-output FILEExport a native image with --compile-only.
--native-image-input FILEExecute an image without reading HDL sources.
--dump-ir-dir DIRWrite native compiler diagnostics; add --dump-ir-and-run to execute as well.
sh
celox run --project /path/to/veryl-project --top smoke --backend tiered --threads 4
celox run test/Top.veryl --top Top --four-state
celox run --project /path/to/veryl-project --top smoke --report --unlimited

--project accepts a Veryl project directory or Veryl.toml as well as celox.toml. --source-file PATH selects a Veryl source relative to the project; repeat it to select multiple files. Heliodor benchmarks invoke this same CLI with --report --unlimited; no separate Celox benchmark executable is used. The report preserves compile/execute/generated-code timing intervals, and tiered execution time includes background compilation and promotion. Short tiered runs need not compile unless --require-compiled is requested. That check accepts executed hotspot groups or regions as well as whole-image compiled execution; publishing code without executing it does not satisfy the check. CELOX_JIT_CONFIG reports the selected strategy and any automatic fallback reason. Hotspot runs also emit CELOX_HOTSPOT_STATS with interpreted/native calls, published, rejected and failed entries, code bytes, and completed compilation work time. Compilation work may overlap execution, so it is not an additional wall-time interval. CELOX_TIERED_* records retain their whole-image meaning. For individual compilation errors, unsupported groups, or memory/code-budget rejections, set RUST_LOG=celox::backend::hotspot=debug.

Manage a multi-file project ​

Save common inputs and named targets in celox.toml:

toml
sources = ["rtl/pkg.sv"]
filelists = ["rtl/design.f"]
include_dirs = ["include"]
default_target = "smoke"

[defines]
SIMULATION = "1"

[diagnostics]
mixed_timescale = "warn"

[targets.smoke]
sources = ["test/Tb.sv"]
top = "Tb"
opt_level = "O1"
max_steps = 1000000

[targets.dut]
top = "Dut"

Both commands resolve the same sources, include directories, macros and top:

sh
celox run --target smoke
celox vpi build --target dut -o build/dut-sim
celox run --project /path/to/celox.toml --target smoke

With no explicit sources or -f arguments, or when --target is present, Celox searches the current directory and its parents for celox.toml. Explicit --project FILE selects a manifest directly. Relative manifest paths resolve from the manifest's directory, including paths in its targets. Positional sources and -f alone run independently of any nearby manifest.

Targets inherit the root settings. Sources are collected in this order: root sources, root filelists, target sources, target filelists, then CLI sources and -f expansions in command-line order. Each list retains its source order. Include directories accumulate in the same layer order. Macro definitions are global to the invocation; later definitions win, with CLI -D definitions applied last. TOML macro values are strings. By default the ordered sources form one compilation unit. Source and header macros, undef directives, compiler directives and compilation-unit declarations carry forward to later files. Use --separate-unitsorsingle_unit = falseat the root or in a target to isolate each source; configured macros then apply afresh to each file.--single-unitoverrides that project setting. This selection applies to bothrunandvpi build. For example, celox run -f rtlmeter.f --top tb --four-stateaccepts RTLmeter source lists whose first file defines macros used by later files. These two compilation models follow IEEE 1800-2023 3.12.1; the standard does not specify a default. The Rust source-list APIs retain their per-file scope;celox_sv_analyzer::syntax::preprocess_sourcesexplicitly preprocesses one unit.--topoverrides the selected top;run's -Oand--max-steps` override the target/root run settings. VPI builds retain the existing force-compatible compilation settings.

SystemVerilog sources and included headers accept non-UTF-8 bytes in comments by default. Invalid comment bytes become spaces while valid UTF-8 and source byte offsets stay intact. Strings and code still require UTF-8. Use --strict-source-encoding or strict_source_encoding = true at the root or in a selected target of celox.toml to require UTF-8 throughout each file.

Without --target, Celox uses default_target, otherwise the root top, otherwise the sole target. Multiple targets without a default require --target. A project may also name a single .veryl entry file; its Veryl project discovery still uses Veryl.toml.

Compilation diagnostic levels can be set in [diagnostics], overridden in [targets.NAME.diagnostics], and overridden again with repeatable --diagnostic CODE=allow|warn|error options on either command. See diagnostic configuration for supported recovery behavior and examples.

Use a file list directly ​

sh
celox run -f test/all.f --top Tb
celox vpi build -f rtl/design.f --top Dut -o build/dut-sim

A .f file contains whitespace-separated source paths and can contain nested lists and preprocessing options:

text
# Paths resolve from this file's directory.
../rtl/pkg.sv
-f ../rtl/design.f
+incdir+../include
+define+SIMULATION=1
"../test/with spaces/Tb.sv"

Supported options are -f FILE, -I DIR/-IDIR, -D NAME[=VALUE]/-DNAME[=VALUE], +incdir+DIR[+DIR...] and +define+NAME[=VALUE][+NAME[=VALUE]...]. Bare macro names expand to 1. Paths may be quoted or use backslash escapes; # and // start comments at a token boundary, and /* ... */ comments are also accepted. Every nested list resolves paths from its own directory. The file-list reader performs no environment, wildcard or shell expansion. Unknown options, unknown TOML fields and cyclic file lists are errors. The CLI accepts -I/--include-dir and -D/--define directly as well. Include directories and macros require SystemVerilog inputs.

Compile a design ​

Pass one source in the Veryl project and name the top-level module:

sh
celox vpi build src/Top.veryl --top Top -o build/top-sim

Celox finds Veryl.toml from the source path and includes the project's source files and dependencies. For a standalone source outside a Veryl project, it compiles that file alone. The output defaults to celox.out when -o is omitted.

For SystemVerilog, pass one or more .sv files in compilation order:

sh
celox vpi build src/types.sv src/Child.sv src/Top.sv --top Top -o build/top-sim

This compiles the specified files using Celox's supported SystemVerilog subset. List package definitions before their consumers. It does not discover a Veryl.toml project or additional SystemVerilog source files. Multiple inputs must all be .sv files; for Veryl, pass one project entry file.

Designs with processes ​

A SystemVerilog design with processes, such as an initial block with delays or system tasks, an always block with delays or event controls, or a clock generator like always #5 clk = ~clk, compiles into a timed simulation. The executable runs its processes in step with cocotb: cocotb's timers and the design's delays share one time axis, and the design's $display/$write output and $finish work as in celox run. A design without processes compiles as before.

Within one time step, the VPI callbacks cocotb waits on run at these points:

cocotb trigger (VPI callback)Runs
Timer (cbAfterDelay), NextTimeStep (cbNextSimTime)at the start of the time step, before the design's processes
RisingEdge, FallingEdge, Edge (cbValueChange)right after the update that changed the value: a process run, a clock edge cocotb or the design drives, a flip-flop commit, a nonblocking update, or the settle of the combinational logic that reads them
ReadWrite (cbReadWriteSynch)when the time step has settled; writes there settle again at the same time
ReadOnly (cbReadOnlySynch)at the end of the time step; writes there are rejected

A value change callback runs after each change, before the simulation goes on (IEEE 1800-2023 38.36.1, 4.10). So the edge of a clock or reset is reported before the flip-flops it triggers commit, whether cocotb or the design drives it; a register's change is reported before its combinational readers follow it, and they are reported in turn once they do; and a change is reported before the processes it wakes run. A pulse is reported as two changes when its updates are separate: in different processes, across a delay or a #0, or across the nonblocking region.

A process's run is one update here: consecutive assignments a process makes before it suspends, such as x = 1; x = 0;, are reported once with the value the run left.

A write from cocotb is a blocking assignment at the current time. Outside the regions of a time step, in a Timer callback for example, a read returns the stored value: what combinational logic derives from a write in the same callback reads as before until the time step settles.

$stop ends the run, as vpiStop does, because the executable has no interactive mode. Pausing instead is tracked in #1886.

Run cocotb ​

Suppose test/test_top.py contains a cocotb test. Run the generated executable from a directory where that module is importable:

sh
PYTHONPATH=test build/top-sim --test-module test_top

The executable automatically:

  • uses python3 and locates its cocotb VPI adapter and libpython;
  • supplies the compiled top-level name to cocotb;
  • writes results.xml and returns a failing exit status when a test fails.

Use another Python environment or result path explicitly when needed:

sh
build/top-sim \
  --test-module test_top \
  --python .venv/bin/python \
  --results-file build/results.xml

--test-filter REGEX selects matching tests; --testcase NAME is also available for cocotb's legacy test selection. --vpi PATH overrides automatic VPI adapter discovery. The corresponding cocotb environment variables remain supported for existing automation: PYGPI_PYTHON_BIN, LIBPYTHON_LOC, CELOX_COCOTB_VPI, COCOTB_TEST_MODULES, COCOTB_TEST_FILTER, and COCOTB_RESULTS_FILE.

Current compatibility ​

The compatibility layer covers cocotb 2.0 and 2.1 paths for module and signal discovery, including escaped signal names, scalar/vector values, packed bit handles, unpacked array elements, real values and string bytes. Immediate deposits and zero-delay inertial updates are supported. Packed variables support whole-vector force/release and deposits through their bit handles while forced; string force/release and delayed VPI writes are not supported. Callbacks cover Start, ReadWrite, ReadOnly, NextTimeStep, Timer, ValueChange, and End regions.

The upstream regression runner runs pinned, unmodified cocotb tests against the generated executable. Its default 23 configurations pass 534 tests with 5 upstream skips, including bridge-thread clock reads, force/release and both inertial-write modes. An inventory records the remaining upstream groups and their unresolved requirements.