proc_ctrl_elab.cpp revision 12855:588919e0e4aa
112855Sgabeblack@google.com/***************************************************************************** 212855Sgabeblack@google.com 312855Sgabeblack@google.com Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 412855Sgabeblack@google.com more contributor license agreements. See the NOTICE file distributed 512855Sgabeblack@google.com with this work for additional information regarding copyright ownership. 612855Sgabeblack@google.com Accellera licenses this file to you under the Apache License, Version 2.0 712855Sgabeblack@google.com (the "License"); you may not use this file except in compliance with the 812855Sgabeblack@google.com License. You may obtain a copy of the License at 912855Sgabeblack@google.com 1012855Sgabeblack@google.com http://www.apache.org/licenses/LICENSE-2.0 1112855Sgabeblack@google.com 1212855Sgabeblack@google.com Unless required by applicable law or agreed to in writing, software 1312855Sgabeblack@google.com distributed under the License is distributed on an "AS IS" BASIS, 1412855Sgabeblack@google.com WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 1512855Sgabeblack@google.com implied. See the License for the specific language governing 1612855Sgabeblack@google.com permissions and limitations under the License. 1712855Sgabeblack@google.com 1812855Sgabeblack@google.com *****************************************************************************/ 1912855Sgabeblack@google.com 2012855Sgabeblack@google.com// proc_ctrl_elab.cpp -- test for 2112855Sgabeblack@google.com// 2212855Sgabeblack@google.com// Original Author: John Aynsley, Doulos, Inc. 2312855Sgabeblack@google.com// 2412855Sgabeblack@google.com// MODIFICATION LOG - modifiers, enter your name, affiliation, date and 2512855Sgabeblack@google.com// 2612855Sgabeblack@google.com// $Log: proc_ctrl_elab.cpp,v $ 2712855Sgabeblack@google.com// Revision 1.2 2011/05/08 19:18:46 acg 2812855Sgabeblack@google.com// Andy Goodrich: remove extraneous + prefixes from git diff. 2912855Sgabeblack@google.com// 3012855Sgabeblack@google.com 3112855Sgabeblack@google.com// Calling process control methods during elaboration 3212855Sgabeblack@google.com 3312855Sgabeblack@google.com#define SC_INCLUDE_DYNAMIC_PROCESSES 3412855Sgabeblack@google.com 3512855Sgabeblack@google.com#include "systemc.h" 3612855Sgabeblack@google.com 3712855Sgabeblack@google.comSC_MODULE(Top) 3812855Sgabeblack@google.com{ 3912855Sgabeblack@google.com SC_CTOR(Top) 4012855Sgabeblack@google.com : caught_throw_it(0) 4112855Sgabeblack@google.com , caught_reset(0) 4212855Sgabeblack@google.com , caught_kill(0) 4312855Sgabeblack@google.com 4412855Sgabeblack@google.com , target_suspend_1_called(false) 4512855Sgabeblack@google.com , target_suspend_2_called(false) 4612855Sgabeblack@google.com , target_suspend_3_called(false) 4712855Sgabeblack@google.com , target_suspend_4_called(false) 48 , target_suspend_5_called(false) 49 50 , target_disable_1_called(false) 51 , target_disable_2_called(false) 52 , target_disable_2_called_again(false) 53 , target_disable_3_called(false) 54 , target_disable_4_called(false) 55 , target_disable_5_called(false) 56 57 , target_sync_reset_1_called(false) 58 , target_sync_reset_2_called(false) 59 , target_sync_reset_3_called(false) 60 , target_sync_reset_4_called(false) 61 62 , reset_1_count(0) 63 , reset_2_count(0) 64 , reset_3_count(0) 65 , reset_4_count(0) 66 { 67 SC_THREAD(ctrl); 68 69 SC_THREAD(target_suspend_1); 70 sensitive << ev; 71 ts1 = sc_get_current_process_handle(); 72 73 SC_THREAD(target_suspend_2); 74 dont_initialize(); 75 sensitive << ev; 76 ts2 = sc_get_current_process_handle(); 77 78 SC_THREAD(target_suspend_3); 79 dont_initialize(); 80 sensitive << ev; 81 ts3 = sc_get_current_process_handle(); 82 83 SC_THREAD(target_suspend_4); 84 dont_initialize(); 85 sensitive << ev; 86 ts4 = sc_get_current_process_handle(); 87 ts4.suspend(); 88 89 SC_THREAD(target_suspend_5); 90 dont_initialize(); 91 sensitive << ev; 92 ts5 = sc_get_current_process_handle(); 93 ts5.suspend(); 94 ts5.resume(); 95 96 SC_THREAD(target_disable_1); 97 sensitive << dummy_ev; 98 td1 = sc_get_current_process_handle(); 99 100 SC_THREAD(target_disable_2); 101 sensitive << ev; 102 td2 = sc_get_current_process_handle(); 103 104 SC_THREAD(target_disable_3); 105 td3 = sc_get_current_process_handle(); 106 107 SC_THREAD(target_disable_4); 108 dont_initialize(); 109 sensitive << ev; 110 td4 = sc_get_current_process_handle(); 111 td4.disable(); 112 113 SC_THREAD(target_disable_5); 114 dont_initialize(); 115 sensitive << ev; 116 td5 = sc_get_current_process_handle(); 117 td5.disable(); 118 td5.enable(); 119 td5.sync_reset_on(); 120 td5.sync_reset_off(); 121 122 SC_THREAD(target_sync_reset_1); 123 sensitive << ev; 124 tr1 = sc_get_current_process_handle(); 125 126 SC_THREAD(target_sync_reset_2); 127 sensitive << ev; 128 tr2 = sc_get_current_process_handle(); 129 130 SC_THREAD(target_sync_reset_3); 131 dont_initialize(); 132 sensitive << ev; 133 tr3 = sc_get_current_process_handle(); 134 135 SC_THREAD(target_sync_reset_4); 136 dont_initialize(); 137 sensitive << ev; 138 tr4 = sc_get_current_process_handle(); 139 tr4.sync_reset_on(); 140 141 try { 142 ts2.throw_it(ex); 143 sc_assert( false ); 144 } 145 catch (std::exception e) { 146 ++caught_throw_it; 147 } 148 149 try { 150 ts2.reset(); 151 sc_assert( false ); 152 } 153 catch (std::exception e) { 154 ++caught_reset; 155 } 156 157 try { 158 ts2.kill(); 159 sc_assert( false ); 160 } 161 catch (std::exception e) { 162 ++caught_kill; 163 } 164 } 165 166 void before_end_of_elaboration() 167 { 168 ts1.suspend(); 169 ts2.suspend(); 170 ts3.suspend(); 171 172 td1.disable(); 173 td2.disable(); 174 td3.disable(); 175 176 tr1.sync_reset_on(); 177 tr2.sync_reset_on(); 178 tr3.sync_reset_on(); 179 180 try { 181 ts2.throw_it(ex); 182 sc_assert( false ); 183 } 184 catch (std::exception e) { 185 ++caught_throw_it; 186 } 187 188 try { 189 ts2.reset(); 190 sc_assert( false ); 191 } 192 catch (std::exception e) { 193 ++caught_reset; 194 } 195 196 try { 197 ts2.kill(); 198 sc_assert( false ); 199 } 200 catch (std::exception e) { 201 ++caught_kill; 202 } 203 } 204 205 void start_of_simulation() 206 { 207 td3.enable(); 208 tr3.sync_reset_off(); 209 210 try { 211 ts2.throw_it(ex); 212 sc_assert( false ); 213 } 214 catch (std::exception e) { 215 ++caught_throw_it; 216 } 217 218 try { 219 ts2.reset(); 220 sc_assert( false ); 221 } 222 catch (std::exception e) { 223 ++caught_reset; 224 } 225 226 try { 227 ts2.kill(); 228 sc_assert( false ); 229 } 230 catch (std::exception e) { 231 ++caught_kill; 232 } 233 } 234 235 sc_event ev, dummy_ev; 236 237 std::exception ex; 238 239 sc_process_handle ts1; 240 sc_process_handle ts2; 241 sc_process_handle ts3; 242 sc_process_handle ts4; 243 sc_process_handle ts5; 244 245 sc_process_handle td1; 246 sc_process_handle td2; 247 sc_process_handle td3; 248 sc_process_handle td4; 249 sc_process_handle td5; 250 251 sc_process_handle tr1; 252 sc_process_handle tr2; 253 sc_process_handle tr3; 254 sc_process_handle tr4; 255 256 int caught_throw_it; 257 int caught_reset; 258 int caught_kill; 259 260 bool target_suspend_1_called; 261 bool target_suspend_2_called; 262 bool target_suspend_3_called; 263 bool target_suspend_4_called; 264 bool target_suspend_5_called; 265 266 bool target_disable_1_called; 267 bool target_disable_2_called; 268 bool target_disable_2_called_again; 269 bool target_disable_3_called; 270 bool target_disable_4_called; 271 bool target_disable_5_called; 272 273 bool target_sync_reset_1_called; 274 bool target_sync_reset_2_called; 275 bool target_sync_reset_3_called; 276 bool target_sync_reset_4_called; 277 278 int reset_1_count; 279 int reset_2_count; 280 int reset_3_count; 281 int reset_4_count; 282 283 void ctrl() 284 { 285 ts3.resume(); 286 287 wait(10, SC_NS); 288 ts1.resume(); 289 ev.notify(); 290 291 wait(10, SC_NS); 292 ts2.resume(); 293 tr2.sync_reset_off(); 294 tr4.sync_reset_off(); 295 296 wait(10, SC_NS); 297 td2.enable(); 298 299 wait(10, SC_NS); 300 ev.notify(); 301 302 wait(10, SC_NS); 303 ev.notify(); 304 td2.disable(); 305 306 wait(10, SC_NS); 307 td4.enable(); 308 ts4.resume(); 309 ev.notify(); 310 } 311 312 void target_suspend_1() 313 { 314 sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); 315 target_suspend_1_called = true; 316 } 317 318 void target_suspend_2() 319 { 320 sc_assert( sc_time_stamp() == sc_time(20, SC_NS) ); 321 target_suspend_2_called = true; 322 } 323 324 void target_suspend_3() 325 { 326 sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); 327 target_suspend_3_called = true; 328 } 329 330 void target_suspend_4() 331 { 332 sc_assert( sc_time_stamp() == sc_time(60, SC_NS) ); 333 target_suspend_4_called = true; 334 } 335 336 void target_suspend_5() 337 { 338 sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); 339 target_suspend_5_called = true; 340 ts5.suspend(); 341 } 342 343 void target_disable_1() 344 { 345 sc_assert( false ); 346 target_disable_1_called = true; 347 } 348 349 void target_disable_2() 350 { 351 sc_assert( sc_time_stamp() == sc_time(40, SC_NS) ); 352 target_disable_2_called = true; 353 wait(); // on ev 354 355 sc_assert( sc_time_stamp() == sc_time(50, SC_NS) ); 356 target_disable_2_called_again = true; 357 } 358 359 void target_disable_3() 360 { 361 sc_assert( sc_time_stamp() == sc_time(0, SC_NS) ); 362 sc_assert( sc_delta_count() == 0 ); 363 target_disable_3_called = true; 364 } 365 366 void target_disable_4() 367 { 368 sc_assert( sc_time_stamp() == sc_time(60, SC_NS) ); 369 target_disable_4_called = true; 370 } 371 372 void target_disable_5() 373 { 374 sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); 375 target_disable_5_called = true; 376 td5.disable(); 377 } 378 379 void target_sync_reset_1() 380 { 381 switch (reset_1_count) 382 { 383 case 0: sc_assert( sc_time_stamp() == sc_time(0, SC_NS) ); 384 sc_assert( sc_delta_count() == 0 ); 385 break; 386 case 1: sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); 387 break; 388 case 2: sc_assert( sc_time_stamp() == sc_time(40, SC_NS) ); 389 break; 390 case 3: sc_assert( sc_time_stamp() == sc_time(50, SC_NS) ); 391 target_sync_reset_1_called = true; 392 break; 393 } 394 ++reset_1_count; 395 396 while (true) 397 { 398 wait(); 399 sc_assert( false ); 400 } 401 } 402 403 void target_sync_reset_2() 404 { 405 switch (reset_2_count) 406 { 407 case 0: sc_assert( sc_time_stamp() == sc_time(0, SC_NS) ); 408 sc_assert( sc_delta_count() == 0 ); 409 break; 410 case 1: sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); 411 break; 412 case 2: sc_assert( false ); 413 break; 414 case 3: sc_assert( false ); 415 break; 416 } 417 ++reset_2_count; 418 419 while (true) 420 { 421 wait(); 422 423 switch (reset_2_count) 424 { 425 case 0: sc_assert( false ); 426 break; 427 case 1: sc_assert( false ); 428 break; 429 case 2: sc_assert( sc_time_stamp() == sc_time(40, SC_NS) ); 430 break; 431 case 3: sc_assert( sc_time_stamp() == sc_time(50, SC_NS) ); 432 target_sync_reset_2_called = true; 433 break; 434 } 435 ++reset_2_count; 436 437 } 438 } 439 440 void target_sync_reset_3() 441 { 442 switch (reset_3_count) 443 { 444 case 0: sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); 445 break; 446 case 1: sc_assert( false ); 447 break; 448 case 2: sc_assert( false ); 449 break; 450 } 451 ++reset_3_count; 452 453 while (true) 454 { 455 wait(); 456 457 switch (reset_3_count) 458 { 459 case 0: sc_assert( false ); 460 break; 461 case 1: sc_assert( sc_time_stamp() == sc_time(40, SC_NS) ); 462 break; 463 case 2: sc_assert( sc_time_stamp() == sc_time(50, SC_NS) ); 464 target_sync_reset_3_called = true; 465 break; 466 } 467 ++reset_3_count; 468 469 } 470 } 471 472 void target_sync_reset_4() 473 { 474 switch (reset_4_count) 475 { 476 case 0: sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); 477 break; 478 case 1: sc_assert( false ); 479 break; 480 case 2: sc_assert( false ); 481 break; 482 } 483 ++reset_4_count; 484 485 while (true) 486 { 487 wait(); 488 489 switch (reset_4_count) 490 { 491 case 0: sc_assert( false ); 492 break; 493 case 1: sc_assert( sc_time_stamp() == sc_time(40, SC_NS) ); 494 break; 495 case 2: sc_assert( sc_time_stamp() == sc_time(50, SC_NS) ); 496 target_sync_reset_4_called = true; 497 break; 498 } 499 ++reset_4_count; 500 501 } 502 } 503}; 504 505int sc_main(int argc, char* argv[]) 506{ 507 Top top("top"); 508 sc_start(); 509 510 sc_assert( top.caught_throw_it == 3 ); 511 sc_assert( top.caught_reset == 3 ); 512 sc_assert( top.caught_kill == 3 ); 513 514 sc_assert( top.target_suspend_1_called ); 515 sc_assert( top.target_suspend_2_called ); 516 sc_assert( top.target_suspend_3_called ); 517 sc_assert( top.target_suspend_4_called ); 518 sc_assert( top.target_suspend_5_called ); 519 520 sc_assert( !top.target_disable_1_called ); 521 sc_assert( top.target_disable_2_called ); 522 sc_assert( top.target_disable_2_called_again ); 523 sc_assert( top.target_disable_3_called ); 524 sc_assert( top.target_disable_4_called ); 525 sc_assert( top.target_disable_5_called ); 526 527 sc_assert( top.target_sync_reset_1_called ); 528 sc_assert( top.target_sync_reset_2_called ); 529 sc_assert( top.target_sync_reset_3_called ); 530 sc_assert( top.target_sync_reset_4_called ); 531 532 cout << endl << "Success" << endl; 533 return 0; 534} 535