Support coverage in -cc and -sc output modes.

This commit is contained in:
Wilson Snyder 2011-07-28 19:41:05 -04:00
parent d12a3dde45
commit bc8c85668a
10 changed files with 78 additions and 15 deletions

View File

@ -13,6 +13,9 @@ indicates the contributor was also the author of the fix; Thanks!
*** Support $fopen and I/O with integer instead of `verilator_file_descriptor.
*** Support coverage in -cc and -sc output modes. [John Li]
Note this requires SystemPerl 1.338 or newer.
**** Fix vpi_register_cb using bad s_cb_data, bug370. [by Thomas Watts]
**** Fix $display missing leading zeros in %0d, bug367. [Alex Solomatnikov]

View File

@ -3054,8 +3054,8 @@ network disk. Network disks are generally far slower.
=item How do I do coverage analysis?
Verilator supports both block (line) coverage and user inserted functional
coverage. Both currently require SystemPerl output mode and the SystemPerl
package.
coverage. Both require the SystemPerl package to be installed but do not
require use of the SystemPerl output mode.
First, run verilator with the --coverage option. If you're using your own
makefile, compile the model with the GCC flag -DSP_COVERAGE_ENABLE (if

View File

@ -116,6 +116,10 @@ ifeq ($(VM_SP),1)
$(SP_PREPROC) -M sp_preproc.d --tree $(VM_PREFIX).sp_tree \
--preproc $(VK_CLASSES_SP)
else
ifeq ($(VM_COVERAGE),1)
CPPFLAGS += -I$(SYSTEMPERL_INCLUDE)
VPATH += $(SYSTEMPERL_INCLUDE)
endif
preproc:
endif

View File

@ -84,10 +84,15 @@ public:
if (v3Global.opt.systemPerl()) {
putMakeClassEntry(of, "Sp.cpp"); // Note Sp.cpp includes SpTraceVcdC
}
else if (v3Global.opt.trace()) {
putMakeClassEntry(of, "verilated_vcd_c.cpp");
if (v3Global.opt.systemC()) {
putMakeClassEntry(of, "verilated_vcd_sc.cpp");
else {
if (v3Global.opt.coverage()) {
putMakeClassEntry(of, "SpCoverage.cpp");
}
if (v3Global.opt.trace()) {
putMakeClassEntry(of, "verilated_vcd_c.cpp");
if (v3Global.opt.systemC()) {
putMakeClassEntry(of, "verilated_vcd_sc.cpp");
}
}
}
}

View File

@ -567,9 +567,6 @@ int main(int argc, char** argv, char** env) {
v3Global.opt.bin(argv[0]);
string argString = V3Options::argString(argc-1, argv+1);
v3Global.opt.parseOpts(new FileLine("COMMAND_LINE",0), argc-1, argv+1);
if (v3Global.opt.coverage() && !v3Global.opt.systemPerl() && !v3Global.opt.lintOnly()) {
v3fatal("Unsupported: Coverage analysis requires --sp output.");
}
if (!v3Global.opt.outFormatOk()
&& !v3Global.opt.preprocOnly()
&& !v3Global.opt.lintOnly()

View File

@ -897,8 +897,12 @@ sub _make_main {
print $fh ' vl_fatal(__FILE__,__LINE__,"main", "%Error: Timeout; never got a $finish");',"\n";
print $fh " }\n";
print $fh " topp->final();\n";
print $fh " SpCoverage::write(\"",$self->{coverage_filename},"\");\n" if $self->{coverage};
if ($self->{coverage}) {
$fh->print("#if VM_COVERAGE\n");
$fh->print(" SpCoverage::write(\"",$self->{coverage_filename},"\");\n");
$fh->print("#endif //VM_COVERAGE\n");
}
if ($self->{trace}) {
$fh->print("#if VM_TRACE\n");
$fh->print(" if (tfp) tfp->close();\n");

View File

@ -0,0 +1,24 @@
#!/usr/bin/perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
# redistribute it and/or modify it under the terms of either the GNU
# Lesser General Public License Version 3 or the Perl Artistic License
# Version 2.0.
top_filename("t/t_cover_line.v");
compile (
verilator_flags2 => ['--cc --coverage-line'],
);
execute (
check_finished=>1,
);
# Read the input .v file and do any CHECK_COVER requests
inline_checks();
ok(1);
1;

View File

@ -0,0 +1,24 @@
#!/usr/bin/perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2003-2009 by Wilson Snyder. This program is free software; you can
# redistribute it and/or modify it under the terms of either the GNU
# Lesser General Public License Version 3 or the Perl Artistic License
# Version 2.0.
top_filename("t/t_cover_line.v");
compile (
verilator_flags2 => ['--sc --coverage-line'],
);
execute (
check_finished=>1,
);
# Read the input .v file and do any CHECK_COVER requests
inline_checks();
ok(1);
1;

View File

@ -7,6 +7,8 @@ if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); di
# Lesser General Public License Version 3 or the Perl Artistic License
# Version 2.0.
top_filename("t/t_cover_line.v");
compile (
verilator_flags2 => ['--sp --coverage-line'],
);

View File

@ -99,7 +99,7 @@ int sc_main(int argc, char* argv[]) {
//==========
// Waves
#if WAVES
#if VM_TRACE
// Before any evaluation, need to know to calculate those signals only used for tracing
Verilated::traceEverOn(true);
#endif
@ -117,7 +117,7 @@ int sc_main(int argc, char* argv[]) {
//==========
// Waves
#if WAVES
#if VM_TRACE
cout << "Enabling waves...\n";
# ifdef SYSTEMPERL
SpTraceFile* tfp = new SpTraceFile;
@ -135,7 +135,7 @@ int sc_main(int argc, char* argv[]) {
reset_l = 1;
while (VL_TIME_Q() < 60 && !passed && !Verilated::gotFinish()) {
#if WAVES
#if VM_TRACE
// Flush the wave files each cycle so we can immediately see the output
// Don't do this in "real" programs, do it in a abort() handler instead
if (tfp) tfp->flush();
@ -156,7 +156,7 @@ int sc_main(int argc, char* argv[]) {
//==========
// Close Waves
#if WAVES
#if VM_TRACE
if (tfp) tfp->close();
#endif
@ -168,7 +168,7 @@ int sc_main(int argc, char* argv[]) {
//==========
// Coverage analysis (since test passed)
mkdir("logs", 0777);
#ifdef SYSTEMPERL
#if VM_COVERAGE
SpCoverage::write(); // Writes logs/coverage.pl
#endif