mirror of
https://github.com/verilator/verilator.git
synced 2025-01-01 04:07:34 +00:00
Misc internal coverage improvements.
This commit is contained in:
parent
201f0d3f5f
commit
17e7da77f0
@ -312,7 +312,8 @@ vluint64_t vl_rand64() VL_MT_SAFE {
|
||||
|
||||
IData VL_RANDOM_I(int obits) VL_MT_SAFE { return vl_rand64() & VL_MASK_I(obits); }
|
||||
QData VL_RANDOM_Q(int obits) VL_MT_SAFE { return vl_rand64() & VL_MASK_Q(obits); }
|
||||
// VL_RANDOM_W currently unused as $random always 32 bits
|
||||
// VL_RANDOM_W currently unused as $random always 32 bits, left for backwards compatibility
|
||||
// LCOV_EXCL_START
|
||||
WDataOutP VL_RANDOM_W(int obits, WDataOutP outwp) VL_MT_SAFE {
|
||||
for (int i = 0; i < VL_WORDS_I(obits); ++i) {
|
||||
if (i < (VL_WORDS_I(obits) - 1)) {
|
||||
@ -323,6 +324,7 @@ WDataOutP VL_RANDOM_W(int obits, WDataOutP outwp) VL_MT_SAFE {
|
||||
}
|
||||
return outwp;
|
||||
}
|
||||
// LCOV_EXCL_STOP
|
||||
|
||||
IData VL_RAND_RESET_I(int obits) VL_MT_SAFE {
|
||||
if (Verilated::randReset() == 0) return 0;
|
||||
|
@ -332,10 +332,10 @@ public:
|
||||
m_insertp->m_keys[addKeynum] = valueIndex(key);
|
||||
m_insertp->m_vals[addKeynum] = valueIndex(val);
|
||||
addKeynum++;
|
||||
if (!legalKey(key)) {
|
||||
if (VL_UNCOVERABLE(!legalKey(key))) {
|
||||
std::string msg
|
||||
= ("%Error: Coverage keys of one character, or letter+digit are illegal: "
|
||||
+ key);
|
||||
+ key); // LCOV_EXCL_LINE
|
||||
VL_FATAL_MT("", 0, "", msg.c_str());
|
||||
}
|
||||
}
|
||||
|
@ -2072,11 +2072,11 @@ PLI_INT32 vpi_control(PLI_INT32 operation, ...) {
|
||||
_VL_VPI_ERROR_RESET();
|
||||
switch (operation) {
|
||||
case vpiFinish: {
|
||||
VL_FINISH_MT(__FILE__, __LINE__, "*VPI*");
|
||||
VL_FINISH_MT("", 0, "*VPI*");
|
||||
return 1;
|
||||
}
|
||||
case vpiStop: {
|
||||
VL_STOP_MT(__FILE__, __LINE__, "*VPI*");
|
||||
VL_STOP_MT("", 0, "*VPI*");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
@ -161,9 +161,11 @@ public:
|
||||
for (int backs = 0; backs < 2;
|
||||
backs++) { // Those with backp() are probably under one leaking without
|
||||
for (NodeMap::iterator it = s_nodes.begin(); it != s_nodes.end(); ++it) {
|
||||
if ((it->second & FLAG_ALLOCATED) && !(it->second & FLAG_IN_TREE)
|
||||
&& !(it->second & FLAG_LEAKED)
|
||||
&& (it->first->backp() ? backs == 1 : backs == 0)) {
|
||||
// LCOV_EXCL_START
|
||||
if (VL_UNCOVERABLE((it->second & FLAG_ALLOCATED) && !(it->second & FLAG_IN_TREE)
|
||||
&& !(it->second & FLAG_LEAKED)
|
||||
&& (it->first->backp() ? backs == 1 : backs == 0))) {
|
||||
|
||||
// Use only AstNode::dump instead of the virtual one, as there
|
||||
// may be varp() and other cross links that are bad.
|
||||
if (v3Global.opt.debugCheck()) {
|
||||
@ -182,6 +184,7 @@ public:
|
||||
}
|
||||
it->second |= FLAG_LEAKED;
|
||||
}
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,8 @@ class EmitCMain : EmitCBaseVisitor {
|
||||
// METHODS
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstNode* nodep) { iterateChildren(nodep); }
|
||||
// This visitor doesn't really iterate, but exist to appease base class
|
||||
virtual void visit(AstNode* nodep) { iterateChildren(nodep); } // LCOV_EXCL_LINE
|
||||
|
||||
public:
|
||||
// CONSTRUCTORS
|
||||
|
@ -330,7 +330,7 @@ void V3Options::fileNfsFlush(const string& filename) {
|
||||
// do a open or opendir on the filename.
|
||||
// Faster to just try both rather than check if a file is a dir.
|
||||
if (DIR* dirp = opendir(filename.c_str())) {
|
||||
closedir(dirp);
|
||||
closedir(dirp); // LCOV_EXCL_LINE
|
||||
} else if (int fd = ::open(filename.c_str(), O_RDONLY)) {
|
||||
if (fd > 0) ::close(fd);
|
||||
}
|
||||
|
17
src/V3Os.cpp
17
src/V3Os.cpp
@ -269,8 +269,8 @@ string V3Os::trueRandom(size_t size) {
|
||||
std::ifstream is("/dev/urandom", std::ios::in | std::ios::binary);
|
||||
// This read uses the size of the buffer.
|
||||
// Flawfinder: ignore
|
||||
if (!is.read(data, size)) {
|
||||
v3fatal("Could not open /dev/urandom, no source of randomness. "
|
||||
if (VL_UNCOVERABLE(!is.read(data, size))) {
|
||||
v3fatal("Could not open /dev/urandom, no source of randomness. " // LCOV_EXCL_LINE
|
||||
"Try specifying a key instead.");
|
||||
}
|
||||
#endif
|
||||
@ -313,15 +313,12 @@ uint64_t V3Os::memUsageBytes() {
|
||||
FILE* fp = fopen(statmFilename, "r");
|
||||
if (!fp) return 0;
|
||||
vluint64_t size, resident, share, text, lib, data, dt; // All in pages
|
||||
if (7
|
||||
!= fscanf(fp,
|
||||
"%" VL_PRI64 "u %" VL_PRI64 "u %" VL_PRI64 "u %" VL_PRI64 "u %" VL_PRI64
|
||||
"u %" VL_PRI64 "u %" VL_PRI64 "u",
|
||||
&size, &resident, &share, &text, &lib, &data, &dt)) {
|
||||
fclose(fp);
|
||||
return 0;
|
||||
}
|
||||
int items = fscanf(fp,
|
||||
"%" VL_PRI64 "u %" VL_PRI64 "u %" VL_PRI64 "u %" VL_PRI64 "u %" VL_PRI64
|
||||
"u %" VL_PRI64 "u %" VL_PRI64 "u",
|
||||
&size, &resident, &share, &text, &lib, &data, &dt);
|
||||
fclose(fp);
|
||||
if (VL_UNCOVERABLE(7 != items)) return 0;
|
||||
return (text + data) * getpagesize();
|
||||
#endif
|
||||
}
|
||||
|
@ -261,7 +261,7 @@ private:
|
||||
|
||||
void castPtr(FileLine* fl, AstTextBlock* txtp) {
|
||||
txtp->addText(fl, m_topName
|
||||
+ "_container* handlep__V = "
|
||||
+ "_container* handlep__V = " // LCOV_EXCL_LINE // lcov bug
|
||||
"static_cast<"
|
||||
+ m_topName + "_container*>(vhandlep__V);\n");
|
||||
}
|
||||
|
@ -292,7 +292,7 @@ public:
|
||||
typename Key2Val::iterator kvit = m_keys.find(k);
|
||||
if (kvit != m_keys.end()) {
|
||||
if (kvit->second == v) {
|
||||
return; // Same value already present; stop.
|
||||
return; // LCOV_EXCL_LINE // Same value already present; stop.
|
||||
}
|
||||
// Must remove element from m_vals[oldValue]
|
||||
removeKeyFromOldVal(k, kvit->second);
|
||||
|
@ -130,10 +130,7 @@ class SliceVisitor : public AstNVisitor {
|
||||
if (!nodep->user1() && !VN_IS(nodep, AssignAlias)) {
|
||||
nodep->user1(true);
|
||||
m_assignError = false;
|
||||
if (debug() >= 9) {
|
||||
cout << endl;
|
||||
nodep->dumpTree(cout, " Deslice-In: ");
|
||||
}
|
||||
if (debug() >= 9) nodep->dumpTree(cout, " Deslice-In: ");
|
||||
AstNodeDType* dtp = nodep->lhsp()->dtypep()->skipRefp();
|
||||
if (AstUnpackArrayDType* arrayp = VN_CAST(dtp, UnpackArrayDType)) {
|
||||
// Left and right could have different msb/lsbs/endianness, but #elements is common
|
||||
@ -148,10 +145,7 @@ class SliceVisitor : public AstNVisitor {
|
||||
if (debug() >= 9) { newp->dumpTree(cout, "-new "); }
|
||||
newlistp = AstNode::addNextNull(newlistp, newp);
|
||||
}
|
||||
if (debug() >= 9) {
|
||||
cout << endl;
|
||||
nodep->dumpTree(cout, " Deslice-Dn: ");
|
||||
}
|
||||
if (debug() >= 9) nodep->dumpTree(cout, " Deslice-Dn: ");
|
||||
nodep->replaceWith(newlistp);
|
||||
VL_DO_DANGLING(nodep->deleteTree(), nodep);
|
||||
// Normal edit iterator will now iterate on all of the expansion assignments
|
||||
|
20
test_regress/t/t_debug_graph_test.pl
Executable file
20
test_regress/t/t_debug_graph_test.pl
Executable file
@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env perl
|
||||
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
|
||||
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
|
||||
#
|
||||
# Copyright 2003 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.
|
||||
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
||||
|
||||
scenarios(vlt => 1);
|
||||
$ENV{VERILATOR_TEST_NO_GDB} and skip("Skipping due to VERILATOR_TEST_NO_GDB");
|
||||
|
||||
lint(
|
||||
# Check we can call dump() on graph, and other things
|
||||
v_flags => ["--lint-only --debug --debugi-V3GraphTest 9 --debugi-V3GraphDfa 9"],
|
||||
);
|
||||
|
||||
ok(1);
|
||||
1;
|
9
test_regress/t/t_debug_graph_test.v
Normal file
9
test_regress/t/t_debug_graph_test.v
Normal file
@ -0,0 +1,9 @@
|
||||
// DESCRIPTION: Verilator: Dotted reference that uses another dotted reference
|
||||
// as the select expression
|
||||
//
|
||||
// This file ONLY is placed into the Public Domain, for any use,
|
||||
// without warranty, 2015 by Todd Strader.
|
||||
// SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
module t (/*AUTOARG*/);
|
||||
endmodule
|
@ -12,15 +12,21 @@ scenarios(vlt => 1);
|
||||
|
||||
$ENV{FOOBARTEST} = "gotit";
|
||||
|
||||
compile(
|
||||
v_flags2 => ["--getenv FOOBARTEST"],
|
||||
expect =>
|
||||
'gotit
|
||||
run(
|
||||
cmd => ["../bin/verilator --getenv FOOBARTEST"],
|
||||
expect => 'gotit
|
||||
',
|
||||
verilator_make_gmake => 0,
|
||||
make_top_shell => 0,
|
||||
make_main => 0,
|
||||
logfile => "$Self->{obj_dir}/simx.log",
|
||||
verilator_run => 1,
|
||||
);
|
||||
|
||||
foreach my $var (qw(MAKE PERL SYSTEMC SYSTEMC_ARCH SYSTEMC_LIBDIR VERILATOR_ROOT)) {
|
||||
run(
|
||||
cmd => ["../bin/verilator --getenv ${var}"],
|
||||
logfile => "$Self->{obj_dir}/simx.log",
|
||||
verilator_run => 1,
|
||||
);
|
||||
}
|
||||
|
||||
ok(1);
|
||||
1;
|
||||
|
19
test_regress/t/t_flag_language_bad.pl
Executable file
19
test_regress/t/t_flag_language_bad.pl
Executable file
@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env perl
|
||||
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
|
||||
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
|
||||
#
|
||||
# Copyright 2008 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.
|
||||
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
||||
|
||||
scenarios(vlt => 1);
|
||||
|
||||
compile(
|
||||
verilator_flags2 => ['--language 1-2-3-4'],
|
||||
fails => 1,
|
||||
);
|
||||
|
||||
ok(1);
|
||||
1;
|
23
test_regress/t/t_vpi_finish.pl
Executable file
23
test_regress/t/t_vpi_finish.pl
Executable file
@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env perl
|
||||
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
|
||||
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
|
||||
#
|
||||
# Copyright 2003 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.
|
||||
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
||||
|
||||
scenarios(simulator => 1);
|
||||
|
||||
compile(
|
||||
v_flags2 => ["--vpi t/t_vpi_finish_c.cpp"],
|
||||
);
|
||||
|
||||
execute(
|
||||
check_finished => 1,
|
||||
);
|
||||
|
||||
ok(1);
|
||||
|
||||
1;
|
17
test_regress/t/t_vpi_finish.v
Normal file
17
test_regress/t/t_vpi_finish.v
Normal file
@ -0,0 +1,17 @@
|
||||
// DESCRIPTION: Verilator: Verilog Test module
|
||||
//
|
||||
// Copyright 2020 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.
|
||||
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
||||
|
||||
module t (/*AUTOARG*/);
|
||||
|
||||
import "DPI-C" function void dpii_test();
|
||||
|
||||
initial begin
|
||||
$write("*-* All Finished *-*\n");
|
||||
dpii_test(); // $finish
|
||||
end
|
||||
endmodule
|
27
test_regress/t/t_vpi_finish_c.cpp
Normal file
27
test_regress/t/t_vpi_finish_c.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
||||
//*************************************************************************
|
||||
//
|
||||
// Copyright 2009-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.
|
||||
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
||||
//
|
||||
//*************************************************************************
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include "svdpi.h"
|
||||
#include "vpi_user.h"
|
||||
|
||||
//======================================================================
|
||||
|
||||
extern "C" {
|
||||
extern void dpii_test();
|
||||
}
|
||||
|
||||
//======================================================================
|
||||
|
||||
void dpii_test() {
|
||||
vpi_control(vpiFinish);
|
||||
}
|
2
test_regress/t/t_vpi_stop_bad.out
Normal file
2
test_regress/t/t_vpi_stop_bad.out
Normal file
@ -0,0 +1,2 @@
|
||||
%Error: Verilog $stop
|
||||
Aborting...
|
25
test_regress/t/t_vpi_stop_bad.pl
Executable file
25
test_regress/t/t_vpi_stop_bad.pl
Executable file
@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env perl
|
||||
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
|
||||
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
|
||||
#
|
||||
# Copyright 2003 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.
|
||||
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
||||
|
||||
scenarios(simulator => 1);
|
||||
|
||||
compile(
|
||||
v_flags2 => ["--vpi t/t_vpi_stop_bad_c.cpp"],
|
||||
);
|
||||
|
||||
execute(
|
||||
fails => 1,
|
||||
check_finished => 0,
|
||||
expect_filename => $Self->{golden_filename},
|
||||
);
|
||||
|
||||
ok(1);
|
||||
|
||||
1;
|
19
test_regress/t/t_vpi_stop_bad.v
Normal file
19
test_regress/t/t_vpi_stop_bad.v
Normal file
@ -0,0 +1,19 @@
|
||||
// DESCRIPTION: Verilator: Verilog Test module
|
||||
//
|
||||
// Copyright 2020 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.
|
||||
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
||||
|
||||
module t (/*AUTOARG*/);
|
||||
|
||||
import "DPI-C" function void dpii_test();
|
||||
|
||||
initial begin
|
||||
dpii_test();
|
||||
$display("Should have stopped above");
|
||||
//$write("*-* All Finished *-*\n");
|
||||
$finish;
|
||||
end
|
||||
endmodule
|
27
test_regress/t/t_vpi_stop_bad_c.cpp
Normal file
27
test_regress/t/t_vpi_stop_bad_c.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
||||
//*************************************************************************
|
||||
//
|
||||
// Copyright 2009-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.
|
||||
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
||||
//
|
||||
//*************************************************************************
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include "svdpi.h"
|
||||
#include "vpi_user.h"
|
||||
|
||||
//======================================================================
|
||||
|
||||
extern "C" {
|
||||
extern void dpii_test();
|
||||
}
|
||||
|
||||
//======================================================================
|
||||
|
||||
void dpii_test() {
|
||||
vpi_control(vpiStop);
|
||||
}
|
@ -71,6 +71,7 @@ unsigned int callback_count = 0;
|
||||
|
||||
int _mon_check_unimpl(p_cb_data cb_data) {
|
||||
static TestVpiHandle cb, clk_h;
|
||||
vpiHandle handle;
|
||||
if (cb_data) {
|
||||
// this is the callback
|
||||
s_vpi_error_info info;
|
||||
@ -123,6 +124,33 @@ int _mon_check_unimpl(p_cb_data cb_data) {
|
||||
CHECK_RESULT(callback_count, 16);
|
||||
vpi_handle_by_multi_index(NULL, 0, NULL);
|
||||
CHECK_RESULT(callback_count, 17);
|
||||
vpi_control(0);
|
||||
CHECK_RESULT(callback_count, 18);
|
||||
|
||||
s_vpi_time time_s;
|
||||
time_s.type = 0;
|
||||
vpi_get_time(NULL, &time_s);
|
||||
CHECK_RESULT(callback_count, 19);
|
||||
|
||||
handle = vpi_put_value(NULL, NULL, NULL, 0);
|
||||
CHECK_RESULT(callback_count, 20);
|
||||
CHECK_RESULT(handle, 0);
|
||||
|
||||
handle = vpi_handle(0, NULL);
|
||||
CHECK_RESULT(callback_count, 21);
|
||||
CHECK_RESULT(handle, 0);
|
||||
|
||||
vpi_iterate(0, NULL);
|
||||
CHECK_RESULT(callback_count, 22);
|
||||
|
||||
handle = vpi_register_cb(NULL);
|
||||
CHECK_RESULT(callback_count, 23);
|
||||
CHECK_RESULT(handle, 0);
|
||||
s_cb_data cb_data_s;
|
||||
cb_data_s.reason = 0; // Bad
|
||||
handle = vpi_register_cb(&cb_data_s);
|
||||
CHECK_RESULT(callback_count, 24);
|
||||
CHECK_RESULT(handle, 0);
|
||||
}
|
||||
return 0; // Ok
|
||||
}
|
||||
@ -173,7 +201,9 @@ int main(int argc, char** argv, char** env) {
|
||||
if (tfp) tfp->dump(main_time);
|
||||
#endif
|
||||
}
|
||||
CHECK_RESULT(callback_count, 17);
|
||||
if (!callback_count) {
|
||||
vl_fatal(FILENM, __LINE__, "main", "%Error: never got callbacks");
|
||||
}
|
||||
if (!Verilated::gotFinish()) {
|
||||
vl_fatal(FILENM, __LINE__, "main", "%Error: Timeout; never got a $finish");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user