elog-gen.py: Support base and test yaml directories

Add an additional argument to pass the directory where the unit
test yaml files are located. Default the base directory to None
as this argument will be passed by the recipe during build time.

Change-Id: I1276d74e383e1517595371c3f6e31fa077eac43f
Signed-off-by: Adriana Kobylak <anoo@us.ibm.com>
diff --git a/Makefile.am b/Makefile.am
index 3f10b0e..973533d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -68,10 +68,11 @@
 
 ELOG_MAKO ?= elog-gen-template.mako.hpp
 LOOKUP_MAKO ?= elog-lookup-template.mako.cpp
-ELOG_YAML_DIR ?= ${abs_srcdir}/tools/example/
+ELOG_YAML_DIR ?= "None"
+ELOG_YAML_DIR_TEST ?= ${abs_srcdir}/tools/
 ELOG_TEMPLATE_DIR ?= ${abs_srcdir}/tools/phosphor-logging/templates/
 REQ_FILES_TO_GEN ?= ${abs_srcdir}/tools/elog-gen.py\
-	$(ELOG_YAML_DIR)/$(ELOG_YAML)\
+	$(ELOG_YAML_DIR_TEST)/$(ELOG_YAML)\
 	${ELOG_TEMPLATE_DIR}/$(ELOG_MAKO)
 
 # Be sure to package up the required script, yaml, and mako template to
@@ -79,9 +80,9 @@
 EXTRA_DIST = $(REQ_FILES_TO_GEN)
 
 elog-gen.hpp: $(REQ_FILES_TO_GEN)
-	$(AM_V_at)$(PYTHON) ${abs_srcdir}/tools/elog-gen.py -y ${ELOG_YAML_DIR} -t ${ELOG_TEMPLATE_DIR} -m $(ELOG_MAKO) -o ${abs_srcdir}/elog-gen.hpp
+	$(AM_V_at)$(PYTHON) ${abs_srcdir}/tools/elog-gen.py -y ${ELOG_YAML_DIR} -u ${ELOG_YAML_DIR_TEST} -t ${ELOG_TEMPLATE_DIR} -m $(ELOG_MAKO) -o ${abs_srcdir}/elog-gen.hpp
 elog-lookup.cpp: $(REQ_FILES_TO_GEN)
-	$(AM_V_at)$(PYTHON) ${abs_srcdir}/tools/elog-gen.py -y ${ELOG_YAML_DIR} -t ${ELOG_TEMPLATE_DIR} -m $(LOOKUP_MAKO) -o ${abs_srcdir}/elog-lookup.cpp
+	$(AM_V_at)$(PYTHON) ${abs_srcdir}/tools/elog-gen.py -y ${ELOG_YAML_DIR} -u ${ELOG_YAML_DIR_TEST} -t ${ELOG_TEMPLATE_DIR} -m $(LOOKUP_MAKO) -o ${abs_srcdir}/elog-lookup.cpp
 
 pkgconfiglibdir = ${libdir}/pkgconfig
 pkgconfiglib_DATA = phosphor-logging.pc
diff --git a/tools/elog-gen.py b/tools/elog-gen.py
index fe4807e..3cf396c 100755
--- a/tools/elog-gen.py
+++ b/tools/elog-gen.py
@@ -56,9 +56,14 @@
     return True
 
 
-def get_error_yaml_files(i_yaml_dir):
+def get_error_yaml_files(i_yaml_dir, i_test_dir):
     yaml_files = []
-    for root, dirs, files in os.walk(i_yaml_dir):
+    if i_yaml_dir != "None":
+        for root, dirs, files in os.walk(i_yaml_dir):
+            for files in filter(lambda file:
+                                file.endswith('.errors.yaml'), files):
+                yaml_files.append(os.path.join(root, files))
+    for root, dirs, files in os.walk(i_test_dir):
         for files in filter(lambda file: file.endswith('.errors.yaml'), files):
             yaml_files.append(os.path.join(root, files))
     return yaml_files
@@ -86,14 +91,15 @@
     return typeMap[i_type]
 
 
-def gen_elog_hpp(i_yaml_dir, i_output_hpp,
+def gen_elog_hpp(i_yaml_dir, i_test_dir, i_output_hpp,
                  i_template_dir, i_elog_mako, i_error_namespace):
     r"""
     Read  yaml file(s) under input yaml dir, grab the relevant data and call
     the mako template to generate the output header file.
 
     Description of arguments:
-    i_yaml_dir                  directory containing error yaml files
+    i_yaml_dir                  directory containing base error yaml files
+    i_test_dir                  directory containing test error yaml files
     i_output_hpp                name of the to be generated output hpp
     i_template_dir              directory containing error mako templates
     i_elog_mako                 error mako template to render
@@ -107,7 +113,7 @@
     meta_data = dict()  # The meta data info (type, format)
     parents = dict()
 
-    error_yamls = get_error_yaml_files(i_yaml_dir)
+    error_yamls = get_error_yaml_files(i_yaml_dir, i_test_dir)
 
     for error_yaml in error_yamls:
         # Verify the error yaml file
@@ -223,9 +229,13 @@
                       help="output hpp to generate, elog-gen.hpp is default")
 
     parser.add_option("-y", "--yamldir", dest="yamldir",
-                      default="./example/xyz/openbmc_project/Example",
+                      default="None",
                       help="Base directory of yaml files to process")
 
+    parser.add_option("-u", "--testdir", dest="testdir",
+                      default="./tools/example/",
+                      help="Unit test directory of yaml files to process")
+
     parser.add_option("-t", "--templatedir", dest="templatedir",
                       default="phosphor-logging/templates/",
                       help="Base directory of files to process")
@@ -237,6 +247,7 @@
     (options, args) = parser.parse_args(i_args)
 
     gen_elog_hpp(options.yamldir,
+                 options.testdir,
                  options.output_hpp,
                  options.templatedir,
                  options.elog_mako,