regulators: Add check_number_of_elements_in_masks function.

Add check_number_of_elements_in_masks function to the config file
validation tool.
It checks if the number of bit masks in the 'masks' property matches
the number of byte values in the 'values' property.

Signed-off-by: Bob King <Bob_King@wistron.com>
Change-Id: Ie33d78867b0c3ba508ff3693fe5969596d70e95a
diff --git a/phosphor-regulators/tools/validate-regulators-config.py b/phosphor-regulators/tools/validate-regulators-config.py
index a9ebb0d..bca989d 100755
--- a/phosphor-regulators/tools/validate-regulators-config.py
+++ b/phosphor-regulators/tools/validate-regulators-config.py
@@ -58,6 +58,34 @@
             device_ids.append(device['id'])
     return device_ids
 
+def check_number_of_elements_in_masks(config_json):
+    r"""
+    Check if the number of bit masks in the 'masks' property matches the number
+    of byte values in the 'values' property.
+    config_json: Configuration file JSON
+    """
+
+    i2c_write_bytes = get_values(config_json, 'i2c_write_bytes')
+    i2c_compare_bytes = get_values(config_json, 'i2c_compare_bytes')
+
+    for object in i2c_write_bytes:
+        if 'masks' in object:
+            if len(object.get('masks', [])) != len(object.get('values', [])):
+                sys.stderr.write("Error: Invalid i2c_write_bytes action.\n"+\
+                "The masks array must have the same size as the values array. "+\
+                "masks: "+str(object.get('masks', []))+\
+                ", values: "+str(object.get('values', []))+'.\n')
+                handle_validation_error()
+
+    for object in i2c_compare_bytes:
+        if 'masks' in object:
+            if len(object.get('masks', [])) != len(object.get('values', [])):
+                sys.stderr.write("Error: Invalid i2c_compare_bytes action.\n"+\
+                "The masks array must have the same size as the values array. "+\
+                "masks: "+str(object.get('masks', []))+\
+                ", values: "+str(object.get('values', []))+'.\n')
+                handle_validation_error()
+
 def check_rule_id_exists(config_json):
     r"""
     Check if a rule_id property specifies a rule ID that does not exist.
@@ -286,3 +314,5 @@
     check_set_device_value_exists(config_json)
 
     check_rule_id_exists(config_json)
+
+    check_number_of_elements_in_masks(config_json)