From: Dave Jiang <dave.jiang@intel.com>
To: Alison Schofield <alison.schofield@intel.com>,
nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org
Subject: Re: [ndctl PATCH 1/2] test/common: add helpers for CXL region replay testing
Date: Thu, 16 Apr 2026 14:08:23 -0700 [thread overview]
Message-ID: <97a4d9ff-dda7-41e2-81f3-3cf94243e3aa@intel.com> (raw)
In-Reply-To: <8646e0b11697e3adb4fc9a83fa486e68a4b9b5c5.1773466514.git.alison.schofield@intel.com>
On 3/13/26 11:21 PM, Alison Schofield wrote:
> Add replay_regions() and supporting helpers to the CXL test common
> library. The helpers capture the current region configuration, trigger
> a region replay by unbinding and rebinding the cxl_acpi driver, and
> verify that the regions reconstructed during enumeration match the
> original configuration.
>
> Replay is enabled by instructing the cxl_test module to preserve its
> decoder registry across the driver unbind/bind cycle. This allows the
> decoder programming associated with user-created regions to survive
> topology teardown so that the regions are reconstructed during driver
> initialization as auto-discovered regions.
>
> Region signatures are derived from region attributes and memdev serial
> numbers so that the replayed configuration can be compared independent
> of topology enumeration order and device numbering.
>
> These helpers provide a reusable mechanism for CXL tests that need to
> exercise region replay behavior. A unit test, cxl-region-replay.sh, is
> posted in a follow-on patch and demonstrates the workflow.
>
> Signed-off-by: Alison Schofield <alison.schofield@intel.com>
Not that I'm great at bash and jq but it looks ok to me.
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> ---
> test/common | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 109 insertions(+)
>
> diff --git a/test/common b/test/common
> index 2eb11b7396d0..048f9680f277 100644
> --- a/test/common
> +++ b/test/common
> @@ -168,3 +168,112 @@ check_dmesg()
>
> # CXL COMMON
> CXL_TEST_QOS_CLASS=42
> +
> +# CXL region replay helpers
> +#
> +# replay_regions() snapshots the current region configuration, performs
> +# a cxl_acpi driver unbind/bind cycle to trigger region replay, and
> +# verifies that the regions reconstructed during enumeration match the
> +# original configuration.
> +#
> +# This allows tests to create regions through the user interface and
> +# then replay them as auto-discovered regions during driver
> +# initialization.
> +#
> +# See example usage in test/cxl-region-replay.sh.
> +
> +CXL_EXPECTED_REGION_SIGS=""
> +
> +cxl_get_memdev_serial()
> +{
> + local memdev="$1"
> +
> + "$CXL" list -m "$memdev" | jq -r '.[0].serial'
> +}
> +
> +cxl_emit_region_signature()
> +{
> + local region="$1"
> + local region_json size type ways gran state
> + local entry pos memdev serial sig
> +
> + region_json=$("$CXL" list -R --targets -r "$region")
> + [[ -n "$region_json" && "$region_json" != "[]" ]] || return 1
> +
> + size=$(jq -r '.[0].size' <<<"$region_json")
> + type=$(jq -r '.[0].type' <<<"$region_json")
> + ways=$(jq -r '.[0].interleave_ways' <<<"$region_json")
> + gran=$(jq -r '.[0].interleave_granularity' <<<"$region_json")
> + state=$(jq -r '.[0].decode_state' <<<"$region_json")
> +
> + sig="size=$size type=$type ways=$ways gran=$gran"
> +
> + while IFS= read -r entry; do
> + pos=$(jq -r '.position' <<<"$entry")
> + memdev=$(jq -r '.memdev' <<<"$entry")
> + serial=$(cxl_get_memdev_serial "$memdev") || return 1
> + [[ -n "$serial" && "$serial" != "null" ]] || return 1
> + sig="$sig pos=$pos serial=$serial"
> + done < <(jq -c '.[0].mappings | sort_by(.position)[]' <<<"$region_json")
> +
> + echo "$sig state=$state"
> +}
> +
> +cxl_collect_region_signatures()
> +{
> + local region
> + local -a regions=()
> +
> + mapfile -t regions < <("$CXL" list -Ri | jq -r '.[].region' | sort) || return 1
> +
> + for region in "${regions[@]}"; do
> + cxl_emit_region_signature "$region" || return 1
> + done | sort
> +}
> +
> +cxl_capture_expected_region_signatures()
> +{
> + CXL_EXPECTED_REGION_SIGS=$(cxl_collect_region_signatures) || return 1
> +}
> +
> +cxl_verify_replayed_regions()
> +{
> + local actual_region_sigs
> + local -a expected_lines=()
> + local -a actual_lines=()
> + local i
> + local expected_line actual_line
> + local expected_struct actual_struct
> + local expected_state actual_state
> +
> + actual_region_sigs=$(cxl_collect_region_signatures) || return 1
> +
> + mapfile -t expected_lines < <(printf '%s\n' "$CXL_EXPECTED_REGION_SIGS" | sed '/^$/d')
> + mapfile -t actual_lines < <(printf '%s\n' "$actual_region_sigs" | sed '/^$/d')
> +
> + [ "${#expected_lines[@]}" -eq "${#actual_lines[@]}" ] || return 1
> +
> + for ((i = 0; i < ${#expected_lines[@]}; i++)); do
> + expected_line=${expected_lines[i]}
> + actual_line=${actual_lines[i]}
> +
> + expected_struct=${expected_line% state=*}
> + expected_state=${expected_line##* state=}
> + actual_struct=${actual_line% state=*}
> + actual_state=${actual_line##* state=}
> +
> + [ "$expected_struct" = "$actual_struct" ] || return 1
> + [ "$expected_state" != "commit" ] || [ "$actual_state" = "commit" ] || return 1
> + done
> +}
> +
> +replay_regions()
> +{
> + echo "replaying existing regions"
> + cxl_capture_expected_region_signatures || return 1
> + echo 1 > /sys/bus/platform/devices/cxl_acpi.0/decoder_reset_preserve_registry
> + echo cxl_acpi.0 > /sys/bus/platform/drivers/cxl_acpi/unbind
> + echo cxl_acpi.0 > /sys/bus/platform/drivers/cxl_acpi/bind
> + echo 0 > /sys/bus/platform/devices/cxl_acpi.0/decoder_reset_preserve_registry
> + cxl_verify_replayed_regions || return 1
> +}
>
> base-commit: d6f32b0afba6c36fbde2aae67230b71f9e70cb07
prev parent reply other threads:[~2026-04-16 21:08 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-14 6:21 [ndctl PATCH 1/2] test/common: add helpers for CXL region replay testing Alison Schofield
2026-03-14 6:21 ` [ndctl PATCH 2/2] test/cxl-region-replay.sh: add test of region replay workflow Alison Schofield
2026-04-16 21:09 ` Dave Jiang
2026-04-16 21:08 ` Dave Jiang [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=97a4d9ff-dda7-41e2-81f3-3cf94243e3aa@intel.com \
--to=dave.jiang@intel.com \
--cc=alison.schofield@intel.com \
--cc=linux-cxl@vger.kernel.org \
--cc=nvdimm@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox