Skip to content

Commit 0a7e8a8

Browse files
author
Matthew Ballance
committed
Enhance support for code coverage through the toolchain
Signed-off-by: Matthew Ballance <matt.ballance@gmail.com>
1 parent dae2437 commit 0a7e8a8

16 files changed

Lines changed: 2057 additions & 47 deletions

examples/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# PyUCIS Examples
2+
3+
This directory contains example applications demonstrating PyUCIS usage.
4+
5+
## Available Examples
6+
7+
### Verilator Coverage Example
8+
9+
**Location:** `verilator/`
10+
11+
**Description:** Complete workflow for collecting coverage from Verilator simulations and converting to UCIS SQLite format.
12+
13+
**Quick Start:**
14+
```bash
15+
cd verilator
16+
make run convert view
17+
```
18+
19+
**Features:**
20+
- SystemVerilog counter design with covergroups
21+
- Automated build and test flow with Makefile
22+
- Verilator coverage collection (line, toggle, branch, expression)
23+
- Conversion from Verilator .dat to UCIS SQLite .cdb format
24+
- Interactive viewing with PyUCIS TUI
25+
- 218 coverage items across 17 design scopes
26+
27+
**Files:** ~1,100 lines of code including:
28+
- SystemVerilog design (counter.sv, counter_tb.sv)
29+
- Python conversion tool (verilator2ucis.py)
30+
- Build automation (Makefile)
31+
- Comprehensive documentation (README.md, EXAMPLE_SUMMARY.md)
32+
33+
**Requirements:**
34+
- Verilator 5.0+
35+
- Python 3.7+
36+
- PyUCIS
37+
38+
**See:** `verilator/README.md` for detailed documentation
39+
40+
---
41+
42+
## Contributing Examples
43+
44+
To add a new example:
45+
1. Create a subdirectory with a descriptive name
46+
2. Include a README.md with usage instructions
47+
3. Provide working code and test data
48+
4. Update this file with a link to your example
49+
50+
## License
51+
52+
All examples are licensed under Apache License 2.0

examples/verilator/.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Build artifacts
2+
obj_dir/
3+
logs/
4+
5+
# Coverage data
6+
coverage.dat
7+
coverage_annotated/
8+
coverage/
9+
10+
# Python cache
11+
__pycache__/
12+
*.pyc
13+
14+
# Editor/IDE files
15+
*.swp
16+
*~
17+
.vscode/
18+
.idea/

examples/verilator/Makefile

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# Makefile for Verilator simulation with coverage
2+
VERILATOR = verilator
3+
VERILATOR_FLAGS = -Wall -Wno-fatal
4+
VERILATOR_COV_FLAGS = --coverage --coverage-line --coverage-toggle --coverage-user
5+
6+
# Directories
7+
SRC_DIR = .
8+
BUILD_DIR = obj_dir
9+
COV_DIR = coverage
10+
11+
# Source files
12+
SV_SOURCES = counter.sv counter_tb.sv
13+
14+
# Top module
15+
TOP_MODULE = counter_tb
16+
17+
# Verilator build target
18+
.PHONY: all
19+
all: build
20+
21+
# Build the simulation with coverage using --binary flag
22+
.PHONY: build
23+
build:
24+
@echo "Building Verilator simulation with coverage..."
25+
$(VERILATOR) $(VERILATOR_FLAGS) $(VERILATOR_COV_FLAGS) \
26+
--binary -j 0 \
27+
--top-module $(TOP_MODULE) \
28+
$(SV_SOURCES)
29+
@echo "Build complete!"
30+
31+
# Run the simulation
32+
.PHONY: run
33+
run: build
34+
@echo "Running simulation..."
35+
@mkdir -p $(COV_DIR)
36+
./$(BUILD_DIR)/V$(TOP_MODULE)
37+
@echo "Simulation complete!"
38+
@echo "Coverage data saved to: coverage.dat"
39+
40+
# Convert Verilator coverage to UCIS SQLite format
41+
.PHONY: convert
42+
convert: run
43+
@echo "Converting Verilator coverage to UCIS SQLite format..."
44+
PYTHONPATH=$(shell cd ../.. && pwd)/src pyucis convert \
45+
--input-format vltcov --output-format sqlite \
46+
coverage.dat -o $(COV_DIR)/coverage.cdb
47+
@echo "Conversion complete! UCIS database: $(COV_DIR)/coverage.cdb"
48+
49+
# View the coverage database with PyUCIS TUI
50+
.PHONY: view
51+
view: convert
52+
@echo "Launching PyUCIS TUI..."
53+
pyucis view --input-format sqlite $(COV_DIR)/coverage.cdb
54+
55+
# Generate coverage report
56+
.PHONY: report
57+
report: convert
58+
@echo "Generating coverage report..."
59+
pyucis show summary --input-format sqlite $(COV_DIR)/coverage.cdb
60+
@echo ""
61+
@echo "Coverage hierarchy:"
62+
pyucis show hierarchy --input-format sqlite $(COV_DIR)/coverage.cdb
63+
64+
# Clean build artifacts
65+
.PHONY: clean
66+
clean:
67+
@echo "Cleaning build artifacts..."
68+
rm -rf $(BUILD_DIR) coverage.dat logs
69+
@echo "Clean complete!"
70+
71+
# Clean everything including coverage database
72+
.PHONY: distclean
73+
distclean: clean
74+
@echo "Cleaning coverage database..."
75+
rm -rf $(COV_DIR)
76+
@echo "Distclean complete!"
77+
78+
# Help
79+
.PHONY: help
80+
help:
81+
@echo "Verilator Coverage Example - Makefile Targets"
82+
@echo "=============================================="
83+
@echo " make build - Build Verilator simulation with coverage"
84+
@echo " make run - Run simulation and generate coverage.dat"
85+
@echo " make convert - Convert coverage.dat to UCIS SQLite (.cdb)"
86+
@echo " make view - Launch PyUCIS TUI to view coverage"
87+
@echo " make report - Generate text coverage reports"
88+
@echo " make clean - Remove build artifacts"
89+
@echo " make distclean- Remove everything including coverage DB"
90+
@echo " make all - Build (default target)"
91+
@echo ""
92+
@echo "Quick start: make run && make convert && make view"

0 commit comments

Comments
 (0)