0
votes

I've got a SystemC testbench (for a VHDL DUT but that's irrelevant right now). I'd like to be able to cause the test to terminate, with a specific exit code, from within an SC_CTHREAD. I am pretty new to SystemC (I'm mostly a verilog/sv guy).

I've tried simply including "exit(error_code)" but while that terminates the simulation, the final exit code comes from my sc_main's return statement. I guess this makes sense since the "exit" probably terminates the separate thread with that exit code, but not the sc_main thread.

I've tried calling sc_stop before that exit, and usually get an error about calling a pure virtual method (I believe that's end_of_simulation, which I have not defined....but that should be optional, right?).

The only way I see to affect the exit code of the process is to change the return statement of sc_main, but that doesn't quite work when all my action is happening in an SC_THREAD created by a constructor of an object somewhere (if it's not obvious I truly don't understand how SystemC works very well, probably because there's a lot of hidden action with secret classes that we can't see, as opposed to verilog where simulation ordering is all there is, assuming you understand blocking/non-blocking).

Is there a way for the SC_THREAD to pass some failure information up to sc_main?

Note: I am running with a commercial simulation tool, and not pure C++. It's possible that there's an implementation bug there. I'm trying to get our pure C++ compile running but it seems to have broken a while ago (I'm not responsible for the SystemC model).

1

1 Answers

0
votes

The answer, of course, is to have sc_main get its return value by reaching directly into the module that it instantiates to get at a member variable:

return(test_module.exit_code);

I need to remember that we're still running C++ and basic C++ rules apply, so this is possible. In my hardware-design mind, I was spinning off modules and threads that had no connection to the classes that they actually are.