test234.cpp revision 12855:588919e0e4aa
1#include <systemc>
2using namespace sc_core;
3using namespace sc_dt;
4using std::cout;
5using std::endl;
6
7// 34) event finder on multiport
8
9struct i_f: virtual sc_interface
10{
11  virtual const sc_event& event() const = 0;
12};
13
14struct Chan: i_f, sc_object
15{
16  virtual const sc_event& event() const { return ev; }
17  sc_event ev;
18};
19
20struct Port: sc_port<i_f,0>
21{
22  sc_event_finder& find_event() const
23  {
24    return *new sc_event_finder_t<i_f>( *this, &i_f::event );
25  }
26};
27
28SC_MODULE(M)
29{
30  Port mp;
31  bool flag, flag2;
32
33  SC_CTOR(M)
34    : flag(false), flag2(false)
35  {
36    SC_THREAD(T);
37    sensitive << mp.find_event();
38  }
39  void T()
40  {
41    wait();
42    sc_assert(sc_time_stamp() == sc_time(1, SC_NS));
43    wait();
44    sc_assert(sc_time_stamp() == sc_time(11, SC_NS));
45    wait();
46    sc_assert(sc_time_stamp() == sc_time(111, SC_NS));
47    flag = true;
48    wait();
49    flag = false;
50  }
51  void end_of_elaboration()
52  {
53    SC_THREAD(T2);
54    for (int i = 0; i < mp.size(); i++)
55      sensitive << mp[i]->event();
56  }
57  void T2()
58  {
59    wait();
60    sc_assert(sc_time_stamp() == sc_time(1, SC_NS));
61    wait();
62    sc_assert(sc_time_stamp() == sc_time(11, SC_NS));
63    wait();
64    sc_assert(sc_time_stamp() == sc_time(111, SC_NS));
65    flag2 = true;
66    wait();
67    flag2 = false;
68  }
69  void end_of_simulation()
70  {
71    sc_assert( flag );
72    sc_assert( flag2 );
73  }
74};
75
76SC_MODULE(Top)
77{
78  M *m;
79  Chan chan1, chan2, chan3;
80  SC_CTOR(Top)
81  {
82    m = new M("m");
83    m->mp(chan1);
84    m->mp(chan2);
85    m->mp(chan3);
86    SC_THREAD(T);
87  }
88  void T()
89  {
90    wait(1, SC_NS);
91    chan1.ev.notify();
92    wait(10, SC_NS);
93    chan2.ev.notify();
94    wait(100, SC_NS);
95    chan3.ev.notify();
96    wait(1, SC_NS);
97    sc_stop();
98  }
99};
100
101int sc_main(int argc, char* argv[])
102{
103  cout << "Should be silent..." << endl;
104
105  Top top("top");
106  sc_start();
107
108  cout << endl << "Success" << endl;
109  return 0;
110}
111