summaryrefslogtreecommitdiff
path: root/src/systemc/tests/systemc/compliance_1666/test234/test234.cpp
blob: 1b546754471c588f9e0e774caae1c798dcf97b5d (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
#include <systemc>
using namespace sc_core;
using namespace sc_dt;
using std::cout;
using std::endl;

// 34) event finder on multiport

struct i_f: virtual sc_interface
{
  virtual const sc_event& event() const = 0;
};

struct Chan: i_f, sc_object
{
  virtual const sc_event& event() const { return ev; }
  sc_event ev;
};

struct Port: sc_port<i_f,0>
{
  sc_event_finder& find_event() const
  {
    return *new sc_event_finder_t<i_f>( *this, &i_f::event );
  }
};

SC_MODULE(M)
{
  Port mp;
  bool flag, flag2;

  SC_CTOR(M)
    : flag(false), flag2(false)
  {
    SC_THREAD(T);
    sensitive << mp.find_event();
  }
  void T()
  {
    wait();
    sc_assert(sc_time_stamp() == sc_time(1, SC_NS));
    wait();
    sc_assert(sc_time_stamp() == sc_time(11, SC_NS));
    wait();
    sc_assert(sc_time_stamp() == sc_time(111, SC_NS));
    flag = true;
    wait();
    flag = false;
  }
  void end_of_elaboration()
  {
    SC_THREAD(T2);
    for (int i = 0; i < mp.size(); i++)
      sensitive << mp[i]->event();
  }
  void T2()
  {
    wait();
    sc_assert(sc_time_stamp() == sc_time(1, SC_NS));
    wait();
    sc_assert(sc_time_stamp() == sc_time(11, SC_NS));
    wait();
    sc_assert(sc_time_stamp() == sc_time(111, SC_NS));
    flag2 = true;
    wait();
    flag2 = false;
  }
  void end_of_simulation()
  {
    sc_assert( flag );
    sc_assert( flag2 );
  }
};

SC_MODULE(Top)
{
  M *m;
  Chan chan1, chan2, chan3;
  SC_CTOR(Top)
  {
    m = new M("m");
    m->mp(chan1);
    m->mp(chan2);
    m->mp(chan3);
    SC_THREAD(T);
  }
  void T()
  {
    wait(1, SC_NS);
    chan1.ev.notify();
    wait(10, SC_NS);
    chan2.ev.notify();
    wait(100, SC_NS);
    chan3.ev.notify();
    wait(1, SC_NS);
    sc_stop();
  }
};

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

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

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