// -*- mode: C++; c-file-style: "cc-mode" -*- //************************************************************************* // DESCRIPTION: verilator_coverage: top implementation // // Code available from: http://www.veripool.org/verilator // //************************************************************************* // // Copyright 2003-2019 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. // // Verilator is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // //************************************************************************* #include "V3Error.h" #include "V3Os.h" #include "VlcOptions.h" #include "VlcTop.h" #include #include #include //###################################################################### void VlcTop::readCoverage(const string& filename, bool nonfatal) { UINFO(2,"readCoverage "<= VlcBuckets::sufficient()) { points().pointNumber(pointnum).testsCoveringInc(); testp->buckets().addData(pointnum, hits); } } } } } void VlcTop::writeCoverage(const string& filename) { UINFO(2,"writeCoverage "<second); os <<"C '"<computrons() != rhsp->computrons()) { return lhsp->computrons() < rhsp->computrons(); } return lhsp->bucketsCovered() > rhsp->bucketsCovered(); } }; void VlcTop::rank() { UINFO(2,"rank...\n"); vluint64_t nextrank = 1; // Sort by computrons, so fast tests get selected first std::vector bytime; for (VlcTests::ByName::iterator it=m_tests.begin(); it!=m_tests.end(); ++it) { VlcTest* testp = *it; if (testp->bucketsCovered()) { // else no points, so can't help us bytime.push_back(*it); } } sort(bytime.begin(), bytime.end(), CmpComputrons()); // Sort the vector VlcBuckets remaining; for (VlcPoints::ByName::iterator it=m_points.begin(); it!=m_points.end(); ++it) { VlcPoint* pointp = &points().pointNumber(it->second); // If any tests hit this point, then we'll need to cover it. if (pointp->testsCovering()) { remaining.addData(pointp->pointNum(), 1); } } // Additional Greedy algorithm // O(n^2) Ouch. Probably the thing to do is randomize the order of data // then hierarchically solve a small subset of tests, and take resulting // solution and move up to larger subset of tests. (Aka quick sort.) while (1) { if (debug()) { UINFO(9,"Left on iter"<::iterator it=bytime.begin(); it!=bytime.end(); ++it) { VlcTest* testp = *it; if (!testp->rank()) { vluint64_t remain = testp->buckets().dataPopCount(remaining); if (remain > bestRemain) { bestTestp = testp; bestRemain = remain; } } } if (VlcTest* testp = bestTestp) { testp->rank(nextrank++); testp->rankPoints(bestRemain); remaining.orData(bestTestp->buckets()); } else { break; // No test covering more stuff found } } } //###################################################################### void VlcTop::annotateCalc() { // Calculate per-line information into filedata structure for (VlcPoints::ByName::iterator it=m_points.begin(); it!=m_points.end(); ++it) { const VlcPoint& point = m_points.pointNumber(it->second); string filename = point.filename(); int lineno = point.lineno(); if (!filename.empty() && lineno!=0) { int column = point.column(); VlcSource& source = sources().findNewSource(filename); string threshStr = point.thresh(); unsigned thresh = (!threshStr.empty()) ? atoi(threshStr.c_str()) : opt.annotateMin(); bool ok = (point.count() >= thresh); UINFO(9, "AnnoCalc count "<second; //UINFO(1,"Source "<second; for (VlcSource::ColumnMap::iterator cit=cmap.begin(); cit!=cmap.end(); ++cit) { VlcSourceCount& col = cit->second; //UINFO(0,"Source "<second; if (!source.needed()) continue; string filename = source.name(); string outfilename = dirname+"/"+V3Os::filenameNonDir(filename); UINFO(1,"annotateOutputFile "< "<second; for (VlcSource::ColumnMap::iterator cit=cmap.begin(); cit!=cmap.end(); ++cit) { VlcSourceCount& col = cit->second; //UINFO(0,"Source "<