summaryrefslogtreecommitdiff
path: root/src/systemc/tests/systemc/1666-2011-compliance/proc_ctrl_elab/proc_ctrl_elab.cpp
blob: a89120921bdf74e8739a52771d6f9b787efe8abb (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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
/*****************************************************************************

  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
  more contributor license agreements.  See the NOTICE file distributed
  with this work for additional information regarding copyright ownership.
  Accellera licenses this file to you under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with the
  License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
  implied.  See the License for the specific language governing
  permissions and limitations under the License.

 *****************************************************************************/

// proc_ctrl_elab.cpp -- test for 
//
//  Original Author: John Aynsley, Doulos, Inc.
//
// MODIFICATION LOG - modifiers, enter your name, affiliation, date and
//
// $Log: proc_ctrl_elab.cpp,v $
// Revision 1.2  2011/05/08 19:18:46  acg
//  Andy Goodrich: remove extraneous + prefixes from git diff.
//

// Calling process control methods during elaboration

#define SC_INCLUDE_DYNAMIC_PROCESSES

#include "systemc.h"

SC_MODULE(Top)
{
  SC_CTOR(Top)
  : caught_throw_it(0)
  , caught_reset(0)
  , caught_kill(0)
  
  , target_suspend_1_called(false)
  , target_suspend_2_called(false)
  , target_suspend_3_called(false)
  , target_suspend_4_called(false)
  , target_suspend_5_called(false)

  , target_disable_1_called(false)
  , target_disable_2_called(false)
  , target_disable_2_called_again(false)
  , target_disable_3_called(false)
  , target_disable_4_called(false)
  , target_disable_5_called(false)

  , target_sync_reset_1_called(false)
  , target_sync_reset_2_called(false)
  , target_sync_reset_3_called(false)
  , target_sync_reset_4_called(false)

  , reset_1_count(0)
  , reset_2_count(0)
  , reset_3_count(0)
  , reset_4_count(0)
  {
    SC_THREAD(ctrl);

    SC_THREAD(target_suspend_1);
      sensitive << ev;
      ts1 = sc_get_current_process_handle();

    SC_THREAD(target_suspend_2);
      dont_initialize();
      sensitive << ev;
      ts2 = sc_get_current_process_handle();

    SC_THREAD(target_suspend_3);
      dont_initialize();
      sensitive << ev;
      ts3 = sc_get_current_process_handle();

    SC_THREAD(target_suspend_4);
      dont_initialize();
      sensitive << ev;
      ts4 = sc_get_current_process_handle();
      ts4.suspend();
      
    SC_THREAD(target_suspend_5);
      dont_initialize();
      sensitive << ev;
      ts5 = sc_get_current_process_handle();
      ts5.suspend();
      ts5.resume();
      
    SC_THREAD(target_disable_1);
      sensitive << dummy_ev;
      td1 = sc_get_current_process_handle();

    SC_THREAD(target_disable_2);
      sensitive << ev;
      td2 = sc_get_current_process_handle();

    SC_THREAD(target_disable_3);
      td3 = sc_get_current_process_handle();
      
    SC_THREAD(target_disable_4);
      dont_initialize();
      sensitive << ev;
      td4 = sc_get_current_process_handle();
      td4.disable();

    SC_THREAD(target_disable_5);
      dont_initialize();
      sensitive << ev;
      td5 = sc_get_current_process_handle();
      td5.disable();
      td5.enable();
      td5.sync_reset_on();
      td5.sync_reset_off();

    SC_THREAD(target_sync_reset_1);
      sensitive << ev;
      tr1 = sc_get_current_process_handle();

    SC_THREAD(target_sync_reset_2);
      sensitive << ev;
      tr2 = sc_get_current_process_handle();

    SC_THREAD(target_sync_reset_3);
      dont_initialize();
      sensitive << ev;
      tr3 = sc_get_current_process_handle();

    SC_THREAD(target_sync_reset_4);
      dont_initialize();
      sensitive << ev;
      tr4 = sc_get_current_process_handle();
      tr4.sync_reset_on();
      
    try {
      ts2.throw_it(ex);
      sc_assert( false );
    }
    catch (std::exception e) {
      ++caught_throw_it;
    }
      
    try {
      ts2.reset();
      sc_assert( false );
    }
    catch (std::exception e) {
      ++caught_reset;
    }
      
    try {
      ts2.kill();
      sc_assert( false );
    }
    catch (std::exception e) {
      ++caught_kill;
    }
  }
  
  void before_end_of_elaboration()
  {
    ts1.suspend();
    ts2.suspend();
    ts3.suspend();

    td1.disable();
    td2.disable();
    td3.disable();
    
    tr1.sync_reset_on();
    tr2.sync_reset_on();
    tr3.sync_reset_on();
      
    try {
      ts2.throw_it(ex);
      sc_assert( false );
    }
    catch (std::exception e) {
      ++caught_throw_it;
    }
      
    try {
      ts2.reset();
      sc_assert( false );
    }
    catch (std::exception e) {
      ++caught_reset;
    }
      
    try {
      ts2.kill();
      sc_assert( false );
    }
    catch (std::exception e) {
      ++caught_kill;
    }
  }

  void start_of_simulation()
  {
    td3.enable();
    tr3.sync_reset_off();
      
    try {
      ts2.throw_it(ex);
      sc_assert( false );
    }
    catch (std::exception e) {
      ++caught_throw_it;
    }
      
    try {
      ts2.reset();
      sc_assert( false );
    }
    catch (std::exception e) {
      ++caught_reset;
    }
      
    try {
      ts2.kill();
      sc_assert( false );
    }
    catch (std::exception e) {
      ++caught_kill;
    }
  }
  
  sc_event ev, dummy_ev;
  
  std::exception ex;  

  sc_process_handle ts1;
  sc_process_handle ts2;  
  sc_process_handle ts3;
  sc_process_handle ts4;
  sc_process_handle ts5;

  sc_process_handle td1;
  sc_process_handle td2;
  sc_process_handle td3;
  sc_process_handle td4;
  sc_process_handle td5;

  sc_process_handle tr1;
  sc_process_handle tr2;
  sc_process_handle tr3;
  sc_process_handle tr4;

  int caught_throw_it;
  int caught_reset;
  int caught_kill;

  bool target_suspend_1_called;
  bool target_suspend_2_called;
  bool target_suspend_3_called;
  bool target_suspend_4_called;
  bool target_suspend_5_called;

  bool target_disable_1_called;
  bool target_disable_2_called;
  bool target_disable_2_called_again;
  bool target_disable_3_called;
  bool target_disable_4_called;
  bool target_disable_5_called;

  bool target_sync_reset_1_called;
  bool target_sync_reset_2_called;
  bool target_sync_reset_3_called;
  bool target_sync_reset_4_called;
  
  int reset_1_count;
  int reset_2_count;
  int reset_3_count;
  int reset_4_count;
  
  void ctrl()
  {
    ts3.resume();
    
    wait(10, SC_NS);
    ts1.resume();
    ev.notify();
    
    wait(10, SC_NS);
    ts2.resume();
    tr2.sync_reset_off();
    tr4.sync_reset_off();
    
    wait(10, SC_NS);
    td2.enable();
    
    wait(10, SC_NS);
    ev.notify();
    
    wait(10, SC_NS);
    ev.notify();
    td2.disable();
    
    wait(10, SC_NS);
    td4.enable();
    ts4.resume();
    ev.notify();
  }
   
  void target_suspend_1()
  {
    sc_assert( sc_time_stamp() == sc_time(10, SC_NS) );
    target_suspend_1_called = true;
  }
   
  void target_suspend_2()
  {
    sc_assert( sc_time_stamp() == sc_time(20, SC_NS) );
    target_suspend_2_called = true;
  }
   
  void target_suspend_3()
  {
    sc_assert( sc_time_stamp() == sc_time(10, SC_NS) );
    target_suspend_3_called = true;
  }
   
  void target_suspend_4()
  {
    sc_assert( sc_time_stamp() == sc_time(60, SC_NS) );
    target_suspend_4_called = true;
  }
   
  void target_suspend_5()
  {
    sc_assert( sc_time_stamp() == sc_time(10, SC_NS) );
    target_suspend_5_called = true;
    ts5.suspend();
  }
   
  void target_disable_1()
  {
    sc_assert( false );
    target_disable_1_called = true;
  }
   
  void target_disable_2()
  {
    sc_assert( sc_time_stamp() == sc_time(40, SC_NS) );
    target_disable_2_called = true;
    wait(); // on ev

    sc_assert( sc_time_stamp() == sc_time(50, SC_NS) );
    target_disable_2_called_again = true;
  }
   
  void target_disable_3()
  {
    sc_assert( sc_time_stamp() == sc_time(0, SC_NS) );
    sc_assert( sc_delta_count() == 0 );
    target_disable_3_called = true;
  }
   
  void target_disable_4()
  {
    sc_assert( sc_time_stamp() == sc_time(60, SC_NS) );
    target_disable_4_called = true;
  }
   
  void target_disable_5()
  {
    sc_assert( sc_time_stamp() == sc_time(10, SC_NS) );
    target_disable_5_called = true;
    td5.disable();
  }
   
  void target_sync_reset_1()
  {
    switch (reset_1_count)
    {
      case 0: sc_assert( sc_time_stamp() == sc_time(0, SC_NS) );
              sc_assert( sc_delta_count() == 0 );
              break;
      case 1: sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); 
              break;
      case 2: sc_assert( sc_time_stamp() == sc_time(40, SC_NS) ); 
              break;
      case 3: sc_assert( sc_time_stamp() == sc_time(50, SC_NS) ); 
              target_sync_reset_1_called = true;
              break;
    }
    ++reset_1_count;
    
    while (true)
    {
      wait();
      sc_assert( false );
    }
  }
   
  void target_sync_reset_2()
  {
    switch (reset_2_count)
    {
      case 0: sc_assert( sc_time_stamp() == sc_time(0, SC_NS) );
              sc_assert( sc_delta_count() == 0 );
              break;
      case 1: sc_assert( sc_time_stamp() == sc_time(10, SC_NS) ); 
              break;
      case 2: sc_assert( false ); 
              break;
      case 3: sc_assert( false ); 
              break;
    }
    ++reset_2_count;
    
    while (true)
    {
      wait();
      
    switch (reset_2_count)
    {
      case 0: sc_assert( false );
              break;
      case 1: sc_assert( false );
              break;
      case 2: sc_assert( sc_time_stamp() == sc_time(40, SC_NS) ); 
              break;
      case 3: sc_assert( sc_time_stamp() == sc_time(50, SC_NS) ); 
              target_sync_reset_2_called = true;
              break;
    }
    ++reset_2_count;
    
    }
  }
   
  void target_sync_reset_3()
  {
    switch (reset_3_count)
    {
      case 0: sc_assert( sc_time_stamp() == sc_time(10, SC_NS) );
              break;
      case 1: sc_assert( false ); 
              break;
      case 2: sc_assert( false ); 
              break;
    }
    ++reset_3_count;
    
    while (true)
    {
      wait();
      
    switch (reset_3_count)
    {
      case 0: sc_assert( false );
              break;
      case 1: sc_assert( sc_time_stamp() == sc_time(40, SC_NS) ); 
              break;
      case 2: sc_assert( sc_time_stamp() == sc_time(50, SC_NS) ); 
              target_sync_reset_3_called = true;
              break;
    }
    ++reset_3_count;
    
    }
  }
   
  void target_sync_reset_4()
  {
    switch (reset_4_count)
    {
      case 0: sc_assert( sc_time_stamp() == sc_time(10, SC_NS) );
              break;
      case 1: sc_assert( false );
              break;
      case 2: sc_assert( false ); 
              break;
    }
    ++reset_4_count;
    
    while (true)
    {
      wait();
      
    switch (reset_4_count)
    {
      case 0: sc_assert( false );
              break;
      case 1: sc_assert( sc_time_stamp() == sc_time(40, SC_NS) ); 
              break;
      case 2: sc_assert( sc_time_stamp() == sc_time(50, SC_NS) ); 
              target_sync_reset_4_called = true;
              break;
    }
    ++reset_4_count;
    
    }
  }
};

int sc_main(int argc, char* argv[])
{
  Top top("top");
  sc_start();

  sc_assert( top.caught_throw_it == 3 );
  sc_assert( top.caught_reset == 3 );
  sc_assert( top.caught_kill == 3 );
  
  sc_assert( top.target_suspend_1_called );
  sc_assert( top.target_suspend_2_called );
  sc_assert( top.target_suspend_3_called );
  sc_assert( top.target_suspend_4_called );
  sc_assert( top.target_suspend_5_called );

  sc_assert( !top.target_disable_1_called );
  sc_assert( top.target_disable_2_called );
  sc_assert( top.target_disable_2_called_again );
  sc_assert( top.target_disable_3_called );
  sc_assert( top.target_disable_4_called );
  sc_assert( top.target_disable_5_called );

  sc_assert( top.target_sync_reset_1_called );
  sc_assert( top.target_sync_reset_2_called );
  sc_assert( top.target_sync_reset_3_called );
  sc_assert( top.target_sync_reset_4_called );
  
  cout << endl << "Success" << endl;
  return 0;
}