sc_verbosity.cpp revision 12855:588919e0e4aa
1/*****************************************************************************
2
3  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4  more contributor license agreements.  See the NOTICE file distributed
5  with this work for additional information regarding copyright ownership.
6  Accellera licenses this file to you under the Apache License, Version 2.0
7  (the "License"); you may not use this file except in compliance with the
8  License.  You may obtain a copy of the License at
9
10    http://www.apache.org/licenses/LICENSE-2.0
11
12  Unless required by applicable law or agreed to in writing, software
13  distributed under the License is distributed on an "AS IS" BASIS,
14  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15  implied.  See the License for the specific language governing
16  permissions and limitations under the License.
17
18 *****************************************************************************/
19
20// sc_verbosity.cpp -- test for
21//
22//  Original Author: John Aynsley, Doulos, Inc.
23//
24// MODIFICATION LOG - modifiers, enter your name, affiliation, date and
25//
26// $Log: sc_verbosity.cpp,v $
27// Revision 1.2  2011/05/08 19:18:46  acg
28//  Andy Goodrich: remove extraneous + prefixes from git diff.
29//
30
31// Verbosity level
32
33#include <systemc>
34using namespace sc_core;
35using std::cout;
36using std::endl;
37
38
39void report_with_verbosity(const char* msg_type)
40{
41  SC_REPORT_INFO_VERB(msg_type, "verbosity=SC_NONE",   SC_NONE);
42  SC_REPORT_INFO_VERB(msg_type, "verbosity=SC_LOW",    SC_LOW);
43  SC_REPORT_INFO_VERB(msg_type, "verbosity=SC_MEDIUM", SC_MEDIUM);
44  SC_REPORT_INFO_VERB(msg_type, "verbosity=SC_HIGH",   SC_HIGH);
45  SC_REPORT_INFO_VERB(msg_type, "verbosity=SC_FULL",   SC_FULL);
46  SC_REPORT_INFO_VERB(msg_type, "verbosity=SC_DEBUG",  SC_DEBUG);
47}
48
49
50SC_MODULE(Top)
51{
52  SC_CTOR(Top)
53  {
54    report_with_verbosity("DEFAULT");
55
56    sc_report_handler::set_verbosity_level( SC_NONE );
57    report_with_verbosity("SC_NONE");
58    sc_assert( sc_report_handler::get_verbosity_level() == 0 );
59
60    sc_report_handler::set_verbosity_level( SC_MEDIUM );
61    report_with_verbosity("SC_MEDIUM");
62    sc_assert( sc_report_handler::get_verbosity_level() == 200 );
63
64    sc_report_handler::set_verbosity_level( SC_FULL );
65    report_with_verbosity("SC_FULL");
66    sc_assert( sc_report_handler::get_verbosity_level() == 400 );
67
68    SC_THREAD(T);
69
70    f = 0;
71  }
72
73  int f;
74
75  void T()
76  {
77    sc_report_handler::set_verbosity_level( SC_LOW );
78    report_with_verbosity("SC_LOW");
79    sc_assert( sc_report_handler::get_verbosity_level() == 100 );
80
81    sc_report_handler::set_verbosity_level( SC_HIGH );
82    report_with_verbosity("SC_HIGH");
83    sc_assert( sc_report_handler::get_verbosity_level() == 300 );
84
85    sc_report_handler::set_verbosity_level( SC_DEBUG );
86    report_with_verbosity("SC_DEBUG");
87    sc_assert( sc_report_handler::get_verbosity_level() == 500 );
88
89    try {
90      SC_REPORT_ERROR("msg_type", "msg");
91    }
92    catch (const sc_report& e) {
93      sc_assert( e.get_verbosity() == SC_MEDIUM );
94      f = 1;
95    }
96  }
97
98};
99
100int sc_main(int argc, char* argv[])
101{
102  Top top("top");
103  sc_start();
104
105  sc_assert( top.f );
106
107  cout << endl << "Success" << endl;
108  return 0;
109}
110