1#include <systemc.h> 2 3// Multiple tests for Annex D.1 and D.2 4 5struct i_f: virtual sc_interface 6{ 7}; 8 9struct Chan: i_f, sc_object 10{ 11}; 12 13struct Port: sc_port<i_f> 14{ 15 Chan chan; 16}; 17 18void check_form_of_suffix(std::string s) 19{ 20 std::string charset = "0123456789"; 21 while (!s.empty()) 22 { 23 sc_assert(s[0] == '_'); 24 s = s.substr(1); 25 sc_assert(!s.empty()); 26 do 27 { 28 sc_assert(charset.find(s[0]) < charset.size()); 29 s = s.substr(1); 30 } while (!s.empty() && (s[0] != '_')); 31 } 32} 33 34SC_MODULE(M) 35{ 36 Port port; 37 38 SC_CTOR(M) 39 { 40 SC_THREAD(T); 41 std::string s1 = std::string(sc_get_current_process_handle().name()); 42 sc_assert(s1.substr(0,7) == "top.m.T"); 43 check_form_of_suffix(s1.substr(7)); 44 45 SC_THREAD(T); 46 std::string s2 = std::string(sc_get_current_process_handle().name()); 47 sc_assert(s2.substr(0,7) == "top.m.T"); 48 check_form_of_suffix(s2.substr(7)); 49 50 SC_THREAD(T); 51 std::string s3 = std::string(sc_get_current_process_handle().name()); 52 sc_assert(s3.substr(0,7) == "top.m.T"); 53 check_form_of_suffix(s3.substr(7)); 54 55 sc_assert(s1 != s2); 56 sc_assert(s2 != s3); 57 sc_assert(s3 != s1); 58 59 SC_THREAD(R); 60 } 61 62 void end_of_elaboration() 63 { 64 sc_assert(port.get_parent_object() == this); 65 sc_assert(port.chan.get_parent_object() == this); 66 sc_assert(get_child_objects().size() == 6); 67 } 68 69 void T() 70 { 71 int i_count = sc_report_handler::get_count(SC_INFO); 72 int w_count = sc_report_handler::get_count(SC_WARNING); 73 int e_count = sc_report_handler::get_count(SC_ERROR); 74 int f_count = sc_report_handler::get_count(SC_FATAL); 75 76 sc_report_handler::set_actions(SC_INFO, SC_DO_NOTHING); 77 sc_report_handler::set_actions(SC_WARNING, SC_DO_NOTHING); 78 sc_report_handler::set_actions(SC_ERROR, SC_DO_NOTHING); 79 sc_report_handler::set_actions(SC_FATAL, SC_DO_NOTHING); 80 81 SC_REPORT_INFO("type", "msg"); 82 83 sc_assert(sc_report_handler::get_count(SC_INFO) == i_count + 1); 84 sc_assert(sc_report_handler::get_count(SC_WARNING) == w_count); 85 sc_assert(sc_report_handler::get_count(SC_ERROR) == e_count); 86 sc_assert(sc_report_handler::get_count(SC_FATAL) == f_count); 87 88 SC_REPORT_WARNING("type", "msg"); 89 90 sc_assert(sc_report_handler::get_count(SC_INFO) == i_count + 1); 91 sc_assert(sc_report_handler::get_count(SC_WARNING) == w_count + 1); 92 sc_assert(sc_report_handler::get_count(SC_ERROR) == e_count); 93 sc_assert(sc_report_handler::get_count(SC_FATAL) == f_count); 94 95 SC_REPORT_ERROR("type", "msg"); 96 97 sc_assert(sc_report_handler::get_count(SC_INFO) == i_count + 1); 98 sc_assert(sc_report_handler::get_count(SC_WARNING) == w_count + 1); 99 sc_assert(sc_report_handler::get_count(SC_ERROR) == e_count + 1); 100 sc_assert(sc_report_handler::get_count(SC_FATAL) == f_count); 101 102 SC_REPORT_FATAL("type", "msg"); 103 104 sc_assert(sc_report_handler::get_count(SC_INFO) == i_count + 1); 105 sc_assert(sc_report_handler::get_count(SC_WARNING) == w_count + 1); 106 sc_assert(sc_report_handler::get_count(SC_ERROR) == e_count + 1); 107 sc_assert(sc_report_handler::get_count(SC_FATAL) == f_count + 1); 108 109 sc_report_handler::set_actions(SC_INFO, SC_DISPLAY); 110 sc_report_handler::set_actions(SC_WARNING, SC_DISPLAY); 111 sc_report_handler::set_actions(SC_ERROR, SC_DISPLAY); 112 sc_report_handler::set_actions(SC_FATAL, SC_DISPLAY); 113 114 SC_REPORT_INFO("type", "msg"); 115 116 sc_assert(sc_report_handler::get_count(SC_INFO) == i_count + 2); 117 sc_assert(sc_report_handler::get_count(SC_WARNING) == w_count + 1); 118 sc_assert(sc_report_handler::get_count(SC_ERROR) == e_count + 1); 119 sc_assert(sc_report_handler::get_count(SC_FATAL) == f_count + 1); 120 121 SC_REPORT_WARNING("type", "msg"); 122 123 sc_assert(sc_report_handler::get_count(SC_INFO) == i_count + 2); 124 sc_assert(sc_report_handler::get_count(SC_WARNING) == w_count + 2); 125 sc_assert(sc_report_handler::get_count(SC_ERROR) == e_count + 1); 126 sc_assert(sc_report_handler::get_count(SC_FATAL) == f_count + 1); 127 128 SC_REPORT_ERROR("type", "msg"); 129 130 sc_assert(sc_report_handler::get_count(SC_INFO) == i_count + 2); 131 sc_assert(sc_report_handler::get_count(SC_WARNING) == w_count + 2); 132 sc_assert(sc_report_handler::get_count(SC_ERROR) == e_count + 2); 133 sc_assert(sc_report_handler::get_count(SC_FATAL) == f_count + 1); 134 135 SC_REPORT_FATAL("type", "msg"); 136 137 sc_assert(sc_report_handler::get_count(SC_INFO) == i_count + 2); 138 sc_assert(sc_report_handler::get_count(SC_WARNING) == w_count + 2); 139 sc_assert(sc_report_handler::get_count(SC_ERROR) == e_count + 2); 140 sc_assert(sc_report_handler::get_count(SC_FATAL) == f_count + 2); 141 } 142 void R() 143 { 144 wait(100, SC_NS); 145 146 int i_count = sc_report_handler::get_count(SC_INFO); 147 int w_count = sc_report_handler::get_count(SC_WARNING); 148 int e_count = sc_report_handler::get_count(SC_ERROR); 149 int f_count = sc_report_handler::get_count(SC_FATAL); 150 151 try { 152 SC_REPORT_ERROR("type", "msg"); 153 } 154 catch (sc_report& rpt) { 155 sc_assert(rpt.get_severity() == SC_ERROR); 156 sc_assert(strcmp(rpt.get_msg_type(), "type") == 0); 157 sc_assert(strcmp(rpt.get_msg(), "msg") == 0); 158 sc_assert(rpt.get_time() == sc_time(0, SC_NS)); 159 sc_assert(strcmp(rpt.get_process_name(), "top.m.R") == 0); 160 } 161 162 sc_assert(sc_report_handler::get_count(SC_INFO) == i_count); 163 sc_assert(sc_report_handler::get_count(SC_WARNING) == w_count); 164 sc_assert(sc_report_handler::get_count(SC_ERROR) == e_count + 1); 165 sc_assert(sc_report_handler::get_count(SC_FATAL) == f_count); 166 } 167}; 168 169SC_MODULE(Top) 170{ 171 M *m; 172 Chan *chan; 173 SC_CTOR(Top) 174 { 175 m = new M("m"); 176 chan = new Chan; 177 m->port.bind(*chan); 178 } 179 void end_of_elaboration() 180 { 181 sc_assert(get_child_objects().size() == 2); 182 } 183}; 184 185int sc_main(int argc, char* argv[]) 186{ 187 cout << "Should be silent except for reports ..." << endl; 188 189 Top top("top"); 190 sc_start(); 191 192 cout << endl << "Success" << endl; 193 return 0; 194} 195