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

// 20) sc_report_handler::stop_after(SC_FATAL,-1) should NOT call sc_stop on 1st fatal error

static bool global_flag_1 = false;
static bool global_flag_2 = false;
static bool global_flag_3 = false;

SC_MODULE(M)
{
  SC_CTOR(M)
  {
    SC_THREAD(T);
  }
  void T()
  {
    SC_REPORT_FATAL("/JA", "A bad thing has happened");
    wait(1, SC_NS);
    sc_assert(sc_report_handler::get_count(SC_FATAL) == 1);
    global_flag_1 = true;

    sc_report_handler::stop_after(SC_FATAL, 0);
    SC_REPORT_FATAL("/JA", "A bad thing has happened");
    wait(1, SC_NS);
    sc_assert(sc_report_handler::get_count(SC_FATAL) == 2);
    global_flag_2 = true;

    sc_report_handler::stop_after(SC_FATAL, -1);
    SC_REPORT_FATAL("/JA", "A bad thing has happened");
    wait(1, SC_NS);
    sc_assert(sc_report_handler::get_count(SC_FATAL) == 3);
    global_flag_3 = true;
  }
};

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 except for 3 fatal errors..." << endl;

  sc_report_handler::set_actions(SC_FATAL, SC_DISPLAY);

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

  sc_assert(global_flag_1);
  sc_assert(global_flag_2);
  sc_assert(global_flag_3);
  sc_assert(sc_report_handler::get_count(SC_INFO) == 0);
  sc_assert(sc_report_handler::get_count(SC_WARNING) == 0);
  sc_assert(sc_report_handler::get_count(SC_ERROR) == 0);
  sc_assert(sc_report_handler::get_count(SC_FATAL) == 3);

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