test211.cpp revision 12855:588919e0e4aa
1#include <systemc>
2using namespace sc_core;
3using namespace sc_dt;
4using std::cout;
5using std::endl;
6
7// 11) sc_is_running()
8
9struct my_port: sc_port<sc_signal_in_if<int> >
10{
11  my_port()
12  {
13    sc_assert(sc_is_running() == false);
14  }
15  ~my_port()
16  {
17    sc_assert(sc_is_running() == false);
18  }
19  void before_end_of_elaboration()
20  {
21    sc_assert(sc_is_running() == false);
22  }
23  void end_of_elaboration()
24  {
25    sc_assert(sc_is_running() == false);
26  }
27  void start_of_simulation()
28  {
29    sc_assert(sc_is_running() == false);
30  }
31  void end_of_simulation()
32  {
33    sc_assert(sc_is_running() == false);
34  }
35  int read()
36  {
37    sc_assert(sc_is_running() == true);
38    return (*this)->read();
39  }
40};
41
42SC_MODULE(M)
43{
44  my_port p;
45  SC_CTOR(M)
46  {
47    sc_assert(sc_is_running() == false);
48    SC_THREAD(T);
49    SC_METHOD(ME);
50  }
51  ~M()
52  {
53    sc_assert(sc_is_running() == false);
54  }
55  void T()
56  {
57    int i = p.read();
58    sc_assert(sc_is_running() == true);
59    wait (1, SC_NS);
60    sc_assert(sc_is_running() == true);
61    wait (1, SC_NS);
62    sc_assert(sc_is_running() == true);
63    wait (1, SC_NS);
64  }
65  void ME()
66  {
67    sc_assert(sc_is_running() == true);
68  }
69  void before_end_of_elaboration()
70  {
71    sc_assert(sc_is_running() == false);
72  }
73  void end_of_elaboration()
74  {
75    sc_assert(sc_is_running() == false);
76  }
77  void start_of_simulation()
78  {
79    sc_assert(sc_is_running() == false);
80  }
81  void end_of_simulation()
82  {
83    sc_assert(sc_is_running() == false);
84  }
85};
86
87struct Top: sc_module
88{
89  M *m;
90  sc_signal<int> sig;
91  Top(sc_module_name)
92  {
93    sc_assert(sc_is_running() == false);
94    m = new M("m");
95    m->p.bind(sig);
96  }
97};
98
99int sc_main(int argc, char* argv[])
100{
101  cout << "Should be silent..." << endl;
102
103  sc_assert(sc_is_running() == false);
104  Top top("top");
105  sc_assert(sc_is_running() == false);
106  sc_start();
107
108  cout << endl << "Success" << endl;
109  return 0;
110}
111