On Fri, Oct 16, 2026 at 05:42:48PM -0400, Gregory Price (Meta) wrote:
> From: Gregory Price <[email protected]>
> 
> Repeat the online/offline pair to cover onlining from 'unplugged', and
> check that offline-memory unplugs an already offline device. After each
> step, check block counts and, where present, daxX.Y/state and the
> 'hotplug_state' reported by 'daxctl list'.

Hi Greg,

Please change how the tests handle the absence of the new sysfs attribute.
If a test expects the new interface, a missing attribute should cause
the test to fail, with a clear error message. We have had problems in
the past with tests silently not executing letting defects go undetected.

Note that we don't require backward compatibility for the unit tests.
The utilities must continue working with older kernels, but tests for new
functionality should fail loudly when that functionality is missing.
(I'm aware that not all tests follow that guideline, and they need fixing.)

Please also leave the existing test cases as they were and run the new
state-dependent cases last.

A few stale state cases would exercise daxctl behavior that the kernel
selftest can't cover - 

  - Offline one memory block out-of-band, verify that daxctl list
    reports hotplug_state "inconsistent", then verify that
    offline-memory still leaves the device unplugged with its blocks
    removed.

  - Offline all blocks out-of-band, then verify that
    "reconfigure-device -m devdax" succeeds and the blocks are removed.

  - With all blocks offline but the device state still reporting
    online, verify that online-memory falls back to the per-block path
    and brings everything online.

For "blocks removed", please check that the device's memory blocks
are gone from /sys/devices/system/memory.  ie verify in sysfs directly
independent of the libdaxctl code being tested.

About multi-range devices-

I found that libdaxctl undercounts memory blocks on multi-range devices.
I'm posting a separate fix and test for that. Nothing in this series needs
to change. I'll cc you for review.

Our ndctl emulation can't exercise multi-range hotplug, but the kernel
selftest can run against a real multi-range device. Could you add coverage
there, including the partial-add case where the kernel reports success
even though not all ranges were added?

-- Alison


> 
> Signed-off-by: Gregory Price <[email protected]>
> ---
>  test/daxctl-devices.sh | 53 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 53 insertions(+)
> 
> diff --git a/test/daxctl-devices.sh b/test/daxctl-devices.sh
> index 659428d..cdb13f6 100755
> --- a/test/daxctl-devices.sh
> +++ b/test/daxctl-devices.sh
> @@ -67,6 +67,40 @@ daxctl_get_mode()
>       "$DAXCTL" list -d "$1" | jq -er '.[].mode'
>  }
>  
> +daxctl_get_online_blocks()
> +{
> +     "$DAXCTL" list -d "$1" | jq -er '.[].online_memblocks'
> +}
> +
> +daxctl_get_total_blocks()
> +{
> +     "$DAXCTL" list -d "$1" | jq -er '.[].total_memblocks'
> +}
> +
> +check_memory_online()
> +{
> +     local total
> +
> +     total=$(daxctl_get_total_blocks "$1")
> +     (( total > 0 ))
> +     [[ $(daxctl_get_online_blocks "$1") == "$total" ]]
> +}
> +
> +check_memory_offline()
> +{
> +     [[ $(daxctl_get_online_blocks "$1") == "0" ]]
> +}
> +
> +# skipped on kernels without daxX.Y/state
> +check_kmem_state()
> +{
> +     local path="/sys/bus/dax/devices/$1/state"
> +
> +     [[ -f "$path" ]] || return 0
> +     [[ $(cat "$path") == "$2" ]]
> +     [[ $("$DAXCTL" list -d "$1" | jq -er '.[].hotplug_state') == "$2" ]]
> +}
> +
>  set_online_policy()
>  {
>       echo "online" > /sys/devices/system/memory/auto_online_blocks
> @@ -100,7 +134,26 @@ daxctl_test()
>       "$DAXCTL" reconfigure-device -N -m system-ram "$daxdev"
>       [[ $(daxctl_get_mode "$daxdev") == "system-ram" ]]
>       "$DAXCTL" online-memory "$daxdev"
> +     check_memory_online "$daxdev"
> +     check_kmem_state "$daxdev" "online_movable"
>       "$DAXCTL" offline-memory "$daxdev"
> +     check_memory_offline "$daxdev"
> +     check_kmem_state "$daxdev" "unplugged"
> +     # again, now from 'unplugged' where supported
> +     "$DAXCTL" online-memory "$daxdev"
> +     check_memory_online "$daxdev"
> +     check_kmem_state "$daxdev" "online_movable"
> +     "$DAXCTL" offline-memory "$daxdev"
> +     check_memory_offline "$daxdev"
> +     check_kmem_state "$daxdev" "unplugged"
> +     # an already offline device is unplugged too, where supported
> +     if [[ -f /sys/bus/dax/devices/$daxdev/state ]]; then
> +             "$DAXCTL" reconfigure-device -m devdax "$daxdev"
> +             "$DAXCTL" reconfigure-device -N -m system-ram "$daxdev"
> +             check_kmem_state "$daxdev" "offline"
> +             "$DAXCTL" offline-memory "$daxdev"
> +             check_kmem_state "$daxdev" "unplugged"
> +     fi
>       "$DAXCTL" reconfigure-device -m devdax "$daxdev"
>       [[ $(daxctl_get_mode "$daxdev") == "devdax" ]]
>       "$DAXCTL" reconfigure-device -m system-ram "$daxdev"
> -- 
> 2.53.0-Meta
> 

Reply via email to