howardhsu Posted December 26, 2014 Report Share Posted December 26, 2014 Hi, I was trying to figure out how to run SystemC simulation in a main function. I have read LRM 4.3.2, Function sc_elab_and_sim, but still can't get it. This is what I did: int sc_elab_and_sim(int argc, char *argv[]) { if (argc == 0) { //Initialize modules and connect them sc_core::sc_start(); return 0; } else{ //Initialize another set of modules and connect them sc_core::sc_start(); return 0; } } int main() { sc_elab_and_sim(0, argv); sc_elab_and_sim(1, argv); return 0; } I use argc to decide which set of modules I want to run, just for test. And I got an exception when it starting second sc_start: libc++abi.dylib: terminating with uncaught exception of type sc_core::sc_report: Error: (E529) insert module failed: simulation running In file: ../../../../src/sysc/kernel/sc_module_registry.cpp:47 I must did something wrong, can anyone tell me? Actually I want to do unit test. Is this the right way or there are other better solutions? Thanks! Quote Link to comment Share on other sites More sharing options...
dakupoto Posted December 29, 2014 Report Share Posted December 29, 2014 Hi, I was trying to figure out how to run SystemC simulation in a main function. I have read LRM 4.3.2, Function sc_elab_and_sim, but still can't get it. This is what I did: int sc_elab_and_sim(int argc, char *argv[]) { if (argc == 0) { //Initialize modules and connect them sc_core::sc_start(); return 0; } else{ //Initialize another set of modules and connect them sc_core::sc_start(); return 0; } } int main() { sc_elab_and_sim(0, argv); sc_elab_and_sim(1, argv); return 0; } I use argc to decide which set of modules I want to run, just for test. And I got an exception when it starting second sc_start: libc++abi.dylib: terminating with uncaught exception of type sc_core::sc_report: Error: (E529) insert module failed: simulation running In file: ../../../../src/sysc/kernel/sc_module_registry.cpp:47 I must did something wrong, can anyone tell me? Actually I want to do unit test. Is this the right way or there are other better solutions? Thanks! Hello Sir, Could you be a bit more specific. It is not clear why you would want to use this method "sc_elab_and_sim". Typically, one would use "sc_main" as in a sample listed below: int sc_main(int argc, char **argv) { /*Declare/define signal channels */ /* Declare/define a clock if needed */ /* Declare/define user-defined modules */ /* Using the signal channels declared/defined previously, interconnect modules */ /* Declare define trace file if needed, and then connect to correct port/channels to examine output */ ?* Start simulation, and run for a pre-defined time period */ } Hope that helps. Quote Link to comment Share on other sites More sharing options...
howardhsu Posted December 29, 2014 Author Report Share Posted December 29, 2014 Hello dakupoto, Thanks for the reply! I want to do unit testing in the main function. For example, I have a priority queue and I want to test whether it works as my expect. I hope I can do one test at a time, like in first one I test whether it can be written and read; and test whether the priority is as my expect in the second test. I want the queue to be "clean" or is a new one before each test starts. And each test is judged with assert statement. If I wrote this in a sequence of actions in sc_main, if one test is failed, the following tests will not be executed. So I was thinking to lunch many SystemC simulation in the main function, each of them do one test. Then I can gather the test results and make a report. The pseudo code in my original post is referenced from here: http://www.accellera.org/Discussion_Forums/helpforum/archive/msg/msg?list_name=help_forum&monthdir=200509&msg=msg00077.html Now I am trying other ways like reset my modules between every tests or create many instances and each one of them is used to run one test. I found that my question should be "How to do unit testing in SystemC" . But still I am curious about how to use sc_elab_and_sim. If anyone could give me a simple example, I'd appreciate it! Quote Link to comment Share on other sites More sharing options...
David Black Posted December 30, 2014 Report Share Posted December 30, 2014 The PoC SystemC simulator implementation is not designed to be restarted at time zero. Thus you cannot run two simulations within one main. maehne 1 Quote Link to comment Share on other sites More sharing options...
howardhsu Posted January 5, 2015 Author Report Share Posted January 5, 2015 Alright... Thanks for reply! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.