From b42104117e97e06136f9f2a016fa7433a011b4b0 Mon Sep 17 00:00:00 2001 From: Dragos Dospinescu Date: Wed, 4 Sep 2024 21:53:33 +0200 Subject: [PATCH 1/2] Fix accellera-official/fc4sc#20 --- examples/fir/src/display.cpp | 2 +- includes/fc4sc_coverpoint.hpp | 27 +++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/examples/fir/src/display.cpp b/examples/fir/src/display.cpp index 04675c9..d344ece 100644 --- a/examples/fir/src/display.cpp +++ b/examples/fir/src/display.cpp @@ -70,7 +70,7 @@ void display::entry(){ << " at time " << sc_time_stamp().to_double() << endl; // generate the coverage database from the collected data - fc4sc::global::coverage_save("coverage_results.xml"); + xml_printer::coverage_save("coverage_results.xml"); sc_stop(); }; } diff --git a/includes/fc4sc_coverpoint.hpp b/includes/fc4sc_coverpoint.hpp index 51493b4..4fb3fdb 100644 --- a/includes/fc4sc_coverpoint.hpp +++ b/includes/fc4sc_coverpoint.hpp @@ -148,6 +148,9 @@ class coverpoint final : public coverpoint_base /*! Expression used to sample the data */ std::function sample_expression; + /*! Sample value resulted from evaluation of the sample_expression() function */ + T sample_value_resulted; + /*! * \brief Create a dynamic copy of this coverpoint with matching bin types */ @@ -550,13 +553,29 @@ class coverpoint final : public coverpoint_base throw e; } if (cond) { + // 1) try to evaluate the sample_expression try { - this->sample(sample_expression()); - } catch(const std::exception& e) { + // sample_expression is a std::function which might throw an exception if it is not bound + sample_value_resulted = sample_expression(); + } + catch(const std::exception& e) { std::cerr << e.what() << "\n"; std::cerr << "sample_expression is not binded for coverpoint " << this->cvp_data->name << "\n"; throw e; } + // 2) sample the value and catch any illegal bin value exception + try { + // sample call might throw an illegal_bin_sample_exception if an illegal_bin is hit + this->sample(sample_value_resulted); + } + catch(illegal_bin_sample_exception &e) { + e.update_cvp_info(this->name()); + std::cerr << e.what() << std::endl; +#ifndef FC4SC_NO_THROW // By default the simulation will stop + std::cerr << "Stopping simulation\n"; + throw(e); +#endif + } } else { // This is a fix so that crosses are not sampled if any of the coverpoints @@ -566,6 +585,10 @@ class coverpoint final : public coverpoint_base } } else { + // NOTE: This is the legacy implementation of the sampling logic + // (before the COVERPOINT macro was added). + // Eventually, it should be removed entirely, since it's obsolete and we + // don't want to have 2 APIs and implementations for the same functioality. this->sample(*sample_point); } } From d337a8cbd3b024d1c2f0da6a4bfe344214361cb4 Mon Sep 17 00:00:00 2001 From: Dragos Dospinescu Date: Wed, 4 Sep 2024 22:17:17 +0200 Subject: [PATCH 2/2] Improve illegal sample exception message in coverpoint - Remove std::cerr from coverpoint's catch of illigal_bin_sample_exception - remove #ifndef of FC4SC_NO_THROW from coverpoint, so that exception is thrown to be catched by covergroup --- includes/fc4sc_coverpoint.hpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/includes/fc4sc_coverpoint.hpp b/includes/fc4sc_coverpoint.hpp index 4fb3fdb..d7dab11 100644 --- a/includes/fc4sc_coverpoint.hpp +++ b/includes/fc4sc_coverpoint.hpp @@ -570,11 +570,7 @@ class coverpoint final : public coverpoint_base } catch(illegal_bin_sample_exception &e) { e.update_cvp_info(this->name()); - std::cerr << e.what() << std::endl; -#ifndef FC4SC_NO_THROW // By default the simulation will stop - std::cerr << "Stopping simulation\n"; throw(e); -#endif } } else {