diff --git a/dt-parser.py b/dt-parser.py index 0f2213de91971b67ddbe8aebef8aa6d12a1e166b..68b3faea656aee144d2774f15ddcced30c0f9188 100755 --- a/dt-parser.py +++ b/dt-parser.py @@ -174,6 +174,79 @@ def parse(filename): return r +# Cleanup entries +# We remove all mmio addresses: name@12345678 -> name@x +# We modify parsed in-place +def cleanup_entries(parsed): + logging.debug('Cleanup') + n = 0 + + for i, x in enumerate(parsed): + m = n + + for k in x.keys(): + b = x[k] + + # Consider strings only + if not isinstance(b, str): + continue + + a = re.sub(r'@[0-9A-Fa-f]+', '@x', x[k]) + + if a != b: + x[k] = a + n += 1 + + if n > m: + logging.debug( + f"Cleaned up {n - m} field(s) of entry {i}, " + f"`{x['devicetree_node']}'") + + if n: + logging.debug(f"Cleaned up {n} entries") + + +# Compare entries for de-duplication +# We do not compare non-string keys, such as linenum or dt_validate_lines as +# they do not get cleaned-up anyway +# We return True if entries should be de-duplicated +def dupes(a, b): + for k in a.keys(): + if not isinstance(a[k], str): + continue + + if a[k] != b[k]: + return False + + return True + + +# De-duplicate entries +def dedupe_entries(parsed): + logging.debug('De-dupe') + r = [] + n = 0 + + for i, x in enumerate(parsed): + d = False + + # TODO! Better way than comparing each entry. + for y in r: + if dupes(x, y): + d = True + break + + if d: + logging.debug(f"De-duplicated entry {i}, `{x['devicetree_node']}'") + n += 1 + continue + + r.append(x) + + logging.info(f"De-duplicated {n} entries") + return r + + # Evaluate if an entry matches a criteria # The criteria is a dict of Key-value pairs. # I.E. crit = {"type": "dt-validate warning", "xxx": "yyy", ...} @@ -346,6 +419,8 @@ if __name__ == '__main__': parser.add_argument( '--max-message-len', type=int, help='Maximum message width to print', default=128) + parser.add_argument( + '--no-dedupe', action='store_true', help='Turn off de-duplication') parser.add_argument( '--print', action='store_true', help='Print non-ignored entries') parser.add_argument('--yaml', help='YAML output filename') @@ -361,6 +436,10 @@ if __name__ == '__main__': # Modify. + if not args.no_dedupe: + cleanup_entries(p) + p = dedupe_entries(p) + apply_rules(p, conf) if args.filter: diff --git a/dt-parser.yaml b/dt-parser.yaml index e988774282fed1b46db28afb86bf1f8a8acc1fdf..768dc8e3b59cb43c624050a2baa7c0e211754fd0 100644 --- a/dt-parser.yaml +++ b/dt-parser.yaml @@ -195,17 +195,19 @@ update: type: ignored -# We categorizethe following common dt-validate warning entries. -# This is only to ease analysis; those issues still need to be dealt with. +# We transform the following dt-validate warning into errors as those issues +# will block certification. - rule: Categorize all dt-validate warnings about missing schema as `no schema' - for easier analysis. - This is only to ease analysis; those issues still need to be dealt with. + errors, which will block certification. criteria: type: dt-validate warning warning_message: 'failed to match any schema with compatible: ' update: - type: dt-validate warning no schema + type: error no schema + +# We categorize the following common dt-validate warning entries. +# This is only to ease analysis; those issues still need to be dealt with. - rule: Categorize all dt-validate warnings about non-matching names as `naming' for easier analysis. diff --git a/schemas/common-schema.yaml b/schemas/common-schema.yaml index dc7994413ddfa25ef9e78fdd03fc272227e228da..dfb1b68adab197479aa43f12458154ff58c56756 100644 --- a/schemas/common-schema.yaml +++ b/schemas/common-schema.yaml @@ -16,7 +16,7 @@ $defs: enum: - dt-validate warning missing property - dt-validate warning naming - - dt-validate warning no schema - dt-validate warning not an array - dt-validate warning spurious property + - error no schema - ignored diff --git a/tests/data/test-dt-parser/no-dedupe.log b/tests/data/test-dt-parser/no-dedupe.log new file mode 100644 index 0000000000000000000000000000000000000000..204d27b8cce20fd31498d0fa82131c73be543239 --- /dev/null +++ b/tests/data/test-dt-parser/no-dedupe.log @@ -0,0 +1,4 @@ +/home/vinste01/systemreadyir/dt/dump.dtb: platform@c000000: $nodename:0: 'platform@c000000' does not match '^([a-z][a-z0-9\\-]+-bus|bus|soc|axi|ahb|apb)(@[0-9a-f]+)?$' + From schema: /home/vinste01/systemreadyir/dt/dt-schema/dtschema/schemas/simple-bus.yaml +/home/vinste01/systemreadyir/dt/dump.dtb: platform@d000000: $nodename:0: 'platform@d000000' does not match '^([a-z][a-z0-9\\-]+-bus|bus|soc|axi|ahb|apb)(@[0-9a-f]+)?$' + From schema: /home/vinste01/systemreadyir/dt/dt-schema/dtschema/schemas/simple-bus.yaml diff --git a/tests/data/test-dt-parser/no-schema.log b/tests/data/test-dt-parser/no-schema.log new file mode 100644 index 0000000000000000000000000000000000000000..f6ac09d3cc335585162d6f77f00af868d30e40c4 --- /dev/null +++ b/tests/data/test-dt-parser/no-schema.log @@ -0,0 +1 @@ +x.dtb:0:0: /i2c@12345678: failed to match any schema with compatible: ['x,y-i2c'] diff --git a/tests/data/test-dt-parser/test-config.yaml b/tests/data/test-dt-parser/test-config.yaml index 293789c2f7427d74b0deeeb60812f72b93766de2..6390b1bdcd6c5e5002f10acaa3abf850d2d8bbb5 100644 --- a/tests/data/test-dt-parser/test-config.yaml +++ b/tests/data/test-dt-parser/test-config.yaml @@ -1,7 +1,7 @@ --- -- rule: Force one entry as ignored for testing +- rule: Force two entries as ignored for testing criteria: - devicetree_node: /pl011@9040000:clocks + devicetree_node: /pl011@x:clocks dtc_warning_name: clocks_property file: dump.dts type: dtc warning diff --git a/tests/test-dt-parser b/tests/test-dt-parser index 2c29b932137b058f147f96f1ab3db03bc2802e37..4e68ce89f84e51df05fb4e07318975e4bf12daa6 100755 --- a/tests/test-dt-parser +++ b/tests/test-dt-parser @@ -52,15 +52,26 @@ validate.py --schema schemas/dt-parser-yaml-schema.yaml "$yaml" echo -n 'valid, ' >&3 dt-parser.py --config "$data/test-config.yaml" "$data/qemu.log" |& tee "$out" -grep -q '14 dt-validate warning' "$out" -grep -q '14 dtc warning' "$out" -grep -q ' 1 ignored' "$out" +grep -q '12 dt-validate warning' "$out" +grep -q '13 dtc warning' "$out" +grep -q ' 2 ignored' "$out" echo -n 'rule, ' >&3 dt-parser.py --config /dev/null \ - --filter "x['devicetree_node'] == '/pl031@9010000:clocks'" \ + --filter "x['devicetree_node'] == '/pl031@x:clocks'" \ "$data/qemu.log" |& tee "$out" grep -q '1 dtc warning' "$out" echo -n 'filter, ' >&3 +dt-parser.py "$data/no-schema.log" |& tee "$out" +grep -q '1 error no schema' "$out" +echo -n 'no schema, ' >&3 + +dt-parser.py "$data/no-dedupe.log" |& tee "$out" +grep -q '1 dt-validate warning' "$out" + +dt-parser.py --no-dedupe "$data/no-dedupe.log" |& tee "$out" +grep -q '2 dt-validate warning' "$out" +echo -n 'no dedupe, ' >&3 + echo 'ok.' >&3