summaryrefslogtreecommitdiff
path: root/src/systemc/tests/systemc/compliance_1666/test206/test206.cpp
blob: 9ab52e9b0c637e66ad29c0f10ae7996017c143f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#define SC_INCLUDE_DYNAMIC_PROCESSES

#include <systemc>
#include <cstring>
using namespace sc_core;
using namespace sc_dt;
using std::cout;
using std::endl;

// 6) sc_get_current_process_handle

SC_MODULE(M)
{
  SC_CTOR(M)
  {
    sc_process_handle h;
    sc_assert (!h.valid());
    h = sc_get_current_process_handle();
    sc_assert (!h.valid());
    SC_THREAD(T);
    h = sc_get_current_process_handle();
    sc_assert (h.valid());
    sc_assert (strcmp(h.name(),"top.m.T") == 0);
    sc_assert (h.proc_kind()==SC_THREAD_PROC_);
    sc_assert (h.dynamic()==false);
    sc_assert (h.terminated()==false);
    sc_assert (h.get_process_object() != 0);
    sc_assert (h.get_parent_object() == this);

    sc_spawn(sc_bind(&M::proc, this), "static_proc");
    h = sc_get_current_process_handle();
    sc_assert (h.valid());
    sc_assert (strcmp(h.name(),"top.m.static_proc") == 0);
    sc_assert (h.proc_kind()==SC_THREAD_PROC_);
    sc_assert (h.dynamic()==false);
    sc_assert (h.terminated()==false);
    sc_assert (h.get_process_object() != 0);
    sc_assert (h.get_parent_object() == this);
  }
  sc_object* obj;
  void T()
  {
    sc_process_handle h;
    sc_assert (!h.valid());
    h = sc_get_current_process_handle();
    sc_assert (h.valid());
    sc_assert (strcmp(h.name(),"top.m.T") == 0);
    sc_assert (h.proc_kind()==SC_THREAD_PROC_);
    sc_assert (h.dynamic()==false);
    sc_assert (h.terminated()==false);
    sc_assert (h.get_process_object() != 0);
    sc_assert (h.get_parent_object() == this);

    obj = h.get_process_object();
    sc_spawn_options opt;
    opt.spawn_method();
    sc_spawn(sc_bind(&M::proc, this), "dynamic_proc", &opt);
    wait(1, SC_NS);
  }
  void proc()
  {
    sc_process_handle h = sc_get_current_process_handle();
    sc_assert (h.valid());
    if (h.dynamic())
    {
      sc_assert (strcmp(h.name(),"top.m.T.dynamic_proc") == 0);
      sc_assert (h.proc_kind()==SC_METHOD_PROC_);
      sc_assert (h.get_parent_object() == obj);
    }
    else
    {
      sc_assert (strcmp(h.name(),"top.m.static_proc") == 0);
      sc_assert (h.proc_kind()==SC_THREAD_PROC_);
      sc_assert (h.get_parent_object() == this);
    }
    sc_assert (h.terminated()==false);
    sc_assert (h.get_process_object() != 0);
  }
};

struct Top: sc_module
{
  M *m;
  Top(sc_module_name)
  {
    m = new M("m");
  }
};

int sc_main(int argc, char* argv[])
{
  cout << "Should be silent..." << endl;
  sc_process_handle h;
  sc_assert (!h.valid());
  h = sc_get_current_process_handle();
  sc_assert (!h.valid());

  Top top("top");
  sc_start();

  cout << endl << "Success" << endl;
  return 0;
}