living_children.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// living_children.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: living_children.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// Not invaliding handles to processes with living children
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    t1 = sc_spawn(sc_bind(&Top::T1, this));
46  }
47
48  sc_process_handle t1, t2a, t2b;
49
50  void T1()
51  {
52    wait(1, SC_NS);
53    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