include_descendants.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// include_descendants.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: include_descendants.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// Process control methods include_descendants argument 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 { 45 SC_THREAD(calling); 46 47 SC_THREAD(target1); 48 t1 = sc_get_current_process_handle(); 49 50 SC_THREAD(target4); 51 t4 = sc_get_current_process_handle(); 52 53 SC_THREAD(target7); 54 t7 = sc_get_current_process_handle(); 55 56 count = 0; 57 f1 = f2 = f3 = f4 = f5 = f6 = f7 = f8 = f9 = f10 = 0; 58 f11 = f12 = f13 = f14 = f15 = f16 = f17 = f18 = 0; 59 } 60 61 sc_process_handle t1, ch2, ch3, t4, ch5, ch6, t7, ch8, ch9; 62 sc_process_handle gch10, gch11, gch12, gch13; 63 sc_event ev; 64 int count; 65 int f1, f2, f3, f4, f5, f6, f7, f8, f9, f10; 66 int f11, f12, f13, f14, f15, f16, f17, f18; 67 68 std::exception ex; 69 70 void calling() 71 { 72 wait(SC_ZERO_TIME); 73 74 count = 1; 75 t1.suspend(SC_INCLUDE_DESCENDANTS); 76 ev.notify(5, SC_NS); 77 wait(10, SC_NS); 78 79 count = 2; 80 t1.resume(SC_INCLUDE_DESCENDANTS); 81 wait(10, SC_NS); 82 83 count = 3; 84 t1.disable(SC_INCLUDE_DESCENDANTS); 85 ev.notify(5, SC_NS); 86 wait(10, SC_NS); 87 88 count = 4; 89 t1.enable(SC_INCLUDE_DESCENDANTS); 90 wait(10, SC_NS); 91 92 count = 5; 93 ev.notify(); 94 wait(10, SC_NS); 95 96 count = 6; 97 t1.sync_reset_on(SC_INCLUDE_DESCENDANTS); 98 wait(10, SC_NS); 99 100 count = 7; 101 ev.notify(); 102 wait(10, SC_NS); 103 104 count = 8; 105 t1.sync_reset_off(SC_INCLUDE_DESCENDANTS); 106 wait(sc_time(110, SC_NS) - sc_time_stamp()); 107 108 count = 10; 109 t4.reset(SC_INCLUDE_DESCENDANTS); 110 wait(sc_time(210, SC_NS) - sc_time_stamp()); 111 112 t7.throw_it(ex, SC_INCLUDE_DESCENDANTS); 113 } 114 115 void target1() 116 { 117 sc_assert(count == 0); 118 ch2 = sc_spawn(sc_bind(&Top::child2, this)); 119 ch3 = sc_spawn(sc_bind(&Top::child3, this)); 120 wait(ch2.terminated_event() & ch3.terminated_event()); 121 f5 = 1; 122 } 123 124 void child2() 125 { 126 if (count == 0) // Initialization 127 { 128 wait(ev); 129 sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); 130 wait(ev); 131 sc_assert(count == 5); 132 sc_assert( sc_time_stamp() == sc_time(40, SC_NS) ); 133 f1 = 1; 134 wait(ev); 135 } 136 else if (count == 7) // Sync reset 137 { 138 sc_assert( sc_time_stamp() == sc_time(60, SC_NS) ); 139 f3 = 1; 140 wait(20, SC_NS); 141 } 142 } 143 144 void child3() 145 { 146 if (count == 0) // Initialization 147 { 148 wait(ev); 149 sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); 150 wait(ev); 151 sc_assert(count == 5); 152 sc_assert( sc_time_stamp() == sc_time(40, SC_NS) ); 153 f2 = 1; 154 wait(ev); 155 } 156 else if (count == 7) // Sync reset 157 { 158 sc_assert( sc_time_stamp() == sc_time(60, SC_NS) ); 159 f4 = 1; 160 wait(20, SC_NS); 161 } 162 } 163 164 void target4() 165 { 166 if (count == 0) 167 { 168 wait(100, SC_NS); 169 count = 9; 170 ch5 = sc_spawn(sc_bind(&Top::child5, this)); 171 ch6 = sc_spawn(sc_bind(&Top::child6, this)); 172 } 173 else // Hard reset 174 { 175 sc_assert( sc_time_stamp() == sc_time(110, SC_NS) ); 176 f11 = 1; 177 } 178 wait(ch5.terminated_event() & ch6.terminated_event()); 179 f6 = 1; 180 } 181 182 void child5() 183 { 184 switch (count) 185 { 186 case 9: sc_assert( sc_time_stamp() == sc_time(100, SC_NS) ); f7=1; break; 187 case 10: sc_assert( sc_time_stamp() == sc_time(110, SC_NS) ); f8=1; break; 188 default: sc_assert( false ); break; 189 } 190 wait(20, SC_NS); 191 } 192 193 void child6() 194 { 195 switch (count) 196 { 197 case 9: sc_assert( sc_time_stamp() == sc_time(100, SC_NS) ); f9=1; break; 198 case 10: sc_assert( sc_time_stamp() == sc_time(110, SC_NS) ); f10=1; break; 199 default: sc_assert( false ); break; 200 } 201 wait(20, SC_NS); 202 } 203 204 void target7() 205 { 206 wait(200, SC_NS); 207 count = 11; 208 ch8 = sc_spawn(sc_bind(&Top::child8, this)); 209 ch9 = sc_spawn(sc_bind(&Top::child9, this)); 210 try { 211 wait(20, SC_NS); 212 } 213 catch (std::exception e) { 214 sc_assert( sc_time_stamp() == sc_time(210, SC_NS) ); 215 } 216 wait(ch8.terminated_event() & ch9.terminated_event()); 217 sc_assert( sc_time_stamp() == sc_time(214, SC_NS) ); 218 f12 = 1; 219 } 220 221 void child8() 222 { 223 gch10 = sc_spawn(sc_bind(&Top::grandchild10, this)); 224 gch11 = sc_spawn(sc_bind(&Top::grandchild11, this)); 225 try { 226 wait(20, SC_NS); 227 } 228 catch (std::exception e) { 229 f13 = 1; 230 sc_assert( sc_time_stamp() == sc_time(210, SC_NS) ); 231 } 232 wait(gch10.terminated_event() & gch11.terminated_event()); 233 } 234 235 void child9() 236 { 237 gch12 = sc_spawn(sc_bind(&Top::grandchild12, this)); 238 gch13 = sc_spawn(sc_bind(&Top::grandchild13, this)); 239 try { 240 wait(20, SC_NS); 241 } 242 catch (std::exception e) { 243 f14 = 1; 244 sc_assert( sc_time_stamp() == sc_time(210, SC_NS) ); 245 } 246 wait(gch12.terminated_event() & gch13.terminated_event()); 247 } 248 249 void grandchild10() 250 { 251 try { 252 wait(20, SC_NS); 253 } 254 catch (std::exception e) { 255 f15 = 1; 256 sc_assert( sc_time_stamp() == sc_time(210, SC_NS) ); 257 } 258 wait(1, SC_NS); 259 } 260 261 void grandchild11() 262 { 263 try { 264 wait(20, SC_NS); 265 } 266 catch (std::exception e) { 267 f16 = 1; 268 sc_assert( sc_time_stamp() == sc_time(210, SC_NS) ); 269 } 270 wait(4, SC_NS); 271 } 272 273 void grandchild12() 274 { 275 try { 276 wait(20, SC_NS); 277 } 278 catch (std::exception e) { 279 f17 = 1; 280 sc_assert( sc_time_stamp() == sc_time(210, SC_NS) ); 281 } 282 wait(2, SC_NS); 283 } 284 285 void grandchild13() 286 { 287 try { 288 wait(20, SC_NS); 289 } 290 catch (std::exception e) { 291 f18 = 1; 292 sc_assert( sc_time_stamp() == sc_time(210, SC_NS) ); 293 } 294 wait(3, SC_NS); 295 } 296 297 SC_HAS_PROCESS(Top); 298}; 299 300int sc_main(int argc, char* argv[]) 301{ 302 Top top("top"); 303 304 sc_start(); 305 306 sc_assert( top.f1 ); 307 sc_assert( top.f2 ); 308 sc_assert( top.f3 ); 309 sc_assert( top.f4 ); 310 sc_assert( top.f5 ); 311 sc_assert( top.f6 ); 312 sc_assert( top.f7 ); 313 sc_assert( top.f8 ); 314 sc_assert( top.f9 ); 315 sc_assert( top.f10 ); 316 sc_assert( top.f11 ); 317 sc_assert( top.f12 ); 318 sc_assert( top.f13 ); 319 sc_assert( top.f14 ); 320 sc_assert( top.f15 ); 321 sc_assert( top.f16 ); 322 sc_assert( top.f17 ); 323 sc_assert( top.f18 ); 324 325 cout << endl << "Success" << endl; 326 return 0; 327} 328 329