test220.cpp revision 12855:588919e0e4aa
1#include <systemc> 2using namespace sc_core; 3using namespace sc_dt; 4using std::cout; 5using std::endl; 6 7// 20) sc_report_handler::stop_after(SC_FATAL,-1) should NOT call sc_stop on 1st fatal error 8 9static bool global_flag_1 = false; 10static bool global_flag_2 = false; 11static bool global_flag_3 = false; 12 13SC_MODULE(M) 14{ 15 SC_CTOR(M) 16 { 17 SC_THREAD(T); 18 } 19 void T() 20 { 21 SC_REPORT_FATAL("/JA", "A bad thing has happened"); 22 wait(1, SC_NS); 23 sc_assert(sc_report_handler::get_count(SC_FATAL) == 1); 24 global_flag_1 = true; 25 26 sc_report_handler::stop_after(SC_FATAL, 0); 27 SC_REPORT_FATAL("/JA", "A bad thing has happened"); 28 wait(1, SC_NS); 29 sc_assert(sc_report_handler::get_count(SC_FATAL) == 2); 30 global_flag_2 = true; 31 32 sc_report_handler::stop_after(SC_FATAL, -1); 33 SC_REPORT_FATAL("/JA", "A bad thing has happened"); 34 wait(1, SC_NS); 35 sc_assert(sc_report_handler::get_count(SC_FATAL) == 3); 36 global_flag_3 = true; 37 } 38}; 39 40struct Top: sc_module 41{ 42 M *m; 43 Top(sc_module_name) 44 { 45 m = new M("m"); 46 } 47}; 48 49int sc_main(int argc, char* argv[]) 50{ 51 cout << "Should be silent except for 3 fatal errors..." << endl; 52 53 sc_report_handler::set_actions(SC_FATAL, SC_DISPLAY); 54 55 Top top("top"); 56 sc_start(); 57 58 sc_assert(global_flag_1); 59 sc_assert(global_flag_2); 60 sc_assert(global_flag_3); 61 sc_assert(sc_report_handler::get_count(SC_INFO) == 0); 62 sc_assert(sc_report_handler::get_count(SC_WARNING) == 0); 63 sc_assert(sc_report_handler::get_count(SC_ERROR) == 0); 64 sc_assert(sc_report_handler::get_count(SC_FATAL) == 3); 65 66 cout << endl << "Success" << endl; 67 return 0; 68} 69