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// old_event_bug.cpp -- test for 21// 22// Original Author: John Aynsley, Doulos, Inc. 23// 24// MODIFICATION LOG - modifiers, enter your name, affiliation, date and 25// 26// $Log: old_event_bug.cpp,v $ 27// Revision 1.2 2011/05/08 19:18:46 acg 28// Andy Goodrich: remove extraneous + prefixes from git diff. 29// 30 31// Longstanding bug when checking for events in signals 32 33#define SC_INCLUDE_DYNAMIC_PROCESSES 34 35#include <systemc> 36 37using namespace sc_core; 38using std::cout; 39using std::endl; 40 41struct Top: sc_module 42{ 43 Top(sc_module_name _name) 44 : counti(0) 45 , countb(0) 46 , reached_the_end(false) 47 { 48 SC_THREAD(T); 49 50 SC_METHOD(MI); 51 sensitive << sigi; 52 dont_initialize(); 53 54 SC_METHOD(MB); 55 sensitive << sigb; 56 dont_initialize(); 57 58 sigi.write(0); 59 sigb.write(false); 60 sigi_dummy.write(0); 61 sigb_dummy.write(false); 62 } 63 64 int counti; 65 int countb; 66 bool reached_the_end; 67 68 sc_signal<int> sigi; 69 sc_signal<bool> sigb; 70 71 sc_signal<int> sigi_dummy; 72 sc_signal<bool> sigb_dummy; 73 74 void T() 75 { 76 sc_assert( sigi.event() == false ); 77 sc_assert( sigb.event() == false ); 78 sc_assert( sigb.posedge() == false ); 79 sc_assert( sigb.negedge() == false ); 80 81 sigi.write(1); 82 wait(sigi.value_changed_event()); 83 sc_assert( sigi.event() ); 84 85 sigb.write(true); 86 wait(sigb.value_changed_event()); 87 sc_assert( sigb.event() ); 88 sc_assert( sigb.posedge() ); 89 sc_assert( sigb.negedge() == false ); 90 91 wait(1, SC_NS); 92 93 sc_assert( sigi.event() == false ); 94 sc_assert( sigb.event() == false ); 95 96 sigi.write(2); 97 sigb.write(false); 98 99 wait(1, SC_NS); 100 101 sc_assert( sigi.event() == false ); 102 sc_assert( sigb.event() == false ); 103 sc_assert( sigb.posedge() == false ); 104 sc_assert( sigb.negedge() == false ); 105 106 sigi_dummy.write(1); 107 sigb_dummy.write(true); 108 109 wait(1, SC_NS); 110 111 sc_assert( sigi_dummy.event() == false ); 112 sc_assert( sigb_dummy.event() == false ); 113 sc_assert( sigb_dummy.posedge() == false ); 114 sc_assert( sigb_dummy.negedge() == false ); 115 116 reached_the_end = true; 117 } 118 119 void MI() 120 { 121 sc_assert( sigi.event() ); 122 ++counti; 123 } 124 125 void MB() 126 { 127 sc_assert( sigb.event() ); 128 ++countb; 129 } 130 131 SC_HAS_PROCESS(Top); 132}; 133 134int sc_main(int argc, char* argv[]) 135{ 136 Top top("top"); 137 138 sc_start(); 139 140 sc_assert( top.counti == 2 ); 141 sc_assert( top.countb == 2 ); 142 sc_assert( top.reached_the_end ); 143 144 cout << endl << "Success" << endl; 145 return 0; 146} 147 148