This directory contains Python scripts and ModelSim/Questa DO files for automated test stimuli generation and simulation execution.
- Overview
- Directory Contents
- Test Script Architecture
- Creating Test Scripts
- Running Scripts
- Related Documentation
The test script infrastructure automates the generation of cycle-accurate test stimuli for VHDL component verification.
Key features:
- Python-based stimuli generation
- Automated
.datfile creation for VHDL testbenches - ModelSim/Questa DO files for compilation and simulation
- Waveform configuration scripts
- Reference model integration
Script types:
*_test.py- Python stimuli generatorssim_*.do- Simulation execution scriptswave_*.do- Waveform display configuration
scripts/
├── README.md # This file
│
├── Python Stimuli Generators:
├── *_test.py # Component-specific test generators
├── layer_test.py # Dense layer tests
├── conv_layer_test.py # Convolutional layer tests
├── neuron_test.py # Neuron tests
├── network_test.py # Network-level tests
│
├── ModelSim/Questa Scripts:
├── sim_*.do # Simulation execution
└── wave_*.do # Waveform configuration
All test scripts follow a consistent pattern for predictable and maintainable test generation.
Test scripts conceptualize each DUT port as a Python list of values. Lists are constructed using comprehensions and loops, then formatted into .dat files.
Python Script DAT File VHDL Testbench
------------- -------- --------------
+----------+
d = [d1, d2, d3, d4, d5] | ex.dat | read file line
w = [w1, w2, w3, w4, w5] | | by line
o = [o1, o2, o3, o4, o5] | d1 w1 o1 |
--> | d2 w2 o2 | --> apply d, w to DUT
| d3 w3 o3 | verify o output
| d4 w4 o4 |
| d5 w5 o5 |
+----------+
Structure:
- One line per simulation cycle
- Space-separated values
- Columns correspond to DUT ports in order
- Values in hexadecimal or decimal format
Example:
# Input_d Input_w Expected_output
00000001 00000002 00000003
00000004 00000005 00000009
00000007 00000008 0000000F
Typical script structure:
# 1. Define test parameters
data_width = 10
num_samples = 100
# 2. Generate input stimuli
input_d = [i for i in range(num_samples)]
input_w = [i * 2 for i in range(num_samples)]
# 3. Calculate expected outputs
output = [d + w for d, w in zip(input_d, input_w)]
# 4. Format and write DAT file
with open('test_data.dat', 'w') as f:
for d, w, o in zip(input_d, input_w, output):
f.write(f"{d:08x} {w:08x} {o:08x}\n")-
Identify DUT ports:
- List all inputs and outputs
- Determine data widths and formats
-
Create Python script:
# component_test.py import numpy as np # Generate test vectors inputs = generate_test_inputs() expected = calculate_expected_outputs(inputs) # Write DAT file write_dat_file("component_test.dat", inputs, expected)
-
Create DO file:
# sim_component.do vcom ../source/component.vhd vcom component_tb.vhd vsim component_tb do wave_component.do run -all -
Test and validate:
- Run Python script to generate stimuli
- Execute DO file in ModelSim/Questa
- Verify outputs match expectations
Consistent naming ensures easy navigation:
| File Type | Pattern | Example |
|---|---|---|
| Python test | <component>_test.py |
neuron_test.py |
| DAT file | <component>_test.dat |
neuron_test.dat |
| Simulation DO | sim_<component>.do |
sim_neuron.do |
| Waveform DO | wave_<component>.do |
wave_neuron.do |
| Testbench | <component>_tb.vhd |
neuron_tb.vhd |
# From scripts/ directory
python neuron_test.py
python layer_test.py# In ModelSim/Questa console
cd simulation/scripts
do sim_neuron.do
do sim_layer.do# 1. Generate test data
python component_test.py
# 2. Run simulation
# In ModelSim/Questa:
do sim_component.do
# 3. View results
# Waveforms appear in GUI
# Console shows pass/fail statusParent directory:
- ../README.md - Simulation environment overview
Component specifications:
- ../../source/README.md - Layer architectures and specifications
Project overview:
- ../../README.md - Complete workflow and quick start