9 #ifdef STK_MESH_TRACE_ENABLED 11 #include <stk_util/unit_test_support/stk_utest_macros.hpp> 13 #include <stk_mesh/base/Trace.hpp> 14 #include <stk_mesh/base/EntityKey.hpp> 23 const std::string SHOULD_SEE_STR =
"should_see";
24 const std::string SHOULD_NOT_SEE_STR =
"should_not_see";
25 unsigned SHOULD_SEE_COUNTER = 0;
27 std::string create_should_see_str(
unsigned counter)
29 std::ostringstream oss;
30 oss << SHOULD_SEE_STR << counter;
34 const char* create_func(
const std::string& func,
bool should_see)
36 std::ostringstream& oss = *(
new std::ostringstream());
38 oss << func <<
"::" << create_should_see_str(SHOULD_SEE_COUNTER++);
41 oss << func <<
"::" << SHOULD_NOT_SEE_STR;
43 return oss.str().c_str();
46 std::string create_string(
bool should_see)
49 return create_should_see_str(SHOULD_SEE_COUNTER++);
52 return SHOULD_NOT_SEE_STR;
57 STKUNIT_UNIT_TEST(UnitTestTrace, testTrace)
66 const EntityKey watch_key(0, 1);
67 const EntityKey not_watch_key(0, 2);
68 const std::string tracing_func =
"stk_classic::mesh::BulkData";
69 const std::string not_tracing_func =
"stk_classic::mesh::MetaData";
70 const stk_classic::mesh::LogMask active_mask = stk_classic::mesh::LOG_ENTITY;
71 const stk_classic::mesh::LogMask inactive_mask = stk_classic::mesh::LOG_BUCKET;
76 std::ostringstream trace_output;
77 stk_classic::mesh::setStream(trace_output);
78 meshlog.setPrintMask(active_mask | stk_classic::mesh::LOG_TRACE);
79 stk_classic::mesh::watch(watch_key);
88 bool should_see =
false;
89 Trace_(create_func(not_tracing_func, should_see));
93 bool should_see =
true;
94 Trace_(create_func(tracing_func, should_see));
98 bool should_see =
false;
99 TraceIf(create_func(not_tracing_func, should_see), active_mask);
103 bool should_see =
false;
104 TraceIf(create_func(tracing_func, should_see), inactive_mask);
105 DiagIf(inactive_mask, create_string(should_see));
109 bool should_see =
true;
110 TraceIf(create_func(tracing_func, should_see), active_mask);
111 DiagIf(active_mask, create_string(should_see));
115 bool should_see =
false;
116 TraceIfWatching(create_func(not_tracing_func, should_see), active_mask, watch_key);
120 bool should_see =
false;
121 TraceIfWatching(create_func(tracing_func, should_see), inactive_mask, watch_key);
122 DiagIfWatching(inactive_mask, watch_key, create_string(should_see));
126 bool should_see =
false;
127 TraceIfWatching(create_func(tracing_func, should_see), active_mask, not_watch_key);
128 DiagIfWatching(active_mask, not_watch_key, create_string(should_see));
132 bool should_see =
true;
133 TraceIfWatching(create_func(tracing_func, should_see), active_mask, watch_key);
134 DiagIfWatching(active_mask, watch_key, create_string(should_see));
141 const std::string trace_output_str = trace_output.str();
144 STKUNIT_ASSERT_EQUAL(trace_output_str.find(SHOULD_NOT_SEE_STR), std::string::npos);
147 for (
unsigned i = 0; i < SHOULD_SEE_COUNTER; ++i) {
148 STKUNIT_ASSERT_NE(trace_output_str.find(create_should_see_str(i)), std::string::npos);
static void addTraceFunction(const std::string &function_prefix)
Member function addTraceFunction adds a function prefix to the list of function prefixes search to en...
Integer type for the entity keys, which is an encoding of the entity type and entity identifier...