1/***************************************************************************** 2 3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 4 more contributor license agreements. See the NOTICE file distributed 5 with this work for additional information regarding copyright ownership. 6 Accellera licenses this file to you under the Apache License, Version 2.0 7 (the "License"); you may not use this file except in compliance with the 8 License. You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 15 implied. See the License for the specific language governing 16 permissions and limitations under the License. 17 18 *****************************************************************************/ 19 20// recursive_kill_bug.cpp -- test for 21// 22// Original Author: John Aynsley, Doulus 23// 24// MODIFICATION LOG - modifiers, enter your name, affiliation, date and 25// 26 27// 28 29#define SC_INCLUDE_DYNAMIC_PROCESSES 30 31#include <systemc> 32 33using namespace sc_core; 34using std::cout; 35using std::endl; 36 37struct Top: sc_module 38{ 39 Top(sc_module_name _name) 40 { 41 SC_THREAD(control); 42 43 SC_METHOD(caller); 44 sensitive << ev; 45 dont_initialize(); 46 caller_handle = sc_get_current_process_handle(); 47 48 SC_THREAD(target); 49 target_handle = sc_get_current_process_handle(); 50 51 count = 0; 52 f0 = f1 = f2 = f3 = f4 = f5 = f6 = f7 = f8 = f9 = 0; 53 } 54 55 struct bomb 56 { 57 sc_process_handle h; 58 59 bomb(sc_process_handle _h) 60 { 61 h = _h; 62 } 63 64 ~bomb() 65 { 66 h.kill(); 67 } 68 }; 69 70 sc_process_handle caller_handle; 71 sc_process_handle target_handle; 72 int count; 73 int f0, f1, f2, f3, f4, f5, f6, f7, f8, f9; 74 sc_event ev; 75 76 void control() 77 { 78 count = 0; 79 wait(10, SC_NS); 80 81 count = 1; 82 ev.notify(); 83 } 84 85 void caller() 86 { 87 f0 = 1; 88 target_handle.kill(); 89 sc_assert( false ); // FAILS !!!!!! 90 } 91 92 void target() 93 { 94 bomb local_obj(caller_handle); 95 sc_assert( count == 0 ); 96 f1 = 1; 97 try { 98 wait(20, SC_NS); 99 } 100 catch (const sc_unwind_exception& e) { 101 sc_assert( count == 1 ); 102 sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); 103 f2 = 1; 104 throw e; 105 } 106 } 107 108 SC_HAS_PROCESS(Top); 109}; 110 111int sc_main(int argc, char* argv[]) 112{ 113 Top top("top"); 114 115 sc_start(); 116 117 sc_assert( top.f0 ); 118 sc_assert( top.f1 ); 119 sc_assert( top.f2 ); 120 121 cout << endl << "Success" << endl; 122 return 0; 123} 124 125