summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorDeepak Kodihalli <dkodihal@in.ibm.com>2017-01-18 00:17:39 -0600
committerDeepak Kodihalli <dkodihal@in.ibm.com>2017-01-27 10:43:03 -0600
commit5d1aace69bea0c76229335dcdc09ec63eda63931 (patch)
tree59445c1ef573400e2d716326a652fcabd19a3502 /tools
parentcbd12c8f5d0d5227f8eebf10302188a9bfc54f20 (diff)
downloadphosphor-logging-5d1aace69bea0c76229335dcdc09ec63eda63931.tar.gz
phosphor-logging-5d1aace69bea0c76229335dcdc09ec63eda63931.zip
elog-gen.py : order inherited errors
The elog-gen.py script should process errors such that the generated code has definitions for parent errors before their child errors are defined. Change-Id: I035292731346bdba969f549c7e4033066814890f Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/elog-gen.py46
-rw-r--r--tools/example/xyz/openbmc_project/Example/Bar.errors.yaml4
-rw-r--r--tools/example/xyz/openbmc_project/Example/Bar.metadata.yaml5
-rw-r--r--tools/example/xyz/openbmc_project/Example/Elog.errors.yaml2
-rw-r--r--tools/example/xyz/openbmc_project/Example/Foo.errors.yaml2
-rw-r--r--tools/phosphor-logging/templates/elog-gen-template.mako.hpp6
6 files changed, 54 insertions, 11 deletions
diff --git a/tools/elog-gen.py b/tools/elog-gen.py
index d1acb79..a6fdb1f 100755
--- a/tools/elog-gen.py
+++ b/tools/elog-gen.py
@@ -18,10 +18,40 @@ import sys
import os
+def order_inherited_errors(i_errors, i_parents):
+ # the ordered list of errors
+ errors = list()
+ has_inheritance = False
+ for error in i_errors:
+ if(i_parents[error] is not None):
+ has_inheritance = True
+ break
+
+ if(has_inheritance):
+ # Order the error codes list such that an error is never placed
+ # before it's parent. This way generated code can ensure parent
+ # definitions preceed child error definitions.
+ while(len(errors) < len(i_errors)):
+ for error in i_errors:
+ if(error in errors):
+ # already ordererd
+ continue
+ if((not i_parents[error]) or (i_parents[error] in errors)):
+ # parent present, or has no parent, either way this error
+ # can be added
+ errors.append(error)
+ else:
+ # no inherited errors
+ errors = i_errors
+
+ return errors
+
+
def check_error_inheritance(i_errors, i_parents):
- for parent in i_parents:
- if(parent and (parent not in i_errors)):
- print parent + " inhertied from, but not defined"
+ for error in i_errors:
+ if(i_parents[error] and (i_parents[error] not in i_errors)):
+ print (error + " inherits " + i_parents[error] +
+ " but the latter is not defined")
return False
return True
@@ -72,9 +102,9 @@ def gen_elog_hpp(i_yaml_dir, i_output_hpp,
errors = list() # Main error codes
error_msg = dict() # Error msg that corresponds to error code
error_lvl = dict() # Error code log level (debug, info, error, ...)
- meta = list() # The meta data names associated (ERRNO, FILE_NAME, ...)
+ meta = dict() # The meta data names associated (ERRNO, FILE_NAME, ...)
meta_data = dict() # The meta data info (type, format)
- parents = list()
+ parents = dict()
error_yamls = get_error_yaml_files(i_yaml_dir)
@@ -111,6 +141,8 @@ def gen_elog_hpp(i_yaml_dir, i_output_hpp,
print "Error - failed to validate error inheritance"
exit(1)
+ errors = order_inherited_errors(errors, parents)
+
# Load the mako template and call it with the required data
yaml_dir = i_yaml_dir.strip("./")
yaml_dir = yaml_dir.strip("../")
@@ -155,7 +187,7 @@ def get_elog_data(i_elog_yaml,
# xyz.openbmc.Foo, we need Foo
# Get 0th inherited error (current support - single inheritance)
parent = i['inherits'][0].split(".").pop()
- parents.append(parent)
+ parents[i['name']] = parent
error_msg[i['name']] = i['description']
error_lvl[i['name']] = match['level']
tmp_meta = []
@@ -167,7 +199,7 @@ def get_elog_data(i_elog_yaml,
meta_data[str_short]['str'] = j['str']
meta_data[str_short]['str_short'] = str_short
meta_data[str_short]['type'] = get_cpp_type(j['type'])
- meta.append(tmp_meta)
+ meta[i['name']] = tmp_meta
# Debug
# for i in errors:
diff --git a/tools/example/xyz/openbmc_project/Example/Bar.errors.yaml b/tools/example/xyz/openbmc_project/Example/Bar.errors.yaml
new file mode 100644
index 0000000..cff338b
--- /dev/null
+++ b/tools/example/xyz/openbmc_project/Example/Bar.errors.yaml
@@ -0,0 +1,4 @@
+- name: Bar
+ description: this is test error Bar
+ inherits:
+ - Foo
diff --git a/tools/example/xyz/openbmc_project/Example/Bar.metadata.yaml b/tools/example/xyz/openbmc_project/Example/Bar.metadata.yaml
new file mode 100644
index 0000000..ceebffd
--- /dev/null
+++ b/tools/example/xyz/openbmc_project/Example/Bar.metadata.yaml
@@ -0,0 +1,5 @@
+- name: Bar
+ level: INFO
+ meta:
+ - str: "BAR_DATA=%s"
+ type: string
diff --git a/tools/example/xyz/openbmc_project/Example/Elog.errors.yaml b/tools/example/xyz/openbmc_project/Example/Elog.errors.yaml
index 1ec9997..6f75178 100644
--- a/tools/example/xyz/openbmc_project/Example/Elog.errors.yaml
+++ b/tools/example/xyz/openbmc_project/Example/Elog.errors.yaml
@@ -1,5 +1,7 @@
- name: TestErrorOne
description: this is test error one
+ inherits:
+ - TestErrorTwo
- name: TestErrorTwo
description: This is test error two
diff --git a/tools/example/xyz/openbmc_project/Example/Foo.errors.yaml b/tools/example/xyz/openbmc_project/Example/Foo.errors.yaml
index 5ab311f..e81571c 100644
--- a/tools/example/xyz/openbmc_project/Example/Foo.errors.yaml
+++ b/tools/example/xyz/openbmc_project/Example/Foo.errors.yaml
@@ -1,4 +1,4 @@
- name: Foo
description: this is test error Foo
inherits:
- - example.xyz.openbmc_project.Example.TestErrorOne
+ - example.xyz.openbmc_project.Example.TestErrorOne
diff --git a/tools/phosphor-logging/templates/elog-gen-template.mako.hpp b/tools/phosphor-logging/templates/elog-gen-template.mako.hpp
index 1ff9150..4222f08 100644
--- a/tools/phosphor-logging/templates/elog-gen-template.mako.hpp
+++ b/tools/phosphor-logging/templates/elog-gen-template.mako.hpp
@@ -30,7 +30,7 @@ namespace ${s}
% endfor
namespace _${classname}
{
- % for b in meta[index]:
+ % for b in meta[name]:
struct ${b}
{
static constexpr auto str = "${meta_data[b]['str']}";
@@ -42,13 +42,13 @@ struct ${b}
% endfor
} // namespace _${classname}
-<% meta_string = ', '.join(meta[index]) %>
+<% meta_string = ', '.join(meta[name]) %>
struct ${classname}
{
static constexpr auto err_code = "${name}";
static constexpr auto err_msg = "${error_msg[name]}";
static constexpr auto L = level::${error_lvl[name]};
- % for b in meta[index]:
+ % for b in meta[name]:
using ${b} = _${classname}::${b};
% endfor
using metadata_types = std::tuple<${meta_string}>;
OpenPOWER on IntegriCloud