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// test05.cpp -- Reset and kill a thread process, including nested kills 21// 22// Original Author: John Aynsley, Doulos 23// 24// MODIFICATION LOG - modifiers, enter your name, affiliation, date and 25// 26// $Log: test05.cpp,v $ 27// Revision 1.1 2011/02/05 21:13:26 acg 28// Andy Goodrich: move of tests John Aynsley will replace. 29// 30// Revision 1.2 2011/01/25 20:54:03 acg 31// Andy Goodrich: regolden for new delta counter rules. 32// 33// Revision 1.1 2011/01/24 12:06:10 acg 34// Andy Goodrich: changes for IEEE 1666 2011 35// 36 37 38#include <systemc> 39 40using namespace sc_core; 41using std::cout; 42using std::endl; 43 44struct M3: sc_module 45{ 46 M3(sc_module_name _name) 47 { 48 SC_THREAD(ticker); 49 k = sc_get_current_process_handle(); 50 51 SC_THREAD(calling); 52 53 SC_THREAD(target); 54 t = sc_get_current_process_handle(); 55 56 killing_over = false; 57 } 58 59 sc_process_handle t, k; 60 sc_event ev; 61 int count; 62 bool killing_over; 63 64 void ticker() 65 { 66 for (;;) 67 { 68 try { 69 wait(10, SC_NS); 70 ev.notify(); 71 } 72 catch (const sc_unwind_exception& ex) { 73 // ticker process killed by target 74 cout << "sc_unwind_exception caught by ticker" << endl; 75 sc_assert( sc_is_unwinding() ); 76 sc_assert( !ex.is_reset() ); 77 sc_assert( count == 1 ); 78 sc_assert( !killing_over ); 79 throw ex; 80 } 81 } 82 } 83 84 void calling() 85 { 86 wait(15, SC_NS); 87 // Target runs at time 10 NS due to notification 88 sc_assert( count == 1 ); 89 90 wait(10, SC_NS); 91 // Target runs again at time 20 NS due to notification 92 sc_assert( count == 2 ); 93 94 t.reset(); 95 // Target reset immediately at time 25 NS 96 sc_assert( count == 0 ); 97 98 wait(10, SC_NS); 99 // Target runs again at time 30 NS due to notification 100 sc_assert( count == 1 ); 101 102 t.kill(); 103 sc_assert( !killing_over ); 104 killing_over = true; 105 106 // Target killed immediately at time 35 NS 107 sc_assert( t.terminated() ); 108 sc_assert( k.terminated() ); 109 110 sc_stop(); 111 } 112 113 void target() 114 { 115 cout << "Target called/reset at " << sc_time_stamp() << endl; 116 count = 0; 117 for (;;) 118 { 119 try { 120 wait(ev); 121 cout << "Target awoke at " << sc_time_stamp() << endl; 122 ++count; 123 } 124 catch (const sc_unwind_exception& ex) { 125 cout << "sc_unwind_exception caught by target" << endl; 126 if (count == 2) 127 sc_assert( ex.is_reset() ); 128 else if (count == 1) 129 { 130 sc_assert( !ex.is_reset() ); 131 sc_assert( !killing_over ); 132 k.kill(); 133 } 134 else 135 sc_assert( false ); 136 throw ex; 137 } 138 } 139 } 140 141 SC_HAS_PROCESS(M3); 142}; 143 144int sc_main(int argc, char* argv[]) 145{ 146 M3 m("m"); 147 148 sc_start(); 149 150 return 0; 151} 152 153