Create a tracing util wrapper
Signed-off-by: Zane Shelley <zshelle@us.ibm.com>
Change-Id: I032b6137921ea06c3ea1f927521731648d68c230
diff --git a/analyzer/hei_user_interface.cpp b/analyzer/hei_user_interface.cpp
index 86137f7..ce6fa87 100644
--- a/analyzer/hei_user_interface.cpp
+++ b/analyzer/hei_user_interface.cpp
@@ -10,6 +10,7 @@
#include <stdio.h>
#include <hei_user_interface.hpp>
+#include <util/trace.hpp>
namespace libhei
{
@@ -36,9 +37,9 @@
if (accessFailure)
{
- printf("Register read failed: chip=%p type=0x%0" PRIx8
- "addr=0x%0" PRIx64 "\n",
- i_chip.getChip(), i_regType, i_address);
+ trace::err("Register read failed: chip=%p type=0x%0" PRIx8
+ "addr=0x%0" PRIx64 "\n",
+ i_chip.getChip(), i_regType, i_address);
o_value = 0; // just in case
}
@@ -51,11 +52,9 @@
void hei_inf(char* format, ...)
{
va_list args;
- fprintf(stdout, "I> ");
va_start(args, format);
- vfprintf(stdout, format, args);
+ trace::inf(format, args);
va_end(args);
- fprintf(stdout, "\n");
}
//------------------------------------------------------------------------------
@@ -64,11 +63,9 @@
void hei_err(char* format, ...)
{
va_list args;
- fprintf(stderr, "E> ");
va_start(args, format);
- vfprintf(stderr, format, args);
+ trace::err(format, args);
va_end(args);
- fprintf(stderr, "\n");
}
} // namespace libhei
diff --git a/analyzer/meson.build b/analyzer/meson.build
index 3113ce6..9ae1548 100644
--- a/analyzer/meson.build
+++ b/analyzer/meson.build
@@ -5,5 +5,6 @@
# Create hardware error analyzer library
analyzer = static_library('analyzer',
analyzer_src,
+ include_directories : incdir,
dependencies : libhei_dep,
install : false)
diff --git a/test/end2end/meson.build b/test/end2end/meson.build
index 98c8462..6897469 100644
--- a/test/end2end/meson.build
+++ b/test/end2end/meson.build
@@ -5,6 +5,7 @@
link_with : [analyzer, attn],
include_directories : incdir,
dependencies : libhei_dep,
+ cpp_args : test_arg,
install : false)
#test('openpower-hw-diags-test', end2end)
diff --git a/test/meson.build b/test/meson.build
index 1704f17..6cdae18 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -1,3 +1,7 @@
+test_arg = [
+ '-DTEST_TRACE',
+]
+
# end2end code exerciser for experiment and testing
subdir('end2end')
@@ -6,5 +10,5 @@
]
foreach t : tests
- test(t, executable(t.underscorify(), t + '.cpp'))
+ test(t, executable(t.underscorify(), t + '.cpp', cpp_args : test_arg))
endforeach
diff --git a/util/trace.hpp b/util/trace.hpp
new file mode 100644
index 0000000..ef940fd
--- /dev/null
+++ b/util/trace.hpp
@@ -0,0 +1,71 @@
+#pragma once
+
+#include <inttypes.h>
+#include <stdio.h>
+
+#include <cstdarg>
+
+#ifndef TEST_TRACE
+#include <phosphor-logging/log.hpp>
+#endif
+
+namespace trace
+{
+
+#ifndef TEST_TRACE
+constexpr size_t MSG_MAX_LEN = 256;
+#endif
+
+/** @brief Information trace (va_list format). */
+inline void inf(const char* format, va_list args)
+{
+#ifdef TEST_TRACE
+
+ vfprintf(stdout, format, args);
+ fprintf(stdout, "\n");
+
+#else
+
+ char msg[MSG_MAX_LEN];
+ vsnprintf(msg, MSG_MAX_LEN, format, args);
+ phosphor::logging::log<phosphor::logging::level::INFO>(msg);
+
+#endif
+}
+
+/** @brief Error trace (va_list format). */
+inline void err(const char* format, va_list args)
+{
+#ifdef TEST_TRACE
+
+ vfprintf(stderr, format, args);
+ fprintf(stderr, "\n");
+
+#else
+
+ char msg[MSG_MAX_LEN];
+ vsnprintf(msg, MSG_MAX_LEN, format, args);
+ phosphor::logging::log<phosphor::logging::level::ERR>(msg);
+
+#endif
+}
+
+/** @brief Information trace (printf format). */
+inline void inf(const char* format, ...)
+{
+ va_list args;
+ va_start(args, format);
+ trace::inf(format, args);
+ va_end(args);
+}
+
+/** @brief Error trace (printf format). */
+inline void err(const char* format, ...)
+{
+ va_list args;
+ va_start(args, format);
+ trace::err(format, args);
+ va_end(args);
+}
+
+} // namespace trace