Jump to content
howardhsu

How to use sc_elab_and_sim?

Recommended Posts

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!

Share this post


Link to post
Share on other sites

 

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.

Share this post


Link to post
Share on other sites

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" :P.

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!

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...