new file mode 100644
@@ -0,0 +1,126 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2022 Intel Corporation. All rights reserved.
+
+. $(dirname $0)/common
+
+rc=1
+
+set -ex
+
+trap 'err $LINENO' ERR
+
+check_prereq "jq"
+
+modprobe -r cxl_test
+modprobe cxl_test
+udevadm settle
+
+destroy_regions()
+{
+ if [[ "$*" ]]; then
+ $CXL destroy-region -f -b cxl_test "$@"
+ else
+ $CXL destroy-region -f -b cxl_test all
+ fi
+}
+
+create_x1_region()
+{
+ mem="$1"
+
+ # find a pmem capable root decoder for this mem
+ decoder=$($CXL list -b cxl_test -D -d root -m "$mem" |
+ jq -r ".[] |
+ select(.pmem_capable == true) |
+ select(.nr_targets == 1) |
+ .decoder")
+
+ if [[ ! $decoder ]]; then
+ echo "no suitable decoder found for $mem, skipping"
+ return
+ fi
+ op_attempted=1
+
+ # create region
+ region=$($CXL create-region -d "$decoder" -m "$mem" | jq -r ".region")
+
+ if [[ ! $region ]]; then
+ echo "create-region failed for $decoder / $mem"
+ err "$LINENO"
+ fi
+
+ # cycle disable/enable
+ $CXL disable-region --bus=cxl_test "$region"
+ $CXL enable-region --bus=cxl_test "$region"
+
+ # cycle destroying and creating the same region
+ destroy_regions "$region"
+ region=$($CXL create-region -d "$decoder" -m "$mem" | jq -r ".region")
+
+ if [[ ! $region ]]; then
+ echo "create-region failed for $decoder / $mem"
+ err "$LINENO"
+ fi
+}
+
+create_subregions()
+{
+ slice=$((256 << 20))
+ mem="$1"
+
+ # find a pmem capable root decoder for this mem
+ decoder=$($CXL list -b cxl_test -D -d root -m "$mem" |
+ jq -r ".[] |
+ select(.pmem_capable == true) |
+ select(.nr_targets == 1) |
+ .decoder")
+
+ if [[ ! $decoder ]]; then
+ echo "no suitable decoder found for $mem, skipping"
+ return
+ fi
+ op_attempted=1
+
+ size="$($CXL list -m "$mem" | jq -r '.[].pmem_size')"
+ if [[ ! $size ]]; then
+ echo "$mem: unable to determine size"
+ err "$LINENO"
+ fi
+
+ num_regions=$((size / slice))
+
+ declare -a regions
+ for (( i = 0; i < num_regions; i++ )); do
+ regions[$i]=$($CXL create-region -d "$decoder" -m "$mem" -s "$slice" | jq -r ".region")
+ if [[ ! $region ]]; then
+ echo "create sub-region failed for $decoder / $mem"
+ err "$LINENO"
+ fi
+ udevadm settle
+ done
+
+ for (( i = (num_regions - 1); i >= 0; i-- )); do
+ destroy_regions "${regions[$i]}"
+ done
+}
+
+# test reading labels directly through cxl-cli
+readarray -t mems < <("$CXL" list -b cxl_test -M | jq -r '.[].memdev')
+
+for mem in ${mems[@]}; do
+ op_attempted=0
+ create_x1_region "$mem"
+ if (( op_attempted == 1 )); then
+ destroy_regions
+ fi
+done
+
+# test multiple subregions under the same decoder, using slices of the same memdev
+# to test out back-to-back pmem DPA allocations on memdevs
+for mem in ${mems[@]}; do
+ op_attempted=0
+ create_subregions "$mem"
+done
+
+modprobe -r cxl_test
@@ -153,6 +153,7 @@ track_uuid = find_program('track-uuid.sh')
cxl_topo = find_program('cxl-topology.sh')
cxl_sysfs = find_program('cxl-region-sysfs.sh')
cxl_labels = find_program('cxl-labels.sh')
+cxl_create_region = find_program('cxl-create-region.sh')
tests = [
[ 'libndctl', libndctl, 'ndctl' ],
@@ -180,6 +181,7 @@ tests = [
[ 'cxl-topology.sh', cxl_topo, 'cxl' ],
[ 'cxl-region-sysfs.sh', cxl_sysfs, 'cxl' ],
[ 'cxl-labels.sh', cxl_labels, 'cxl' ],
+ [ 'cxl-create-region.sh', cxl_create_region, 'cxl' ],
]
if get_option('destructive').enabled()
Add a unit test to exercise the cxl-create-region command with different combinations of memdevs and decoders, using cxl_test based mocked devices. Cc: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Vishal Verma <vishal.l.verma@intel.com> --- test/cxl-create-region.sh | 126 ++++++++++++++++++++++++++++++++++++++ test/meson.build | 2 + 2 files changed, 128 insertions(+) create mode 100644 test/cxl-create-region.sh