diff --git a/Dockerfile.gcc b/Dockerfile.gcc index d596dc1d99a5..8888e4c01fdd 100644 --- a/Dockerfile.gcc +++ b/Dockerfile.gcc @@ -193,6 +193,7 @@ RUN python3 eve/check-config.py \ --tree-root . \ --config /kernel-out/.config \ --flavour "${KERNEL_FLAVOUR}" \ + --base-defconfig "arch/x86/configs/${BASE_DEFCONFIG}" \ $(for f in ${KERNEL_FRAGMENTS}; do echo --fragment "$f"; done) \ --core-defconfig arch/x86/configs/eve-core_defconfig \ --advisory-parity diff --git a/eve/check-config.py b/eve/check-config.py index 4eb0951b861c..8d950684cb15 100644 --- a/eve/check-config.py +++ b/eve/check-config.py @@ -124,6 +124,32 @@ def check_fragment_disjoint(fragments): return problems +def check_symbols_declared(sources, symbol_map): + """Every symbol the base defconfig or a fragment names must be declared. + + olddefconfig silently drops an assignment to a symbol that no Kconfig in + the tree declares, so an entry whose symbol was removed or renamed + upstream quietly stops doing anything. check_fragment_values notices a + fragment's '=y' or '=m' request for such a symbol only as a value that + did not hold; for a fragment's '# CONFIG_X is not set', and for every + line of the base defconfig, nothing notices at all. CRYPTO_CRC32_PCLMUL, + CRYPTO_VMAC and X86_5LEVEL, recorded in eve/drift/, are entries of the + 6.12 eve-core_defconfig that 6.18 no longer declares. + + `sources` is an ordered list of (path, {SYMBOL: value}) pairs: the base + defconfig, then each fragment in the order the flavour applies them. + """ + problems = [] + for path, values in sources: + for symbol in sorted(values): + if symbol not in symbol_map: + problems.append( + "CONFIG_%s: %s sets %s, but no Kconfig in this tree declares it" + % (symbol, path, values[symbol]) + ) + return problems + + def check_fragment_values(config, fragments, exceptions): """Every symbol's EFFECTIVE request must hold that value after olddefconfig. @@ -295,11 +321,14 @@ def report_donor_drift(config, donor, symbol_map): def run_checks(config, symbol_map, fragments, exceptions, boot_symbols, - core_config, divergences, deny, advisory_parity): + core_config, divergences, deny, advisory_parity, + base_defconfig=None): """Run every check. Returns (exit_code, report_text). `fragments` is an ordered list of (path, {SYMBOL: value}) pairs, in the order the flavour applies them (as merge_config.sh would apply them). + `base_defconfig` is the (path, {SYMBOL: value}) pair of the defconfig + the flavour starts from, or None to check the fragments alone. """ lines = [] fatal = 0 @@ -316,6 +345,9 @@ def section(title, problems, is_fatal): if is_fatal: fatal += len(problems) + sources = ([base_defconfig] if base_defconfig else []) + list(fragments) + section("defconfig and fragment symbols declared in this tree", + check_symbols_declared(sources, symbol_map), True) section("fragment layering (which layer wins an overlap)", check_fragment_disjoint(fragments), False) section("fragment effective values held after olddefconfig", @@ -341,6 +373,7 @@ def main(argv=None): parser.add_argument("--flavour", required=True, choices=["core", "rt", "hwe", "ai"]) parser.add_argument("--fragment", action="append", default=[]) + parser.add_argument("--base-defconfig") parser.add_argument("--core-defconfig", required=True) parser.add_argument("--advisory-parity", action="store_true") args = parser.parse_args(argv) @@ -351,6 +384,9 @@ def main(argv=None): # Ordered list of (path, {SYMBOL: value}) pairs, in the order the # flavour applies them - order matters because fragments layer. fragments = [(path, parse_fragment(path)) for path in args.fragment] + base_defconfig = None + if args.base_defconfig: + base_defconfig = (args.base_defconfig, parse_config(args.base_defconfig)) core_config = parse_config(args.core_defconfig) deny = args.flavour in DENY_FLAVOURS @@ -373,6 +409,7 @@ def main(argv=None): os.path.join(policy_dir, "behavioural-divergence")), deny=deny, advisory_parity=args.advisory_parity, + base_defconfig=base_defconfig, ) print("=== eve config policy: flavour=%s ===" % args.flavour) print(report) diff --git a/eve/tests/test_check_config.py b/eve/tests/test_check_config.py index 25707fa2822c..eb00624b458a 100644 --- a/eve/tests/test_check_config.py +++ b/eve/tests/test_check_config.py @@ -150,6 +150,54 @@ def test_later_fragment_reported_as_winner(self): self.assertIn("rt.fragment wins", problems[0]) +class TestSymbolsDeclared(unittest.TestCase): + SYMMAP = { + "SOUND": "sound", + "MEGARAID_SAS": "drivers/scsi/megaraid", + "PANIC_ON_OOPS": "kernel", + } + + def test_declared_symbols_pass(self): + sources = [ + ("eve-hwe_defconfig", {"PANIC_ON_OOPS": "y"}), + ("deny.fragment", {"SOUND": "n"}), + ("boot.fragment", {"MEGARAID_SAS": "y"}), + ] + self.assertEqual( + check_config.check_symbols_declared(sources, self.SYMMAP), [] + ) + + def test_undeclared_not_set_request_is_reported(self): + # '# CONFIG_X is not set' for a symbol the tree no longer declares + # holds trivially, so check_fragment_values cannot see it. + sources = [("deny.fragment", {"SOUND": "n", "GONE_UPSTREAM": "n"})] + problems = check_config.check_symbols_declared(sources, self.SYMMAP) + self.assertEqual(len(problems), 1) + self.assertIn("CONFIG_GONE_UPSTREAM", problems[0]) + self.assertIn("deny.fragment", problems[0]) + + def test_undeclared_defconfig_symbol_is_reported(self): + # e.g. CRYPTO_VMAC, set by the 6.12 eve-core_defconfig and no + # longer declared in 6.18. + sources = [("eve-core_defconfig", {"PANIC_ON_OOPS": "y", "CRYPTO_VMAC": "y"})] + problems = check_config.check_symbols_declared(sources, self.SYMMAP) + self.assertEqual(len(problems), 1) + self.assertIn("CONFIG_CRYPTO_VMAC", problems[0]) + self.assertIn("eve-core_defconfig", problems[0]) + self.assertIn("sets y", problems[0]) + + def test_every_source_naming_the_symbol_is_reported(self): + # Each line is a separate stale entry that has to be removed. + sources = [ + ("eve-hwe_defconfig", {"GONE_UPSTREAM": "m"}), + ("common.fragment", {"GONE_UPSTREAM": "y"}), + ] + problems = check_config.check_symbols_declared(sources, self.SYMMAP) + self.assertEqual(len(problems), 2) + self.assertIn("eve-hwe_defconfig", problems[0]) + self.assertIn("common.fragment", problems[1]) + + class TestFragmentValues(unittest.TestCase): def test_all_requested_values_present(self): cfg = {"SOUND": "n", "MEGARAID_SAS": "y"} @@ -435,6 +483,40 @@ def test_deny_disabled_for_core_flavour(self): ) self.assertEqual(rc, 0) + def test_undeclared_symbol_fails_the_build(self): + rc, out = check_config.run_checks( + config={"SOUND": "n", "PANIC_ON_OOPS": "y"}, + symbol_map=self.SYMMAP, + fragments=[("deny.fragment", {"SOUND": "n", "GONE_UPSTREAM": "n"})], + exceptions=set(), + boot_symbols=set(), + core_config={}, + divergences=set(), + deny=False, + advisory_parity=False, + ) + self.assertEqual(rc, 1) + self.assertIn("FAIL defconfig and fragment symbols declared", out) + self.assertIn("GONE_UPSTREAM", out) + + def test_base_defconfig_symbols_are_checked(self): + rc, out = check_config.run_checks( + config={"PANIC_ON_OOPS": "y"}, + symbol_map=self.SYMMAP, + fragments=[], + exceptions=set(), + boot_symbols=set(), + core_config={}, + divergences=set(), + deny=False, + advisory_parity=False, + base_defconfig=("eve-core_defconfig", + {"PANIC_ON_OOPS": "y", "X86_5LEVEL": "n"}), + ) + self.assertEqual(rc, 1) + self.assertIn("X86_5LEVEL", out) + self.assertIn("eve-core_defconfig", out) + def test_fragment_overlap_is_advisory_not_fatal(self): # Overlapping fragments (layering) must not affect the exit code, # even though the values genuinely differ across layers - only @@ -459,6 +541,38 @@ def test_fragment_overlap_is_advisory_not_fatal(self): self.assertIn("SOUND", out) +class TestMain(unittest.TestCase): + def _tree(self, d, defconfig_text): + write(os.path.join(d, "kernel", "Kconfig"), + "config PANIC_ON_OOPS\n\tbool\n") + write(os.path.join(d, "eve-core_defconfig"), defconfig_text) + write(os.path.join(d, ".config"), "CONFIG_PANIC_ON_OOPS=y\n") + return [ + "--tree-root", d, + "--config", os.path.join(d, ".config"), + "--flavour", "core", + "--core-defconfig", os.path.join(d, "eve-core_defconfig"), + ] + + def test_base_defconfig_undeclared_symbol_fails(self): + with tempfile.TemporaryDirectory() as d: + args = self._tree(d, "CONFIG_PANIC_ON_OOPS=y\nCONFIG_CRYPTO_VMAC=y\n") + with mock.patch("sys.stdout"): + rc = check_config.main( + args + ["--base-defconfig", + os.path.join(d, "eve-core_defconfig")]) + self.assertEqual(rc, 1) + + def test_base_defconfig_declared_symbols_pass(self): + with tempfile.TemporaryDirectory() as d: + args = self._tree(d, "CONFIG_PANIC_ON_OOPS=y\n") + with mock.patch("sys.stdout"): + rc = check_config.main( + args + ["--base-defconfig", + os.path.join(d, "eve-core_defconfig")]) + self.assertEqual(rc, 0) + + class TestDonorDrift(unittest.TestCase): SYMMAP = { "E1000E": "drivers/net/ethernet/intel/e1000e",