112855Sgabeblack@google.com/*****************************************************************************
212855Sgabeblack@google.com
312855Sgabeblack@google.com  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
412855Sgabeblack@google.com  more contributor license agreements.  See the NOTICE file distributed
512855Sgabeblack@google.com  with this work for additional information regarding copyright ownership.
612855Sgabeblack@google.com  Accellera licenses this file to you under the Apache License, Version 2.0
712855Sgabeblack@google.com  (the "License"); you may not use this file except in compliance with the
812855Sgabeblack@google.com  License.  You may obtain a copy of the License at
912855Sgabeblack@google.com
1012855Sgabeblack@google.com    http://www.apache.org/licenses/LICENSE-2.0
1112855Sgabeblack@google.com
1212855Sgabeblack@google.com  Unless required by applicable law or agreed to in writing, software
1312855Sgabeblack@google.com  distributed under the License is distributed on an "AS IS" BASIS,
1412855Sgabeblack@google.com  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1512855Sgabeblack@google.com  implied.  See the License for the specific language governing
1612855Sgabeblack@google.com  permissions and limitations under the License.
1712855Sgabeblack@google.com
1812855Sgabeblack@google.com *****************************************************************************/
1912855Sgabeblack@google.com
2012855Sgabeblack@google.com/*****************************************************************************
2112855Sgabeblack@google.com
2212855Sgabeblack@google.com  test01.cpp --
2312855Sgabeblack@google.com
2412855Sgabeblack@google.com  Original Author: Andy Goodrich, Forte Design Systems, 8 December 2005
2512855Sgabeblack@google.com
2612855Sgabeblack@google.com *****************************************************************************/
2712855Sgabeblack@google.com
2812855Sgabeblack@google.com/*****************************************************************************
2912855Sgabeblack@google.com
3012855Sgabeblack@google.com  MODIFICATION LOG - modifiers, enter your name, affiliation, date and
3112855Sgabeblack@google.com  changes you are making here.
3212855Sgabeblack@google.com
3312855Sgabeblack@google.com      Name, Affiliation, Date:
3412855Sgabeblack@google.com  Description of Modification:
3512855Sgabeblack@google.com
3612855Sgabeblack@google.com *****************************************************************************/
3712855Sgabeblack@google.com
3812855Sgabeblack@google.com// Test of return values for sc_process handle instances, along with
3912855Sgabeblack@google.com// comparison operators.
4012855Sgabeblack@google.com
4112855Sgabeblack@google.com#include "systemc.h"
4212855Sgabeblack@google.com
4312855Sgabeblack@google.comSC_MODULE(DUT)
4412855Sgabeblack@google.com{
4512855Sgabeblack@google.com    SC_CTOR(DUT)
4612855Sgabeblack@google.com    {
4712855Sgabeblack@google.com        SC_CTHREAD(process_a, m_clk.pos());
4812855Sgabeblack@google.com        SC_THREAD(process_b)
4912855Sgabeblack@google.com        sensitive << m_clk.pos();
5012855Sgabeblack@google.com    }
5112855Sgabeblack@google.com    void process_a()
5212855Sgabeblack@google.com    {
5312855Sgabeblack@google.com        m_a = sc_get_current_process_handle();
5412855Sgabeblack@google.com        sc_process_handle b;
5512855Sgabeblack@google.com        sc_process_handle c = sc_get_current_process_handle();
5612855Sgabeblack@google.com
5712855Sgabeblack@google.com        // TEST COMPARISONS:
5812855Sgabeblack@google.com
5912855Sgabeblack@google.com        if ( m_a == b )
6012855Sgabeblack@google.com        {
6112855Sgabeblack@google.com            cout << __FILE__ << " " << __LINE__
6212855Sgabeblack@google.com                 << " non-null process handle == null process handle" << endl;
6312855Sgabeblack@google.com        }
6412855Sgabeblack@google.com        if ( m_a != c )
6512855Sgabeblack@google.com        {
6612855Sgabeblack@google.com            cout << __FILE__ << " " << __LINE__
6712855Sgabeblack@google.com                 << " process handles for same process not equal" << endl;
6812855Sgabeblack@google.com        }
6912855Sgabeblack@google.com        wait(1);
7012855Sgabeblack@google.com
7112855Sgabeblack@google.com        // TEST RETURN VALUES:
7212855Sgabeblack@google.com
7312855Sgabeblack@google.com        const std::vector<sc_object*>& objects = m_a.get_child_objects();
7412855Sgabeblack@google.com        if ( objects.size() != 0 )
7512855Sgabeblack@google.com        {
7612855Sgabeblack@google.com            cout << __FILE__ << " " << __LINE__
7712855Sgabeblack@google.com                 << "get_child_objects() returned non-null vector" << endl;
7812855Sgabeblack@google.com        }
7912855Sgabeblack@google.com        if ( m_a.get_parent_object() == 0 )
8012855Sgabeblack@google.com        {
8112855Sgabeblack@google.com            cout << __FILE__ << " " << __LINE__
8212855Sgabeblack@google.com                 << " get_parent_object() returned null value" << endl;
8312855Sgabeblack@google.com        }
8412855Sgabeblack@google.com        if ( !strcmp( m_a.name(), "") )
8512855Sgabeblack@google.com        {
8612855Sgabeblack@google.com            cout << __FILE__ << " " << __LINE__
8712855Sgabeblack@google.com                 << "name() returned empty string" << endl;
8812855Sgabeblack@google.com        }
8912855Sgabeblack@google.com        if ( m_a.proc_kind() != SC_CTHREAD_PROC_ )
9012855Sgabeblack@google.com        {
9112855Sgabeblack@google.com            cout << __FILE__ << " " << __LINE__
9212855Sgabeblack@google.com                 << "proc_kind() returned " << m_a.proc_kind()
9312855Sgabeblack@google.com                 << " not " << SC_CTHREAD_PROC_ << endl;
9412855Sgabeblack@google.com        }
9512855Sgabeblack@google.com        if ( m_a.terminated() )
9612855Sgabeblack@google.com        {
9712855Sgabeblack@google.com            cout << __FILE__ << " " << __LINE__
9812855Sgabeblack@google.com                 << "terminated() returned true" << endl;
9912855Sgabeblack@google.com        }
10012855Sgabeblack@google.com        if ( !m_a.valid() )
10112855Sgabeblack@google.com        {
10212855Sgabeblack@google.com            cout << __FILE__ << " " << __LINE__
10312855Sgabeblack@google.com                 << "valid() returned false" << endl;
10412855Sgabeblack@google.com        }
10512855Sgabeblack@google.com    }
10612855Sgabeblack@google.com    void process_b()
10712855Sgabeblack@google.com    {
10812855Sgabeblack@google.com        wait(1);
10912855Sgabeblack@google.com        sc_process_handle b = sc_get_current_process_handle();
11012855Sgabeblack@google.com        if ( m_a == b )
11112855Sgabeblack@google.com        {
11212855Sgabeblack@google.com            cout << __FILE__ << " " << __LINE__
11312855Sgabeblack@google.com                 << " process handles for two different processes were equal"
11412855Sgabeblack@google.com                 << endl;
11512855Sgabeblack@google.com        }
11612855Sgabeblack@google.com        if ( b.get_parent_object() == 0 )
11712855Sgabeblack@google.com        {
11812855Sgabeblack@google.com            cout << __FILE__ << " " << __LINE__
11912855Sgabeblack@google.com                 << " get_parent_object() returned null value" << endl;
12012855Sgabeblack@google.com        }
12112855Sgabeblack@google.com        if ( b.proc_kind() != SC_THREAD_PROC_ )
12212855Sgabeblack@google.com        {
12312855Sgabeblack@google.com            cout << __FILE__ << " " << __LINE__
12412855Sgabeblack@google.com                 << "proc_kind() returned " << b.proc_kind()
12512855Sgabeblack@google.com                 << " not " << SC_THREAD_PROC_ << endl;
12612855Sgabeblack@google.com        }
12712855Sgabeblack@google.com        wait(2);
12812855Sgabeblack@google.com        if ( m_a.valid() )
12912855Sgabeblack@google.com        {
13012855Sgabeblack@google.com            if ( !m_a.terminated() )
13112855Sgabeblack@google.com            {
13212855Sgabeblack@google.com                cout << __FILE__ << " " << __LINE__
13312855Sgabeblack@google.com                     << "terminated() returned false" << endl;
13412855Sgabeblack@google.com            }
13512855Sgabeblack@google.com        }
13612855Sgabeblack@google.com        else
13712855Sgabeblack@google.com        {
13812855Sgabeblack@google.com            if ( m_a.terminated() )
13912855Sgabeblack@google.com            {
14012855Sgabeblack@google.com                cout << __FILE__ << " " << __LINE__
14112855Sgabeblack@google.com                     << "terminated() returned true" << endl;
14212855Sgabeblack@google.com            }
14312855Sgabeblack@google.com        }
14412855Sgabeblack@google.com    }
14512855Sgabeblack@google.com
14612855Sgabeblack@google.com    sc_process_handle m_a;
14712855Sgabeblack@google.com    sc_in<bool>       m_clk;
14812855Sgabeblack@google.com};
14912855Sgabeblack@google.com
15012855Sgabeblack@google.com
15112855Sgabeblack@google.comint sc_main(int argc, char* argv[])
15212855Sgabeblack@google.com{
15312855Sgabeblack@google.com    sc_clock          clock;
15412855Sgabeblack@google.com    DUT               dut("dut");
15512855Sgabeblack@google.com    sc_process_handle handle;
15612855Sgabeblack@google.com    sc_process_handle handle2;
15712855Sgabeblack@google.com
15812855Sgabeblack@google.com    dut.m_clk(clock);
15912855Sgabeblack@google.com    if ( handle == handle2 )
16012855Sgabeblack@google.com    {
16112855Sgabeblack@google.com        cout << __FILE__ << " " << __LINE__
16212855Sgabeblack@google.com             << " == operator returned true" << endl;
16312855Sgabeblack@google.com    }
16412855Sgabeblack@google.com    if ( !(handle != handle2) )
16512855Sgabeblack@google.com    {
16612855Sgabeblack@google.com        cout << __FILE__ << " " << __LINE__
16712855Sgabeblack@google.com             << " != operator returned true" << endl;
16812855Sgabeblack@google.com    }
16912855Sgabeblack@google.com    const std::vector<sc_object*>& objects = handle.get_child_objects();
17012855Sgabeblack@google.com    if ( objects.size() != 0 )
17112855Sgabeblack@google.com    {
17212855Sgabeblack@google.com        cout << __FILE__ << " " << __LINE__
17312855Sgabeblack@google.com             << " get_child_objects() returned non-null vector" << endl;
17412855Sgabeblack@google.com    }
17512855Sgabeblack@google.com    if ( handle.get_parent_object() != 0 )
17612855Sgabeblack@google.com    {
17712855Sgabeblack@google.com        cout << __FILE__ << " " << __LINE__
17812855Sgabeblack@google.com             << " get_parent_object() returned non-null value" << endl;
17912855Sgabeblack@google.com    }
18012855Sgabeblack@google.com    if ( strcmp( handle.name(), "") )
18112855Sgabeblack@google.com    {
18212855Sgabeblack@google.com        cout << __FILE__ << " " << __LINE__
18312855Sgabeblack@google.com             << " name() returned non-empty string" << endl;
18412855Sgabeblack@google.com    }
18512855Sgabeblack@google.com    if ( handle.proc_kind() != SC_NO_PROC_ )
18612855Sgabeblack@google.com    {
18712855Sgabeblack@google.com        cout << __FILE__ << " " << __LINE__
18812855Sgabeblack@google.com             << " proc_kind() returned " << handle.proc_kind()
18912855Sgabeblack@google.com             << " not " << SC_NO_PROC_ << endl;
19012855Sgabeblack@google.com    }
19112855Sgabeblack@google.com    if ( handle.terminated() )
19212855Sgabeblack@google.com    {
19312855Sgabeblack@google.com        cout << __FILE__ << " " << __LINE__
19412855Sgabeblack@google.com             << " terminated() returned true" << endl;
19512855Sgabeblack@google.com    }
19612855Sgabeblack@google.com    if ( handle.valid() )
19712855Sgabeblack@google.com    {
19812855Sgabeblack@google.com        cout << __FILE__ << " " << __LINE__
19912855Sgabeblack@google.com             << " valid() returned true" << endl;
20012855Sgabeblack@google.com    }
20112855Sgabeblack@google.com
20212855Sgabeblack@google.com    sc_start(10, SC_NS);
20312855Sgabeblack@google.com    cout << "Program completed" << endl;
20412855Sgabeblack@google.com    return 0;
20512855Sgabeblack@google.com}
206