summaryrefslogtreecommitdiff
path: root/src/systemc/tests/systemc/compliance_1666/test203a/test203a.cpp
blob: ad2a6b0f008b3f3269b91d50e56937614ab461e7 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#define SC_INCLUDE_DYNAMIC_PROCESSES

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

// 3) Process handle methods, including invalid and terminated process

void invalid_handle_check(sc_process_handle& h)
{

    sc_assert(h.valid() == false);
    sc_assert(strcmp(h.name(), "") == 0);
    sc_assert(h.proc_kind() == SC_NO_PROC_);
    sc_assert(h.get_process_object() == 0);
    std::vector<sc_object*> children = h.get_child_objects();
    sc_assert(children.size() == 0);
    sc_assert(h.get_parent_object() == 0);
    sc_assert(h.terminated() == false);
    sc_assert(h.dynamic() == false);
    sc_assert( !(h == h) );
    sc_assert(h != h);

    cout << "There should be warning 11 messages" << endl;

    h.disable();
    h.enable();
    h.is_unwinding();
    h.kill();
    h.reset();
    h.resume();
    h.suspend();
    h.sync_reset_off();
    h.sync_reset_on();
    h.terminated_event();
    h.throw_it(sc_user(), SC_NO_DESCENDANTS);

    cout << "End of warning messages" << endl;
}

SC_MODULE(M)
{
  sc_in_clk clk;
  SC_CTOR(M)
  {
    sc_process_handle h;
    invalid_handle_check(h);

    SC_THREAD(T);
    SC_CTHREAD(CT, clk.pos());
    SC_METHOD(ME);

    sc_process_handle h3 = sc_spawn(sc_bind(&M::stat_thread, this), "stat_thread");
    sc_spawn_options opt;
    opt.spawn_method();
    sc_process_handle h4 = sc_spawn(sc_bind(&M::stat_method, this), "stat_method", &opt);

    std::vector<sc_object*> children = this->get_child_objects();
    sc_assert(children.size() == 6);
  }
  void T()
  {
    sc_process_handle h;
    invalid_handle_check(h);

    sc_process_handle h2 = sc_get_current_process_handle();
    sc_assert(h2.valid() == true);
    sc_assert(strcmp(h2.name(), "top.m.T") == 0);
    sc_assert(h2.proc_kind() == SC_THREAD_PROC_);
    sc_assert(h2.get_process_object() != 0);
    std::vector<sc_object*> children2 = h2.get_child_objects();
    sc_assert(children2.size() == 0);
    sc_assert(h2.get_parent_object() == this);
    sc_assert(h2.terminated() == false);
    sc_assert(h2.dynamic() == false);
    sc_assert(h2 == h2);
    sc_assert(h2 != h);

    sc_process_handle h3 = sc_spawn(sc_bind(&M::dyn_thread, this), "dyn_thread");
    wait(1, SC_NS);

    if (h3.valid() == true)
    {
      sc_assert(strcmp(h3.name(), "top.m.T.dyn_thread") == 0);
      sc_assert(h3.proc_kind() == SC_THREAD_PROC_);
      sc_assert(h3.get_process_object() != 0);
      std::vector<sc_object*> children3 = h3.get_child_objects();
      sc_assert(children3.size() == 0);
      sc_assert(h3.get_parent_object() == sc_get_current_process_handle().get_process_object());
      sc_assert(h3.terminated() == true);
      sc_assert(h3.dynamic() == true);
      sc_assert(h3 == h3);
      sc_assert( !(h3 != h3) );
    }

    sc_spawn_options opt;
    opt.spawn_method();
    sc_process_handle h4 = sc_spawn(sc_bind(&M::dyn_method, this), "dyn_method", &opt);
    sc_assert(h4 != h3);

    wait(10, SC_NS);
    sc_stop();
  }

  void stat_thread()
  {
    sc_process_handle h;
    invalid_handle_check(h);

    wait(5, SC_NS);

    sc_process_handle h3 = sc_get_current_process_handle();
    sc_assert(h3.valid() == true);
    sc_assert(strcmp(h3.name(), "top.m.stat_thread") == 0);
    sc_assert(h3.proc_kind() == SC_THREAD_PROC_);
    sc_assert(h3.get_process_object() != 0);
    std::vector<sc_object*> children3 = h3.get_child_objects();
    sc_assert(children3.size() == 0);
    sc_assert(h3.get_parent_object() != 0);
    sc_assert(h3.terminated() == false);
    sc_assert(h3.dynamic() == false);
    sc_assert(h3 == h3);
    sc_assert(h3 != h);

    sc_process_handle h4;
    h4 = h3;
    sc_assert(h4 == h3);
    sc_assert(h4 != h);
  }

  void stat_method()
  {
    sc_process_handle h;
    invalid_handle_check(h);

    sc_process_handle h3 = sc_get_current_process_handle();
    sc_assert(h3.valid() == true);
    sc_assert(strcmp(h3.name(), "top.m.stat_method") == 0);
    sc_assert(h3.proc_kind() == SC_METHOD_PROC_);
    sc_assert(h3.get_process_object() != 0);
    std::vector<sc_object*> children3 = h3.get_child_objects();
    sc_assert(children3.size() == 0);
    sc_assert(h3.get_parent_object() != 0);
    sc_assert(h3.terminated() == false);
    sc_assert(h3.dynamic() == false);
    sc_assert(h3 == h3);
    sc_assert(h3 != h);

    sc_process_handle h4;
    h4 = h3;
    sc_assert(h4 == h3);
    sc_assert(h4 != h);
  }

  void dyn_thread()
  {
    sc_process_handle h;
    invalid_handle_check(h);

    sc_process_handle h3 = sc_get_current_process_handle();
    sc_assert(h3.valid() == true);
    sc_assert(strcmp(h3.name(), "top.m.T.dyn_thread") == 0);
    sc_assert(h3.proc_kind() == SC_THREAD_PROC_);
    sc_assert(h3.get_process_object() != 0);
    std::vector<sc_object*> children3 = h3.get_child_objects();
    sc_assert(children3.size() == 0);
    sc_assert(h3.get_parent_object() != 0);
    sc_assert(h3.terminated() == false);
    sc_assert(h3.dynamic() == true);
    sc_assert(h3 == h3);
    sc_assert(h3 != h);

    sc_process_handle h4(h3);
    sc_assert(h4 == h3);
  }

  void dyn_method()
  {
    sc_process_handle h;
    invalid_handle_check(h);

    sc_process_handle h3 = sc_get_current_process_handle();
    sc_assert(h3.valid() == true);
    sc_assert(strcmp(h3.name(), "top.m.T.dyn_method") == 0);
    sc_assert(h3.proc_kind() == SC_METHOD_PROC_);
    sc_assert(h3.get_process_object() != 0);
    std::vector<sc_object*> children3 = h3.get_child_objects();
    sc_assert(children3.size() == 0);
    sc_assert(h3.get_parent_object() != 0);
    sc_assert(h3.terminated() == false);
    sc_assert(h3.dynamic() == true);
    sc_assert(h3 == h3);
    sc_assert(h3 != h);

    sc_process_handle h4(h3);
    sc_assert(h4 == h3);
  }

  void CT()
  {
    sc_process_handle h;
    invalid_handle_check(h);

    sc_process_handle h2 = sc_get_current_process_handle();
    sc_assert(h2.valid() == true);
    sc_assert(strcmp(h2.name(), "top.m.CT") == 0);
    sc_assert(h2.proc_kind() == SC_CTHREAD_PROC_);
    sc_assert(h2.get_process_object() != 0);
    std::vector<sc_object*> children2 = h2.get_child_objects();
    sc_assert(children2.size() == 0);
    sc_assert(h2.get_parent_object() == this);
    sc_assert(h2.terminated() == false);
    sc_assert(h2.dynamic() == false);
    sc_assert(h2 == h2);
    sc_assert(h2 != h);
  }

  void ME()
  {
    sc_process_handle h;
    invalid_handle_check(h);

    sc_process_handle h2 = sc_get_current_process_handle();
    sc_assert(h2.valid() == true);
    sc_assert(strcmp(h2.name(), "top.m.ME") == 0);
    sc_assert(h2.proc_kind() == SC_METHOD_PROC_);
    sc_assert(h2.get_process_object() != 0);
    std::vector<sc_object*> children2 = h2.get_child_objects();
    sc_assert(children2.size() == 0);
    sc_assert(h2.get_parent_object() == this);
    sc_assert(h2.terminated() == false);
    sc_assert(h2.dynamic() == false);
    sc_assert(h2 == h2);
    sc_assert(h2 != h);
  }

};

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

int sc_main(int argc, char* argv[])
{
  cout << "Should be silent except for warning messages" << endl;

  sc_process_handle h;
  invalid_handle_check(h);

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

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