Add VerilatedCovContext::forcePerInstance (#2793).

This commit is contained in:
Wilson Snyder 2021-03-19 22:24:00 -04:00
parent 3fd3526d76
commit b6c393e9f0
9 changed files with 53 additions and 8 deletions

View File

@ -17,6 +17,7 @@ Verilator 4.201 devel
* Changed TIMESCALEMOD from error into a warning.
* Verilated signals now use VlWide and VlPacked in place of C arrays.
* Mark --no-relative-cfuncs as scheduled for deprecation.
* Add VerilatedCovContext::forcePerInstance (#2793). [Kevin Laeufer]
* Fix class unpacked-array compile error (#2774). [Iru Cai]
* Fix exceeding command-line ar limit (#2834). [Yinan Xu]
* Fix false $dumpfile warning on model save (#2834). [Yinan Xu]

View File

@ -107,6 +107,7 @@ private:
VerilatedCovImpItem* m_insertp VL_GUARDED_BY(m_mutex) = nullptr; ///< Item about to insert
const char* m_insertFilenamep VL_GUARDED_BY(m_mutex) = nullptr; ///< Filename about to insert
int m_insertLineno VL_GUARDED_BY(m_mutex) = 0; ///< Line number about to insert
bool m_forcePerInstance VL_GUARDED_BY(m_mutex) = false; ///< Force per_instance
public:
// CONSTRUCTORS
@ -245,6 +246,11 @@ private:
public:
// PUBLIC METHODS
void forcePerInstance(bool flag) VL_MT_SAFE_EXCLUDES(m_mutex) {
Verilated::quiesce();
const VerilatedLockGuard lock(m_mutex);
m_forcePerInstance = flag;
}
void clear() VL_MT_SAFE_EXCLUDES(m_mutex) {
Verilated::quiesce();
const VerilatedLockGuard lock(m_mutex);
@ -362,6 +368,7 @@ public:
std::string name;
std::string hier;
bool per_instance = false;
if (m_forcePerInstance) per_instance = true;
for (int i = 0; i < VerilatedCovConst::MAX_KEYS; ++i) {
if (itemp->m_keys[i] != VerilatedCovConst::KEY_UNDEF) {
@ -413,6 +420,9 @@ public:
//=============================================================================
// VerilatedCovContext
void VerilatedCovContext::forcePerInstance(bool flag) VL_MT_SAFE {
impp()->forcePerInstance(flag);
}
void VerilatedCovContext::clear() VL_MT_SAFE { impp()->clear(); }
void VerilatedCovContext::clearNonMatch(const char* matchp) VL_MT_SAFE {
impp()->clearNonMatch(matchp);

View File

@ -96,6 +96,8 @@ public:
// METHODS
/// Return default filename
static const char* defaultFilename() VL_PURE { return "coverage.dat"; }
/// Make all data per_instance, overriding point's per_instance
void forcePerInstance(bool flag) VL_MT_SAFE;
/// Write all coverage data to a file
void write(const char* filenamep = defaultFilename()) VL_MT_SAFE;
/// Clear coverage points (and call delete on all items)

View File

@ -26,6 +26,7 @@ files_identical_sorted("$Self->{obj_dir}/coverage1.dat", "t/t_cover_lib_1.out");
files_identical_sorted("$Self->{obj_dir}/coverage2.dat", "t/t_cover_lib_2.out");
files_identical_sorted("$Self->{obj_dir}/coverage3.dat", "t/t_cover_lib_3.out");
files_identical_sorted("$Self->{obj_dir}/coverage4.dat", "t/t_cover_lib_4.out");
files_identical_sorted("$Self->{obj_dir}/coverage1_per_instance.dat", "t/t_cover_lib_1_per_instance.out");
ok(1);
1;

View File

@ -1,4 +1,7 @@
# SystemC::Coverage-3
C 'f../../t/t_cover_lib_c.cppl39pagesp_user/t_cover_lib_cokept_onehmain' 100
C 'f../../t/t_cover_lib_c.cppl40pagesp_user/t_cover_lib_cokept_twohmain' 210
C 'f../../t/t_cover_lib_c.cppl41pagesp_user/t_cover_lib_colost_threehmain' 220
C 'f../../t/t_cover_lib_c.cppl37pagesp_user/t_cover_lib_cP0htop.a*.pi' 500
C 'f../../t/t_cover_lib_c.cppl37pagesp_user/t_cover_lib_cP1htop.a0.npi' 200
C 'f../../t/t_cover_lib_c.cppl37pagesp_user/t_cover_lib_cP1htop.a1.npi' 300
C 'f../../t/t_cover_lib_c.cppl46pagesp_user/t_cover_lib_cokept_onehmain' 100
C 'f../../t/t_cover_lib_c.cppl47pagesp_user/t_cover_lib_cokept_twohmain' 210
C 'f../../t/t_cover_lib_c.cppl48pagesp_user/t_cover_lib_colost_threehmain' 220

View File

@ -0,0 +1,8 @@
# SystemC::Coverage-3
C 'f../../t/t_cover_lib_c.cppl37pagesp_user/t_cover_lib_cP0htop.a0.pi' 200
C 'f../../t/t_cover_lib_c.cppl37pagesp_user/t_cover_lib_cP0htop.a1.pi' 300
C 'f../../t/t_cover_lib_c.cppl37pagesp_user/t_cover_lib_cP1htop.a0.npi' 200
C 'f../../t/t_cover_lib_c.cppl37pagesp_user/t_cover_lib_cP1htop.a1.npi' 300
C 'f../../t/t_cover_lib_c.cppl46pagesp_user/t_cover_lib_cokept_onehmain' 100
C 'f../../t/t_cover_lib_c.cppl47pagesp_user/t_cover_lib_cokept_twohmain' 210
C 'f../../t/t_cover_lib_c.cppl48pagesp_user/t_cover_lib_colost_threehmain' 220

View File

@ -1,3 +1,3 @@
# SystemC::Coverage-3
C 'f../../t/t_cover_lib_c.cppl39pagesp_user/t_cover_lib_cokept_onehmain' 100
C 'f../../t/t_cover_lib_c.cppl40pagesp_user/t_cover_lib_cokept_twohmain' 210
C 'f../../t/t_cover_lib_c.cppl46pagesp_user/t_cover_lib_cokept_onehmain' 100
C 'f../../t/t_cover_lib_c.cppl47pagesp_user/t_cover_lib_cokept_twohmain' 210

View File

@ -1,3 +1,3 @@
# SystemC::Coverage-3
C 'f../../t/t_cover_lib_c.cppl39pagesp_user/t_cover_lib_cokept_onehmain' 0
C 'f../../t/t_cover_lib_c.cppl40pagesp_user/t_cover_lib_cokept_twohmain' 0
C 'f../../t/t_cover_lib_c.cppl46pagesp_user/t_cover_lib_cokept_onehmain' 0
C 'f../../t/t_cover_lib_c.cppl47pagesp_user/t_cover_lib_cokept_twohmain' 0

View File

@ -30,9 +30,16 @@ int errors = 0;
const char* name() { return "main"; }
void hier_insert(VerilatedCovContext* covContextp, vluint64_t* countp, const char* hierp,
const char* peri) {
// This needs to be a function at one line number so all of the
// line numbers for coverage are constant, otherwise instances won't combine.
VL_COVER_INSERT(covContextp, countp, "hier", hierp, "per_instance", peri);
}
int main() {
vluint32_t covers[1];
vluint64_t coverw[2];
vluint64_t coverw[6];
VerilatedCovContext* covContextp = Verilated::defaultContextp()->coveragep();
@ -40,13 +47,26 @@ int main() {
VL_COVER_INSERT(covContextp, &coverw[0], "comment", "kept_two");
VL_COVER_INSERT(covContextp, &coverw[1], "comment", "lost_three");
hier_insert(covContextp, &coverw[2], "top.a0.pi", "0");
hier_insert(covContextp, &coverw[3], "top.a1.pi", "0");
hier_insert(covContextp, &coverw[4], "top.a0.npi", "1");
hier_insert(covContextp, &coverw[5], "top.a1.npi", "1");
covers[0] = 100;
coverw[0] = 210;
coverw[1] = 220;
coverw[2] = 200;
coverw[3] = 300;
coverw[4] = 200;
coverw[5] = 300;
#ifdef T_COVER_LIB
TEST_CHECK_CSTR(covContextp->defaultFilename(), "coverage.dat");
covContextp->write(VL_STRINGIFY(TEST_OBJ_DIR) "/coverage1.dat");
covContextp->forcePerInstance(true);
covContextp->write(VL_STRINGIFY(TEST_OBJ_DIR) "/coverage1_per_instance.dat");
covContextp->forcePerInstance(false);
covContextp->clearNonMatch("kept_");
covContextp->write(VL_STRINGIFY(TEST_OBJ_DIR) "/coverage2.dat");
covContextp->zero();