Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 13fa6f8

Browse filesBrowse files
committed
Created
0 parents  commit 13fa6f8
Copy full SHA for 13fa6f8

File tree

Expand file treeCollapse file tree

13 files changed

+970
-0
lines changed
Filter options
Expand file treeCollapse file tree

13 files changed

+970
-0
lines changed

‎.gitignore

Copy file name to clipboard
+41Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Compiled Object files
2+
*.slo
3+
*.lo
4+
*.o
5+
*.obj
6+
7+
# Precompiled Headers
8+
*.gch
9+
*.pch
10+
11+
# Compiled Dynamic libraries
12+
*.so
13+
*.dylib
14+
*.dll
15+
16+
# Fortran module files
17+
*.mod
18+
19+
# Compiled Static libraries
20+
*.lai
21+
*.la
22+
*.a
23+
*.lib
24+
25+
# Verilator/simulator temporaries
26+
*.dmp
27+
*.log
28+
*.csrc
29+
*.vcd
30+
obj_*
31+
logs
32+
33+
# Executables
34+
*.exe
35+
*.out
36+
*.app
37+
*.gcda
38+
*.gcov
39+
*.gcno
40+
*qmake_gcov
41+
*.pro.user

‎.travis.yml

Copy file name to clipboard
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
language: cpp
2+
dist: focal
3+
os: linux
4+
compiler: gcc
5+
#cache: ccache
6+
7+
services:
8+
- docker
9+
10+
# This uses the latest version of Verilator, you may prefer :stable
11+
# We run make from inside the container, overriding default entry point (Verilator binary itself)
12+
# You may prefer to build install Verilator from git locally (slower but avoids docker)
13+
script:
14+
- docker run -ti -v ${PWD}:/work --user $(id -u):$(id -g) -e CCACHE_DIR=/work/.ccache --entrypoint make verilator/verilator:latest
15+
16+
after_success:
17+
- bash <(curl -s https://codecov.io/bash)

‎Codecov.png

Copy file name to clipboard
1.24 KB
Loading

‎LICENSE

Copy file name to clipboardExpand all lines: LICENSE
+674Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

‎Makefile

Copy file name to clipboard
+107Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
######################################################################
2+
#
3+
# DESCRIPTION: Make Verilator model and run coverage
4+
#
5+
# This calls the object directory makefile. That allows the objects to
6+
# be placed in the "current directory" which simplifies the Makefile.
7+
#
8+
# This file is placed under the Creative Commons Public Domain, for
9+
# any use, without warranty, 2020 by Wilson Snyder.
10+
# SPDX-License-Identifier: CC0-1.0
11+
#
12+
######################################################################
13+
14+
ifneq ($(words $(CURDIR)),1)
15+
$(error Unsupported: GNU Make cannot build in directories containing spaces, build elsewhere: '$(CURDIR)')
16+
endif
17+
18+
# This example started with the Verilator example files.
19+
# Please see those examples for commented sources, here:
20+
# https://github.com/verilator/verilator/tree/master/examples
21+
22+
######################################################################
23+
# Set up variables
24+
25+
# If $VERILATOR_ROOT isn't in the environment, we assume it is part of a
26+
# package install, and verilator is in your path. Otherwise find the
27+
# binary relative to $VERILATOR_ROOT (such as when inside the git sources).
28+
ifeq ($(VERILATOR_ROOT),)
29+
VERILATOR = verilator
30+
VERILATOR_COVERAGE = verilator_coverage
31+
else
32+
export VERILATOR_ROOT
33+
VERILATOR = $(VERILATOR_ROOT)/bin/verilator
34+
VERILATOR_COVERAGE = $(VERILATOR_ROOT)/bin/verilator_coverage
35+
endif
36+
37+
VERILATOR_FLAGS =
38+
# Generate C++ in executable form
39+
VERILATOR_FLAGS += -cc --exe
40+
# Generate makefile dependencies (not shown as complicates the Makefile)
41+
#VERILATOR_FLAGS += -MMD
42+
# Optimize
43+
VERILATOR_FLAGS += -Os -x-assign 0
44+
# Warn abount lint issues; may not want this on less solid designs
45+
VERILATOR_FLAGS += -Wall
46+
# Make waveforms
47+
#VERILATOR_FLAGS += --trace
48+
# Check SystemVerilog assertions
49+
VERILATOR_FLAGS += --assert
50+
# Generate coverage analysis
51+
VERILATOR_FLAGS += --coverage
52+
# Run make to compile model, with as many CPUs as are free
53+
VERILATOR_FLAGS += --build -j
54+
# Run Verilator in debug mode
55+
#VERILATOR_FLAGS += --debug
56+
# Add this trace to get a backtrace in gdb
57+
#VERILATOR_FLAGS += --gdbbt
58+
59+
# Input files for Verilator
60+
VERILATOR_INPUT = -f input.vc top.v sim_main.cpp
61+
62+
######################################################################
63+
64+
# Create annotated source
65+
VERILATOR_COV_FLAGS += --annotate logs/annotated
66+
# A single coverage hit is considered good enough
67+
VERILATOR_COV_FLAGS += --annotate-min 1
68+
# Create LCOV info
69+
VERILATOR_COV_FLAGS += --write-info logs/coverage.info
70+
# Input file from Verilator
71+
VERILATOR_COV_FLAGS += logs/coverage.dat
72+
73+
######################################################################
74+
default: run
75+
76+
run:
77+
@echo
78+
@echo "-- Verilator coverage example"
79+
80+
@echo
81+
@echo "-- VERILATE ----------------"
82+
$(VERILATOR) $(VERILATOR_FLAGS) $(VERILATOR_INPUT)
83+
84+
@echo
85+
@echo "-- RUN ---------------------"
86+
@rm -rf logs
87+
@mkdir -p logs
88+
obj_dir/Vtop
89+
90+
@echo
91+
@echo "-- COVERAGE ----------------"
92+
@rm -rf logs/annotated
93+
$(VERILATOR_COVERAGE) $(VERILATOR_COV_FLAGS)
94+
95+
@echo
96+
@echo "-- DONE --------------------"
97+
98+
99+
######################################################################
100+
# Other targets
101+
102+
show-config:
103+
$(VERILATOR) -V
104+
105+
maintainer-copy::
106+
clean mostlyclean distclean maintainer-clean::
107+
-rm -rf obj_dir logs *.log *.dmp *.vpd core

‎README.md

Copy file name to clipboard
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# travis_verilator_gcov
2+
3+
[![Travis CI logo](TravisCI.png)](https://travis-ci.org)
4+
![Whitespace](Whitespace.png)
5+
[![Codecov logo](Codecov.png)](https://www.codecov.io)
6+
![Whitespace](Whitespace.png)
7+
[![Verilator logo](verilator_56x48-min.png)](https://verilator.org)
8+
9+
[![Build Status](https://travis-ci.org/verilator/example-systemverilog.svg?branch=master)](https://travis-ci.org/verilator/example-systemverilog)
10+
[![codecov.io](https://codecov.io/github/verilator/example-systemverilog/coverage.svg?branch=master)](https://codecov.io/github/verilator/example-systemverilog?branch=master)
11+
12+
This GitHub is part of [the SystemVerilog Verilator Codecov Tutorial](https://github.com/verilator/example-systemverilog).
13+
14+
The goal of this project is to demonstrate a SystemVerilog project with:
15+
* Verilator
16+
* C++ compiler: `g++`
17+
* Travis-CI running Docker
18+
* Code coverage with `verilator_coverage` (note: it should show the code coverage is below 100%)
19+
* Code coverage published in CodeCov.
20+
21+
We are happy to help if you have any questions. Please contact email our Support at [support@codecov.io](mailto:support@codecov.io)

‎TravisCI.png

Copy file name to clipboard
5.29 KB
Loading

‎Whitespace.png

Copy file name to clipboard
129 Bytes
Loading

‎build.sh

Copy file name to clipboard
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
qmake travis_qmake_gcc_cpp11_gcov.pro
3+
make

‎input.vc

Copy file name to clipboard
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This file typically lists flags required by a large project, e.g. include directories
2+
+libext+.v+.sv+.vh+.svh -y .

‎sim_main.cpp

Copy file name to clipboard
+56Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// DESCRIPTION: Verilator: Verilog example module
2+
//
3+
// This file ONLY is placed under the Creative Commons Public Domain, for
4+
// any use, without warranty, 2017 by Wilson Snyder.
5+
// SPDX-License-Identifier: CC0-1.0
6+
//======================================================================
7+
8+
#include <verilated.h>
9+
10+
#include "Vtop.h"
11+
12+
vluint64_t main_time = 0;
13+
double sc_time_stamp() {
14+
return main_time; // Note does conversion to real, to match SystemC
15+
}
16+
17+
int main(int argc, char** argv, char** env) {
18+
// This example started with the Verilator example files.
19+
// Please see those examples for commented sources, here:
20+
// https://github.com/verilator/verilator/tree/master/examples
21+
22+
if (0 && argc && argv && env) {}
23+
24+
Verilated::debug(0);
25+
Verilated::randReset(2);
26+
Verilated::traceEverOn(true);
27+
Verilated::commandArgs(argc, argv);
28+
Verilated::mkdir("logs");
29+
30+
Vtop* top = new Vtop; // Or use a const unique_ptr, or the VL_UNIQUE_PTR wrapper
31+
32+
top->clk = 0;
33+
while (!Verilated::gotFinish()) {
34+
++main_time;
35+
top->clk = !top->clk;
36+
top->reset = (main_time < 10) ? 1 : 0;
37+
if (main_time < 5) {
38+
// Zero coverage if still early in reset, otherwise toggles there may
39+
// falsely indicate a signal is covered
40+
VerilatedCov::zero();
41+
}
42+
top->eval();
43+
}
44+
45+
top->final();
46+
47+
// Coverage analysis (since test passed)
48+
#if VM_COVERAGE
49+
Verilated::mkdir("logs");
50+
VerilatedCov::write("logs/coverage.dat");
51+
#endif
52+
53+
delete top;
54+
top = NULL;
55+
exit(0);
56+
}

‎top.v

Copy file name to clipboard
+49Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// DESCRIPTION: Verilator: Verilog example module
2+
//
3+
// This file ONLY is placed under the Creative Commons Public Domain, for
4+
// any use, without warranty, 2003 by Wilson Snyder.
5+
// SPDX-License-Identifier: CC0-1.0
6+
// ======================================================================
7+
8+
module top
9+
(input logic clk,
10+
input logic reset);
11+
12+
// Create 100 cycles of example stimulus
13+
reg [31:0] count_c;
14+
always_ff @ (posedge clk) begin
15+
//$display("[%0t] clk=%b reset=%b", $time, clk, reset);
16+
if (reset) begin
17+
count_c <= 0;
18+
end
19+
else begin
20+
count_c <= count_c + 1;
21+
if (count_c >= 99) begin
22+
$write("*-* All Finished *-*\n");
23+
$finish;
24+
end
25+
end
26+
end
27+
28+
// Example coverage analysis
29+
cover property (@(posedge clk) count_c == 30); // Hit
30+
cover property (@(posedge clk) count_c == 300); // Not covered
31+
32+
// Example toggle analysis
33+
wire count_hit_50; // Hit
34+
wire count_hit_500; // Not covered
35+
36+
assign count_hit_50 = (count_c == 50);
37+
assign count_hit_500 = (count_c == 500);
38+
39+
// Example line and block coverage
40+
always_comb begin
41+
if (count_hit_50) begin // Hit
42+
$write("[%0t] got 50\n", $time); // Hit
43+
end
44+
if (count_hit_500) begin // Not covered
45+
$write("[%0t] got 600\n", $time); // Not covered
46+
end
47+
end
48+
49+
endmodule

‎verilator_56x48-min.png

Copy file name to clipboard
1.47 KB
Loading

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.