summaryrefslogtreecommitdiff
path: root/src/systemc/tests/systemc/compliance_1666/test219/test219.cpp
blob: 0dc0f536162b66a69977c14565421e63c44112aa (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
#define SC_INCLUDE_DYNAMIC_PROCESSES

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

// 19) Call to sc_spawn in what would have been the final update phase...

sc_event ev;

struct Prim: sc_prim_channel, sc_interface
{
  Prim() : count(0) {}

  void write() {
    request_update();
  }
  void update() {
    sc_spawn(sc_bind(&Prim::spawned_proc, this));
  }
  void spawned_proc()
  {
    ++ count;
    ev.notify(5, SC_NS);
  }
  const sc_event& default_event() const { return ev; }
  int count;
};

SC_MODULE(M)
{
  Prim prim;
  SC_CTOR(M)
    : ME_count(0)
  {
    SC_THREAD(T);
    SC_METHOD(ME);
      sensitive << prim;
      dont_initialize();
  }
  void T()
  {
    wait(10, SC_NS);
    prim.write();
    sc_assert(sc_time_stamp() == sc_time(10, SC_NS));
  }
  void ME()
  {
    ++ ME_count;
    sc_assert(sc_time_stamp() == sc_time(15, SC_NS));
  }
  int ME_count;
};

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;

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

  sc_assert(top.m->prim.count == 1);
  sc_assert(top.m->ME_count == 1);


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