OpenHTF, the open-source hardware testing framework in Python

OpenHTF (Open Hardware Testing Framework) is an open-source Python framework for hardware testing, originally created at Google. Phases, measurements with limits, plugs for instruments, an operator UI and JSON test records.

OpenHTF is a Python framework for writing hardware test scripts: the functional, end-of-line and burn-in tests that decide whether a board or a product passes. It was originally created at Google and is used from design verification through validation to manufacturing.

This documentation is maintained by the team at TofuPilot, a plug-and-play database and analytics app for OpenHTF tests. It is independent from Google (see the disclaimer).

Start here

How a test is built

OpenHTF tests are Python scripts that run a series of test steps on a Device Under Test (DUT), taking measurements along the way. The framework handles setup, execution and teardown, records everything, and produces a pass/fail outcome.

Phases

Test steps — plain Python functions — that perform actions and return pass, fail, or skip. Phases →

Measurements

Values captured during phases, with optional validators (limits, regex, custom) that decide the outcome. Measurements →

Plugs

Reusable classes that wrap external hardware and software — instruments, the DUT's serial port, the operator. Plugs →

Test Record

Structured output with outcomes, measurements, logs and attachments, written by output callbacks to JSON or a database. Test Record →

main.py
import openhtf as htf
from openhtf.plugs import plug
from multimeter_plug import MultimeterPlug

@plug(multimeter=MultimeterPlug)
@htf.measures(
    htf.Measurement("voltage")
    .in_range(3.0, 3.5)
    .with_units("V"))
def test_voltage(test, multimeter):
    voltage = multimeter.measure_voltage()
    test.measurements.voltage = voltage

def main():
    test = htf.Test(test_voltage)
    test.execute(lambda: "SN0001") # DUT S/N

if __name__ == "__main__":
    main()
multimeter_plug.py
from openhtf.plugs import BasePlug

class MultimeterPlug(BasePlug):
    # Simulate connecting to the multimeter
    def __init__(self):
        self.connected = True

    # Simulate measuring the voltage
    def measure_voltage(self):
        return 3.3

    # Simulate disconnecting from the multimeter
    # Called automatically by OpenHTF at test end
    def tearDown(self):
        self.connected = False

Go deeper

Frequently asked

On this page

First-pass yield
0%4.1
Track with TofuPilot