@@ -9,57 +9,174 @@ BUILD_DIR = obj_dir
99COV_DIR = coverage
1010
1111# Source files
12- SV_SOURCES = counter.sv counter_tb.sv
12+ SV_SOURCES = counter.sv
13+ TEST_SOURCES = counter_tb.sv test_basic_counting.sv test_load_operations.sv test_overflow.sv test_reset.sv
1314
14- # Top module
15- TOP_MODULE = counter_tb
15+ # Test names
16+ TESTS = counter_tb test_basic_counting test_load_operations test_overflow test_reset
1617
1718# Verilator build target
1819.PHONY : all
1920all : build
2021
21- # Build the simulation with coverage using --binary flag
22+ # Build all test executables
2223.PHONY : build
2324build :
24- @echo " Building Verilator simulation with coverage..."
25+ @echo " Building all test simulations with coverage..."
26+ @for test in $(TESTS ) ; do \
27+ echo " Building $$ test..." ; \
28+ $(VERILATOR ) $(VERILATOR_FLAGS ) $(VERILATOR_COV_FLAGS ) \
29+ --binary -j 0 \
30+ --top-module $$ test \
31+ $(SV_SOURCES ) $$ test.sv || exit 1; \
32+ done
33+ @echo " Build complete!"
34+
35+ # Run all tests and collect separate coverage files
36+ .PHONY : run-all
37+ run-all : build
38+ @echo " Running all tests and collecting coverage..."
39+ @mkdir -p $(COV_DIR )
40+ @for test in $(TESTS ) ; do \
41+ echo " " ; \
42+ echo " =================================================" ; \
43+ echo " Running $$ test..." ; \
44+ echo " =================================================" ; \
45+ ./$(BUILD_DIR ) /V$$ test || exit 1; \
46+ mv coverage.dat $(COV_DIR ) /$$ test.dat; \
47+ echo " Coverage saved to: $( COV_DIR) /$$ test.dat" ; \
48+ done
49+ @echo " "
50+ @echo " All tests complete!"
51+ @echo " Coverage files:"
52+ @ls -lh $(COV_DIR ) /* .dat
53+
54+ # Convert all coverage files to separate UCIS databases
55+ .PHONY : convert-all
56+ convert-all : run-all
57+ @echo " Converting all coverage files to UCIS SQLite format..."
58+ @for test in $(TESTS ) ; do \
59+ echo " Converting $$ test.dat..." ; \
60+ PYTHONPATH=$(shell cd ../.. && pwd) /src pyucis convert \
61+ --input-format vltcov --output-format sqlite \
62+ $(COV_DIR ) /$$ test.dat -o $(COV_DIR ) /$$ test.cdb || exit 1; \
63+ done
64+ @echo " Conversion complete!"
65+ @echo " Individual databases:"
66+ @ls -lh $(COV_DIR ) /* .cdb
67+
68+ # Merge all coverage databases into one
69+ .PHONY : merge
70+ merge : convert-all
71+ @echo " Merging all coverage databases..."
72+ PYTHONPATH=$(shell cd ../.. && pwd) /src pyucis merge \
73+ --input-format sqlite --output-format sqlite \
74+ -o $(COV_DIR ) /merged.cdb \
75+ $(COV_DIR ) /counter_tb.cdb \
76+ $(COV_DIR ) /test_basic_counting.cdb \
77+ $(COV_DIR ) /test_load_operations.cdb \
78+ $(COV_DIR ) /test_overflow.cdb \
79+ $(COV_DIR ) /test_reset.cdb
80+ @echo " Merge complete! Database: $( COV_DIR) /merged.cdb"
81+
82+ # Run single test (use TEST=<name>)
83+ .PHONY : run
84+ run :
85+ ifndef TEST
86+ @echo "Error: Please specify TEST=<name>"
87+ @echo "Available tests: $(TESTS)"
88+ @exit 1
89+ endif
90+ @echo "Building and running $(TEST)..."
91+ $(VERILATOR) $(VERILATOR_FLAGS) $(VERILATOR_COV_FLAGS) \
92+ --binary -j 0 \
93+ --top-module $(TEST) \
94+ $(SV_SOURCES) $(TEST).sv
95+ @mkdir -p $(COV_DIR)
96+ ./$(BUILD_DIR)/V$(TEST)
97+ @mv coverage.dat $(COV_DIR)/$(TEST).dat
98+ @echo "Coverage saved to: $(COV_DIR)/$(TEST).dat"
99+
100+ # Build the simulation with coverage using --binary flag (original test)
101+ .PHONY : build-original
102+ build-original :
103+ @echo " Building original counter_tb with coverage..."
25104 $(VERILATOR ) $(VERILATOR_FLAGS ) $(VERILATOR_COV_FLAGS ) \
26105 --binary -j 0 \
27- --top-module $( TOP_MODULE ) \
28- $(SV_SOURCES )
106+ --top-module counter_tb \
107+ $(SV_SOURCES ) counter_tb.sv
29108 @echo " Build complete!"
30109
31- # Run the simulation
32- .PHONY : run
33- run : build
34- @echo " Running simulation..."
110+ # Run the original simulation
111+ .PHONY : run-original
112+ run-original : build-original
113+ @echo " Running original simulation..."
35114 @mkdir -p $(COV_DIR )
36- ./$(BUILD_DIR ) /V$(TOP_MODULE )
115+ ./$(BUILD_DIR ) /Vcounter_tb
116+ @mv coverage.dat $(COV_DIR ) /counter_tb.dat
37117 @echo " Simulation complete!"
38- @echo " Coverage data saved to: coverage .dat"
118+ @echo " Coverage data saved to: $( COV_DIR ) /counter_tb .dat"
39119
40- # Convert Verilator coverage to UCIS SQLite format
120+ # Convert original coverage to UCIS SQLite format
41121.PHONY : convert
42- convert : run
122+ convert : run-original
43123 @echo " Converting Verilator coverage to UCIS SQLite format..."
44124 PYTHONPATH=$(shell cd ../.. && pwd) /src pyucis convert \
45125 --input-format vltcov --output-format sqlite \
46- coverage .dat -o $(COV_DIR ) /coverage .cdb
47- @echo " Conversion complete! UCIS database: $( COV_DIR) /coverage .cdb"
126+ $( COV_DIR ) /counter_tb .dat -o $(COV_DIR ) /counter_tb .cdb
127+ @echo " Conversion complete! UCIS database: $( COV_DIR) /counter_tb .cdb"
48128
49- # View the coverage database with PyUCIS TUI
129+ # View the merged coverage database with PyUCIS TUI
50130.PHONY : view
51- view : convert
52- @echo " Launching PyUCIS TUI..."
53- pyucis view --input-format sqlite $(COV_DIR ) /coverage.cdb
131+ view : merge
132+ @echo " Launching PyUCIS TUI for merged database..."
133+ pyucis view --input-format sqlite $(COV_DIR ) /merged.cdb
134+
135+ # View individual test coverage
136+ .PHONY : view-test
137+ view-test :
138+ ifndef TEST
139+ @echo "Error: Please specify TEST=<name>"
140+ @echo "Available tests: $(TESTS)"
141+ @exit 1
142+ endif
143+ @echo "Launching PyUCIS TUI for $(TEST)..."
144+ pyucis view --input-format sqlite $(COV_DIR)/$(TEST).cdb
54145
55- # Generate coverage report
146+ # Generate coverage report for merged database
56147.PHONY : report
57- report : convert
58- @echo " Generating coverage report..."
59- pyucis show summary --input-format sqlite $(COV_DIR ) /coverage.cdb
148+ report : merge
149+ @echo " Generating coverage report for merged database..."
150+ @echo " "
151+ @echo " ======================================"
152+ @echo " Test Execution Summary"
153+ @echo " ======================================"
154+ @pyucis show tests --input-format sqlite $(COV_DIR ) /merged.cdb | grep -v " PyUCIS\|====\|Skill\|Note\|For more" | grep -A1000 " {"
155+ @echo " "
156+ @echo " ======================================"
157+ @echo " Code Coverage Summary"
158+ @echo " ======================================"
159+ @PYTHONPATH=$(shell cd ../.. && pwd) /src python3 report_coverage.py $(COV_DIR ) /merged.cdb
160+ @echo " "
161+ @echo " For detailed test contribution analysis, run: make query-tests"
162+
163+ # Query test coverage information
164+ .PHONY : query-tests
165+ query-tests : merge
166+ @echo " Querying test coverage information..."
60167 @echo " "
61- @echo " Coverage hierarchy:"
62- pyucis show hierarchy --input-format sqlite $(COV_DIR ) /coverage.cdb
168+ @echo " Test Coverage Summary:"
169+ @echo " ======================"
170+ PYTHONPATH=$(shell cd ../.. && pwd) /src python3 -c " \
171+ from ucis.sqlite import SqliteUCIS; \
172+ from ucis.history_node_kind import HistoryNodeKind; \
173+ db = SqliteUCIS.open_readonly('$(COV_DIR ) /merged.cdb'); \
174+ tests = list(db.historyNodes(HistoryNodeKind.TEST)); \
175+ print(f'Total tests: {len(tests)}'); \
176+ print(''); \
177+ for test in tests: \
178+ print(f' {test.getLogicalName()}'); \
179+ db.close()"
63180
64181# Clean build artifacts
65182.PHONY : clean
@@ -78,15 +195,32 @@ distclean: clean
78195# Help
79196.PHONY : help
80197help :
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)"
198+ @echo " Verilator Multi-Test Coverage Example - Makefile Targets"
199+ @echo " =========================================================="
91200 @echo " "
92- @echo " Quick start: make run && make convert && make view"
201+ @echo " Multi-Test Workflow:"
202+ @echo " make run-all - Run all tests and generate coverage files"
203+ @echo " make convert-all - Convert all coverage to UCIS databases"
204+ @echo " make merge - Merge all databases into merged.cdb"
205+ @echo " make view - View merged coverage in PyUCIS TUI"
206+ @echo " make report - Generate coverage report"
207+ @echo " make query-tests - Show test coverage information"
208+ @echo " "
209+ @echo " Single Test Workflow:"
210+ @echo " make run TEST=<name> - Run specific test"
211+ @echo " make view-test TEST=<name>- View specific test coverage"
212+ @echo " "
213+ @echo " Available tests:"
214+ @echo " counter_tb - Original comprehensive test"
215+ @echo " test_basic_counting - Basic increment functionality"
216+ @echo " test_load_operations - Load signal testing"
217+ @echo " test_overflow - Overflow detection"
218+ @echo " test_reset - Reset behavior"
219+ @echo " "
220+ @echo " Other:"
221+ @echo " make build - Build all test executables"
222+ @echo " make clean - Remove build artifacts"
223+ @echo " make distclean - Remove everything including coverage DB"
224+ @echo " "
225+ @echo " Quick start: make merge && make view"
226+
0 commit comments