summaryrefslogtreecommitdiff
path: root/src/systemc/tests/systemc/compliance_1666/test200/test200.cpp
blob: 5f68240aaf53b7fc4fc337fef512fd4eb7174ca1 (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
#include <systemc.h>

// Multiple tests for Annex D.1 and D.2

struct i_f: virtual sc_interface
{
};

struct Chan: i_f, sc_object
{
};

struct Port: sc_port<i_f>
{
  Chan chan;
};

void check_form_of_suffix(std::string s)
{
  std::string charset = "0123456789";
  while (!s.empty())
  {
    sc_assert(s[0] == '_');
    s = s.substr(1);
    sc_assert(!s.empty());
    do
    {
      sc_assert(charset.find(s[0]) < charset.size());
      s = s.substr(1);
    } while (!s.empty() && (s[0] != '_'));
  }
}

SC_MODULE(M)
{
  Port port;

  SC_CTOR(M)
  {
    SC_THREAD(T);
    std::string s1 = std::string(sc_get_current_process_handle().name());
    sc_assert(s1.substr(0,7) == "top.m.T");
    check_form_of_suffix(s1.substr(7));

    SC_THREAD(T);
    std::string s2 = std::string(sc_get_current_process_handle().name());
    sc_assert(s2.substr(0,7) == "top.m.T");
    check_form_of_suffix(s2.substr(7));

    SC_THREAD(T);
    std::string s3 = std::string(sc_get_current_process_handle().name());
    sc_assert(s3.substr(0,7) == "top.m.T");
    check_form_of_suffix(s3.substr(7));

    sc_assert(s1 != s2);
    sc_assert(s2 != s3);
    sc_assert(s3 != s1);

    SC_THREAD(R);
  }

  void end_of_elaboration()
  {
    sc_assert(port.get_parent_object() == this);
    sc_assert(port.chan.get_parent_object() == this);
    sc_assert(get_child_objects().size() == 6);
  }

  void T()
  {
    int i_count = sc_report_handler::get_count(SC_INFO);
    int w_count = sc_report_handler::get_count(SC_WARNING);
    int e_count = sc_report_handler::get_count(SC_ERROR);
    int f_count = sc_report_handler::get_count(SC_FATAL);

    sc_report_handler::set_actions(SC_INFO,    SC_DO_NOTHING);
    sc_report_handler::set_actions(SC_WARNING, SC_DO_NOTHING);
    sc_report_handler::set_actions(SC_ERROR,   SC_DO_NOTHING);
    sc_report_handler::set_actions(SC_FATAL,   SC_DO_NOTHING);

    SC_REPORT_INFO("type", "msg");

    sc_assert(sc_report_handler::get_count(SC_INFO)    == i_count + 1);
    sc_assert(sc_report_handler::get_count(SC_WARNING) == w_count);
    sc_assert(sc_report_handler::get_count(SC_ERROR)   == e_count);
    sc_assert(sc_report_handler::get_count(SC_FATAL)   == f_count);

    SC_REPORT_WARNING("type", "msg");

    sc_assert(sc_report_handler::get_count(SC_INFO)    == i_count + 1);
    sc_assert(sc_report_handler::get_count(SC_WARNING) == w_count + 1);
    sc_assert(sc_report_handler::get_count(SC_ERROR)   == e_count);
    sc_assert(sc_report_handler::get_count(SC_FATAL)   == f_count);

    SC_REPORT_ERROR("type", "msg");

    sc_assert(sc_report_handler::get_count(SC_INFO)    == i_count + 1);
    sc_assert(sc_report_handler::get_count(SC_WARNING) == w_count + 1);
    sc_assert(sc_report_handler::get_count(SC_ERROR)   == e_count + 1);
    sc_assert(sc_report_handler::get_count(SC_FATAL)   == f_count);

    SC_REPORT_FATAL("type", "msg");

    sc_assert(sc_report_handler::get_count(SC_INFO)    == i_count + 1);
    sc_assert(sc_report_handler::get_count(SC_WARNING) == w_count + 1);
    sc_assert(sc_report_handler::get_count(SC_ERROR)   == e_count + 1);
    sc_assert(sc_report_handler::get_count(SC_FATAL)   == f_count + 1);

    sc_report_handler::set_actions(SC_INFO,    SC_DISPLAY);
    sc_report_handler::set_actions(SC_WARNING, SC_DISPLAY);
    sc_report_handler::set_actions(SC_ERROR,   SC_DISPLAY);
    sc_report_handler::set_actions(SC_FATAL,   SC_DISPLAY);

    SC_REPORT_INFO("type", "msg");

    sc_assert(sc_report_handler::get_count(SC_INFO)    == i_count + 2);
    sc_assert(sc_report_handler::get_count(SC_WARNING) == w_count + 1);
    sc_assert(sc_report_handler::get_count(SC_ERROR)   == e_count + 1);
    sc_assert(sc_report_handler::get_count(SC_FATAL)   == f_count + 1);

    SC_REPORT_WARNING("type", "msg");

    sc_assert(sc_report_handler::get_count(SC_INFO)    == i_count + 2);
    sc_assert(sc_report_handler::get_count(SC_WARNING) == w_count + 2);
    sc_assert(sc_report_handler::get_count(SC_ERROR)   == e_count + 1);
    sc_assert(sc_report_handler::get_count(SC_FATAL)   == f_count + 1);

    SC_REPORT_ERROR("type", "msg");

    sc_assert(sc_report_handler::get_count(SC_INFO)    == i_count + 2);
    sc_assert(sc_report_handler::get_count(SC_WARNING) == w_count + 2);
    sc_assert(sc_report_handler::get_count(SC_ERROR)   == e_count + 2);
    sc_assert(sc_report_handler::get_count(SC_FATAL)   == f_count + 1);

    SC_REPORT_FATAL("type", "msg");

    sc_assert(sc_report_handler::get_count(SC_INFO)    == i_count + 2);
    sc_assert(sc_report_handler::get_count(SC_WARNING) == w_count + 2);
    sc_assert(sc_report_handler::get_count(SC_ERROR)   == e_count + 2);
    sc_assert(sc_report_handler::get_count(SC_FATAL)   == f_count + 2);
  }
  void R()
  {
  wait(100, SC_NS);

    int i_count = sc_report_handler::get_count(SC_INFO);
    int w_count = sc_report_handler::get_count(SC_WARNING);
    int e_count = sc_report_handler::get_count(SC_ERROR);
    int f_count = sc_report_handler::get_count(SC_FATAL);

    try {
      SC_REPORT_ERROR("type", "msg");
    }
    catch (sc_report& rpt) {
      sc_assert(rpt.get_severity() == SC_ERROR);
      sc_assert(strcmp(rpt.get_msg_type(), "type") == 0);
      sc_assert(strcmp(rpt.get_msg(), "msg") == 0);
      sc_assert(rpt.get_time() == sc_time(0, SC_NS));
      sc_assert(strcmp(rpt.get_process_name(), "top.m.R") == 0);
    }

    sc_assert(sc_report_handler::get_count(SC_INFO)    == i_count);
    sc_assert(sc_report_handler::get_count(SC_WARNING) == w_count);
    sc_assert(sc_report_handler::get_count(SC_ERROR)   == e_count + 1);
    sc_assert(sc_report_handler::get_count(SC_FATAL)   == f_count);
  }
};

SC_MODULE(Top)
{
  M *m;
  Chan *chan;
  SC_CTOR(Top)
  {
    m = new M("m");
    chan = new Chan;
    m->port.bind(*chan);
  }
  void end_of_elaboration()
  {
    sc_assert(get_child_objects().size() == 2);
  }
};

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

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

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