test200.cpp revision 12855
112855Sgabeblack@google.com#include <systemc.h> 212855Sgabeblack@google.com 312855Sgabeblack@google.com// Multiple tests for Annex D.1 and D.2 412855Sgabeblack@google.com 512855Sgabeblack@google.comstruct i_f: virtual sc_interface 612855Sgabeblack@google.com{ 712855Sgabeblack@google.com}; 812855Sgabeblack@google.com 912855Sgabeblack@google.comstruct Chan: i_f, sc_object 1012855Sgabeblack@google.com{ 1112855Sgabeblack@google.com}; 1212855Sgabeblack@google.com 1312855Sgabeblack@google.comstruct Port: sc_port<i_f> 1412855Sgabeblack@google.com{ 1512855Sgabeblack@google.com Chan chan; 1612855Sgabeblack@google.com}; 1712855Sgabeblack@google.com 1812855Sgabeblack@google.comvoid check_form_of_suffix(std::string s) 1912855Sgabeblack@google.com{ 2012855Sgabeblack@google.com std::string charset = "0123456789"; 2112855Sgabeblack@google.com while (!s.empty()) 2212855Sgabeblack@google.com { 2312855Sgabeblack@google.com sc_assert(s[0] == '_'); 2412855Sgabeblack@google.com s = s.substr(1); 2512855Sgabeblack@google.com sc_assert(!s.empty()); 2612855Sgabeblack@google.com do 2712855Sgabeblack@google.com { 2812855Sgabeblack@google.com sc_assert(charset.find(s[0]) < charset.size()); 2912855Sgabeblack@google.com s = s.substr(1); 3012855Sgabeblack@google.com } while (!s.empty() && (s[0] != '_')); 3112855Sgabeblack@google.com } 3212855Sgabeblack@google.com} 3312855Sgabeblack@google.com 3412855Sgabeblack@google.comSC_MODULE(M) 3512855Sgabeblack@google.com{ 3612855Sgabeblack@google.com Port port; 3712855Sgabeblack@google.com 3812855Sgabeblack@google.com SC_CTOR(M) 3912855Sgabeblack@google.com { 4012855Sgabeblack@google.com SC_THREAD(T); 4112855Sgabeblack@google.com std::string s1 = std::string(sc_get_current_process_handle().name()); 4212855Sgabeblack@google.com sc_assert(s1.substr(0,7) == "top.m.T"); 4312855Sgabeblack@google.com check_form_of_suffix(s1.substr(7)); 4412855Sgabeblack@google.com 4512855Sgabeblack@google.com SC_THREAD(T); 4612855Sgabeblack@google.com std::string s2 = std::string(sc_get_current_process_handle().name()); 4712855Sgabeblack@google.com sc_assert(s2.substr(0,7) == "top.m.T"); 4812855Sgabeblack@google.com check_form_of_suffix(s2.substr(7)); 4912855Sgabeblack@google.com 5012855Sgabeblack@google.com SC_THREAD(T); 5112855Sgabeblack@google.com std::string s3 = std::string(sc_get_current_process_handle().name()); 5212855Sgabeblack@google.com sc_assert(s3.substr(0,7) == "top.m.T"); 5312855Sgabeblack@google.com check_form_of_suffix(s3.substr(7)); 5412855Sgabeblack@google.com 5512855Sgabeblack@google.com sc_assert(s1 != s2); 5612855Sgabeblack@google.com sc_assert(s2 != s3); 5712855Sgabeblack@google.com sc_assert(s3 != s1); 5812855Sgabeblack@google.com 5912855Sgabeblack@google.com SC_THREAD(R); 6012855Sgabeblack@google.com } 6112855Sgabeblack@google.com 6212855Sgabeblack@google.com void end_of_elaboration() 6312855Sgabeblack@google.com { 6412855Sgabeblack@google.com sc_assert(port.get_parent_object() == this); 6512855Sgabeblack@google.com sc_assert(port.chan.get_parent_object() == this); 6612855Sgabeblack@google.com sc_assert(get_child_objects().size() == 6); 6712855Sgabeblack@google.com } 6812855Sgabeblack@google.com 6912855Sgabeblack@google.com void T() 7012855Sgabeblack@google.com { 7112855Sgabeblack@google.com int i_count = sc_report_handler::get_count(SC_INFO); 7212855Sgabeblack@google.com int w_count = sc_report_handler::get_count(SC_WARNING); 7312855Sgabeblack@google.com int e_count = sc_report_handler::get_count(SC_ERROR); 7412855Sgabeblack@google.com int f_count = sc_report_handler::get_count(SC_FATAL); 7512855Sgabeblack@google.com 7612855Sgabeblack@google.com sc_report_handler::set_actions(SC_INFO, SC_DO_NOTHING); 7712855Sgabeblack@google.com sc_report_handler::set_actions(SC_WARNING, SC_DO_NOTHING); 7812855Sgabeblack@google.com sc_report_handler::set_actions(SC_ERROR, SC_DO_NOTHING); 7912855Sgabeblack@google.com sc_report_handler::set_actions(SC_FATAL, SC_DO_NOTHING); 8012855Sgabeblack@google.com 8112855Sgabeblack@google.com SC_REPORT_INFO("type", "msg"); 8212855Sgabeblack@google.com 8312855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_INFO) == i_count + 1); 8412855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_WARNING) == w_count); 8512855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_ERROR) == e_count); 8612855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_FATAL) == f_count); 8712855Sgabeblack@google.com 8812855Sgabeblack@google.com SC_REPORT_WARNING("type", "msg"); 8912855Sgabeblack@google.com 9012855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_INFO) == i_count + 1); 9112855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_WARNING) == w_count + 1); 9212855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_ERROR) == e_count); 9312855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_FATAL) == f_count); 9412855Sgabeblack@google.com 9512855Sgabeblack@google.com SC_REPORT_ERROR("type", "msg"); 9612855Sgabeblack@google.com 9712855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_INFO) == i_count + 1); 9812855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_WARNING) == w_count + 1); 9912855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_ERROR) == e_count + 1); 10012855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_FATAL) == f_count); 10112855Sgabeblack@google.com 10212855Sgabeblack@google.com SC_REPORT_FATAL("type", "msg"); 10312855Sgabeblack@google.com 10412855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_INFO) == i_count + 1); 10512855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_WARNING) == w_count + 1); 10612855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_ERROR) == e_count + 1); 10712855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_FATAL) == f_count + 1); 10812855Sgabeblack@google.com 10912855Sgabeblack@google.com sc_report_handler::set_actions(SC_INFO, SC_DISPLAY); 11012855Sgabeblack@google.com sc_report_handler::set_actions(SC_WARNING, SC_DISPLAY); 11112855Sgabeblack@google.com sc_report_handler::set_actions(SC_ERROR, SC_DISPLAY); 11212855Sgabeblack@google.com sc_report_handler::set_actions(SC_FATAL, SC_DISPLAY); 11312855Sgabeblack@google.com 11412855Sgabeblack@google.com SC_REPORT_INFO("type", "msg"); 11512855Sgabeblack@google.com 11612855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_INFO) == i_count + 2); 11712855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_WARNING) == w_count + 1); 11812855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_ERROR) == e_count + 1); 11912855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_FATAL) == f_count + 1); 12012855Sgabeblack@google.com 12112855Sgabeblack@google.com SC_REPORT_WARNING("type", "msg"); 12212855Sgabeblack@google.com 12312855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_INFO) == i_count + 2); 12412855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_WARNING) == w_count + 2); 12512855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_ERROR) == e_count + 1); 12612855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_FATAL) == f_count + 1); 12712855Sgabeblack@google.com 12812855Sgabeblack@google.com SC_REPORT_ERROR("type", "msg"); 12912855Sgabeblack@google.com 13012855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_INFO) == i_count + 2); 13112855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_WARNING) == w_count + 2); 13212855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_ERROR) == e_count + 2); 13312855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_FATAL) == f_count + 1); 13412855Sgabeblack@google.com 13512855Sgabeblack@google.com SC_REPORT_FATAL("type", "msg"); 13612855Sgabeblack@google.com 13712855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_INFO) == i_count + 2); 13812855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_WARNING) == w_count + 2); 13912855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_ERROR) == e_count + 2); 14012855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_FATAL) == f_count + 2); 14112855Sgabeblack@google.com } 14212855Sgabeblack@google.com void R() 14312855Sgabeblack@google.com { 14412855Sgabeblack@google.com wait(100, SC_NS); 14512855Sgabeblack@google.com 14612855Sgabeblack@google.com int i_count = sc_report_handler::get_count(SC_INFO); 14712855Sgabeblack@google.com int w_count = sc_report_handler::get_count(SC_WARNING); 14812855Sgabeblack@google.com int e_count = sc_report_handler::get_count(SC_ERROR); 14912855Sgabeblack@google.com int f_count = sc_report_handler::get_count(SC_FATAL); 15012855Sgabeblack@google.com 15112855Sgabeblack@google.com try { 15212855Sgabeblack@google.com SC_REPORT_ERROR("type", "msg"); 15312855Sgabeblack@google.com } 15412855Sgabeblack@google.com catch (sc_report& rpt) { 15512855Sgabeblack@google.com sc_assert(rpt.get_severity() == SC_ERROR); 15612855Sgabeblack@google.com sc_assert(strcmp(rpt.get_msg_type(), "type") == 0); 15712855Sgabeblack@google.com sc_assert(strcmp(rpt.get_msg(), "msg") == 0); 15812855Sgabeblack@google.com sc_assert(rpt.get_time() == sc_time(0, SC_NS)); 15912855Sgabeblack@google.com sc_assert(strcmp(rpt.get_process_name(), "top.m.R") == 0); 16012855Sgabeblack@google.com } 16112855Sgabeblack@google.com 16212855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_INFO) == i_count); 16312855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_WARNING) == w_count); 16412855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_ERROR) == e_count + 1); 16512855Sgabeblack@google.com sc_assert(sc_report_handler::get_count(SC_FATAL) == f_count); 16612855Sgabeblack@google.com } 16712855Sgabeblack@google.com}; 16812855Sgabeblack@google.com 16912855Sgabeblack@google.comSC_MODULE(Top) 17012855Sgabeblack@google.com{ 17112855Sgabeblack@google.com M *m; 17212855Sgabeblack@google.com Chan *chan; 17312855Sgabeblack@google.com SC_CTOR(Top) 17412855Sgabeblack@google.com { 17512855Sgabeblack@google.com m = new M("m"); 17612855Sgabeblack@google.com chan = new Chan; 17712855Sgabeblack@google.com m->port.bind(*chan); 17812855Sgabeblack@google.com } 17912855Sgabeblack@google.com void end_of_elaboration() 18012855Sgabeblack@google.com { 18112855Sgabeblack@google.com sc_assert(get_child_objects().size() == 2); 18212855Sgabeblack@google.com } 18312855Sgabeblack@google.com}; 18412855Sgabeblack@google.com 18512855Sgabeblack@google.comint sc_main(int argc, char* argv[]) 18612855Sgabeblack@google.com{ 18712855Sgabeblack@google.com cout << "Should be silent except for reports ..." << endl; 18812855Sgabeblack@google.com 18912855Sgabeblack@google.com Top top("top"); 19012855Sgabeblack@google.com sc_start(); 19112855Sgabeblack@google.com 19212855Sgabeblack@google.com cout << endl << "Success" << endl; 19312855Sgabeblack@google.com return 0; 19412855Sgabeblack@google.com} 195