Skip to content

soc: apple: tunable: add KUnit tests - #2916

Merged
RyanTheTide merged 1 commit into
integration/aurorafrom
kunit/apple-tunable
Nov 23, 2026
Merged

RyanTheTide merged 1 commit into
integration/aurorafrom
kunit/apple-tunable

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem. Apple hardware tunables are (offset, mask, value) triplets from devicetree that get written into a device's MMIO range. The parser and the apply step had no test.

Change. A new apple-tunable suite (drivers/soc/apple/tunable-test.c, a module of its own using the exported API) parses properties of a device node built by the test and applies the result to a buffer of kernel memory:

  • triplet decoding; refusal of a missing, empty or badly sized property;
  • refusal of a resource that is too small, of unaligned offsets, of offsets past the end of the resource, and the resource start handling;
  • the mask/value arithmetic, the order of the writes, a value with bits outside its mask, and a NULL tunable.

Plus a standalone drivers/soc/apple/tunable.kunitconfig. Tests only, no functional change.

Testing.

  • kunit.py run --arch=arm64 (QEMU, gcc): 12/12, standalone kunitconfig 12/12, and again with all six of this series' branches merged on integration/aurora 322eadc.
  • Negative controls: offset bound loosened to the end of the resource (2 cases fail), apply keeps the old bits under the mask instead of clearing them (3), the length check by u32 instead of by triplet (1).
  • checkpatch --strict: 0 errors; one warning (MAINTAINERS update for the new files) and the usual CHECK on kunit_test_suite().

Still to run. Nothing on hardware: the change is test-only.

Assisted-by: LLM (Claude:Opus 5.5)

Hardware tunables come from devicetree properties of (offset, mask,
value) triplets and are written into a device's MMIO range. Add a
suite that parses properties of a device node built by the test and
applies the result to a buffer of kernel memory: the triplet decoding,
the refusal of a missing, empty or badly sized property, of offsets
that are unaligned or past the end of the resource, and the mask and
value arithmetic and order of the writes.

Tests only, no functional change.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Review at ba4b931.

Test-only, with no change to tunable.c. The suite is its own module, calls the exported devm_apple_tunable_parse() and apple_tunable_apply() (no copied code), and the Kconfig is correct: tristate, defaults to KUNIT_ALL_TESTS, and selects APPLE_TUNABLE under the same ARCH_APPLE || COMPILE_TEST dependency. The test vectors are synthetic patterns (0xa5a5a5xx, 0xdeadbeef, 0xabcd0000), not machine tunables. Mutations are caught: offset % 4 to % 2 (offsets 1/3/5/7), > size - 4 to > size (0x20 in a 0x20 resource), and dropping & ~mask (apply_mask_value). One small point: parse_resource_start only confirms that the parser ignores res->start, which is the current contract and fine.

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formal §1–§6 pre-PR checklist review at ba4b931a5b2971732525a3009256f1a51ed737aa.

Checklist Summary

  • §1 No model gating: Pass (test-only).
  • §2 Production-ready, no hacks: Pass. drivers/soc/apple/tunable.c is untouched (0 lines changed; no driver behavior change and no symbol visibility change under CONFIG_KUNIT=n). tunable-test.o builds as a standalone tristate KUnit module calling only exported devm_apple_tunable_parse() and apple_tunable_apply(), with matching ARCH_APPLE || COMPILE_TEST dependencies and clean kunit_device_register() / devm / kunit_kzalloc() LIFO teardown.
  • §3 Safety: Pass (operates solely on a test-local device_node and kernel memory buffer; touches no live DT or MMIO; all buffer bounds and DEFINE_RES_MEM(..., 0) unsigned size arithmetic verified).
  • §4 Clean-room & attribution: Pass (human author/committer and Signed-off-by: Ryan Murray <[email protected]> only, zero AI trailers in commit; PR body disclosure present; synthetic patterns only).
  • §5 Evidence: Pass for test-only PR (kunit.py 12/12 + negative controls reported; waiting on CI completion).
  • §6 Naming: Pass.

Verdict

0 code or policy blockers found. Leaving as COMMENT only because CI is not yet fully green at this head (host-tests, source, DWC3/ATC builtin-no-atc, and DWC3/ATC modular-no-atc are green; kunit, rust-build, and DWC3/ATC builtin-modular-atc are still queued). Ready for APPROVE as soon as the remaining CI checks pass.

Assisted-by: LLM (Gemini 4 Neon)

@DjDeveloperr DjDeveloperr left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All 7/7 CI checks (including kunit, host-tests, source, rust-build, and the 3x DWC3/ATC build matrix) are now green on ba4b931a5b29. Standalone KUnit-only coverage for apple-tunable (tunable.c untouched) with 0 code or policy blockers — ready for MERGETRAIN-LINUX4.

Assisted-by: LLM (Gemini 4 Neon)

@RyanTheTide
RyanTheTide merged commit f9d2146 into integration/aurora Nov 23, 2026
7 checks passed
@RyanTheTide
RyanTheTide deleted the kunit/apple-tunable branch November 27, 2026 13:21
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