living_children.cpp revision 12855:588919e0e4aa
14090Ssaidi@eecs.umich.edu/*****************************************************************************
24090Ssaidi@eecs.umich.edu
34090Ssaidi@eecs.umich.edu  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
44090Ssaidi@eecs.umich.edu  more contributor license agreements.  See the NOTICE file distributed
54090Ssaidi@eecs.umich.edu  with this work for additional information regarding copyright ownership.
64090Ssaidi@eecs.umich.edu  Accellera licenses this file to you under the Apache License, Version 2.0
74090Ssaidi@eecs.umich.edu  (the "License"); you may not use this file except in compliance with the
84090Ssaidi@eecs.umich.edu  License.  You may obtain a copy of the License at
94090Ssaidi@eecs.umich.edu
104090Ssaidi@eecs.umich.edu    http://www.apache.org/licenses/LICENSE-2.0
114090Ssaidi@eecs.umich.edu
124090Ssaidi@eecs.umich.edu  Unless required by applicable law or agreed to in writing, software
134090Ssaidi@eecs.umich.edu  distributed under the License is distributed on an "AS IS" BASIS,
144090Ssaidi@eecs.umich.edu  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
154090Ssaidi@eecs.umich.edu  implied.  See the License for the specific language governing
164090Ssaidi@eecs.umich.edu  permissions and limitations under the License.
174090Ssaidi@eecs.umich.edu
184090Ssaidi@eecs.umich.edu *****************************************************************************/
194090Ssaidi@eecs.umich.edu
204090Ssaidi@eecs.umich.edu// living_children.cpp -- test for
214090Ssaidi@eecs.umich.edu//
224090Ssaidi@eecs.umich.edu//  Original Author: John Aynsley, Doulos, Inc.
234090Ssaidi@eecs.umich.edu//
244090Ssaidi@eecs.umich.edu// MODIFICATION LOG - modifiers, enter your name, affiliation, date and
254090Ssaidi@eecs.umich.edu//
264090Ssaidi@eecs.umich.edu// $Log: living_children.cpp,v $
274090Ssaidi@eecs.umich.edu// Revision 1.2  2011/05/08 19:18:46  acg
284090Ssaidi@eecs.umich.edu//  Andy Goodrich: remove extraneous + prefixes from git diff.
294090Ssaidi@eecs.umich.edu//
304090Ssaidi@eecs.umich.edu
314090Ssaidi@eecs.umich.edu// Not invaliding handles to processes with living children
324090Ssaidi@eecs.umich.edu
334090Ssaidi@eecs.umich.edu#define SC_INCLUDE_DYNAMIC_PROCESSES
344090Ssaidi@eecs.umich.edu
354090Ssaidi@eecs.umich.edu#include <systemc>
364090Ssaidi@eecs.umich.edu
374090Ssaidi@eecs.umich.eduusing namespace sc_core;
3813103Skevin.brodsky@arm.comusing std::cout;
3912464Sjang.hanhwi@gmail.comusing std::endl;
404090Ssaidi@eecs.umich.edu
414090Ssaidi@eecs.umich.edustruct Top: sc_module
424090Ssaidi@eecs.umich.edu{
434090Ssaidi@eecs.umich.edu  Top(sc_module_name _name)
444090Ssaidi@eecs.umich.edu  {
454090Ssaidi@eecs.umich.edu    t1 = sc_spawn(sc_bind(&Top::T1, this));
464090Ssaidi@eecs.umich.edu  }
474090Ssaidi@eecs.umich.edu
484090Ssaidi@eecs.umich.edu  sc_process_handle t1, t2a, t2b;
494090Ssaidi@eecs.umich.edu
504090Ssaidi@eecs.umich.edu  void T1()
514090Ssaidi@eecs.umich.edu  {
524090Ssaidi@eecs.umich.edu    wait(1, SC_NS);
534090Ssaidi@eecs.umich.edu    t2a = sc_spawn(sc_bind(&Top::T2, this));
54    t2b = sc_spawn(sc_bind(&Top::T2, this));
55    wait(1, SC_NS);
56    sc_assert( t2a.valid() );
57    sc_assert( t2b.valid() );
58
59    std::vector<sc_object*> children = t1.get_child_objects();
60    sc_assert( children.size() == 2);
61
62    sc_event_and_list and_list = t2a.terminated_event() & t2b.terminated_event();
63    wait( and_list );
64
65    sc_assert( t2a.valid() );
66    sc_assert( t2a.terminated() );
67    sc_assert( t2b.valid() );
68    sc_assert( t2b.terminated() );
69    sc_assert( sc_time_stamp() == sc_time(3, SC_NS) );
70  }
71
72  void T2()
73  {
74    wait(2, SC_NS);
75    sc_process_handle t3 = sc_spawn(sc_bind(&Top::T3, this));
76    wait(SC_ZERO_TIME);
77    sc_assert( t3.valid() );
78
79    sc_process_handle me = sc_get_current_process_handle();
80    sc_assert( me.get_parent_object() ); // Parent handle shall still be valid
81    std::vector<sc_object*> children = me.get_child_objects();
82    sc_assert( children.size() == 1);
83
84    std::vector<sc_event*> my_events = me.get_child_events();
85    sc_assert( my_events.size() == 0 );
86  }
87
88  void T3()
89  {
90    wait(3, SC_NS);
91    sc_process_handle me = sc_get_current_process_handle();
92    sc_assert( me.get_parent_object() ); // Parent handle shall still be valid
93  }
94
95  SC_HAS_PROCESS(Top);
96};
97
98int sc_main(int argc, char* argv[])
99{
100  Top top("top");
101
102  sc_start();
103
104  cout << endl << "Success" << endl;
105  return 0;
106}
107
108