Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macro FC4SC_NO_THROW stop simulation action work unexpected when illegal bin touched #20

Open
seabeam opened this issue Jun 7, 2024 · 6 comments · May be fixed by #21
Open

Macro FC4SC_NO_THROW stop simulation action work unexpected when illegal bin touched #20

seabeam opened this issue Jun 7, 2024 · 6 comments · May be fixed by #21

Comments

@seabeam
Copy link

seabeam commented Jun 7, 2024

Hi,

When illegal bin touched, simulation will be stopped regardless of whether it is defiened or not. The root cause is:

In fc4sc_coverpoint.hpp, line 555:

} 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;
}

It catch an exception and type is std::exception then throw, but the cvg will not catch the excpetion in fc4sc_covergroup.hpp, line 190:

    catch(illegal_bin_sample_exception &e) {
      e.update_cvg_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
    }

Due to the expected exception type is illegal_bin_sample_exception not std::exception, the simulation will be stopped.

Can you help to double check it pls?

Thanks!

@SchulzSt
Copy link
Contributor

Could you please provide a minimal example to test against?

@seabeam
Copy link
Author

seabeam commented Aug 24, 2024

Could you please provide a minimal example to test against?

Refer to the examples/fir/src/stimulus.h


#include "fc4sc.hpp"

class stimulus_coverage : public covergroup {
public:
  CG_CONS(stimulus_coverage) {};

  int value = 0;

  void sample(int value) {
    this->value = value;
    covergroup::sample();
  }

  COVERPOINT(int, values_cvp, value) {
    bin<int>("zero", 0),
    illegal_bin<int>("illegal", 1)
  };
};

int main() {
  stimulus_coverage cvg;
  
  cvg.sample(1);
  cvg.sample(0);
  
  return 0;
}

log:

Illegal sample in [/values_cvp/illegal] on value [1]!
sample_expression is not binded for coverpoint values_cvp
terminate called after throwing an instance of 'std::exception'
  what():  std::exception

@seabeam
Copy link
Author

seabeam commented Aug 25, 2024

Hi SchulzSt,

Moreover, the FC4SC_NO_THROW macro works well in:

int SAMPLE_POINT(value, values_cvp);
coverpoint<int> values_cvp = coverpoint<int> (this, "values_cvp",
    illegal_bin<int>("illegal", 1)
);

Due to the COVERPOINT macro will set has_sample_expression = true, then it capture the exception type is std::exception, while the coverpoint constructor will disable has_sample_expression, the function void coverpoint::sample(const T &cvp_val) can catch and rethrow the type of exception illegal_bin_sample_exception

amiq-consulting pushed a commit to amiq-consulting/accellera-fc4sc that referenced this issue Sep 4, 2024
@amiq-consulting amiq-consulting linked a pull request Sep 4, 2024 that will close this issue
@amiq-consulting
Copy link

amiq-consulting commented Sep 4, 2024

Thanks @seabeam for the detailed breakdown and example. I successfully reproduced the bug.

The problem is indeed caused an illegal bin sample, which throws exception of type illegal_bin_sample_exception, as expected. But instead of being caught by the covergroup, it is caught by the coverpoint (and casted to std::exception when thrown again), which makes it past the covergoup.

You are also correct about the fix.
Implemented it in #21.

EDIT: also, FC4SC_NO_THROW macro could benefit from a rename, since the macro only controls exceptions related to sampling on illegal_bin. This would obviously not be backwards compatible, so maybe not worth it?

@SchulzSt
Copy link
Contributor

@seabeam: Can you please check if #21 solves your issue?

@seabeam
Copy link
Author

seabeam commented Nov 2, 2024

@seabeam: Can you please check if #21 solves your issue?

Yes, It solved in this commit of includes/fc4sc_coverpoint.hpp. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants