Device Under Test

Learn how to track the serial number of the Unit Under Test (UUT) with OpenHTF for better traceability during test execution.

Last updated · Verified with OpenHTF 1.6.1

Track the serial number of the unit under test with each run.

Before the phases run, the operator is prompted for the serial number of the device under test. The value is available to every phase as test.dut_id and is stored in the test record for traceability.

  • test.execute(test_start=...)user_input.prompt_for_test_start()
  • Operator promptEnter DUT ID
  • phases run
  • TestRecorddut_id
  • Test end

When running tests, tracking serial numbers is important for traceability. With OpenHTF, you can either manually enter the serial number at the start of the test or set it programmatically during the test.

Prompt at start

You can prompt the operator to input the serial number manually at the start of the test.

main.py
from openhtf import Test, PhaseResult
from openhtf.plugs import user_input

def power_on(test):
    return PhaseResult.CONTINUE

def main():
    test = Test(power_on)
    test.execute(test_start=user_input.prompt_for_test_start()) # Prompt at start

if __name__ == '__main__':
    main()

When executed, the script prompts the user to enter a serial number. The prompt is a regular phase returned by prompt_for_test_start(), and it takes options:

messagestr

Prompt text. Default: 'Enter a DUT ID in order to start the test.'

timeout_sfloat or None

Seconds to wait before the start phase times out. Default: 24 hours.

validatorcallable

Function applied to the typed string; its return value becomes the DUT ID. Raise to reject the input and re-prompt. Default: identity.

main.py
import re
from openhtf import Test, PhaseResult
from openhtf.plugs import user_input

def validate_sn(sn: str) -> str:
    sn = sn.strip().upper()
    if not re.fullmatch(r"SN\d{4}", sn):
        raise ValueError(f"Bad serial number: {sn!r}")
    return sn

def power_on(test):
    return PhaseResult.CONTINUE

def main():
    test = Test(power_on)
    test.execute(test_start=user_input.prompt_for_test_start(
        message="Scan the barcode on the PCB",
        timeout_s=300,
        validator=validate_sn,
    ))

if __name__ == '__main__':
    main()

A barcode scanner in keyboard-wedge mode types the serial and presses Enter, so this prompt works unchanged on the production floor.

Terminal
Enter a DUT ID in order to start the test.
--> SN1234

======================= test: openhtf_test  outcome: PASS ======================

Set at start

You can set the serial number at the start of the test.

main.py
from openhtf import Test, PhaseResult

def power_on(test):
    return PhaseResult.CONTINUE

def main():
    test = Test(power_on)
    test.execute(lambda: 'SN1234') # Set at start

if __name__ == '__main__':
    main()

Set during test

You can set the serial number during the test, for example after reading it from the device over a serial link or from an EEPROM.

main.py
from openhtf import Test, PhaseResult

def get_sn(test):
    test.test_record.dut_id = 'SN1234' # Set during test
    return PhaseResult.CONTINUE

def main():
    test = Test(get_sn)
    test.execute()

if __name__ == '__main__':
    main()

Default DUT ID

If no start trigger and no phase sets dut_id, OpenHTF records UNKNOWN_DUT. Override that fallback with test.configure(default_dut_id="...") — see Test Options. The ignore_early_canceled_tests example uses it to drop records for tests aborted before an operator scanned anything.

On this page

First-pass yield
0%4.1
Track with TofuPilot