elog-gen.py : implement error inheritance

If an error inherits another error (via the error YAML interface), have
the child error inherit parent's metadata. Only single inheritance is
supported as of now.

Change-Id: I9ff295f4db04a9c5389f66e04f5d28287f9628a9
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
diff --git a/logging_test.cpp b/logging_test.cpp
index b781482..6a5f07f 100644
--- a/logging_test.cpp
+++ b/logging_test.cpp
@@ -81,7 +81,13 @@
                 example::xyz::openbmc_project::Example::TestErrorOne::
                     FILE_PATH(test_string),
                 example::xyz::openbmc_project::Example::TestErrorOne::
-                    FILE_NAME("elog_test_3.txt"));
+                    FILE_NAME("elog_test_3.txt"),
+                example::xyz::openbmc_project::Example::TestErrorTwo::
+                    DEV_ADDR(0xDEAD),
+                example::xyz::openbmc_project::Example::TestErrorTwo::
+                    DEV_ID(0x100),
+                example::xyz::openbmc_project::Example::TestErrorTwo::
+                    DEV_NAME("test case 3"));
     }
     catch (elogException<example::xyz::openbmc_project::Example::TestErrorOne>& e)
     {
@@ -115,7 +121,10 @@
     {
         elog<TestErrorOne>(TestErrorOne::ERRNUM(number),
                            prev_entry<TestErrorOne::FILE_PATH>(),
-                           TestErrorOne::FILE_NAME("elog_test_4.txt"));
+                           TestErrorOne::FILE_NAME("elog_test_4.txt"),
+                           TestErrorTwo::DEV_ADDR(0xDEAD),
+                           TestErrorTwo::DEV_ID(0x100),
+                           TestErrorTwo::DEV_NAME("test case 4"));
     }
     catch (elogExceptionBase& e)
     {
diff --git a/tools/elog-gen.py b/tools/elog-gen.py
index a6fdb1f..e9f4fc0 100755
--- a/tools/elog-gen.py
+++ b/tools/elog-gen.py
@@ -151,7 +151,8 @@
     f.write(template.render(
             errors=errors, error_msg=error_msg,
             error_lvl=error_lvl, meta=meta,
-            meta_data=meta_data, error_namespace=i_error_namespace))
+            meta_data=meta_data, error_namespace=i_error_namespace,
+            parents=parents))
     f.close()
 
 
diff --git a/tools/phosphor-logging/templates/elog-gen-template.mako.hpp b/tools/phosphor-logging/templates/elog-gen-template.mako.hpp
index 4222f08..e39deea 100644
--- a/tools/phosphor-logging/templates/elog-gen-template.mako.hpp
+++ b/tools/phosphor-logging/templates/elog-gen-template.mako.hpp
@@ -42,7 +42,16 @@
     % endfor
 
 }  // namespace _${classname}
-<% meta_string = ', '.join(meta[name]) %>
+<%
+    meta_string = ', '.join(meta[name])
+
+    parent = parents[name]
+    while parent:
+        parent_meta = [parent + "::" + p for p in meta[parent]]
+        parent_meta = ', '.join(parent_meta)
+        meta_string = meta_string + ", " + parent_meta
+        parent = parents[parent]
+%>
 struct ${classname}
 {
     static constexpr auto err_code = "${name}";