Skip to content

tools/kernel-pr-check: build an included .c through the file that includes it - #851

Merged
derekross merged 2 commits into
derekross:mainfrom
Somnius:kpc-included-c-1116
Nov 18, 2026
Merged

derekross merged 2 commits into
derekross:mainfrom
Somnius:kpc-included-c-1116

Conversation

@Somnius

@Somnius Somnius commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

kernel-pr-check --build builds each touched .c on its own, so a KUnit test that its driver #includes at the end can't pass. That's what failed on derekross/linux-omarchy-mobile#265: max77759_charger_test.c uses the driver's static functions, so built alone it stops at "undeclared function guard_classify". Upstream does the same thing in a few places, e.g. drm_panic.c with tests/drm_panic_test.c, firewire's node-tree-test.c and x86's cpa-test.c.

Now a touched .c is still built alone first, exactly as before. Only if that fails does it look for the .c files in the same or the parent directory that include it (the include path is resolved, not just the name matched) and build the first of them that builds. It prints a line when it does, and a second one when the include isn't compiled under the current config, so a test behind an off KUNIT option is reported as not build-tested instead of passing quietly.

Tested: tests/kernel-pr-check passes (22 ok). Run by hand on #265's branch with --build --merge in the build container, every check is ok and it says:

# drivers/power/supply/max77759_charger_test.c does not build alone; it is included by drivers/power/supply/max77759_charger.c, which builds
# drivers/power/supply/max77759_charger_test.c is not compiled by drivers/power/supply/max77759_charger.c under this config, so it is not build-tested here
ok - W=1 builds of 2 touched C files

The KUnit tests themselves I run under UML (10 of 10 pass on #265), since omamobile.config has no KUNIT. There's no case for this in the test script because the builds there are run by hand, as its header says.

…ludes it

A KUnit test that its driver #includes at the end (drm_panic.c and
tests/drm_panic_test.c upstream) can't build on its own, so the W=1 step
failed it. A touched .c is still built alone first; only when that fails
is a .c in the same or the parent directory that includes it built
instead, and the output says so, including when the include isn't
compiled under the current config.
@derekross

Copy link
Copy Markdown
Owner

Thanks, Lef: this is a real gap, and upstream does use the pattern, so the gate has to cope with it. I ran main's tool and yours side by side in the build container on kernel #265, and I get exactly what you describe: main fails max77759_charger_test.c, yours prints the two lines and passes.

The part I'd like changed is what happens after the second line. On #265 the include is under #if IS_ENABLED(CONFIG_CHARGER_MAX77759_KUNIT_TEST) and our config has no KUNIT, so none of the test file was compiled, and the result still reads ok - W=1 builds of 2 touched C files. To see how far that goes I made a throwaway commit with a zz_decoy.c that can't compile (int x = undeclared_thing;) and a zz_inc.c that includes it inside #if 0: main fails it, and with this change it passes with the same two lines. Nobody would do that on purpose, but the gate's summary line is what gets quoted, so it shouldn't count a file it didn't compile.

Could you:

  1. Keep a file that wasn't compiled out of the "ok" count and say so in the result line itself, in the skip form the tool already uses, so a grep for SKIP finds it. Something like ok - W=1 builds of 1 touched C file; 1 not compiled under this config (max77759_charger_test.c, included by max77759_charger.c) # SKIP.
  2. Only take the fallback when the file isn't an object of its own: if the directory's Makefile names <file>.o, it is meant to build alone and should fail as before. I checked the three upstream examples you cite and device-bluejay: descriptor and notes from Google's GPL bluejay device tree #265: none of the included tests appears in a Makefile, so the rule separates the two cases.
  3. Add the cases to tests/kernel-pr-check. Its --build section already has a stand-in make for the device-tree comparison (from "# --build" on); a stand-in that fails one object and builds the includer, once with the file in the includer's .cmd and once without, covers both branches.

Two smaller things, as you like: when the build goes through the includer, the W=1 warnings line is printed under the test file's name though the warnings are the includer's, so naming the includer there would help; and the comment says "the same or the parent directory" while the search covers everything under the parent.

Once this is in I'll re-run #265's check. Its test file will then show as not compiled here, which is right: your UML run is the evidence for it, so please keep that result in #265's description.

A .c reached through its includer counted as built even when the include
sits under a config that is off, so nothing of it was compiled. It now
counts only when the includer's .cmd lists it (paths with ../ resolved);
otherwise the result is a SKIP that names it and its includer.

The includer is tried only when no Makefile or Kbuild from the file's
directory up to the searched parent names the file's .o. The W=1
warnings line names the includer, a touched includer's warnings aren't
listed twice, and the comment matches the search (anywhere under the
parent directory). tests/kernel-pr-check covers each case with a
stand-in compiler.
@Somnius

Somnius commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @derekross, good catch with the decoy, that's exactly the hole. Fixed in 4062ae7:

  1. A file reached only through its includer counts as built only when the includer's .cmd lists it (paths with ../ resolved). If it doesn't, it stays out of the ok count and the line uses the skip form, e.g. ok - W=1 builds of 1 touched C file; 1 not compiled under this config (max77759_charger_test.c, included by max77759_charger.c) # SKIP.
  2. The includer fallback is only taken when no Makefile or Kbuild from the file's directory up to the searched parent names its .o. If one does, a failed build fails as before.
  3. tests/kernel-pr-check has the cases with a stand-in compiler: listed in the .cmd, not listed, named by the own Makefile, by the parent's Makefile and by a Kbuild, a ../ path in the .cmd, and a touched includer whose warnings now show once. 28 ok, and I checked the new cases fail with the old tool.

The two small ones are in too: the warnings line names the includer, and the comment says the search covers anywhere under the parent directory.

I haven't run it against #265 in the build container yet, so its result there is yours to see. I'll keep the UML run in #265's description.

@derekross

Copy link
Copy Markdown
Owner

Thanks, Lef. 4062ae7 does all three, and the two small ones as well. tests/kernel-pr-check passes on your branch merged with today's main (28), and the new cases bite: with cmd_lists forced true the "not compiled" case fails on its SKIP line, with own_object forced false the Makefile case fails, and main's tool fails your first new case.

You said you hadn't run it in the build container, so I did, your tool beside main's:

  • device-bluejay: descriptor and notes from Google's GPL bluejay device tree #265 at its current head: main still fails max77759_charger_test.c; yours prints ok - W=1 builds of 1 touched C file; 1 not compiled under this config (max77759_charger_test.c, included by max77759_charger.c) # SKIP and every other line is ok.
  • My decoy from last time (a file that can't compile, included inside #if 0): no longer in the ok count; it is the SKIP in ok - W=1 builds of 3 touched C files; 1 not compiled under this config (zz_a_decoy.c, included by zz_a_inc.c) # SKIP.
  • A file that really is compiled through its includer (it uses a static its includer defines, so it can't build alone): counted, with the real kbuild's .cmd, which the stand-in compiler in the tests can't show. That was the case I most wanted to see with a real build.
  • The decoy with obj-y += zz_a_decoy.o added to the Makefile: not ok, as on main.

CI is green. Merging, and then I'll re-run #265's check; it should come back green with that SKIP line, and your UML run stays the evidence for the test itself.

@derekross
derekross merged commit d0028d0 into derekross:main Nov 18, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants