Testing¶
Testing frameworks and methodologies for elasticai.creator.
HW-in-the-Loop Testing¶
The HW-in-the-Loop testing framework in elasticai.creator enables testing of hardware implementations by synthesizing VHDL designs and running them on actual hardware devices.
Key Components¶
- The
HWTesterclass manages hardware testing, including device connections, bitstream uploads, and hardware function execution. - The
HWTester.prepare_hw_function(src_dir, id=None)method prepares and uploads a hardware function for testing.
Workflow¶
- Generate VHDL and constraint files
- Synthesize VHDL into bitstream
- Connect to hardware device
- Upload bitstream to FPGA
- Execute hardware function
- Retrieve results
Example¶
import elasticai.experiment_framework.remote_control as eaixp_rc
import pytest
from elasticai.experiment_framework.synthesis import CachedVivadoSynthesis
from elasticai.creator.testing import HWTester
@pytest.mark.hardware
def test_hardware_function(tmp_path):
# Setup
synthesis = CachedVivadoSynthesis()
device = eaixp_rc.probe_for_devices()[0]
tester = HWTester(
synth_fn=synthesis.synthesize,
device=eaixp_rc.remote_control.connect_remote_control(device),
)
hw_id = generate_vhdl_files_and_return_id(...)
# Prepare and run hardware function
with tester.prepare_hw_function(build_dir, id=hw_id) as run_inference:
predictions = run_inference(b"\x01\x01\x00\x01", 3)
# Verify results
assert predictions == expected_output_words
Implementation Details¶
Device Management¶
Uses remote control interface via context manager, without direct dependency on elasticai.experiment_framework.
Hardware Function Identification¶
- With ID: Checks if function is already loaded (avoids re-upload)
- Without ID (None): Always uploads bitstream
API Reference¶
Related Projects¶
- Elastic-AI Experiment Framework - Hardware device control and synthesis tools
Requirements¶
- Hardware device connected to system
- Synthesis tools configured (e.g., Vivado)
- Device communication context manager
Use @pytest.mark.hardware marker for hardware tests.
Best Practices¶
- Use context manager pattern for hardware functions
- Provide hardware function IDs to avoid unnecessary re-uploads