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/*****************************************************************************
21
22  test01.cpp --
23
24  Original Author: Andy Goodrich, Forte Design Systems, 8 December 2005
25
26 *****************************************************************************/
27
28/*****************************************************************************
29
30  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
31  changes you are making here.
32
33      Name, Affiliation, Date:
34  Description of Modification:
35
36 *****************************************************************************/
37
38// Test of return values for sc_process handle instances, along with
39// comparison operators.
40
41#include "systemc.h"
42
43SC_MODULE(DUT)
44{
45    SC_CTOR(DUT)
46    {
47        SC_CTHREAD(process_a, m_clk.pos());
48        SC_THREAD(process_b)
49        sensitive << m_clk.pos();
50    }
51    void process_a()
52    {
53        m_a = sc_get_current_process_handle();
54        sc_process_handle b;
55        sc_process_handle c = sc_get_current_process_handle();
56
57        // TEST COMPARISONS:
58
59        if ( m_a == b )
60        {
61            cout << __FILE__ << " " << __LINE__
62                 << " non-null process handle == null process handle" << endl;
63        }
64        if ( m_a != c )
65        {
66            cout << __FILE__ << " " << __LINE__
67                 << " process handles for same process not equal" << endl;
68        }
69        wait(1);
70
71        // TEST RETURN VALUES:
72
73        const std::vector<sc_object*>& objects = m_a.get_child_objects();
74        if ( objects.size() != 0 )
75        {
76            cout << __FILE__ << " " << __LINE__
77                 << "get_child_objects() returned non-null vector" << endl;
78        }
79        if ( m_a.get_parent_object() == 0 )
80        {
81            cout << __FILE__ << " " << __LINE__
82                 << " get_parent_object() returned null value" << endl;
83        }
84        if ( !strcmp( m_a.name(), "") )
85        {
86            cout << __FILE__ << " " << __LINE__
87                 << "name() returned empty string" << endl;
88        }
89        if ( m_a.proc_kind() != SC_CTHREAD_PROC_ )
90        {
91            cout << __FILE__ << " " << __LINE__
92                 << "proc_kind() returned " << m_a.proc_kind()
93                 << " not " << SC_CTHREAD_PROC_ << endl;
94        }
95        if ( m_a.terminated() )
96        {
97            cout << __FILE__ << " " << __LINE__
98                 << "terminated() returned true" << endl;
99        }
100        if ( !m_a.valid() )
101        {
102            cout << __FILE__ << " " << __LINE__
103                 << "valid() returned false" << endl;
104        }
105    }
106    void process_b()
107    {
108        wait(1);
109        sc_process_handle b = sc_get_current_process_handle();
110        if ( m_a == b )
111        {
112            cout << __FILE__ << " " << __LINE__
113                 << " process handles for two different processes were equal"
114                 << endl;
115        }
116        if ( b.get_parent_object() == 0 )
117        {
118            cout << __FILE__ << " " << __LINE__
119                 << " get_parent_object() returned null value" << endl;
120        }
121        if ( b.proc_kind() != SC_THREAD_PROC_ )
122        {
123            cout << __FILE__ << " " << __LINE__
124                 << "proc_kind() returned " << b.proc_kind()
125                 << " not " << SC_THREAD_PROC_ << endl;
126        }
127        wait(2);
128        if ( m_a.valid() )
129        {
130            if ( !m_a.terminated() )
131            {
132                cout << __FILE__ << " " << __LINE__
133                     << "terminated() returned false" << endl;
134            }
135        }
136        else
137        {
138            if ( m_a.terminated() )
139            {
140                cout << __FILE__ << " " << __LINE__
141                     << "terminated() returned true" << endl;
142            }
143        }
144    }
145
146    sc_process_handle m_a;
147    sc_in<bool>       m_clk;
148};
149
150
151int sc_main(int argc, char* argv[])
152{
153    sc_clock          clock;
154    DUT               dut("dut");
155    sc_process_handle handle;
156    sc_process_handle handle2;
157
158    dut.m_clk(clock);
159    if ( handle == handle2 )
160    {
161        cout << __FILE__ << " " << __LINE__
162             << " == operator returned true" << endl;
163    }
164    if ( !(handle != handle2) )
165    {
166        cout << __FILE__ << " " << __LINE__
167             << " != operator returned true" << endl;
168    }
169    const std::vector<sc_object*>& objects = handle.get_child_objects();
170    if ( objects.size() != 0 )
171    {
172        cout << __FILE__ << " " << __LINE__
173             << " get_child_objects() returned non-null vector" << endl;
174    }
175    if ( handle.get_parent_object() != 0 )
176    {
177        cout << __FILE__ << " " << __LINE__
178             << " get_parent_object() returned non-null value" << endl;
179    }
180    if ( strcmp( handle.name(), "") )
181    {
182        cout << __FILE__ << " " << __LINE__
183             << " name() returned non-empty string" << endl;
184    }
185    if ( handle.proc_kind() != SC_NO_PROC_ )
186    {
187        cout << __FILE__ << " " << __LINE__
188             << " proc_kind() returned " << handle.proc_kind()
189             << " not " << SC_NO_PROC_ << endl;
190    }
191    if ( handle.terminated() )
192    {
193        cout << __FILE__ << " " << __LINE__
194             << " terminated() returned true" << endl;
195    }
196    if ( handle.valid() )
197    {
198        cout << __FILE__ << " " << __LINE__
199             << " valid() returned true" << endl;
200    }
201
202    sc_start(10, SC_NS);
203    cout << "Program completed" << endl;
204    return 0;
205}
206