File size: 8,181 Bytes
eb82b91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# UVM Verification Framework — User Guide

## Overview

Automated UVM testbench generation from YAML / FuseSoC `.core` specifications. Outputs a complete, ready-to-compile UVM environment for protocol interfaces (UART, SPI, I2C, APB, AXI4-Lite, Wishbone) with AI/ML-powered coverage optimization.

## Architecture

```
Spec (.core / .yaml)
       |
       v
 Generation Engine (Jinja2 + ML)
       |
       v
 +----------------------------+
 |  Generated UVM Testbench  |
 |  +----------------------+ |
 |  | testbench.sv          | |
 |  | interface_{name}.sv   | |
 |  | sequence_item_{n}.sv  | |
 |  | driver_{name}.sv      | |
 |  | monitor_{name}.sv     | |
 |  | agent_{name}.sv       | |
 |  | env_{name}.sv         | |
 |  | scoreboard_{name}.sv  | |
 |  | coverage_collector.sv | |
 |  | protocol_checker.sv   | |
 |  | ral_model_{name}.sv   | |
 |  | base_sequence_{n}.sv  | |
 |  | test_{name}.sv        | |
 |  +----------------------+ |
 +----------------------------+
```

## Quick Start

### 1. Install

```bash
pip install -r requirements.txt
pip install -r requirements-dev.txt   # optional: dev/lint
```

### 2. Generate a UVM testbench

```bash
# From YAML spec
python -m src.main --spec configs/uart_demo.yaml

# From FuseSoC .core spec
python -m src.main --spec configs/uart16550-1.5.core

# With auto-training (AI coverage optimization)
python -m src.main --spec configs/uart16550-1.5.core --auto-train --max-iterations 3
```

### 3. Output

```
output/{design_name}_tb/
  testbench.sv              # Top-level module
  interface_{name}.sv       # Clocking + modport
  sequence_item_{name}.sv   # Transaction object
  driver_{name}.sv          # Bus driver
  monitor_{name}.sv         # Bus monitor
  agent_{name}.sv           # Agent (sequencer + driver + monitor)
  environment_{name}.sv     # Env (agent + scoreboard + coverage + RAL)
  scoreboard_{name}.sv      # Scoreboard (TX/RX compare, error check)
  coverage_collector_{name}.sv  # Functional coverage groups
  protocol_checker_{name}.sv    # SVA assertions
  ral_model_{name}.sv       # RAL model + adapter + predictor
  base_sequence_{name}.sv   # Sequence library
  test_{name}.sv            # Test library
  compile.f                 # Compile file list
  sim_{name}.tcl            # Simulation script
```

## Spec Format

### YAML format

```yaml
design_name: uart16550
protocol: uart

interfaces:
  - name: bus
    direction: slave
    protocol: wishbone
    signals:
      - {name: addr, direction: input, width: 3}
      - {name: data_in, direction: input, width: 8}
      - {name: data_out, direction: output, width: 8}

  - name: serial
    direction: master
    protocol: uart
    signals:
      - {name: tx, direction: output, width: 1}
      - {name: rx, direction: input, width: 1}

registers:
  - name: RBR
    address: 0x00
    access: ro
    size: 8
    description: Receiver Buffer Register
  - name: THR
    address: 0x00
    access: wo
    size: 8
  - name: IER
    address: 0x01
    access: rw
    size: 8
  - name: LCR
    address: 0x03
    access: rw
    size: 8
    reset: 0x03

clocks:
  clk: 50MHz
  reset: {name: rst_n, polarity: active_low}
```

### FuseSoC .core format

See `configs/uart16550-1.5.core` for a complete example.

## UVM VIP Integration

### Packaging as a VIP

The generated output is structured as a self-contained UVM Verification IP:

```
{design_name}_vip/
  pkg/
    {design_name}_vip_pkg.sv       # UVM package (all files)
    {design_name}_reg_pkg.sv        # RAL package
  src/
    {design_name}_if.sv             # Interface
    {design_name}_agent.sv          # Agent
    {design_name}_env.sv            # Environment
    {design_name}_driver.sv         # Driver
    {design_name}_monitor.sv        # Monitor
    {design_name}_scoreboard.sv     # Scoreboard
    {design_name}_coverage.sv       # Coverage collector
    {design_name}_checker.sv        # Protocol checker
    {design_name}_ral.sv            # RAL model
    {design_name}_sequences.sv      # Sequence library
    {design_name}_tests.sv          # Test library
  sim/
    compile.f                       # Compile list
    sim.do                          # Questa script
    sim.tcl                         # Generic TCL script
  examples/
    smoke_test.sv                   # Standalone testbench
```

### Integration into a larger SoC environment

```systemverilog
// 1. Import the VIP
import uart_vip_pkg::*;

// 2. Instantiate interface
uart_if uart_if_inst (
  .clk   (sys_clk),
  .rst_n (sys_rst_n),
  .tx    (uart_tx),
  .rx    (uart_rx)
);

// 3. Configure via config_db
initial begin
  uvm_config_db#(virtual uart_if)::set(
    null, "uvm_test_top", "vif", uart_if_inst
  );
end

// 4. Run test
initial begin
  run_test("uart_smoke_test");
end
```

### Configuration parameters

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `protocol` | string | `"uart"` | Protocol selection |
| `model_type` | string | `"v2"` | Generation model (template / v2) |
| `rl_strategy` | string | `"ucb"` | RL exploration strategy |
| `enable_learning` | bool | true | Enable RL + coverage feedback |
| `strict_uvm` | bool | true | Generate IEEE 1800.2 compliant code |
| `max_iterations` | int | 1 | Auto-training iterations |

## AI/ML Features

### Coverage Prediction

The coverage predictor uses a 3-model ensemble (RandomForest + GradientBoosting + LinearRegression) with Ridge meta-blender to predict functional coverage gaps and suggest targeted sequences.

### Reinforcement Learning

Q-learning with:
- Double Q-learning (two independent Q-tables)
- Prioritized experience replay
- N-step returns
- Eligibility traces
- 5 exploration strategies (epsilon-greedy, softmax, UCB, Thompson, NoisyNet)

States are encoded as `{protocol}:{file_type}:{complexity}`.

### Auto-Training Loop

```
1. Generate UVM testbench
2. Run simulation (or stub)
3. Predict coverage gaps
4. Generate targeted sequences
5. Re-train RL model
6. Repeat until coverage target met
```

## Regression Management

### Running regressions

```bash
# Single test
python -m src.main --spec configs/uart16550-1.5.core \
  --test smoke

# All tests
python regression/run_regression.py \
  --spec configs/uart16550-1.5.core

# Multi-seed regression
python regression/run_regression.py \
  --spec configs/uart16550-1.5.core \
  --seeds 100 \
  --tests smoke,loopback,interrupt
```

### YAML regression spec

```yaml
regression:
  name: uart_full_regression
  spec: configs/uart16550-1.5.core
  tests:
    - uart_smoke_test
    - uart_reg_access_test
    - uart_loopback_test
    - uart_interrupt_test
    - uart_fifo_test
    - uart_random_test
  seeds: [10, 20, 30, 50, 100]
  simulator: questa
  coverage: true
  output: results/
```

## Simulator Support

| Simulator | Status | Notes |
|-----------|--------|-------|
| Questa/ModelSim | ✅ | Full support via .do / .tcl script |
| VCS | ✅ | Compatible (IEEE 1800.2 compliant) |
| Xcelium | ✅ | Compatible |
| Icarus Verilog | ✅ | Basic support (stub mode) |

## Project Structure

```
UVM-verification/
  configs/             # Spec files (.yaml, .core)
  docs/                # Documentation
  frontend/            # React UI
  protocols/           # Protocol definitions (UART, SPI, I2C, etc.)
  regression/          # Regression scripts
  src/                 # Core engine
    features/          # Spec feature extraction
    generation/        # Template engine
      templates/       # Jinja2 UVM templates
    models/            # ML models (RL, coverage predictor, etc.)
    evaluation/        # Quality scoring, SV checking
    pipeline.py        # Auto-training pipeline
  vip/                 # Packaged VIP files
  output/              # Generated testbenches
```

## Testing

```bash
# Run unit tests
python -m pytest tests/

# Test coverage prediction
python -m pytest tests/test_coverage_predictor.py -v

# Test RL learner
python -m pytest tests/test_rl_learner.py -v

# Test pipeline end-to-end
python test_pipeline.py
```

## Docker

```bash
docker-compose up --build
# Frontend: http://localhost:7860
# API:      http://localhost:8000/docs
```

## License

MIT License — see LICENSE file.