Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Test Scripts and Stimuli Generation

This directory contains Python scripts and ModelSim/Questa DO files for automated test stimuli generation and simulation execution.

Table of Contents

Overview

The test script infrastructure automates the generation of cycle-accurate test stimuli for VHDL component verification.

Key features:

  • Python-based stimuli generation
  • Automated .dat file creation for VHDL testbenches
  • ModelSim/Questa DO files for compilation and simulation
  • Waveform configuration scripts
  • Reference model integration

Script types:

  • *_test.py - Python stimuli generators
  • sim_*.do - Simulation execution scripts
  • wave_*.do - Waveform display configuration

Directory Contents

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

Test Script Architecture

All test scripts follow a consistent pattern for predictable and maintainable test generation.

Standard Structure

Test scripts conceptualize each DUT port as a Python list of values. Lists are constructed using comprehensions and loops, then formatted into .dat files.

Data Flow Pipeline

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 |
                              +----------+

DAT File Format

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

Python Script Pattern

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")

Creating Test Scripts

Step-by-Step Guide

  1. Identify DUT ports:

    • List all inputs and outputs
    • Determine data widths and formats
  2. 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)
  3. Create DO file:

    # sim_component.do
    vcom ../source/component.vhd
    vcom component_tb.vhd
    vsim component_tb
    do wave_component.do
    run -all
  4. Test and validate:

    • Run Python script to generate stimuli
    • Execute DO file in ModelSim/Questa
    • Verify outputs match expectations

Naming Conventions

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

Running Scripts

Generating Stimuli

# From scripts/ directory
python neuron_test.py
python layer_test.py

Running Simulations

# In ModelSim/Questa console
cd simulation/scripts
do sim_neuron.do
do sim_layer.do

Complete Workflow

# 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 status

Related Documentation

Parent directory:

Component specifications:

Project overview: