summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am14
-rw-r--r--logging_test.cpp40
-rwxr-xr-xtools/elog-gen.py35
-rw-r--r--tools/example/xyz/openbmc_project/Example/Elog.errors.yaml8
-rw-r--r--tools/phosphor-logging/templates/elog-gen-template.mako.hpp10
5 files changed, 67 insertions, 40 deletions
diff --git a/Makefile.am b/Makefile.am
index 9166164..ac50cc9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -16,15 +16,19 @@ CLEANFILES=elog-gen.hpp
# systemd required for journal interfaces
logging_test_LDFLAGS = $(SYSTEMD_LIBS)
-ELOG_YAML ?= ${abs_srcdir}/tools/example/xyz/openbmc_project/Example/Elog.errors.yaml
-ELOG_MAKO ?= ${abs_srcdir}/tools/phosphor-logging/templates/elog-gen-template.mako.hpp
-REQ_FILES_TO_GEN ?= ${abs_srcdir}/tools/elog-gen.py $(ELOG_YAML) $(ELOG_MAKO)
+ELOG_YAML ?= xyz/openbmc_project/Example/Elog.errors.yaml
+ELOG_MAKO ?= elog-gen-template.mako.hpp
+ELOG_YAML_DIR ?= tools/example/
+ELOG_TEMPLATE_DIR ?= tools/phosphor-logging/templates/
+REQ_FILES_TO_GEN ?= ${abs_srcdir}/tools/elog-gen.py\
+ ${abs_srcdir}/$(ELOG_YAML_DIR)/$(ELOG_YAML)\
+ ${abs_srcdir}/${ELOG_TEMPLATE_DIR}/$(ELOG_MAKO)
# Be sure to package up the required script, yaml, and mako template to
# generate the header file
EXTRA_DIST = $(REQ_FILES_TO_GEN)
elog-gen.hpp: $(REQ_FILES_TO_GEN)
- $(AM_V_at)${abs_srcdir}/tools/elog-gen.py -e $(ELOG_YAML) -m $(ELOG_MAKO) -o ${abs_srcdir}/elog-gen.hpp
+ $(AM_V_at)${abs_srcdir}/tools/elog-gen.py -r ${abs_srcdir}/${ELOG_YAML_DIR} -t ${abs_srcdir}/${ELOG_TEMPLATE_DIR} -e $(ELOG_YAML) -m $(ELOG_MAKO) -o ${abs_srcdir}/elog-gen.hpp
-SUBDIRS = test \ No newline at end of file
+SUBDIRS = test
diff --git a/logging_test.cpp b/logging_test.cpp
index 6c7d343..55d7d45 100644
--- a/logging_test.cpp
+++ b/logging_test.cpp
@@ -75,36 +75,36 @@ int main()
const char *test_string = "/tmp/test_string/";
try
{
- elog<org::freedesktop::DBus::Error::FileNotFound>(
- org::freedesktop::DBus::Error::FileNotFound::
+ elog<xyz::openbmc_project::Example::Error::TestErrorOne>(
+ xyz::openbmc_project::Example::Error::TestErrorOne::
ERRNUM(number),
- org::freedesktop::DBus::Error::FileNotFound::
+ xyz::openbmc_project::Example::Error::TestErrorOne::
FILE_PATH(test_string),
- org::freedesktop::DBus::Error::FileNotFound::
+ xyz::openbmc_project::Example::Error::TestErrorOne::
FILE_NAME("elog_test_3.txt"));
}
- catch (elogException<org::freedesktop::DBus::Error::FileNotFound>& e)
+ catch (elogException<xyz::openbmc_project::Example::Error::TestErrorOne>& e)
{
std::cout << "elog exception caught: " << e.what() << std::endl;
}
// Reduce our error namespaces
- using namespace org::freedesktop::DBus::Error;
+ using namespace xyz::openbmc_project::Example::Error;
// Now read back and verify our data made it into the journal
std::stringstream stream;
stream << std::hex << number;
- rc = validate_journal(FileNotFound::ERRNUM::str_short,
+ rc = validate_journal(TestErrorOne::ERRNUM::str_short,
std::string(stream.str()).c_str());
if(rc)
return(rc);
- rc = validate_journal(FileNotFound::FILE_PATH::str_short,
+ rc = validate_journal(TestErrorOne::FILE_PATH::str_short,
test_string);
if(rc)
return(rc);
- rc = validate_journal(FileNotFound::FILE_NAME::str_short,
+ rc = validate_journal(TestErrorOne::FILE_NAME::str_short,
"elog_test_3.txt");
if(rc)
return(rc);
@@ -113,9 +113,9 @@ int main()
number = 0x9876;
try
{
- elog<FileNotFound>(FileNotFound::ERRNUM(number),
- prev_entry<FileNotFound::FILE_PATH>(),
- FileNotFound::FILE_NAME("elog_test_4.txt"));
+ elog<TestErrorOne>(TestErrorOne::ERRNUM(number),
+ prev_entry<TestErrorOne::FILE_PATH>(),
+ TestErrorOne::FILE_NAME("elog_test_4.txt"));
}
catch (elogExceptionBase& e)
{
@@ -125,18 +125,18 @@ int main()
// Now read back and verify our data made it into the journal
stream.str("");
stream << std::hex << number;
- rc = validate_journal(FileNotFound::ERRNUM::str_short,
+ rc = validate_journal(TestErrorOne::ERRNUM::str_short,
std::string(stream.str()).c_str());
if(rc)
return(rc);
// This should just be equal to what we put in test 3
- rc = validate_journal(FileNotFound::FILE_PATH::str_short,
+ rc = validate_journal(TestErrorOne::FILE_PATH::str_short,
test_string);
if(rc)
return(rc);
- rc = validate_journal(FileNotFound::FILE_NAME::str_short,
+ rc = validate_journal(TestErrorOne::FILE_NAME::str_short,
"elog_test_4.txt");
if(rc)
return(rc);
@@ -144,13 +144,13 @@ int main()
// Compile fail tests
// Simple test to prove we fail to compile due to missing param
- //elog<FileNotFound>(FileNotFound::ERRNUM(1),
- // FileNotFound::FILE_PATH("test"));
+ //elog<TestErrorOne>(TestErrorOne::ERRNUM(1),
+ // TestErrorOne::FILE_PATH("test"));
// Simple test to prove we fail to compile due to invalid param
- //elog<FileNotFound>(FileNotFound::ERRNUM(1),
- // FileNotFound::FILE_PATH("test"),
- // FileNotFound::FILE_NAME(1));
+ //elog<TestErrorOne>(TestErrorOne::ERRNUM(1),
+ // TestErrorOne::FILE_PATH("test"),
+ // TestErrorOne::FILE_NAME(1));
return 0;
}
diff --git a/tools/elog-gen.py b/tools/elog-gen.py
index 7f2448d..7234e8b 100755
--- a/tools/elog-gen.py
+++ b/tools/elog-gen.py
@@ -19,13 +19,15 @@ import sys
import os
-def gen_elog_hpp(i_elog_yaml, i_input_mako, i_output_hpp):
+def gen_elog_hpp(i_rootdir, i_elog_yaml, i_input_mako, i_output_hpp):
r"""
Read the input yaml file, grab the relevant data and call the mako
template to generate the header file.
Description of arguments:
+ i_rootdir base directory to search for yaml files
i_elog_yaml yaml file describing the error logs
+ i_input_mako input mako template file to use
i_output_hpp header file to output the generated code to
"""
@@ -37,7 +39,7 @@ def gen_elog_hpp(i_elog_yaml, i_input_mako, i_output_hpp):
meta_data = dict() # The meta data info (type, format)
# see elog.yaml for reference
- ifile = yaml.safe_load(open(i_elog_yaml))
+ ifile = yaml.safe_load(open("/".join((i_rootdir,i_elog_yaml))))
err_count = 0
for i in ifile:
# Grab the main error and it's info
@@ -69,14 +71,15 @@ def gen_elog_hpp(i_elog_yaml, i_input_mako, i_output_hpp):
f = open(i_output_hpp, 'w')
f.write(mytemplate.render(errors=errors, error_msg=error_msg,
error_lvl=error_lvl, meta=meta,
- meta_data=meta_data))
+ meta_data=meta_data,elog_yaml=i_elog_yaml))
f.close()
def main(i_args):
parser = OptionParser()
- parser.add_option("-e", "--elog", dest="elog_yaml", default="elog.yaml",
+ parser.add_option("-e", "--elog", dest="elog_yaml",
+ default="xyz/openbmc_project/Example/Elog.errors.yaml",
help="input error yaml file to parse")
parser.add_option("-m", "--mako", dest="elog_mako",
@@ -87,13 +90,31 @@ def main(i_args):
default="elog-gen.hpp",
help="output hpp to generate, elog-gen.hpp is default")
+ parser.add_option("-r", "--rootdir", dest="rootdir",
+ default="example",
+ help="Base directory of yaml files to process")
+
+ parser.add_option("-t", "--templatedir", dest="templatedir",
+ default="phosphor-logging/templates/",
+ help="Base directory of files to process")
+
(options, args) = parser.parse_args(i_args)
- if (not (os.path.isfile(options.elog_yaml))):
- print "Can not find input yaml file " + options.elog_yaml
+ # Verify the input yaml file
+ yaml_path = "/".join((options.rootdir,options.elog_yaml))
+ if (not (os.path.isfile(yaml_path))):
+ print "Can not find input yaml file " + yaml_path
+ exit(1)
+
+ # Verify the input mako file
+ template_path = "/".join((options.templatedir,options.elog_mako))
+ if (not (os.path.isfile(template_path))):
+ print "Can not find input template file " + template_path
exit(1)
- gen_elog_hpp(options.elog_yaml, options.elog_mako,
+ gen_elog_hpp(options.rootdir,
+ options.elog_yaml,
+ template_path,
options.output_hpp)
# Only run if it's a script
diff --git a/tools/example/xyz/openbmc_project/Example/Elog.errors.yaml b/tools/example/xyz/openbmc_project/Example/Elog.errors.yaml
index 6d7cf0b..9ae2028 100644
--- a/tools/example/xyz/openbmc_project/Example/Elog.errors.yaml
+++ b/tools/example/xyz/openbmc_project/Example/Elog.errors.yaml
@@ -1,5 +1,5 @@
-- name: org.freedesktop.DBus.Error.FileNotFound
- description: A required file was not found
+- name: TestErrorOne
+ description: this is test error one
level: INFO
meta:
- str: "ERRNUM=0x%.4X"
@@ -9,8 +9,8 @@
- str: FILE_NAME=%s
type: const char *
-- name: xyz.openbmc_project.Hwsv.Error.Scom
- description: Getscom call failed
+- name: TestErrorTwo
+ description: This is test error two
level: ERR
meta:
- str: DEV_ADDR=0x%.8X
diff --git a/tools/phosphor-logging/templates/elog-gen-template.mako.hpp b/tools/phosphor-logging/templates/elog-gen-template.mako.hpp
index cb7137d..b9d3d5e 100644
--- a/tools/phosphor-logging/templates/elog-gen-template.mako.hpp
+++ b/tools/phosphor-logging/templates/elog-gen-template.mako.hpp
@@ -16,14 +16,16 @@ namespace logging
% for a in errors:
<%
- namespaces = errors[a].split('.')
- classname = namespaces.pop()
+ namespaces = elog_yaml.split('/')
+ namespaces.pop()
+ classname = errors[a]
%>\
% for s in namespaces:
namespace ${s}
{
% endfor
-
+namespace Error
+{
namespace _${classname}
{
% for b in meta[a]:
@@ -49,7 +51,7 @@ struct ${classname}
% endfor
using metadata_types = std::tuple<${meta_string}>;
};
-
+} // namespace Error
% for s in reversed(namespaces):
} // namespace ${s}
% endfor
OpenPOWER on IntegriCloud