test03.cpp revision 12855:588919e0e4aa
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// test03.cpp -- Quick Test Of kill() And reset() sc_process_handle Methods. 21// 22// Original Author: John Aynsley, Doulos 23// 24// MODIFICATION LOG - modifiers, enter your name, affiliation, date and 25// 26// $Log: test03.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.1 2011/01/20 16:55:01 acg 31// Andy Goodrich: changes for IEEE 1666 2011. 32// 33 34#define SC_INCLUDE_DYNAMIC_PROCESSES 35 36#include <systemc> 37 38using namespace sc_core; 39using std::cout; 40using std::endl; 41 42struct M3: sc_module 43{ 44 M3(sc_module_name _name) 45 { 46 SC_THREAD(ticker); 47 SC_THREAD(calling); 48 SC_THREAD(target); 49 t = sc_get_current_process_handle(); 50 } 51 52 sc_process_handle t; 53 sc_event ev; 54 int count; 55 56 void ticker() 57 { 58 for (;;) 59 { 60 wait(10, SC_NS); 61 ev.notify(); 62 } 63 } 64 65 void calling() 66 { 67 wait(15, SC_NS); 68 // Target runs at time 10 NS due to notification 69 sc_assert( count == 1 ); 70 71 wait(10, SC_NS); 72 // Target runs again at time 20 NS due to notification 73 sc_assert( count == 2 ); 74 75 t.reset(); 76 // Target reset immediately at time 25 NS 77 sc_assert( count == 0 ); 78 79 wait(10, SC_NS); 80 // Target runs again at time 30 NS due to notification 81 sc_assert( count == 1 ); 82 83 t.kill(); 84 // Target killed immediately at time 35 NS 85 sc_assert( t.terminated() ); 86 87 sc_stop(); 88 } 89 90 void target() 91 { 92 cout << "Target called/reset at " << sc_time_stamp() << endl; 93 count = 0; 94 for (;;) 95 { 96 wait(ev); 97 cout << "Target awoke at " << sc_time_stamp() << endl; 98 ++count; 99 } 100 } 101 102 SC_HAS_PROCESS(M3); 103}; 104 105int sc_main(int argc, char* argv[]) 106{ 107 M3 m("m"); 108 109 sc_start(); 110 111 return 0; 112} 113 114