sc_start_starvation.cpp revision 12855:588919e0e4aa
1 2// sc_start with event starvation policy 3 4#define SC_INCLUDE_DYNAMIC_PROCESSES 5 6#include <systemc> 7using namespace sc_core; 8using std::cout; 9using std::endl; 10 11SC_MODULE(Top) 12{ 13 SC_CTOR(Top) 14 { 15 SC_THREAD(T); 16 } 17 18 sc_event ev2; 19 20 void T() 21 { 22 sc_assert( sc_get_status() == SC_RUNNING ); 23 ev2.notify(150, SC_NS); 24 25 //wait(ev2); // Inserting this line makes the test pass 26 } 27}; 28 29int sc_main(int argc, char* argv[]) 30{ 31 Top top("top"); 32 33 sc_event ev; 34 ev.notify(250, SC_NS); 35 36 sc_assert( sc_get_status() == SC_ELABORATION ); 37 sc_assert( sc_time_stamp() == SC_ZERO_TIME ); 38 sc_start(100, SC_NS); 39 sc_assert( sc_get_status() == SC_PAUSED ); 40 sc_assert( sc_time_stamp() == sc_time(100, SC_NS) ); 41 42 sc_start(10, SC_NS, SC_RUN_TO_TIME); 43 sc_assert( sc_time_stamp() == sc_time(110, SC_NS) ); 44 45 sc_start(10, SC_NS, SC_EXIT_ON_STARVATION); 46 sc_assert( sc_time_stamp() == sc_time(110, SC_NS) ); 47 48 sc_start(80, SC_NS, SC_EXIT_ON_STARVATION); 49 50 cout << "sc_time_stamp() = " << sc_time_stamp() << endl; 51 cout << "sc_pending_activity_at_future_time() = " << sc_pending_activity_at_future_time() << endl; 52 cout << "sc_time_to_pending_activity() = " << sc_time_to_pending_activity() << endl; 53 54 sc_assert( sc_time_stamp() == sc_time(150, SC_NS) ); // FAILS. Does not see ev2 55 56 sc_start(50, SC_NS, SC_EXIT_ON_STARVATION); 57 sc_assert( sc_time_stamp() == sc_time(150, SC_NS) ); 58 59 sc_start(50, SC_NS, SC_RUN_TO_TIME); 60 sc_assert( sc_time_stamp() == sc_time(200, SC_NS) ); 61 62 sc_start(); 63 sc_assert( sc_get_status() == SC_PAUSED ); 64 sc_assert( sc_time_stamp() == sc_time(250, SC_NS) ); 65 66 ev.notify(SC_ZERO_TIME); 67 sc_start(); 68 sc_assert( sc_time_stamp() == sc_time(250, SC_NS) ); 69 70 ev.notify(10, SC_NS); 71 sc_start(); 72 sc_assert( sc_time_stamp() == sc_time(260, SC_NS) ); 73 74 ev.notify(10, SC_NS); 75 sc_start(sc_time(100, SC_NS), SC_EXIT_ON_STARVATION); 76 sc_assert( sc_time_stamp() == sc_time(270, SC_NS) ); 77 78 ev.notify(10, SC_NS); 79 sc_start(sc_time(100, SC_NS)); // SC_RUN_TO_TIME 80 sc_assert( sc_time_stamp() == sc_time(370, SC_NS) ); 81 sc_assert( sc_get_status() == SC_PAUSED ); 82 83 cout << endl << "Success" << endl; 84 return 0; 85} 86