diff --git a/.github/workflows/dt-checks.yml b/.github/workflows/dt-checks.yml index b76ea1c58b3e1..23eba7e3c8a41 100644 --- a/.github/workflows/dt-checks.yml +++ b/.github/workflows/dt-checks.yml @@ -64,6 +64,9 @@ jobs: - name: GPU binding compatibility and resource contracts run: python3 scripts/dtc/apple-agx-binding-test.py + - name: Documented chosen warning filter + run: python3 scripts/dtc/apple-dt-check-test.py + - name: CHECK_DTBS and dt_binding_check, base vs head id: dt env: diff --git a/scripts/dtc/apple-dt-check-test.py b/scripts/dtc/apple-dt-check-test.py new file mode 100644 index 0000000000000..68cc016e477f9 --- /dev/null +++ b/scripts/dtc/apple-dt-check-test.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only +"""Exercise the production /chosen warning filter without building device trees.""" + +import os +from pathlib import Path +import subprocess +import sys +import tempfile +import unittest + + +CHECKER = Path(__file__).with_name("apple-dt-check.sh") +SCHEMA = "http://devicetree.org/schemas/chosen.yaml" +DOCUMENTED = "linux-enablement-mac,dapf-halted-handoff" +UNKNOWN = "linux-enablement-mac,bogus" + + +class ChosenWarningFilterTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + source = CHECKER.read_text() + start = source.index("filter_documented_chosen() {") + end = source.index("\nextract_warnings() {", start) + cls.filter_script = source[start:end] + '\nfilter_documented_chosen "$1"\n' + + def setUp(self): + self.work = tempfile.TemporaryDirectory(prefix="chosen-filter-test-") + self.addCleanup(self.work.cleanup) + self.bindings = Path(self.work.name) + (self.bindings / "halted-handoff.yaml").write_text( + "properties:\n" + f" {DOCUMENTED}:\n" + " $ref: /schemas/types.yaml#/definitions/string-array\n" + ) + + def filter(self, warning, bindings=None): + env = os.environ.copy() + env["PATH"] = str(Path(sys.executable).parent) + os.pathsep + env.get("PATH", "") + result = subprocess.run( + ["bash", "-c", self.filter_script, str(CHECKER), str(bindings or self.bindings)], + input=warning, text=True, capture_output=True, env=env, check=True, + ) + return result.stdout + + def warning(self, properties, schema, inline=False): + names = ", ".join(f"'{prop}'" for prop in properties) + verb = "does" if len(properties) == 1 else "do" + line = ( + f"apple/t8132-j715.dtb: chosen: {names} {verb} not match any of " + "the regexes: '^framebuffer', '^pinctrl-[0-9]+$'" + ) + if schema is None: + return line + "\n" + if inline: + return line + f" from schema $id: {schema}\n" + return line + f"\n\tfrom schema $id: {schema}\n" + + def test_documented_properties_with_or_without_empty_fragment(self): + for suffix in ("", "#"): + for inline in (False, True): + with self.subTest(suffix=suffix, inline=inline): + warning = self.warning([DOCUMENTED], SCHEMA + suffix, inline) + self.assertEqual(self.filter(warning), "") + + def test_j715_warning_uses_the_real_chosen_bindings(self): + properties = [ + DOCUMENTED, + "linux-enablement-mac,dapf-handoff", + "linux-enablement-mac,dapf-power-on-handoff", + "linux-enablement-mac,disk-boot", + ] + bindings = CHECKER.parents[2] / "Documentation/devicetree/bindings/chosen" + self.assertEqual(self.filter(self.warning(properties, SCHEMA), bindings), "") + + def test_undocumented_properties_are_still_reported(self): + for suffix in ("", "#"): + for inline in (False, True): + with self.subTest(suffix=suffix, inline=inline): + warning = self.warning([DOCUMENTED, UNKNOWN], SCHEMA + suffix, inline) + expected = self.warning([UNKNOWN], SCHEMA + suffix, inline) + self.assertEqual(self.filter(warning), expected) + + def test_other_schemas_and_nonempty_fragments_are_preserved(self): + for schema in (None, SCHEMA + "#/$defs/other", SCHEMA + "##", + "http://devicetree.org/schemas/other.yaml"): + with self.subTest(schema=schema): + warning = self.warning([DOCUMENTED], schema) + self.assertEqual(self.filter(warning), warning) + + def test_other_nodes_and_type_errors_are_preserved(self): + warning = ( + "apple/t8132-j715.dtb: aliases: 'bogus' does not match any of the regexes: 'serial'\n" + f"\tfrom schema $id: {SCHEMA}\n" + f"apple/t8132-j715.dtb: chosen: {DOCUMENTED}: 42 is not of type 'string'\n" + f"\tfrom schema $id: {SCHEMA}\n" + ) + self.assertEqual(self.filter(warning), warning) + + +if __name__ == "__main__": + unittest.main() diff --git a/scripts/dtc/apple-dt-check.sh b/scripts/dtc/apple-dt-check.sh index 38e8badcb9e46..1262f2be1e5e2 100755 --- a/scripts/dtc/apple-dt-check.sh +++ b/scripts/dtc/apple-dt-check.sh @@ -96,7 +96,7 @@ while i < n: j += 1 i = j - if schema_id != CHOSEN_SCHEMA_ID: + if schema_id is None or schema_id.removesuffix("#") != CHOSEN_SCHEMA_ID.removesuffix("#"): sys.stdout.write(raw) for c in cont: sys.stdout.write(c)