Repository navigation
soc: apple: rtkit-helper: add KUnit tests - #2941
Conversation
Add a suite for the RTKit helper's own callbacks, run directly on a test context with the AP power request behind a KUnit static stub (a small wrapper, apple_rtkit_helper_send_ap_power(), that is the same call otherwise): - shared-memory setup: DMA allocation for a request without an address, SRAM placement inside, at the edges, one byte outside, straddling, zero and huge sizes, an iova+size that wraps, and no SRAM at all; adopted strict and legacy sessions; repeated setup and destroy; - the inherited buffer list from a test devicetree node: count limits, bad endpoints, zero size, a bad mapped flag, wrap, the 44-bit edge, and one bad entry rejecting the list; - the sleep state machine: prepare, suspend_late, suspend, resume and complete, the PM notifier, idle notices unanswered, answered late or still pending at the next sleep, a crashed co-processor, adopted s2idle with and without the CPU running, freeze, and input preservation. Tests only, no functional change. Signed-off-by: Ryan Murray <[email protected]>
|
Review at a5dbac8.
|
There was a problem hiding this comment.
Formal pre-PR checklist review at a5dbac8de4515535e24273c1a7f5cdf8af5016f1.
Blockers
- Missing
OFKconfig dependency (drivers/soc/apple/Kconfig:158):APPLE_RTKIT_HELPERdepends onAPPLE_RTKIT->APPLE_MAILBOX(ARCH_APPLE || (64BIT && COMPILE_TEST)), notOF. UnderCOMPILE_TEST=y, CONFIG_OF=n, CONFIG_SUSPEND=y, CONFIG_KUNIT=y,of_find_property()andof_device_is_compatible()compile to no-op stubs returningNULL/false, causing all 8rtkh_inherit_*test cases to fail at runtime. Add&& OF. - NULL dereference and global PM state corruption on
rtkh_test_init()abort (drivers/soc/apple/rtkit-helper-test.c:108-161): KUnit executessuite->exit(test)even whensuite->init(test)aborts early viaKUNIT_ASSERT_*. Ifkunit_kzalloc()fails (test->priv == NULL),rtkh_test_exit()dereferencesctx->dev(NULL pointer dereference). Ifkunit_device_register(),ctx->asc, orctx->sram_memfails before line 143,ctx->saved_flags/ctx->saved_targetare0andrtkh_test_exit()clobbers globalpm_suspend_global_flagsandpm_suspend_target_stateto0. Guardif (!ctx) return;and restore the PM globals viakunit_add_action_or_reset()immediately after saving them. - Kconfig prevents building on
asahi.config/ modular KUnit + global PM lock (drivers/soc/apple/Kconfig:158,rtkit-helper-test.c:143-160):CONFIG_APPLE_RTKIT_HELPER=minarch/arm64/configs/asahi.config, sodepends on APPLE_RTKIT_HELPER=y && KUNIT=y && SUSPENDnever builds on the fleet/distro config. Convert to atristatetest module (VISIBLE_IF_KUNIT/EXPORT_SYMBOL_IF_KUNIT) and wrap thepm_suspend_global_flags/pm_suspend_target_statemutations withlock_system_sleep()/unlock_system_sleep()so a loadable test cannot race a real system suspend.
Non-blocking notes & CI
- Production
drivers/soc/apple/rtkit-helper.cchange (apple_rtkit_helper_send_ap_power()) is properly guarded by#if IS_ENABLED(CONFIG_APPLE_RTKIT_HELPER_KUNIT_TEST)and is behavior-identical when tests are disabled. dev->of_node = NULLinrtkh_test_exit()and devres teardown order forrtkh_pm_register()are sound (givenctx != NULL).- CI note:
rust-buildis in progress andDWC3/ATC builtin-no-atc/builtin-modular-atcare still queued..github/workflows/sep-source.yml'skunitjob only runsapple_sep*, notapple-rtkit-helper.
Checklist (§1–§6)
- §1–§3, §6: Pass (synthetic SRAM/ASC buffers and zeroed
struct apple_rtkit). - §4: Pass (human author/committer + human
Signed-off-by:, no AI trailers in commits, PRAssisted-by:present). - §5: Satisfied for production driver (strictly no functional change when
CONFIG_APPLE_RTKIT_HELPER_KUNIT_TEST=n).
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
DjDeveloperr
left a comment
There was a problem hiding this comment.
Verdict: MERGE at a5dbac8de451
Blockers: none.
Checked: no Apple material, no runtime change: the PR adds a KUnit suite, and the driver change only exposes internals to it (built only with the test option). Tests that run only in CI need no hardware row. CI green. This replaces my earlier review.
Evidence
Follow-up, not blocking: under COMPILE_TEST with CONFIG_OF=n, the rtkh_inherit_* cases fail because the OF helpers are stubs. Add depends on OF to the test option.
Superseded by the review at a5dbac8
Problem. The RTKit helper (the generic co-processor driver used for the MTP and others) had no test of its own callbacks: firmware buffer placement, the inherited buffer list, and its sleep state machine.
Change. A new
apple-rtkit-helpersuite (drivers/soc/apple/rtkit-helper-test.c, included from the driver). It calls the helper's callbacks directly on a test context. The AP power request goes through a small wrapper,apple_rtkit_helper_send_ap_power(), that a KUnit static stub can redirect; otherwise it is the same call.Plus a standalone
drivers/soc/apple/rtkit-helper.kunitconfig. Tests only, no functional change.Testing.
kunit.py run --arch=arm64(QEMU, gcc): 36/36, standalone kunitconfig 38/39 (the extra suite pulled in has one unrelated skip,apple_g17_rx_util_min_test, needs UCLAMP_TASK), and again with this wave's three branches merged on the integration/aurora tip.Notes for reviewers
shmem_destroyis a no-op today, so a buffer that setup allocated withdma_alloc_coherent()is not freed when RTKit hands it back. soc: apple: start and stop the T8140 MTP without a live handoff #1764 (draft) changes this on purpose only underfree_buffers, because a quiesced firmware may still write into its buffer. This suite therefore does not assert either behaviour; a case for it can join that PR.struct apple_rtkitfromrtkit-internal.h(same directory), so it follows that struct's layout.Still to run. Nothing on hardware: the change is test-only.