Fault Hardware Testing Framework

4.0.1 · active · verified Fri Apr 17

Fault is a Python package for testing hardware designs, forming a core part of the magma ecosystem. It provides a unified, high-level interface to simulate and verify digital circuits directly from Python, supporting various hardware description languages and simulation targets like Verilator and Icarus. Currently at version 4.0.1, Fault is actively maintained with major versions typically introducing significant API improvements and architectural refactorings.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a simple Magma circuit, create a `fault.Tester` for it, apply inputs (`poke`), verify outputs (`expect`), and run the simulation using a Verilator target. Note that external simulators like Verilator often require system-level installation in addition to Python packages.

import magma as m
import fault

# Define a simple circuit using Magma
class MyCircuit(m.Circuit):
    io = m.IO(I=m.In(m.Bit), O=m.Out(m.Bit))
    io.O @= io.I

# Create a Tester instance for the circuit
tester = fault.Tester(MyCircuit)

# Poke inputs and expect outputs
tester.poke(MyCircuit.I, 1)
tester.expect(MyCircuit.O, 1)
tester.poke(MyCircuit.I, 0)
tester.expect(MyCircuit.O, 0)

# Compile and run the test using a target (e.g., Verilator)
# Ensure 'verilator' is installed on your system and 'fault-verilator' is installed via pip
try:
    tester.compile_and_run("verilator", magma_output="mlir")
    print("Test passed successfully with Verilator!")
except Exception as e:
    print(f"Test failed: {e}")
    print("Make sure 'verilator' is installed and in your PATH, and 'pip install fault-verilator' has been run.")

view raw JSON →