Skip to content

Commit

Permalink
dt-validate: Add an 'only matching compatible' schema validation mode
Browse files Browse the repository at this point in the history
Add an 'only matching compatible' schema validation mode which only
applies the schema matching nodes' compatible string. Currently, only
the most specific (i.e. 1st) compatible string in the instance is used,
but that may change in the future. This mode tends to be 4x faster (on
top of the recent 6-7x speed up) while still giving 80-90% of the
warnings. Mostly the core schemas are skipped.

Signed-off-by: Rob Herring <[email protected]>
  • Loading branch information
robherring committed Apr 10, 2024
1 parent dc5e8d9 commit 64b72b0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion dtschema/dtb_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
verbose = False
show_unmatched = False
match_schema_file = None
compatible_match = False


class schema_group():
Expand All @@ -30,7 +31,8 @@ def check_node(self, tree, node, disabled, nodename, fullname, filename):
node['$nodename'] = [nodename]

try:
for error in self.validator.iter_errors(node, filter=match_schema_file):
for error in self.validator.iter_errors(node, filter=match_schema_file,
compatible_match=compatible_match):

# Disabled nodes might not have all the required
# properties filled in, such as a regulator or a
Expand Down Expand Up @@ -93,6 +95,7 @@ def main():
global verbose
global show_unmatched
global match_schema_file
global compatible_match

ap = argparse.ArgumentParser(fromfile_prefix_chars='@',
epilog='Arguments can also be passed in a file prefixed with a "@" character.')
Expand All @@ -101,6 +104,8 @@ def main():
ap.add_argument('-s', '--schema', help="preparsed schema file or path to schema files")
ap.add_argument('-p', '--preparse', help="preparsed schema file (deprecated, use '-s')")
ap.add_argument('-l', '--limit', help="limit validation to schemas with $id matching LIMIT substring")
ap.add_argument('-c', '--compatible-match', action="store_true",
help="limit validation to schema matching nodes' most specific compatible string")
ap.add_argument('-m', '--show-unmatched',
help="Print out node 'compatible' strings which don't match any schema.",
action="store_true")
Expand All @@ -114,6 +119,7 @@ def main():
verbose = args.verbose
show_unmatched = args.show_unmatched
match_schema_file = args.limit
compatible_match = args.compatible_match

# Maintain prior behaviour which accepted file paths by stripping the file path
if args.url_path and args.limit:
Expand Down
6 changes: 5 additions & 1 deletion dtschema/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def annotate_error(self, id, error):
error.linecol = -1, -1
error.note = None

def iter_errors(self, instance, filter=None):
def iter_errors(self, instance, filter=None, compatible_match=False):
if 'compatible' in instance:
inst_compat = instance['compatible'][0]
if inst_compat in self.compat_map:
Expand All @@ -421,6 +421,10 @@ def iter_errors(self, instance, filter=None):
).iter_errors(instance):
self.annotate_error(schema['$id'], error)
yield error

if compatible_match:
return

for schema_id in self.always_schemas:
if filter and filter not in schema_id:
continue
Expand Down

0 comments on commit 64b72b0

Please sign in to comment.