Added end2end test case
Added end2end test case for exercising code from attention event to isolator.
Signed-off-by: Ben Tyner <ben.tyner@ibm.com>
Change-Id: I5bde1c50e4b70e284e99e71bb69d55041310c0d0
diff --git a/attn/attn_handler.cpp b/attn/attn_handler.cpp
index ec600e5..4a5382d 100644
--- a/attn/attn_handler.cpp
+++ b/attn/attn_handler.cpp
@@ -1,12 +1,12 @@
#include <libpdbg.h>
#include <analyzer/analyzer_main.hpp>
-#include <phosphor-logging/log.hpp>
-#include <sdbusplus/bus.hpp>
+#include <bp_handler.hpp>
+#include <logging.hpp>
+#include <ti_handler.hpp>
#include <iomanip>
-
-using namespace phosphor::logging;
+#include <sstream>
namespace attn
{
@@ -34,22 +34,6 @@
int handleSpecial(bool i_breakpoints);
/**
- * @brief Notify Cronus over dbus interface
- *
- * @param i_proc Processor number with Special attention
- * @param i_core Core number with special attention
- * @param i_thread Thread number with special attention
- */
-void notifyCronus(uint32_t i_proc, uint32_t i_core, uint32_t i_thread);
-
-/**
- * @brief Start host diagnostic mode
- *
- * Start the host diagnostic mode systemd unit
- */
-void startHostDiagnosticMode();
-
-/**
* @brief The main attention handler logic
*
* @param i_breakpoints true = breakpoint special attn handling enabled
@@ -68,20 +52,20 @@
proc = pdbg_target_index(target); // get processor number
std::stringstream ss; // log message stream
- ss << "[ATTN] checking processor " << proc << std::endl;
+ ss << "checking processor " << proc << std::endl;
log<level::INFO>(ss.str().c_str());
// get active attentions on processor
if (0 != fsi_read(target, 0x1007, &isr_val))
{
std::stringstream ss; // log message stream
- ss << "[ATTN] Error! cfam read 0x1007 FAILED" << std::endl;
+ ss << "Error! cfam read 0x1007 FAILED" << std::endl;
log<level::INFO>(ss.str().c_str());
}
else
{
std::stringstream ss; // log message stream
- ss << "[ATTN] cfam 0x1007 = 0x";
+ ss << "cfam 0x1007 = 0x";
ss << std::hex << std::setw(8) << std::setfill('0');
ss << isr_val << std::endl;
log<level::INFO>(ss.str().c_str());
@@ -90,13 +74,13 @@
if (0 != fsi_read(target, 0x100d, &isr_mask))
{
std::stringstream ss; // log message stream
- ss << "[ATTN] Error! cfam read 0x100d FAILED" << std::endl;
+ ss << "Error! cfam read 0x100d FAILED" << std::endl;
log<level::INFO>(ss.str().c_str());
}
else
{
std::stringstream ss; // log message stream
- ss << "[ATTN] cfam 0x100d = 0x";
+ ss << "cfam 0x100d = 0x";
ss << std::hex << std::setw(8) << std::setfill('0');
ss << isr_mask << std::endl;
log<level::INFO>(ss.str().c_str());
@@ -110,7 +94,10 @@
// bit 0 on "left": bit 1 = checkstop
if (isr_val & isr_mask & 0x40000000)
{
- handleCheckstop();
+ if (0 == handleCheckstop())
+ {
+ break;
+ }
}
// bit 0 on "left": bit 2 = special attention
@@ -134,13 +121,13 @@
int rc = 1; // vital attention handling not yet supported
std::stringstream ss; // log message stream
- ss << "[ATTN] vital" << std::endl;
+ ss << "vital" << std::endl;
log<level::INFO>(ss.str().c_str());
if (0 != rc)
{
std::stringstream ss; // log message stream
- ss << "[ATTN] vital NOT handled" << std::endl;
+ ss << "vital NOT handled" << std::endl;
log<level::INFO>(ss.str().c_str());
}
@@ -152,10 +139,10 @@
*/
int handleCheckstop()
{
- int rc = 1; // checkstop handling not yet supported
+ int rc = 0; // checkstop handling supported
std::stringstream ss; // log message stream
- ss << "[ATTN] checkstop" << std::endl;
+ ss << "checkstop" << std::endl;
log<level::INFO>(ss.str().c_str());
analyzer::analyzeHardware();
@@ -176,18 +163,18 @@
std::stringstream ss; // log message stream
- ss << "[ATTN] special" << std::endl;
+ ss << "special" << std::endl;
// Right now we always handle breakpoint special attentions if breakpoint
// attn handling is enabled. This will eventually check if breakpoint attn
// handing is enabled AND there is a breakpoint pending.
if (true == i_breakpoints)
{
- ss << "[ATTN] breakpoint" << std::endl;
+ ss << "breakpoint" << std::endl;
log<level::INFO>(ss.str().c_str());
- // Cronus will determine proc, core and thread so just notify
- notifyCronus(0, 0, 0); // proc-0, core-0, thread-0
+ // Call the breakpoint special attention handler
+ bpHandler();
}
// Right now if breakpoint attn handling is not enabled we will treat the
// special attention as a TI. This will eventually be changed to check
@@ -195,11 +182,11 @@
// handling is enbaled or not.
else
{
- ss << "[ATTN] TI (terminate immediately)" << std::endl;
+ ss << "TI (terminate immediately)" << std::endl;
log<level::INFO>(ss.str().c_str());
- // Start host diagnostic mode
- startHostDiagnosticMode();
+ // Call TI special attention handler
+ tiHandler();
}
// TODO recoverable errors?
@@ -207,53 +194,4 @@
return rc;
}
-/**
- * @brief Notify Cronus over dbus interface
- */
-void notifyCronus(uint32_t i_proc, uint32_t i_core, uint32_t i_thread)
-{
- std::stringstream ss; // log message stream
-
- // log status info
- ss << "[ATTN] notify ";
- ss << i_proc << ", " << i_core << ", " << i_thread << std::endl;
- log<level::INFO>(ss.str().c_str());
-
- // notify Cronus over dbus
- auto bus = sdbusplus::bus::new_system();
- auto msg = bus.new_signal("/", "org.openbmc.cronus", "Brkpt");
-
- std::array<uint32_t, 3> params{i_proc, i_core, i_thread};
- msg.append(params);
-
- msg.signal_send();
-
- return;
-}
-
-/**
- * @brief Start host diagnostic mode
- * */
-void startHostDiagnosticMode()
-{
- std::stringstream ss; // log message stream
-
- // log status info
- ss << "[ATTN] start host diagnostic mode service" << std::endl;
- log<level::INFO>(ss.str().c_str());
-
- // Use the systemd service manager object interface to call the start unit
- // method with the obmc-host-diagnostic-mode target.
- auto bus = sdbusplus::bus::new_system();
- auto method = bus.new_method_call(
- "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
- "org.freedesktop.systemd1.Manager", "StartUnit");
-
- method.append("obmc-host-diagnostic-mode@0.target"); // unit to activate
- method.append("replace"); // mode = replace conflicting queued jobs
- bus.call_noreply(method); // start the service
-
- return;
-}
-
} // namespace attn
diff --git a/attn/attn_monitor.cpp b/attn/attn_monitor.cpp
index 15c924c..eb46978 100644
--- a/attn/attn_monitor.cpp
+++ b/attn/attn_monitor.cpp
@@ -2,9 +2,7 @@
#include "attn_handler.hpp"
-#include <phosphor-logging/log.hpp>
-
-using namespace phosphor::logging;
+#include <logging.hpp>
namespace attn
{
@@ -12,7 +10,7 @@
/** @brief Register a callback for gpio event */
void AttnMonitor::scheduleGPIOEvent()
{
- std::string logMessage = "[ATTN] ... waiting for events ...";
+ std::string logMessage = "... waiting for events ...";
log<level::INFO>(logMessage.c_str());
// Register async callback, note that callback is a
@@ -22,8 +20,8 @@
[this](const boost::system::error_code& ec) {
if (ec)
{
- std::string logMessage = "[ATTN] ATTN GPIO Async error: " +
- std::string(ec.message());
+ std::string logMessage =
+ "GPIO Async wait error: " + std::string(ec.message());
log<level::INFO>(logMessage.c_str());
}
else
@@ -43,7 +41,7 @@
if (gpiod_line_event_read_fd(iv_gpioEventDescriptor.native_handle(),
&gpioEvent) < 0)
{
- logMessage = "[ATTN] ATTN GPIO Failed can't read file descriptor!";
+ logMessage = "GPIO line read failed";
log<level::INFO>(logMessage.c_str());
}
else
@@ -57,13 +55,13 @@
// gpio == 1, GPIO handler should not be executing
case 1:
- logMessage = "[ATTN] ATTN GPIO sync!";
+ logMessage = "GPIO handler out of sync";
log<level::INFO>(logMessage.c_str());
break;
// unexpected value
default:
- logMessage = "[ATTN] ATTN GPIO read unexpected valuel!";
+ logMessage = "GPIO line unexpected value";
log<level::INFO>(logMessage.c_str());
}
}
@@ -75,7 +73,7 @@
{
if (0 != gpiod_line_request(iv_gpioLine, &iv_gpioConfig, 0))
{
- std::string logMessage = "[ATTN] failed request for GPIO";
+ std::string logMessage = "failed request for GPIO";
log<level::INFO>(logMessage.c_str());
}
else
@@ -85,7 +83,7 @@
gpioLineFd = gpiod_line_event_get_fd(iv_gpioLine);
if (gpioLineFd < 0)
{
- std::string logMessage = "[ATTN] failed to get file descriptor";
+ std::string logMessage = "failed to get file descriptor";
log<level::INFO>(logMessage.c_str());
}
else
diff --git a/attn/bp_handler.cpp b/attn/bp_handler.cpp
new file mode 100644
index 0000000..7b4744c
--- /dev/null
+++ b/attn/bp_handler.cpp
@@ -0,0 +1,35 @@
+#include <logging.hpp>
+#include <sdbusplus/bus.hpp>
+
+#include <sstream>
+
+namespace attn
+{
+
+/**
+ * @brief Notify Cronus over dbus interface
+ *
+ * When the special attention is due to a breakpoint condition we will notify
+ * Cronus over the dbus interface.
+ */
+void bpHandler()
+{
+ // trace message
+ std::stringstream ss;
+ ss << "Notify Cronus" << std::endl;
+ log<level::INFO>(ss.str().c_str());
+
+ // notify Cronus over dbus
+ auto bus = sdbusplus::bus::new_system();
+ auto msg = bus.new_signal("/", "org.openbmc.cronus", "Brkpt");
+
+ // Cronus will figure out proc, core, thread so just send 0,0,0
+ std::array<uint32_t, 3> params{0, 0, 0};
+ msg.append(params);
+
+ msg.signal_send();
+
+ return;
+}
+
+} // namespace attn
diff --git a/attn/bp_handler.hpp b/attn/bp_handler.hpp
new file mode 100644
index 0000000..4c7dcb0
--- /dev/null
+++ b/attn/bp_handler.hpp
@@ -0,0 +1,13 @@
+#pragma once
+
+namespace attn
+{
+
+/**
+ * @brief Breakpoint special attention handler
+ *
+ * Handler for special attention events due to a breakpoint condition.
+ */
+void bpHandler();
+
+} // namespace attn
diff --git a/attn/logging.cpp b/attn/logging.cpp
new file mode 100644
index 0000000..423e9ca
--- /dev/null
+++ b/attn/logging.cpp
@@ -0,0 +1,14 @@
+#include <logging.hpp>
+#include <phosphor-logging/log.hpp>
+
+namespace attn
+{
+
+/** @brief Log message of type INFO using phosphor logging */
+template <>
+void log<INFO>(const char* i_message)
+{
+ phosphor::logging::log<phosphor::logging::level::INFO>(i_message);
+}
+
+} // namespace attn
diff --git a/attn/logging.hpp b/attn/logging.hpp
new file mode 100644
index 0000000..9a4b0dc
--- /dev/null
+++ b/attn/logging.hpp
@@ -0,0 +1,21 @@
+#pragma once
+
+namespace attn
+{
+
+/** @brief Logging level types */
+enum level
+{
+ INFO
+};
+
+/**
+ * @brief Log message of different types
+ *
+ * Log messages of different types (level) such as informational, debug,
+ * errors etc.
+ */
+template <level L>
+void log(const char* i_message);
+
+} // namespace attn
diff --git a/attn/meson.build b/attn/meson.build
index dfa1ce9..6a81213 100644
--- a/attn/meson.build
+++ b/attn/meson.build
@@ -6,7 +6,7 @@
'-DBOOST_ERROR_CODE_HEADER_ONLY',
'-DBOOST_SYSTEM_NO_DEPRECATED']
-# dependency to link dbus support
+# dependency to link sdbusplus support
sdbusplus = dependency('sdbusplus', version : '>=1.0')
# dependency to link gpiod support
@@ -29,10 +29,23 @@
'systemdsystemunitdir')
)
+# see if phosphor-logging is available, if not use test case logging code
+h = 'phosphor-logging/log.hpp'
+if cmplr.compiles('#include <@0@>'.format(h), name : '#include <@0@>'.format(h))
+ logging_src = 'logging.cpp'
+else
+ logging_src = '../test/end2end/logging.cpp'
+endif
+
+# gather attention sources to be used here and elsewhere if needed
+attn_src = files('attn_main.cpp', 'attn_handler.cpp', 'attn_monitor.cpp',
+ 'bp_handler.cpp', 'ti_handler.cpp', logging_src)
+
+# Create attention handler library
attn = static_library('attn_handler',
- 'attn_main.cpp', 'attn_handler.cpp', 'attn_monitor.cpp',
- include_directories : incdir,
- dependencies : [whole_archive, libpdbg,
- no_whole_archive, sdbusplus, libgpiod],
- cpp_args : boost_args,
- install : true)
+ attn_src,
+ include_directories : incdir,
+ dependencies : [whole_archive, libpdbg,
+ no_whole_archive, sdbusplus, libgpiod],
+ cpp_args : boost_args,
+ install : true)
diff --git a/attn/ti_handler.cpp b/attn/ti_handler.cpp
new file mode 100644
index 0000000..cca2a66
--- /dev/null
+++ b/attn/ti_handler.cpp
@@ -0,0 +1,31 @@
+#include <logging.hpp>
+#include <sdbusplus/bus.hpp>
+
+#include <sstream>
+
+namespace attn
+{
+
+/** @brief Start host diagnostic mode systemd unit */
+void tiHandler()
+{
+ // trace message
+ std::stringstream ss;
+ ss << "start host diagnostic mode service" << std::endl;
+ log<level::INFO>(ss.str().c_str());
+
+ // Use the systemd service manager object interface to call the start unit
+ // method with the obmc-host-diagnostic-mode target.
+ auto bus = sdbusplus::bus::new_system();
+ auto method = bus.new_method_call(
+ "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
+ "org.freedesktop.systemd1.Manager", "StartUnit");
+
+ method.append("obmc-host-diagnostic-mode@0.target"); // unit to activate
+ method.append("replace"); // mode = replace conflicting queued jobs
+ bus.call_noreply(method); // start the service
+
+ return;
+}
+
+} // namespace attn
diff --git a/attn/ti_handler.hpp b/attn/ti_handler.hpp
new file mode 100644
index 0000000..d3b83cd
--- /dev/null
+++ b/attn/ti_handler.hpp
@@ -0,0 +1,13 @@
+#pragma once
+
+/**
+ * @brief TI special attention handler
+ *
+ * Handle special attention due to a terminate immediately (TI) condition.
+ */
+namespace attn
+{
+
+void tiHandler();
+
+} // namespace attn