Internal code coverage cleanups.

This commit is contained in:
Wilson Snyder 2021-03-07 21:05:15 -05:00
parent 1533693654
commit 9483ebefae
10 changed files with 47 additions and 67 deletions

View File

@ -191,8 +191,8 @@ public:
// Empty non-threaded mutex to avoid #ifdefs in consuming code
class VerilatedMutex final {
public:
void lock() {}
void unlock() {}
void lock() {} // LCOV_EXCL_LINE
void unlock() {} // LCOV_EXCL_LINE
};
// Empty non-threaded lock guard to avoid #ifdefs in consuming code
@ -202,8 +202,8 @@ class VerilatedLockGuard final {
public:
explicit VerilatedLockGuard(VerilatedMutex&) {}
~VerilatedLockGuard() = default;
void lock() {}
void unlock() {}
void lock() {} // LCOV_EXCL_LINE
void unlock() {} // LCOV_EXCL_LINE
};
#endif // VL_THREADED

View File

@ -61,7 +61,7 @@ public:
std::string filename() const { return m_filename; }
virtual void close() VL_MT_UNSAFE_ONE { flush(); }
virtual void flush() VL_MT_UNSAFE_ONE {}
inline VerilatedSerialize& write(const void* __restrict datap, size_t size) VL_MT_UNSAFE_ONE {
VerilatedSerialize& write(const void* __restrict datap, size_t size) VL_MT_UNSAFE_ONE {
const vluint8_t* __restrict dp = (const vluint8_t* __restrict)datap;
while (size) {
bufferCheck();
@ -122,7 +122,7 @@ public:
std::string filename() const { return m_filename; }
virtual void close() VL_MT_UNSAFE_ONE { flush(); }
virtual void flush() VL_MT_UNSAFE_ONE {}
inline VerilatedDeserialize& read(void* __restrict datap, size_t size) VL_MT_UNSAFE_ONE {
VerilatedDeserialize& read(void* __restrict datap, size_t size) VL_MT_UNSAFE_ONE {
vluint8_t* __restrict dp = static_cast<vluint8_t* __restrict>(datap);
while (size) {
bufferCheck();

View File

@ -352,7 +352,7 @@ template <> void VerilatedTrace<VL_DERIVED_T>::traceInit() VL_MT_UNSAFE {
template <>
void VerilatedTrace<VL_DERIVED_T>::declCode(vluint32_t code, vluint32_t bits, bool tri) {
if (!code) {
if (VL_UNCOVERABLE(!code)) {
VL_FATAL_MT(__FILE__, __LINE__, "", "Internal: internal trace problem, code 0 is illegal");
}
// Note: The tri-state flag is not used by Verilator, but is here for
@ -655,6 +655,8 @@ void verilated_trace_imp_selftest() {
#define SELF_CHECK_TS(scale) \
SELF_CHECK(doubleToTimescale(timescaleToDouble(scale)), std::string{scale});
SELF_CHECK_TS("100s");
SELF_CHECK_TS("10s");
SELF_CHECK_TS("1s");
SELF_CHECK_TS("100ms");
SELF_CHECK_TS("10ms");

View File

@ -879,6 +879,10 @@ void vcdTestMain(const char* filenamep) {
{
VerilatedVcdC* vcdp = new VerilatedVcdC;
vcdp->evcd(true);
vcdp->set_time_unit("1ms");
vcdp->set_time_unit(std::string("1ms"));
vcdp->set_time_resolution("1ns");
vcdp->set_time_resolution(std::string("1ns"));
vcdp->spTrace()->addInitCb(&vcdInit, 0);
vcdp->spTrace()->addFullCb(&vcdFull, 0);
vcdp->spTrace()->addChgCb(&vcdChange, 0);

View File

@ -167,7 +167,7 @@ public:
of.puts(string("SYSTEMC_LIBDIR ?= ") + V3Options::getenvSYSTEMC_LIBDIR() + "\n");
// Only check it if we really need the value
if (v3Global.opt.usingSystemCLibs() && !V3Options::systemCFound()) {
if (v3Global.opt.systemC() && !V3Options::systemCFound()) {
v3fatal("Need $SYSTEMC_INCLUDE in environment or when Verilator configured,\n"
"and need $SYSTEMC_LIBDIR in environment or when Verilator configured\n"
"Probably System-C isn't installed, see http://www.systemc.org\n");

View File

@ -225,7 +225,7 @@ void FileLine::forwardToken(const char* textp, size_t size, bool trackLines) {
if (*sp == '\n') {
if (trackLines) linenoInc();
m_lastColumn = 1;
} else if (*sp == '\r') {
} else if (VL_UNCOVERABLE(*sp == '\r')) { // Generally stripped by preproc
} else { // Tabs are considered one column; hence column means number of chars
++m_lastColumn;
}

View File

@ -37,7 +37,7 @@ class VOptionBool final {
// Class to track options that are either not specified (and default
// true/false), versus user setting the option to true or false
public:
enum en : uint8_t { OPT_DEFAULT_FALSE = 0, OPT_DEFAULT_TRUE, OPT_TRUE, OPT_FALSE, _ENUM_END };
enum en : uint8_t { OPT_DEFAULT_FALSE = 0, OPT_DEFAULT_TRUE, OPT_TRUE, OPT_FALSE };
enum en m_e;
inline VOptionBool()
: m_e{OPT_DEFAULT_FALSE} {}
@ -49,23 +49,15 @@ public:
operator en() const { return m_e; }
bool isDefault() const { return m_e == OPT_DEFAULT_FALSE || m_e == OPT_DEFAULT_TRUE; }
bool isTrue() const { return m_e == OPT_TRUE || m_e == OPT_DEFAULT_TRUE; }
bool isFalse() const { return m_e == OPT_FALSE || m_e == OPT_DEFAULT_FALSE; }
bool isSetTrue() const { return m_e == OPT_TRUE; }
bool isSetFalse() const { return m_e == OPT_FALSE; }
void setTrueOrFalse(bool flag) { m_e = flag ? OPT_TRUE : OPT_FALSE; }
const char* ascii() const {
static const char* const names[] = {"DEFAULT_FALSE", "DEFAULT_TRUE", "TRUE", "FALSE"};
return names[m_e];
}
};
inline bool operator==(const VOptionBool& lhs, const VOptionBool& rhs) {
return lhs.m_e == rhs.m_e;
}
inline bool operator==(const VOptionBool& lhs, VOptionBool::en rhs) { return lhs.m_e == rhs; }
inline bool operator==(VOptionBool::en lhs, const VOptionBool& rhs) { return lhs == rhs.m_e; }
inline std::ostream& operator<<(std::ostream& os, const VOptionBool& rhs) {
return os << rhs.ascii();
}
//######################################################################
@ -97,43 +89,11 @@ public:
VTimescale(const string& value, bool& badr);
VTimescale(double value, bool& badr) {
badr = false;
if (value == 10e2) {
m_e = TS_100S;
} else if (value == 1e1) {
m_e = TS_10S;
} else if (value == 1e0) {
m_e = TS_1S;
} else if (value == 1e-1) {
m_e = TS_100MS;
} else if (value == 1e-2) {
m_e = TS_10MS;
} else if (value == 1e-3) {
m_e = TS_1MS;
} else if (value == 1e-4) {
m_e = TS_100US;
} else if (value == 1e-5) {
m_e = TS_10US;
} else if (value == 1e-6) {
m_e = TS_1US;
} else if (value == 1e-7) {
m_e = TS_100NS;
} else if (value == 1e-8) {
m_e = TS_10NS;
} else if (value == 1e-9) {
m_e = TS_1NS;
} else if (value == 1e-10) {
m_e = TS_100PS;
} else if (value == 1e-11) {
m_e = TS_10PS;
} else if (value == 1e-12) {
m_e = TS_1PS;
} else if (value == 1e-13) {
m_e = TS_100FS;
} else if (value == 1e-14) {
m_e = TS_10FS;
} else if (value == 1e-15) {
m_e = TS_1FS;
} else {
for (int i = TS_100S; i < _ENUM_END; ++i) {
m_e = static_cast<en>(i);
if (multiplier() == value) break;
}
if (multiplier() != value) {
m_e = NONE;
badr = true;
}
@ -450,7 +410,6 @@ public:
string bin() const { return m_bin; }
string flags() const { return m_flags; }
bool systemC() const { return m_systemC; }
bool usingSystemCLibs() const { return !lintOnly() && systemC(); }
bool savable() const { return m_savable; }
bool stats() const { return m_stats; }
bool statsVars() const { return m_statsVars; }
@ -562,7 +521,6 @@ public:
string modPrefix() const { return m_modPrefix; }
string pipeFilter() const { return m_pipeFilter; }
string prefix() const { return m_prefix; }
string protectKey() const { return m_protectKey; }
string protectKeyDefaulted(); // Set default key if not set by user
string protectLib() const { return m_protectLib; }
string protectLibName(bool shared) {
@ -589,7 +547,6 @@ public:
const V3StringSet& libraryFiles() const { return m_libraryFiles; }
const V3StringList& vFiles() const { return m_vFiles; }
const V3StringList& forceIncs() const { return m_forceIncs; }
const V3LangCode& defaultLanguage() const { return m_defaultLanguage; }
bool hasParameter(const string& name);
string parameter(const string& name);

View File

@ -1159,7 +1159,7 @@ sub compile {
entering => "$self->{obj_dir}",
cmd => [$ENV{MAKE},
"-C ".$self->{obj_dir},
"-f ".$::RealBin."/Makefile_obj",
"-f ".$FindBin::RealBin."/Makefile_obj",
($self->{verbose} ? "" : "--no-print-directory"),
"VM_PREFIX=$self->{VM_PREFIX}",
"TEST_OBJ_DIR=$self->{obj_dir}",
@ -1332,6 +1332,7 @@ sub execute {
%param,
expect=>$param{expect}, # backward compatible name
expect_filename=>$param{expect_filename}, # backward compatible name
verilator_run => 1,
);
}
else {
@ -1547,23 +1548,28 @@ sub _run {
#entering => # Print entering directory information
#verilator_run => # Move gcov data to parallel area
@_);
my $command = join(' ',@{$param{cmd}});
$command = "time $command" if $opt_benchmark && $command !~ /^cd /;
print "\t$command";
print " > $param{logfile}" if $param{logfile};
print "\n";
if ($param{verilator_run}) {
# Gcov fails when parallel jobs write same data file,
# so we make sure output dir is unique across all running jobs.
# We can't just put each one in obj_dir as it uses too much disk.
# so we make sure .gcda output dir is unique across all running jobs.
# We can't just put each one in a unique obj_dir as it uses too much disk.
# Must use absolute path as some execute()s have different PWD
$ENV{GCOV_PREFIX_STRIP} = 99;
$ENV{GCOV_PREFIX} = "$self->{t_dir}/obj_dist/gcov_$self->{running_id}";
$ENV{GCOV_PREFIX} = File::Spec->rel2abs("$FindBin::RealBin/obj_dist/gcov_$self->{running_id}");
mkdir $ENV{GCOV_PREFIX};
print "export GCOV_PREFIX_STRIP=99 GCOV_PREFIX=$ENV{GCOV_PREFIX}\n" if $self->{verbose};
} else {
delete $ENV{GCOV_PREFIX_STRIP};
delete $ENV{GCOV_PREFIX};
}
print "\t$command";
print " > $param{logfile}" if $param{logfile};
print "\n";
# Execute command redirecting output, keeping order between stderr and stdout.
# Must do low-level IO so GCC interaction works (can't be line-based)
my $status;

View File

@ -16,8 +16,9 @@ module t;
`endif
`endif
`endif
$system("exit 0");
$system("echo hello");
$system("ls"); // IData
$system("exit 0"); // QData
$system("echo hello"); // WDATA
`ifndef VCS
i = $system("exit 0");
if (i!==0) $stop;

View File

@ -49,6 +49,10 @@ int main(int argc, char** argv, char** env) {
Verilated::commandArgs(argc, argv); // Commonly used
CHECK_RESULT_CSTR(Verilated::commandArgsPlusMatch("not-matching"), "");
const char* argadd[] = {"+testingPlusAdd+2", nullptr};
Verilated::commandArgsAdd(1, argadd);
CHECK_RESULT_CSTR(Verilated::commandArgsPlusMatch("testingPlusAdd"), "+testingPlusAdd+2");
Verilated::assertOn(true);
CHECK_RESULT(Verilated::assertOn(), true);
@ -59,6 +63,9 @@ int main(int argc, char** argv, char** env) {
CHECK_RESULT(Verilated::debug(), 9);
Verilated::debug(0);
Verilated::errorLimit(2);
CHECK_RESULT(Verilated::errorLimit(), 2);
Verilated::fatalOnError(true);
CHECK_RESULT(Verilated::fatalOnError(), true);
@ -76,6 +83,9 @@ int main(int argc, char** argv, char** env) {
Verilated::randReset(0);
CHECK_RESULT(Verilated::randReset(), 0);
Verilated::randSeed(1234);
CHECK_RESULT(Verilated::randSeed(), 1234);
Verilated::traceEverOn(true); // Commonly used
CHECK_RESULT_CSTR(Verilated::productName(), Verilated::productName());